summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-23 02:44:25 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-23 02:44:25 +0400
commit5d5c52d5a558b49fb8db814198315627d1c119e5 (patch)
treeabecab17dbde305151a6e960f7891ee2c8c1ed33
parente642358ffe4673ab0a03c5aafa628ffc86b17abd (diff)
Add convertion from routing table to list
-rw-r--r--src/Network/BitTorrent/DHT/Routing.hs22
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
440type TableEntry ip = (NodeInfo ip, Timestamp)
441
442tableEntry :: NodeEntry ip -> TableEntry ip
443tableEntry (a :-> b) = (a, b)
444
445-- | Non-empty list of buckets.
446toBucketList :: Table ip -> [Bucket ip]
447toBucketList (Tip _ _ b) = [b]
448toBucketList (Zero t b) = b : toBucketList t
449toBucketList (One b t) = b : toBucketList t
450
451toList :: Eq ip => Table ip -> [[TableEntry ip]]
452toList = L.map (L.map tableEntry . PSQ.toList) . toBucketList