summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-02 22:37:33 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-02 22:37:33 +0400
commit61619558b26b96048ffd18a7bf4cbe41d5fffa2f (patch)
tree42de4d8fd2b63e567a6821802a07ce1bb887de4e /src/Network/BitTorrent/DHT
parent469b2c84af865863a852bda5137640a2463c9a8b (diff)
Stop bootstrapping when table is full
Diffstat (limited to 'src/Network/BitTorrent/DHT')
-rw-r--r--src/Network/BitTorrent/DHT/Routing.hs13
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs1
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
328nullTable :: Eq ip => NodeId -> BucketCount -> Table ip 330nullTable :: Eq ip => NodeId -> BucketCount -> Table ip
329nullTable nid n = Tip nid (bucketCount (pred n)) PSQ.empty 331nullTable 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
335null :: Table ip -> Bool
336null (Tip _ _ b) = PSQ.null b
337null _ = False
338
339full :: Table ip -> Bool
340full (Tip _ n _) = n == 0
341full (Zero t b) = PSQ.size b == defaultBucketSize && full t
342full (One b t) = PSQ.size b == defaultBucketSize && full t
332 343
333-- | Get the /spine/ node id. 344-- | Get the /spine/ node id.
334thisId :: Table ip -> NodeId 345thisId :: 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