summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/Session.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-01-11 08:38:39 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-01-11 08:38:39 +0400
commit353c25a17d4100afd23127fc32d96995a9c70388 (patch)
tree30aabe426b98b4d90f2c0d34b70999c563e7cb38 /src/Network/BitTorrent/DHT/Session.hs
parentc349e7c07caa7484169c0e9d9e8f10d60d339f28 (diff)
Unify kclosest and kclosestHash functions
Diffstat (limited to 'src/Network/BitTorrent/DHT/Session.hs')
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index 149b7dd2..5ceca4a3 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -26,7 +26,6 @@ module Network.BitTorrent.DHT.Session
26 , getTable 26 , getTable
27 , getNodeId 27 , getNodeId
28 , getClosest 28 , getClosest
29 , getClosestHash
30 , insertNode 29 , insertNode
31 30
32 -- * Peer storage 31 -- * Peer storage
@@ -327,21 +326,10 @@ getNodeId = asks thisNodeId
327-- 326--
328-- This operation used for 'find_nodes' query. 327-- This operation used for 'find_nodes' query.
329-- 328--
330getClosest :: Eq ip => NodeId -> DHT ip [NodeInfo ip] 329getClosest :: Eq ip => TableKey k => k -> DHT ip [NodeInfo ip]
331getClosest nid = do 330getClosest node = do
332 k <- asks (optK . options) 331 k <- asks (optK . options)
333 kclosest k nid <$> getTable 332 kclosest k node <$> getTable
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--
341getClosestHash :: Eq ip => InfoHash -> DHT ip [NodeInfo ip]
342getClosestHash ih = do
343 k <- asks (optK . options)
344 kclosestHash k ih <$> getTable
345 333
346-- | This operation do not block but acquire exclusive access to 334-- | This operation do not block but acquire exclusive access to
347-- routing table. 335-- routing table.
@@ -378,11 +366,15 @@ lookupPeers ih = do
378 366
379type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] 367type PeerList ip = Either [NodeInfo ip] [PeerAddr ip]
380 368
369-- |
370--
371-- This operation used 'getClosest' as failback.
372--
381getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip) 373getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip)
382getPeerList ih = do 374getPeerList ih = do
383 ps <- lookupPeers ih 375 ps <- lookupPeers ih
384 if L.null ps 376 if L.null ps
385 then Left <$> getClosestHash ih 377 then Left <$> getClosest ih
386 else return (Right ps) 378 else return (Right ps)
387 379
388{----------------------------------------------------------------------- 380{-----------------------------------------------------------------------