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.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Network/BitTorrent/DHT/ContactInfo.hs b/src/Network/BitTorrent/DHT/ContactInfo.hs
index 26bdeae9..f9dae567 100644
--- a/src/Network/BitTorrent/DHT/ContactInfo.hs
+++ b/src/Network/BitTorrent/DHT/ContactInfo.hs
@@ -1,3 +1,4 @@
1{-# LANGUAGE BangPatterns #-}
1module Network.BitTorrent.DHT.ContactInfo 2module Network.BitTorrent.DHT.ContactInfo
2 ( PeerStore 3 ( PeerStore
3 , Network.BitTorrent.DHT.ContactInfo.lookup 4 , Network.BitTorrent.DHT.ContactInfo.lookup
@@ -120,8 +121,8 @@ newtype PeerStore ip = PeerStore (HashMap InfoHash (SwarmData ip))
120type Timestamp = POSIXTime 121type Timestamp = POSIXTime
121 122
122data SwarmData ip = SwarmData 123data SwarmData ip = SwarmData
123 { peers :: PSQ (PeerAddr ip) Timestamp 124 { peers :: !(PSQ (PeerAddr ip) Timestamp)
124 , name :: Maybe ByteString 125 , name :: !(Maybe ByteString)
125 } 126 }
126 127
127 128
@@ -210,16 +211,16 @@ freshPeers ih tm (PeerStore m) = fromMaybe ([],PeerStore m) $ do
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 return $! (ps,PeerStore m')
214 215
215incomp :: (x -> Maybe (r,x)) -> x -> Maybe ((r,x),x) 216incomp :: (x -> Maybe (r,x)) -> x -> Maybe ((r,x),x)
216incomp f x = do 217incomp !f !x = do
217 (result,x') <- f x 218 (result,x') <- f x
218 pure $ ( (result,x'), x' ) 219 pure $! ( (result,x'), x' )
219 220
220-- | Used in 'announce_peer' DHT queries. 221-- | Used in 'announce_peer' DHT queries.
221insertPeer :: Ord a => InfoHash -> Maybe ByteString -> PeerAddr a -> PeerStore a -> PeerStore a 222insertPeer :: Ord a => InfoHash -> Maybe ByteString -> PeerAddr a -> PeerStore a -> PeerStore a
222insertPeer ih name a (PeerStore m) = PeerStore (HM.insertWith swarmInsert ih a' m) 223insertPeer !ih !name !a !(PeerStore m) = seq a' $ PeerStore (HM.insertWith swarmInsert ih a' m)
223 where 224 where
224 a' = SwarmData { peers = PSQ.singleton a 0 225 a' = SwarmData { peers = PSQ.singleton a 0
225 , name = name } 226 , name = name }