-msgLoop :: PeerState -> ByteString -> IO ()
-msgLoop state pieceHash =
- let numPieces = (toInteger . (`quot` 20) . BC.length) pieceHash
- pieceStatus = mkPieceMap numPieces pieceHash
- in
- forever $ do
- -- if meInterested and he NOT Choking, pick a piece to download
- -- and send a requestmsg.
- msg <- getMsg (handle state)
- putStrLn $ "got a " ++ show msg
- case msg of
- BitFieldMsg bss -> do
- let pieceList = bitfieldToList (unpack bss)
- print pieceList
- -- for each pieceIndex in pieceList, make an entry in the pieceStatus
- -- map with pieceIndex as the key and modify the value to add the peer.
-
- -- download each of the piece in order
- UnChokeMsg -> do
- print msg
- msgLoop (state {heChoking = False}) pieceHash
- _ -> print msg
+msgLoop :: PeerState -> PieceMap -> IO ()
+msgLoop state pieceStatus =
+ forever $ do
+ -- if meInterested and he NOT Choking, pick a piece to download
+ -- and send a requestmsg.
+ msg <- getMsg (handle state)
+ putStrLn $ "got a " ++ show msg
+ case msg of
+ BitFieldMsg bss -> do
+ let pieceList = bitfieldToList (unpack bss)
+ print pieceList
+ -- for each pieceIndex in pieceList, make an entry in the pieceStatus
+ -- map with pieceIndex as the key and modify the value to add the peer.
+
+ -- download each of the piece in order
+ UnChokeMsg -> do
+ print msg
+ msgLoop (state {heChoking = False}) pieceStatus
+ _ -> print msg