]> git.rkrishnan.org Git - functorrent.git/commitdiff
return a list of bytestring blocks corresponding to the piece index
authorRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 24 Jul 2015 14:19:32 +0000 (19:49 +0530)
committerRamakrishnan Muthukrishnan <ram@rkrishnan.org>
Fri, 24 Jul 2015 14:19:32 +0000 (19:49 +0530)
src/FuncTorrent/Peer.hs

index d74333a28f26b5af751300b303da19e31a569efc..b9138b7dbbffbcb9d26763b50359c199fdf4f61d 100644 (file)
@@ -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)