diff options
Diffstat (limited to 'src/Network/BitTorrent/DHT/Session.hs')
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 24 |
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 | -- |
330 | getClosest :: Eq ip => NodeId -> DHT ip [NodeInfo ip] | 329 | getClosest :: Eq ip => TableKey k => k -> DHT ip [NodeInfo ip] |
331 | getClosest nid = do | 330 | getClosest 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 | -- | ||
341 | getClosestHash :: Eq ip => InfoHash -> DHT ip [NodeInfo ip] | ||
342 | getClosestHash 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 | ||
379 | type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] | 367 | type PeerList ip = Either [NodeInfo ip] [PeerAddr ip] |
380 | 368 | ||
369 | -- | | ||
370 | -- | ||
371 | -- This operation used 'getClosest' as failback. | ||
372 | -- | ||
381 | getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip) | 373 | getPeerList :: Eq ip => InfoHash -> DHT ip (PeerList ip) |
382 | getPeerList ih = do | 374 | getPeerList 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 | {----------------------------------------------------------------------- |