diff options
author | joe <joe@jerkface.net> | 2017-07-27 22:23:25 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-07-27 22:23:25 -0400 |
commit | 2590178387d6f5334b35290229d91224c9af3324 (patch) | |
tree | 0a817240b44a12eda1fd37d573d54a064c3c3966 /src/Network | |
parent | 6eb020b921bad6b4c7fefc35d20ca7ac50012d38 (diff) |
Limit routing buckets to 24.
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/DHT/Routing.hs | 13 |
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) | |||
388 | defaultBucketCount :: Int | 388 | defaultBucketCount :: Int |
389 | defaultBucketCount = 20 | 389 | defaultBucketCount = 20 |
390 | 390 | ||
391 | defaultMaxBucketCount :: Word | ||
392 | defaultMaxBucketCount = 24 | ||
393 | |||
391 | data Info ni nid = Info | 394 | data 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 | ||
685 | bktCount :: BucketList ni -> Int | 694 | bktCount :: BucketList ni -> Int |