Nothing -> putStrLn "Nothing to download"
Just workPiece -> do
let pLen = len (pieceStatus ! workPiece)
+ putStrLn $ "piece length = " ++ show pLen
pBS <- downloadPiece (handle pState) workPiece pLen
- -- if not $ verifyHash pBS (hash (pieceStatus ! workPiece))
- -- then
- -- putStrLn $ "Hash mismatch: " ++ show (hash (pieceStatus ! workPiece)) ++ " vs " ++ show (take 20 (SHA1.hash pBS))
- -- else do
- writeFileAtOffset "/tmp/download.file" (workPiece * pLen) pBS
- msgLoop pState (adjust (\pieceData -> pieceData { state = Have }) workPiece pieceStatus)
+ if not $ verifyHash pBS (hash (pieceStatus ! workPiece))
+ then
+ putStrLn $ "Hash mismatch: " ++ show (hash (pieceStatus ! workPiece)) ++ " vs " ++ show (take 20 (SHA1.hash pBS))
+ else do
+ writeFileAtOffset "/tmp/download.file" (workPiece * pLen) pBS
+ msgLoop pState (adjust (\pieceData -> pieceData { state = Have }) workPiece pieceStatus)
| otherwise = do
msg <- getMsg (handle pState)
putStrLn $ "<-- " ++ show msg ++ "from peer: " ++ show (peer pState)