return h
doHandshake :: Bool -> Handle -> Peer -> ByteString -> String -> IO ()
-doHandshake isClient h peer infoHash peerid =
+doHandshake True h peer infoHash peerid = do
let hs = genHandshakeMsg infoHash peerid
- in
- if isClient
- then do
- hPut h hs
- putStrLn $ "--> handhake to peer: " ++ show peer
- _ <- hGet h (length (unpack hs))
- putStrLn $ "<-- handshake from peer: " ++ show peer
- return ()
- else do
- putStrLn $ "waiting for a handshake"
- hsMsg <- hGet h (length (unpack hs))
- putStrLn $ "<-- handshake from peer: " ++ show peer
- let rxInfoHash = take 20 $ drop 28 hsMsg
- if rxInfoHash /= infoHash
- then do
- putStrLn $ "infoHashes does not match"
- hClose h
- return ()
- else do
- _ <- hPut h hs
- putStrLn $ "--> handhake to peer: " ++ show peer
- return ()
+ hPut h hs
+ putStrLn $ "--> handhake to peer: " ++ show peer
+ _ <- hGet h (length (unpack hs))
+ putStrLn $ "<-- handshake from peer: " ++ show peer
+ return ()
+doHandshake False h peer infoHash peerid = do
+ let hs = genHandshakeMsg infoHash peerid
+ putStrLn $ "waiting for a handshake"
+ hsMsg <- hGet h (length (unpack hs))
+ putStrLn $ "<-- handshake from peer: " ++ show peer
+ let rxInfoHash = take 20 $ drop 28 hsMsg
+ if rxInfoHash /= infoHash
+ then do
+ putStrLn $ "infoHashes does not match"
+ hClose h
+ return ()
+ else do
+ _ <- hPut h hs
+ putStrLn $ "--> handhake to peer: " ++ show peer
+ return ()
bitfieldToList :: [Word8] -> [Integer]
bitfieldToList bs = go bs 0