diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-11 07:20:53 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-11 07:20:53 +0400 |
commit | f3a8a1d678243f644ebc37ae46ecac63dacbde83 (patch) | |
tree | 15e555a39f58f0064486b299e9cc4f16a1fe8ef4 /src/Network/BitTorrent | |
parent | ef2e4cc8b79ec88dd7ed06ca0438fd3288383141 (diff) |
Add documentation for routing table operations
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index e53639a3..149b7dd2 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -96,9 +96,10 @@ defaultAlpha = 3 | |||
96 | 96 | ||
97 | -- TODO add replication loop | 97 | -- TODO add replication loop |
98 | 98 | ||
99 | -- | Original Kamelia DHT uses term /publish/ . BitTorrent DHT uses | 99 | -- | Original Kamelia DHT uses term /publish/ for data replication |
100 | -- term /announce/ since the purpose . Later in documentation, we use | 100 | -- process. BitTorrent DHT uses term /announce/ since the purpose of |
101 | -- terms /publish/ and /announce/ interchangible. | 101 | -- the DHT is peer discovery. Later in documentation, we use terms |
102 | -- /publish/ and /announce/ interchangible. | ||
102 | data Options = Options | 103 | data Options = Options |
103 | { -- | The degree of parallelism in 'find_node' queries. More | 104 | { -- | The degree of parallelism in 'find_node' queries. More |
104 | -- parallism lead to faster bootstrapping and lookup operations, | 105 | -- parallism lead to faster bootstrapping and lookup operations, |
@@ -310,6 +311,8 @@ checkToken addr questionableToken = do | |||
310 | -- Routing table | 311 | -- Routing table |
311 | -----------------------------------------------------------------------} | 312 | -----------------------------------------------------------------------} |
312 | 313 | ||
314 | -- | Get current routing table. Normally you don't need to use this | ||
315 | -- function, but it can be usefull for debugging and profiling purposes. | ||
313 | getTable :: DHT ip (Table ip) | 316 | getTable :: DHT ip (Table ip) |
314 | getTable = do | 317 | getTable = do |
315 | var <- asks routingTable | 318 | var <- asks routingTable |
@@ -319,16 +322,29 @@ getTable = do | |||
319 | getNodeId :: DHT ip NodeId | 322 | getNodeId :: DHT ip NodeId |
320 | getNodeId = asks thisNodeId | 323 | getNodeId = asks thisNodeId |
321 | 324 | ||
325 | -- | Find a set of closest nodes from routing table of this node. (in | ||
326 | -- no particular order) | ||
327 | -- | ||
328 | -- This operation used for 'find_nodes' query. | ||
329 | -- | ||
322 | getClosest :: Eq ip => NodeId -> DHT ip [NodeInfo ip] | 330 | getClosest :: Eq ip => NodeId -> DHT ip [NodeInfo ip] |
323 | getClosest nid = do | 331 | getClosest nid = do |
324 | k <- asks (optK . options) | 332 | k <- asks (optK . options) |
325 | kclosest k nid <$> getTable | 333 | kclosest k nid <$> getTable |
326 | 334 | ||
335 | -- | Find a set of closest nodes from routing table of this node. (in | ||
336 | -- no particular order) | ||
337 | -- | ||
338 | -- This operation used as failback in 'get_peers' query, see | ||
339 | -- 'getPeerList'. | ||
340 | -- | ||
327 | getClosestHash :: Eq ip => InfoHash -> DHT ip [NodeInfo ip] | 341 | getClosestHash :: Eq ip => InfoHash -> DHT ip [NodeInfo ip] |
328 | getClosestHash ih = do | 342 | getClosestHash ih = do |
329 | k <- asks (optK . options) | 343 | k <- asks (optK . options) |
330 | kclosestHash k ih <$> getTable | 344 | kclosestHash k ih <$> getTable |
331 | 345 | ||
346 | -- | This operation do not block but acquire exclusive access to | ||
347 | -- routing table. | ||
332 | insertNode :: Address ip => NodeInfo ip -> DHT ip ThreadId | 348 | insertNode :: Address ip => NodeInfo ip -> DHT ip ThreadId |
333 | insertNode info = fork $ do | 349 | insertNode info = fork $ do |
334 | var <- asks routingTable | 350 | var <- asks routingTable |
@@ -340,7 +356,8 @@ insertNode info = fork $ do | |||
340 | <> T.pack (show (pretty t)) | 356 | <> T.pack (show (pretty t)) |
341 | return t | 357 | return t |
342 | Just t' -> do | 358 | Just t' -> do |
343 | let logMsg = "Routing table updated: " <> pretty t <> " -> " <> pretty t' | 359 | let logMsg = "Routing table updated: " |
360 | <> pretty t <> " -> " <> pretty t' | ||
344 | $(logDebugS) "insertNode" (T.pack (render logMsg)) | 361 | $(logDebugS) "insertNode" (T.pack (render logMsg)) |
345 | return t' | 362 | return t' |
346 | 363 | ||