diff options
author | joe <joe@jerkface.net> | 2018-06-09 15:59:22 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2018-06-09 15:59:22 -0400 |
commit | e4e4650d004cba42bfd8897d9658bfcaec82fb6d (patch) | |
tree | 3a4476002f04b099dd3e02072010efeed2579222 /src/Network/BitTorrent/DHT/ContactInfo.hs | |
parent | e75cc83de37b628418c313b61db8864a04763562 (diff) |
bittorrent: Expire old peer announcements.
Diffstat (limited to 'src/Network/BitTorrent/DHT/ContactInfo.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT/ContactInfo.hs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/DHT/ContactInfo.hs b/src/Network/BitTorrent/DHT/ContactInfo.hs index c8187772..dfc93ed7 100644 --- a/src/Network/BitTorrent/DHT/ContactInfo.hs +++ b/src/Network/BitTorrent/DHT/ContactInfo.hs | |||
@@ -5,6 +5,7 @@ module Network.BitTorrent.DHT.ContactInfo | |||
5 | , Network.BitTorrent.DHT.ContactInfo.lookup | 5 | , Network.BitTorrent.DHT.ContactInfo.lookup |
6 | , Network.BitTorrent.DHT.ContactInfo.freshPeers | 6 | , Network.BitTorrent.DHT.ContactInfo.freshPeers |
7 | , Network.BitTorrent.DHT.ContactInfo.insertPeer | 7 | , Network.BitTorrent.DHT.ContactInfo.insertPeer |
8 | , deleteOlderThan | ||
8 | , knownSwarms | 9 | , knownSwarms |
9 | ) where | 10 | ) where |
10 | 11 | ||
@@ -234,3 +235,15 @@ insertPeer !ih !name !a !(PeerStore m) = seq a' $ PeerStore (HM.insertWith swarm | |||
234 | where | 235 | where |
235 | a' = SwarmData { peers = PSQ.singleton a 0 | 236 | a' = SwarmData { peers = PSQ.singleton a 0 |
236 | , name = name } | 237 | , name = name } |
238 | |||
239 | deleteOlderThan :: POSIXTime -> PeerStore -> PeerStore | ||
240 | deleteOlderThan cutoff (PeerStore m) = PeerStore $ HM.mapMaybe gc m | ||
241 | where | ||
242 | gc :: SwarmData -> Maybe SwarmData | ||
243 | gc swarms = fmap (\ps -> swarms { peers = ps }) $ gcPSQ (peers swarms) | ||
244 | |||
245 | gcPSQ :: PSQKey a => PSQ a Timestamp -> Maybe (PSQ a Timestamp) | ||
246 | gcPSQ ps = case minView ps of | ||
247 | Nothing -> Nothing | ||
248 | Just (_ :-> tm, ps') | tm < cutoff -> gcPSQ ps' | ||
249 | Just _ -> Just ps | ||