diff options
Diffstat (limited to 'src/Network/BitTorrent/DHT/Routing.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT/Routing.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/DHT/Routing.hs b/src/Network/BitTorrent/DHT/Routing.hs index fee52380..68edef56 100644 --- a/src/Network/BitTorrent/DHT/Routing.hs +++ b/src/Network/BitTorrent/DHT/Routing.hs | |||
@@ -46,6 +46,7 @@ module Network.BitTorrent.DHT.Routing | |||
46 | -- * Construction | 46 | -- * Construction |
47 | , Network.BitTorrent.DHT.Routing.nullTable | 47 | , Network.BitTorrent.DHT.Routing.nullTable |
48 | , Network.BitTorrent.DHT.Routing.insert | 48 | , Network.BitTorrent.DHT.Routing.insert |
49 | , Network.BitTorrent.DHT.Routing.merge | ||
49 | 50 | ||
50 | -- * Conversion | 51 | -- * Conversion |
51 | , Network.BitTorrent.DHT.Routing.TableEntry | 52 | , Network.BitTorrent.DHT.Routing.TableEntry |
@@ -457,3 +458,10 @@ toBucketList (One b t) = b : toBucketList t | |||
457 | 458 | ||
458 | toList :: Eq ip => Table ip -> [[TableEntry ip]] | 459 | toList :: Eq ip => Table ip -> [[TableEntry ip]] |
459 | toList = L.map (L.map tableEntry . PSQ.toList) . toBucketList | 460 | toList = L.map (L.map tableEntry . PSQ.toList) . toBucketList |
461 | |||
462 | merge :: Eq ip => Table ip -> Table ip -> Routing ip (Table ip) | ||
463 | merge a b = do | ||
464 | let ns = concatMap PSQ.toList $ toBucketList a | ||
465 | -- TODO: merge timestamps as well and let refresh take care of ping. | ||
466 | as <- filterM (needPing . nodeAddr . PSQ.key) ns | ||
467 | foldM (flip $ Network.BitTorrent.DHT.Routing.insert) b $ map PSQ.key as | ||