diff options
author | joe <joe@jerkface.net> | 2017-01-25 20:25:29 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-01-25 20:25:29 -0500 |
commit | af87d80ebe4cf46a1aeb0a9421708ea52d09000b (patch) | |
tree | 3cdebe5ee719c044cd52b0701255895e39e55bc4 /src/Network/BitTorrent/DHT/ContactInfo.hs | |
parent | 71db760db0291f8df7a7fa854a7a315e59556f71 (diff) |
Immediately forget swarms for which we've never seen peers.
Diffstat (limited to 'src/Network/BitTorrent/DHT/ContactInfo.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT/ContactInfo.hs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/DHT/ContactInfo.hs b/src/Network/BitTorrent/DHT/ContactInfo.hs index 117325fc..ea3b96f0 100644 --- a/src/Network/BitTorrent/DHT/ContactInfo.hs +++ b/src/Network/BitTorrent/DHT/ContactInfo.hs | |||
@@ -202,15 +202,15 @@ batchSize = 64 | |||
202 | 202 | ||
203 | -- | Used in 'get_peers' DHT queries. | 203 | -- | Used in 'get_peers' DHT queries. |
204 | freshPeers :: Ord a => InfoHash -> Timestamp -> PeerStore a -> ([PeerAddr a], PeerStore a) | 204 | freshPeers :: Ord a => InfoHash -> Timestamp -> PeerStore a -> ([PeerAddr a], PeerStore a) |
205 | freshPeers ih tm (PeerStore m) = (ps, PeerStore m') | 205 | freshPeers ih tm (PeerStore m) = fromMaybe ([],PeerStore m) $ do |
206 | where | 206 | swarm <- HM.lookup ih m |
207 | swarm = fromMaybe (SwarmData PSQ.empty Nothing) $ HM.lookup ih m | 207 | let ps0 = take batchSize $ unfoldr (incomp minView) (peers swarm) |
208 | ps0 = take batchSize $ unfoldr (incomp minView) (peers swarm) | 208 | peers' = case reverse ps0 of |
209 | peers' = case reverse ps0 of | 209 | (_,psq):_ -> psq |
210 | (_,psq):_ -> psq | 210 | _ -> peers swarm |
211 | _ -> peers swarm | 211 | ps = L.map (key . fst) ps0 |
212 | ps = L.map (key . fst) ps0 | 212 | m' = HM.insert ih swarm { peers = L.foldl' (\q p -> PSQ.insert p tm q) peers' ps } m |
213 | m' = HM.insert ih swarm { peers = L.foldl' (\q p -> PSQ.insert p tm q) peers' ps } m | 213 | return (ps,PeerStore m') |
214 | 214 | ||
215 | incomp :: (x -> Maybe (r,x)) -> x -> Maybe ((r,x),x) | 215 | incomp :: (x -> Maybe (r,x)) -> x -> Maybe ((r,x),x) |
216 | incomp f x = do | 216 | incomp f x = do |