summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-27 08:23:10 -0400
committerjoe <joe@jerkface.net>2017-07-27 08:23:10 -0400
commit7a4b181bf39c3e33f0d9a78390fc6237cee783f8 (patch)
tree29773b7147c4366d7b1085c2cf6eee33c744e406
parent59a12c22732741754fbd3f58c05aa6324aea273a (diff)
Bug-fix: Enabled storing multiple peers in a swarm.
-rw-r--r--src/Data/Wrapper/PSQ.hs2
-rw-r--r--src/Network/BitTorrent/DHT/ContactInfo.hs6
2 files changed, 5 insertions, 3 deletions
diff --git a/src/Data/Wrapper/PSQ.hs b/src/Data/Wrapper/PSQ.hs
index 87648e84..58a6f624 100644
--- a/src/Data/Wrapper/PSQ.hs
+++ b/src/Data/Wrapper/PSQ.hs
@@ -62,7 +62,7 @@ insertWith :: (PSQKey k, Ord p) => (p -> p -> p) -> k -> p -> PSQ k p -> PSQ k p
62insertWith f k p0 q = snd $ Q.alter f' k q 62insertWith f k p0 q = snd $ Q.alter f' k q
63 where 63 where
64 f' (Just (p,())) = ((),Just (f p0 p, ())) 64 f' (Just (p,())) = ((),Just (f p0 p, ()))
65 f' Nothing = ((),Nothing) 65 f' Nothing = ((),Just (p0,()))
66{-# INLINE insertWith #-} 66{-# INLINE insertWith #-}
67 67
68singleton :: (PSQKey k, Ord p) => k -> p -> PSQ k p 68singleton :: (PSQKey k, Ord p) => k -> p -> PSQ k p
diff --git a/src/Network/BitTorrent/DHT/ContactInfo.hs b/src/Network/BitTorrent/DHT/ContactInfo.hs
index b7d7f2a2..9c336f93 100644
--- a/src/Network/BitTorrent/DHT/ContactInfo.hs
+++ b/src/Network/BitTorrent/DHT/ContactInfo.hs
@@ -174,10 +174,12 @@ swarmSingleton a = SwarmData
174 , name = Nothing } 174 , name = Nothing }
175 175
176swarmInsert :: SwarmData -> SwarmData -> SwarmData 176swarmInsert :: SwarmData -> SwarmData -> SwarmData
177swarmInsert old new = SwarmData 177swarmInsert new old = SwarmData
178 { peers = L.foldl' (\q (a :-> t) -> PSQ.insertWith (\p _ -> p) a t q) (peers old) (PSQ.toList $ peers new) 178 { peers = L.foldl' (\q (a :-> t) -> PSQ.insertWith newerTimeStamp a t q) (peers old) (PSQ.toList $ peers new)
179 , name = name new <|> name old -- TODO: decodeUtf8' check 179 , name = name new <|> name old -- TODO: decodeUtf8' check
180 } 180 }
181 where
182 newerTimeStamp newtime oldtime = if newtime > oldtime then newtime else oldtime
181 183
182isSwarmOccupied SwarmData{..} = not $ PSQ.null peers 184isSwarmOccupied SwarmData{..} = not $ PSQ.null peers
183 185