summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-07-27 22:23:25 -0400
committerjoe <joe@jerkface.net>2017-07-27 22:23:25 -0400
commit2590178387d6f5334b35290229d91224c9af3324 (patch)
tree0a817240b44a12eda1fd37d573d54a064c3c3966 /src/Network
parent6eb020b921bad6b4c7fefc35d20ca7ac50012d38 (diff)
Limit routing buckets to 24.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/DHT/Routing.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Network/DHT/Routing.hs b/src/Network/DHT/Routing.hs
index 0391c116..85525a90 100644
--- a/src/Network/DHT/Routing.hs
+++ b/src/Network/DHT/Routing.hs
@@ -388,6 +388,9 @@ split testNodeIdBit i b = (Bucket ns qs, Bucket ms rs)
388defaultBucketCount :: Int 388defaultBucketCount :: Int
389defaultBucketCount = 20 389defaultBucketCount = 20
390 390
391defaultMaxBucketCount :: Word
392defaultMaxBucketCount = 24
393
391data Info ni nid = Info 394data Info ni nid = Info
392 { myBuckets :: BucketList ni 395 { myBuckets :: BucketList ni
393 , myNodeId :: nid 396 , myNodeId :: nid
@@ -678,8 +681,14 @@ modifyBucket space nid f (BucketList self bkts)
678 | kademliaTestBit space d i = second (: buckets) <$> f bucket 681 | kademliaTestBit space d i = second (: buckets) <$> f bucket
679 | otherwise = second (bucket :) <$> go (succ i) buckets 682 | otherwise = second (bucket :) <$> go (succ i) buckets
680 683
681 go !i [bucket] = second (: []) <$> f bucket 684 go !i [bucket] = second (: []) <$> f bucket <|> gosplit
682 <|> go i (splitTip (kademliaTestBit space . kademliaLocation space) self i bucket) 685 where
686 gosplit | i < defaultMaxBucketCount = go i (splitTip ( kademliaTestBit space
687 . kademliaLocation space )
688 self
689 i
690 bucket)
691 | otherwise = Nothing -- Limit the number of buckets.
683 692
684 693
685bktCount :: BucketList ni -> Int 694bktCount :: BucketList ni -> Int