From: Ramakrishnan Muthukrishnan Date: Sat, 25 Jul 2015 06:42:03 +0000 (+0530) Subject: bugfix: calculate proper file offset X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/css/index.php?a=commitdiff_plain;h=968ccbf7652c3718fca087d3c2610cd56f6cf2b4;p=functorrent.git bugfix: calculate proper file offset --- diff --git a/src/FuncTorrent/Peer.hs b/src/FuncTorrent/Peer.hs index 845c14a..baf9ce8 100644 --- a/src/FuncTorrent/Peer.hs +++ b/src/FuncTorrent/Peer.hs @@ -218,7 +218,8 @@ msgLoop pState pieceStatus | not (meInterested pState) && heChoking pState = do then putStrLn $ "Hash mismatch: " ++ show (hash (pieceStatus ! workPiece)) ++ " vs " ++ show (take 20 (SHA1.hash pBS)) else do - let fileOffset = if workPiece == 0 then 0 else (len (pieceStatus ! (workPiece - 1))) + let fileOffset = if workPiece == 0 then 0 else workPiece * len (pieceStatus ! (workPiece - 1)) + putStrLn $ "Write into file at offset: " ++ show fileOffset writeFileAtOffset "/tmp/download.file" fileOffset pBS msgLoop pState (adjust (\pieceData -> pieceData { state = Have }) workPiece pieceStatus) | otherwise = do