diff options
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 |