diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-02 22:37:33 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-02 22:37:33 +0400 |
commit | 61619558b26b96048ffd18a7bf4cbe41d5fffa2f (patch) | |
tree | 42de4d8fd2b63e567a6821802a07ce1bb887de4e /src/Network/BitTorrent/DHT | |
parent | 469b2c84af865863a852bda5137640a2463c9a8b (diff) |
Stop bootstrapping when table is full
Diffstat (limited to 'src/Network/BitTorrent/DHT')
-rw-r--r-- | src/Network/BitTorrent/DHT/Routing.hs | 13 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 1 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/DHT/Routing.hs b/src/Network/BitTorrent/DHT/Routing.hs index f6926cb1..22076a39 100644 --- a/src/Network/BitTorrent/DHT/Routing.hs +++ b/src/Network/BitTorrent/DHT/Routing.hs | |||
@@ -29,6 +29,8 @@ module Network.BitTorrent.DHT.Routing | |||
29 | , NodeCount | 29 | , NodeCount |
30 | 30 | ||
31 | -- * Query | 31 | -- * Query |
32 | , Network.BitTorrent.DHT.Routing.null | ||
33 | , Network.BitTorrent.DHT.Routing.full | ||
32 | , thisId | 34 | , thisId |
33 | , shape | 35 | , shape |
34 | , Network.BitTorrent.DHT.Routing.size | 36 | , Network.BitTorrent.DHT.Routing.size |
@@ -328,7 +330,16 @@ instance Pretty (Table ip) where | |||
328 | nullTable :: Eq ip => NodeId -> BucketCount -> Table ip | 330 | nullTable :: Eq ip => NodeId -> BucketCount -> Table ip |
329 | nullTable nid n = Tip nid (bucketCount (pred n)) PSQ.empty | 331 | nullTable nid n = Tip nid (bucketCount (pred n)) PSQ.empty |
330 | where | 332 | where |
331 | bucketCount x = max 0 (min 160 x) | 333 | bucketCount x = max 0 (min 159 x) |
334 | |||
335 | null :: Table ip -> Bool | ||
336 | null (Tip _ _ b) = PSQ.null b | ||
337 | null _ = False | ||
338 | |||
339 | full :: Table ip -> Bool | ||
340 | full (Tip _ n _) = n == 0 | ||
341 | full (Zero t b) = PSQ.size b == defaultBucketSize && full t | ||
342 | full (One b t) = PSQ.size b == defaultBucketSize && full t | ||
332 | 343 | ||
333 | -- | Get the /spine/ node id. | 344 | -- | Get the /spine/ node id. |
334 | thisId :: Table ip -> NodeId | 345 | thisId :: Table ip -> NodeId |
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index c47f7491..d3315a42 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -23,6 +23,7 @@ module Network.BitTorrent.DHT.Session | |||
23 | , checkToken | 23 | , checkToken |
24 | 24 | ||
25 | -- * Routing table | 25 | -- * Routing table |
26 | , getTable | ||
26 | , getNodeId | 27 | , getNodeId |
27 | , getClosest | 28 | , getClosest |
28 | , getClosestHash | 29 | , getClosestHash |