From dee4c3617bf46858525ba7675190d532c8594059 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Wed, 6 May 2015 23:28:11 +0530
Subject: [PATCH] more debugging prints

---
 src/FuncTorrent/Peer.hs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/FuncTorrent/Peer.hs b/src/FuncTorrent/Peer.hs
index 36607ea..7b263a5 100644
--- a/src/FuncTorrent/Peer.hs
+++ b/src/FuncTorrent/Peer.hs
@@ -133,20 +133,20 @@ instance Binary PeerMsg where
      8 -> liftA3 CancelMsg getInteger getInteger getInteger
        where getInteger = fromIntegral <$> getWord32be
      9 -> liftM (PortMsg . fromIntegral) getWord16be
-     _ -> error "unknown message ID"
+     _ -> error ("unknown message ID: " ++ show msgid)
 
 getMsg :: Handle -> IO PeerMsg
 getMsg h = do
   lBS <- hGet h 4
-  let lenBS = length (unpack lBS)
-  putStrLn $ "bytes read: " ++ (show lenBS)
   let l = bsToInt lBS
   if l == 0
     then return KeepAliveMsg
     else do
-    putStrLn $ "len: " ++ (show lBS)
-    msg <- hGet h l
-    return $ decode $ fromStrict $ append lBS msg
+    putStrLn $ "len: " ++ show l
+    msgType <- hGet h 1
+    putStrLn $ "msg Type: " ++ show msgType
+    msg <- hGet h (l - 1)
+    return $ decode $ fromStrict $ concat [lBS, msgType, msg]
 
 bsToInt :: ByteString -> Int
 bsToInt x = fromIntegral (runGet getWord32be (fromChunks (return x)))
@@ -157,4 +157,4 @@ bsToInt x = fromIntegral (runGet getWord32be (fromChunks (return x)))
 msgLoop :: Handle -> IO ()
 msgLoop h = forever $ do
   msg <- getMsg h
-  putStrLn $ "got a " ++ (show msg)
+  putStrLn $ "got a " ++ show msg
-- 
2.45.2