summaryrefslogtreecommitdiff
path: root/src
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
parent469b2c84af865863a852bda5137640a2463c9a8b (diff)
Stop bootstrapping when table is full
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent/DHT.hs3
-rw-r--r--src/Network/BitTorrent/DHT/Routing.hs13
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs1
3 files changed, 16 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs
index a098d339..38de1f91 100644
--- a/src/Network/BitTorrent/DHT.hs
+++ b/src/Network/BitTorrent/DHT.hs
@@ -41,6 +41,7 @@ import Text.PrettyPrint.Class
41import Data.Torrent.InfoHash 41import Data.Torrent.InfoHash
42import Network.BitTorrent.Core 42import Network.BitTorrent.Core
43import Network.BitTorrent.DHT.Message 43import Network.BitTorrent.DHT.Message
44import Network.BitTorrent.DHT.Routing
44import Network.BitTorrent.DHT.Session 45import Network.BitTorrent.DHT.Session
45import Network.KRPC 46import Network.KRPC
46 47
@@ -103,6 +104,8 @@ bootstrap startNodes = do
103 $(logInfoS) "bootstrap" "Node bootstrapping finished" 104 $(logInfoS) "bootstrap" "Node bootstrapping finished"
104 where 105 where
105 insertClosest addr = do 106 insertClosest addr = do
107 t <- getTable
108 unless (full t) $ do
106 nid <- getNodeId 109 nid <- getNodeId
107 result <- try $ FindNode nid <@> addr 110 result <- try $ FindNode nid <@> addr
108 case result of 111 case result of
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