diff options
-rw-r--r-- | src/Network/BitTorrent/DHT/Routing.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/DHT/Routing.hs b/src/Network/BitTorrent/DHT/Routing.hs index 73fe358a..f62c9f56 100644 --- a/src/Network/BitTorrent/DHT/Routing.hs +++ b/src/Network/BitTorrent/DHT/Routing.hs | |||
@@ -47,6 +47,10 @@ module Network.BitTorrent.DHT.Routing | |||
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 | 49 | ||
50 | -- * Conversion | ||
51 | , Network.BitTorrent.DHT.Routing.TableEntry | ||
52 | , Network.BitTorrent.DHT.Routing.toList | ||
53 | |||
50 | -- * Routing | 54 | -- * Routing |
51 | , Timestamp | 55 | , Timestamp |
52 | , Routing | 56 | , Routing |
@@ -428,3 +432,21 @@ insert info @ NodeInfo {..} = go (0 :: BitIx) | |||
428 | | n == 0 = Tip nid n <$> insertNode info bucket | 432 | | n == 0 = Tip nid n <$> insertNode info bucket |
429 | | otherwise = Tip nid n <$> insertNode info bucket | 433 | | otherwise = Tip nid n <$> insertNode info bucket |
430 | <|> go (succ i) (splitTip nid n i bucket) | 434 | <|> go (succ i) (splitTip nid n i bucket) |
435 | |||
436 | {----------------------------------------------------------------------- | ||
437 | -- Conversion | ||
438 | -----------------------------------------------------------------------} | ||
439 | |||
440 | type TableEntry ip = (NodeInfo ip, Timestamp) | ||
441 | |||
442 | tableEntry :: NodeEntry ip -> TableEntry ip | ||
443 | tableEntry (a :-> b) = (a, b) | ||
444 | |||
445 | -- | Non-empty list of buckets. | ||
446 | toBucketList :: Table ip -> [Bucket ip] | ||
447 | toBucketList (Tip _ _ b) = [b] | ||
448 | toBucketList (Zero t b) = b : toBucketList t | ||
449 | toBucketList (One b t) = b : toBucketList t | ||
450 | |||
451 | toList :: Eq ip => Table ip -> [[TableEntry ip]] | ||
452 | toList = L.map (L.map tableEntry . PSQ.toList) . toBucketList | ||