diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-12-09 16:45:36 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-12-09 16:45:36 -0400 |
commit | d16930a3936afd2a511efb64d24736b823cebbd7 (patch) | |
tree | e60e6a8fe29f129367448741d46f4d3e6ee7fc49 /P2P | |
parent | 5a919f01d178b8d6c0bb3b0b40d8c7fea7ff7ac6 (diff) |
debug dump P2P messages
Diffstat (limited to 'P2P')
-rw-r--r-- | P2P/IO.hs | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -40,6 +40,7 @@ import Control.Concurrent import Control.Concurrent.Async import qualified Data.ByteString as B import qualified Data.ByteString.Lazy as L +import System.Log.Logger (debugM) -- Type of interpreters of the Proto free monad. type RunProto m = forall a. (MonadIO m, MonadMask m) => Proto a -> m (Either String a) @@ -96,7 +97,9 @@ runNet :: (MonadIO m, MonadMask m) => P2PConnection -> RunProto m -> NetF (Proto runNet conn runner f = case f of SendMessage m next -> do v <- liftIO $ tryNonAsync $ do - hPutStrLn (connOhdl conn) (unwords (formatMessage m)) + let l = unwords (formatMessage m) + debugM "p2p" ("P2P > " ++ l) + hPutStrLn (connOhdl conn) l hFlush (connOhdl conn) case v of Left e -> return (Left (show e)) @@ -106,12 +109,14 @@ runNet conn runner f = case f of case v of Left e -> return (Left (show e)) Right Nothing -> return (Left "protocol error") - Right (Just l) -> case parseMessage l of - Just m -> runner (next m) - Nothing -> runner $ do - let e = ERROR $ "protocol parse error: " ++ show l - net $ sendMessage e - next e + Right (Just l) -> do + liftIO $ debugM "p2p" ("P2P < " ++ l) + case parseMessage l of + Just m -> runner (next m) + Nothing -> runner $ do + let e = ERROR $ "protocol parse error: " ++ show l + net $ sendMessage e + next e SendBytes len b p next -> do v <- liftIO $ tryNonAsync $ do ok <- sendExactly len b (connOhdl conn) p |