summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/Session.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/DHT/Session.hs')
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs25
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.
102data Options = Options 103data 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.
313getTable :: DHT ip (Table ip) 316getTable :: DHT ip (Table ip)
314getTable = do 317getTable = do
315 var <- asks routingTable 318 var <- asks routingTable
@@ -319,16 +322,29 @@ getTable = do
319getNodeId :: DHT ip NodeId 322getNodeId :: DHT ip NodeId
320getNodeId = asks thisNodeId 323getNodeId = 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--
322getClosest :: Eq ip => NodeId -> DHT ip [NodeInfo ip] 330getClosest :: Eq ip => NodeId -> DHT ip [NodeInfo ip]
323getClosest nid = do 331getClosest 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--
327getClosestHash :: Eq ip => InfoHash -> DHT ip [NodeInfo ip] 341getClosestHash :: Eq ip => InfoHash -> DHT ip [NodeInfo ip]
328getClosestHash ih = do 342getClosestHash 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.
332insertNode :: Address ip => NodeInfo ip -> DHT ip ThreadId 348insertNode :: Address ip => NodeInfo ip -> DHT ip ThreadId
333insertNode info = fork $ do 349insertNode 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