diff options
-rw-r--r-- | src/Network/BitTorrent/DHT.hs | 3 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Routing.hs | 13 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 1 |
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 | |||
41 | import Data.Torrent.InfoHash | 41 | import Data.Torrent.InfoHash |
42 | import Network.BitTorrent.Core | 42 | import Network.BitTorrent.Core |
43 | import Network.BitTorrent.DHT.Message | 43 | import Network.BitTorrent.DHT.Message |
44 | import Network.BitTorrent.DHT.Routing | ||
44 | import Network.BitTorrent.DHT.Session | 45 | import Network.BitTorrent.DHT.Session |
45 | import Network.KRPC | 46 | import 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 | |||
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 |