summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/ContactInfo.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/DHT/ContactInfo.hs')
-rw-r--r--src/Network/BitTorrent/DHT/ContactInfo.hs18
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.
204freshPeers :: Ord a => InfoHash -> Timestamp -> PeerStore a -> ([PeerAddr a], PeerStore a) 204freshPeers :: Ord a => InfoHash -> Timestamp -> PeerStore a -> ([PeerAddr a], PeerStore a)
205freshPeers ih tm (PeerStore m) = (ps, PeerStore m') 205freshPeers 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
215incomp :: (x -> Maybe (r,x)) -> x -> Maybe ((r,x),x) 215incomp :: (x -> Maybe (r,x)) -> x -> Maybe ((r,x),x)
216incomp f x = do 216incomp f x = do