run' pieceMap c handle = do
msg <- liftIO recvMsg
liftIO $ sendResponse msg
- updateState msg
+ updateStats msg
where
recvMsg = readChan c
sendResponse msg =
len' = len (pieceMap ! n)
bs' <- readFileAtOffset handle offset len'
return $ verifyHash bs' hash'
- updateState (ReadPiece _ l _) =
+ updateStats (ReadPiece _ l _) =
modify (\st -> st {bytesRead = bytesRead st + l})
- updateState (WritePiece (Piece _ bs)) =
+ updateStats (WritePiece (Piece _ bs)) =
modify (\st -> st {bytesWritten = bytesWritten st + fromIntegral (BS.length bs)})
- updateState _ = modify id
+ updateStats _ = modify id
pieceMapFromFile :: FilePath -> Integer -> PieceMap -> IO PieceMap
pieceMapFromFile filePath fileLen pieceMap = do