summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/ContactInfo.hs
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-01-27 08:50:51 -0500
committerjoe <joe@jerkface.net>2017-01-27 08:50:51 -0500
commit0d1de683de78a70ce9c054b444bb6f19c39d112c (patch)
treef3a57d89c0673ee949b4e3a1f28885fb621f78b0 /src/Network/BitTorrent/DHT/ContactInfo.hs
parent77a317310d4f7929335fafe3cfbf53afd45faa82 (diff)
More strictness.
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 }