From 447335009ff6b762073004de1c0cab3b4372ed44 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Tue, 18 Mar 2014 18:44:42 +0400 Subject: Do not change status after Completed event --- src/Network/BitTorrent/Tracker/Session.hs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Network/BitTorrent/Tracker/Session.hs b/src/Network/BitTorrent/Tracker/Session.hs index f1b4eae8..a9f436e8 100644 --- a/src/Network/BitTorrent/Tracker/Session.hs +++ b/src/Network/BitTorrent/Tracker/Session.hs @@ -106,10 +106,10 @@ needNotify Stopped (Just Paused ) = Just False needNotify Completed (Just Paused ) = Just True -- | Client status after event announce succeed. -nextStatus :: Event -> Status -nextStatus Started = Running -nextStatus Stopped = Paused -nextStatus Completed = Running +nextStatus :: Event -> Maybe Status +nextStatus Started = Just Running +nextStatus Stopped = Just Paused +nextStatus Completed = Nothing -- must keep previous status seconds :: Int -> NominalDiffTime seconds n = realToFrac (toEnum n :: Uni) @@ -141,8 +141,10 @@ notifyTo mgr ih event entry @ TrackerEntry {..} = do else do let q = SAnnounceQuery ih def Nothing (Just event) res <- RPC.announce mgr trackerURI q - TrackerEntry trackerURI (Just (nextStatus event)) - <$> cachePeers res <*> cacheScrape res + let status' = nextStatus event <|> statusSent + TrackerEntry trackerURI status' + <$> cachePeers res + <*> cacheScrape res {----------------------------------------------------------------------- -- Multitracker Session @@ -207,7 +209,8 @@ notifyAll mgr Session {..} event = do -- This function /may/ block until tracker query proceed. notify :: Manager -> Session -> Event -> IO () notify mgr ses event = do - prevStatus <- swapMVar (currentStatus ses) (nextStatus event) + prevStatus <- modifyMVar (currentStatus ses) $ \ s -> + return (fromMaybe s (nextStatus event), s) when (needNotify event (Just prevStatus) == Just True) $ do notifyAll mgr ses event -- cgit v1.2.3