diff options
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/Tracker/Session.hs | 39 |
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 | |||
94 | nullEntry uri = TrackerEntry uri Nothing def def | 94 | nullEntry 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? |
97 | needNotify :: Maybe Event -> Maybe Status -> Bool | 97 | needNotify :: Maybe Event -> Maybe Status -> Maybe Bool |
98 | needNotify Nothing _ = True | 98 | needNotify Nothing Nothing = Just True |
99 | needNotify (Just Started) Nothing = True | 99 | needNotify (Just Started) Nothing = Just True |
100 | needNotify (Just Stopped) Nothing = False | 100 | needNotify (Just Stopped) Nothing = Just False |
101 | needNotify (Just Completed) Nothing = False | 101 | needNotify (Just Completed) Nothing = Just False |
102 | needNotify Nothing (Just Running) = True | 102 | |
103 | needNotify Nothing (Just Paused ) = True | 103 | needNotify Nothing (Just Running) = Nothing |
104 | needNotify (Just Started) (Just Running) = Nothing | ||
105 | needNotify (Just Stopped) (Just Running) = Just True | ||
106 | needNotify (Just Completed) (Just Running) = Just True | ||
107 | |||
108 | needNotify Nothing (Just Paused ) = Just False | ||
109 | needNotify (Just Started) (Just Paused ) = Just True | ||
110 | needNotify (Just Stopped) (Just Paused ) = Just False | ||
111 | needNotify (Just Completed) (Just Paused ) = Just True | ||
104 | 112 | ||
105 | -- | Client status after event announce succeed. | 113 | -- | Client status after event announce succeed. |
106 | nextStatus :: Maybe Event -> Status | 114 | nextStatus :: 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. |
131 | announceTo :: Manager -> InfoHash -> Maybe Event | 139 | announceTo :: Manager -> InfoHash -> Maybe Event |
132 | -> TrackerEntry -> IO TrackerEntry | 140 | -> TrackerEntry -> IO TrackerEntry |
133 | announceTo mgr ih mevent entry @ TrackerEntry {..} | 141 | announceTo 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 |