return h
doHandshake :: Bool -> Handle -> Peer -> ByteString -> String -> IO ()
-doHandshake True h peer infoHash peerid = do
- let hs = genHandshakeMsg infoHash peerid
+doHandshake True h p infohash peerid = do
+ let hs = genHandshakeMsg infohash peerid
hPut h hs
- putStrLn $ "--> handhake to peer: " ++ show peer
+ putStrLn $ "--> handhake to peer: " ++ show p
_ <- hGet h (length (unpack hs))
- putStrLn $ "<-- handshake from peer: " ++ show peer
+ putStrLn $ "<-- handshake from peer: " ++ show p
return ()
-doHandshake False h peer infoHash peerid = do
- let hs = genHandshakeMsg infoHash peerid
+doHandshake False h p 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
+ putStrLn $ "<-- handshake from peer: " ++ show p
let rxInfoHash = take 20 $ drop 28 hsMsg
- if rxInfoHash /= infoHash
+ if rxInfoHash /= infohash
then do
putStrLn "infoHashes does not match"
hClose h
return ()
else do
_ <- hPut h hs
- putStrLn $ "--> handhake to peer: " ++ show peer
+ putStrLn $ "--> handhake to peer: " ++ show p
return ()
bitfieldToList :: [Word8] -> [Integer]
PState { meInterested = False, heChoking = True } -> do
liftIO $ sendMsg h InterestedMsg
gets peer >>= (\p -> liftIO $ putStrLn $ "--> InterestedMsg to peer: " ++ show p)
- modify (\st -> st { meInterested = True })
+ modify (\st' -> st' { meInterested = True })
msgLoop pieceStatus file
PState { meInterested = True, heChoking = False } ->
case pickPiece pieceStatus of
-- download each of the piece in order
msgLoop pieceStatus' file
UnChokeMsg -> do
- modify (\st -> st {heChoking = False })
+ modify (\st' -> st' {heChoking = False })
msgLoop pieceStatus file
ChokeMsg -> do
- modify (\st -> st {heChoking = True })
+ modify (\st' -> st' {heChoking = True })
msgLoop pieceStatus file
InterestedMsg -> do
- modify (\st -> st {heInterested = True})
+ modify (\st' -> st' {heInterested = True})
msgLoop pieceStatus file
NotInterestedMsg -> do
- modify (\st -> st {heInterested = False})
+ modify (\st' -> st' {heInterested = False})
msgLoop pieceStatus file
CancelMsg _ _ _ -> -- check if valid index, begin, length
msgLoop pieceStatus file