From d7b276585a4faccc7d78baafb7ea011f3135856a Mon Sep 17 00:00:00 2001 From: Sam T Date: Sun, 30 Jun 2013 18:58:31 +0400 Subject: ~ Keep track left progress bytes. --- src/Network/BitTorrent.hs | 2 +- src/Network/BitTorrent/Internal.hs | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/Network') diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs index 30735023..b6e2eadf 100644 --- a/src/Network/BitTorrent.hs +++ b/src/Network/BitTorrent.hs @@ -154,4 +154,4 @@ exchange storage = awaitEvent >>= handler offer <- peerOffer if BF.null offer then return () - else handler (Available offer) \ No newline at end of file + else handler (Available offer) diff --git a/src/Network/BitTorrent/Internal.hs b/src/Network/BitTorrent/Internal.hs index bf47b87b..eaeb04e8 100644 --- a/src/Network/BitTorrent/Internal.hs +++ b/src/Network/BitTorrent/Internal.hs @@ -153,14 +153,14 @@ uploadedProgress (fromIntegral -> amount) = uploaded +~ amount {-# INLINE uploadedProgress #-} -- | Used when leecher join client session. -enqueuedProgress :: Int -> Progress -> Progress -enqueuedProgress (fromIntegral -> amount) = left +~ amount +enqueuedProgress :: Integer -> Progress -> Progress +enqueuedProgress amount = left +~ amount {-# INLINE enqueuedProgress #-} -- | Used when leecher leave client session. -- (e.g. user deletes not completed torrent) -dequeuedProgress :: Int -> Progress -> Progress -dequeuedProgress (fromIntegral -> amount) = left -~ amount +dequeuedProgress :: Integer -> Progress -> Progress +dequeuedProgress amount = left -~ amount {-# INLINE dequeuedProgress #-} {----------------------------------------------------------------------- @@ -349,8 +349,10 @@ newSeeder cs t @ Torrent {..} -- | New swarm in which the client allowed both download and upload. newLeecher :: ClientSession -> Torrent -> IO SwarmSession -newLeecher cs t @ Torrent {..} - = newSwarmSession defLeacherConns (haveNone (pieceCount tInfo)) cs t +newLeecher cs t @ Torrent {..} = do + se <- newSwarmSession defLeacherConns (haveNone (pieceCount tInfo)) cs t + atomically $ modifyTVar' (currentProgress cs) (enqueuedProgress (contentLength tInfo)) + return se --isLeacher :: SwarmSession -> IO Bool --isLeacher = undefined -- cgit v1.2.3