From: Ramakrishnan Muthukrishnan Date: Fri, 24 Jul 2015 14:19:32 +0000 (+0530) Subject: return a list of bytestring blocks corresponding to the piece index X-Git-Url: https://git.rkrishnan.org/specifications/vdrive//%22?a=commitdiff_plain;h=08039c1a7bad8f6a6f14110e1853552b5c5bf618;p=functorrent.git return a list of bytestring blocks corresponding to the piece index --- diff --git a/src/FuncTorrent/Peer.hs b/src/FuncTorrent/Peer.hs index d74333a..b9138b7 100644 --- a/src/FuncTorrent/Peer.hs +++ b/src/FuncTorrent/Peer.hs @@ -208,10 +208,6 @@ msgLoop pState pieceStatus | meInterested pState == False && Just workPiece -> do let pLen = len (pieceStatus ! workPiece) _ <- downloadPiece (handle pState) workPiece pLen - -- sendMsg (handle state) (RequestMsg workPiece 0 pLen) - -- putStrLn $ "--> RequestMsg for Piece " ++ (show workPiece) ++ "to peer: " ++ show (peer state) ++ " of length: " ++ show pLen - -- msg <- getMsg (handle state) - -- putStrLn $ "<-- " ++ show msg ++ "from peer: " ++ show (peer state) msgLoop pState (adjust (\pieceData -> pieceData { state = Have }) workPiece pieceStatus) | otherwise = do msg <- getMsg (handle pState) @@ -267,7 +263,7 @@ handlePeerMsgs p m peerId = do pieceStatus = mkPieceMap numPieces pieceHash (splitNum fileLen pLen) msgLoop state pieceStatus -downloadPiece :: Handle -> Integer -> Integer -> IO [PeerMsg] +downloadPiece :: Handle -> Integer -> Integer -> IO [ByteString] downloadPiece h index pieceLength = do let chunks = splitNum pieceLength 16384 forM (zip [0..] chunks) (\(i, pLen) -> do @@ -275,12 +271,9 @@ downloadPiece h index pieceLength = do putStrLn $ "--> " ++ "RequestMsg for Piece " ++ (show index) ++ ", part: " ++ show i ++ " of length: " ++ show pLen - rMsg <- getMsg h - case rMsg of - PieceMsg index begin block -> - putStrLn $ " <-- PieceMsg for Piece: " - ++ show index - ++ ", offset: " - ++ show begin - _ -> putStrLn " <-- UnKnown msg from Peer" - return rMsg) + PieceMsg index begin block <- getMsg h + putStrLn $ " <-- PieceMsg for Piece: " + ++ show index + ++ ", offset: " + ++ show begin + return block)