summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/Tracker/Session.hs39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/Network/BitTorrent/Tracker/Session.hs b/src/Network/BitTorrent/Tracker/Session.hs
index e13bc6f0..118befd3 100644
--- a/src/Network/BitTorrent/Tracker/Session.hs
+++ b/src/Network/BitTorrent/Tracker/Session.hs
@@ -94,13 +94,21 @@ nullEntry :: URI -> TrackerEntry
94nullEntry uri = TrackerEntry uri Nothing def def 94nullEntry uri = TrackerEntry uri Nothing def def
95 95
96-- | Do we need to notify this /specific/ tracker? 96-- | Do we need to notify this /specific/ tracker?
97needNotify :: Maybe Event -> Maybe Status -> Bool 97needNotify :: Maybe Event -> Maybe Status -> Maybe Bool
98needNotify Nothing _ = True 98needNotify Nothing Nothing = Just True
99needNotify (Just Started) Nothing = True 99needNotify (Just Started) Nothing = Just True
100needNotify (Just Stopped) Nothing = False 100needNotify (Just Stopped) Nothing = Just False
101needNotify (Just Completed) Nothing = False 101needNotify (Just Completed) Nothing = Just False
102needNotify Nothing (Just Running) = True 102
103needNotify Nothing (Just Paused ) = True 103needNotify Nothing (Just Running) = Nothing
104needNotify (Just Started) (Just Running) = Nothing
105needNotify (Just Stopped) (Just Running) = Just True
106needNotify (Just Completed) (Just Running) = Just True
107
108needNotify Nothing (Just Paused ) = Just False
109needNotify (Just Started) (Just Paused ) = Just True
110needNotify (Just Stopped) (Just Paused ) = Just False
111needNotify (Just Completed) (Just Paused ) = Just True
104 112
105-- | Client status after event announce succeed. 113-- | Client status after event announce succeed.
106nextStatus :: Maybe Event -> Status 114nextStatus :: Maybe Event -> Status
@@ -130,13 +138,16 @@ cacheScrape AnnounceInfo {..} =
130-- | Make announce request to specific tracker returning new state. 138-- | Make announce request to specific tracker returning new state.
131announceTo :: Manager -> InfoHash -> Maybe Event 139announceTo :: Manager -> InfoHash -> Maybe Event
132 -> TrackerEntry -> IO TrackerEntry 140 -> TrackerEntry -> IO TrackerEntry
133announceTo mgr ih mevent entry @ TrackerEntry {..} 141announceTo mgr ih mevent entry @ TrackerEntry {..} = do
134 | mevent `needNotify` statusSent = do 142 let shouldNotify = needNotify mevent statusSent
135 let q = SAnnounceQuery ih def Nothing mevent 143 mustNotify <- maybe (isExpired peersCache) return shouldNotify
136 res <- RPC.announce mgr trackerURI q 144 if not mustNotify
137 TrackerEntry trackerURI (Just (nextStatus mevent)) 145 then return entry
138 <$> cachePeers res <*> cacheScrape res 146 else do
139 | otherwise = return entry 147 let q = SAnnounceQuery ih def Nothing mevent
148 res <- RPC.announce mgr trackerURI q
149 TrackerEntry trackerURI (Just (nextStatus mevent))
150 <$> cachePeers res <*> cacheScrape res
140 151
141{----------------------------------------------------------------------- 152{-----------------------------------------------------------------------
142-- Multitracker Session 153-- Multitracker Session