From 677c54a4ed4e4ecb185b46a8272add4c6df04b0b Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sun, 16 Feb 2014 23:59:52 +0400 Subject: Move ping function to Query module --- src/Network/BitTorrent/DHT.hs | 2 +- src/Network/BitTorrent/DHT/Query.hs | 8 ++++++++ src/Network/BitTorrent/DHT/Session.hs | 6 ------ 3 files changed, 9 insertions(+), 7 deletions(-) (limited to 'src/Network') diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs index 92d1ec63..8b212ee8 100644 --- a/src/Network/BitTorrent/DHT.hs +++ b/src/Network/BitTorrent/DHT.hs @@ -136,7 +136,7 @@ bootstrap startNodes = do $(logInfoS) "bootstrap" "Start node bootstrapping" nid <- asks thisNodeId -- TODO filter duplicated in startNodes list - aliveNodes <- queryParallel (ping <$> startNodes) + aliveNodes <- queryParallel (pingQ <$> startNodes) _ <- sourceList [aliveNodes] $= search nid (findNodeQ nid) $$ C.consume $(logInfoS) "bootstrap" "Node bootstrapping finished" diff --git a/src/Network/BitTorrent/DHT/Query.hs b/src/Network/BitTorrent/DHT/Query.hs index 724c07e6..dcb217d6 100644 --- a/src/Network/BitTorrent/DHT/Query.hs +++ b/src/Network/BitTorrent/DHT/Query.hs @@ -11,6 +11,7 @@ module Network.BitTorrent.DHT.Query -- * Search -- ** Step , Iteration + , pingQ , findNodeQ , getPeersQ , announceQ @@ -85,6 +86,13 @@ handlers = [pingH, findNodeH, getPeersH, announceH] type Iteration ip o = NodeInfo ip -> DHT ip (Either [NodeInfo ip] [o ip]) +-- | The most basic query. May be used to check if the given node is +-- alive or get its 'NodeId'. +pingQ :: Address ip => NodeAddr ip -> DHT ip (NodeInfo ip) +pingQ addr = do + (nid, Ping) <- queryNode addr Ping + return (NodeInfo nid addr) + -- TODO match with expected node id findNodeQ :: Address ip => NodeId -> Iteration ip NodeInfo findNodeQ nid NodeInfo {..} = do diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index 11e1c81a..6f13cf78 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs @@ -55,7 +55,6 @@ module Network.BitTorrent.DHT.Session , queryNode , queryParallel , (<@>) - , ping ) where import Prelude hiding (ioError) @@ -463,8 +462,3 @@ queryParallel queries = do where cleanup :: [Either QueryFailure a] -> [a] cleanup = mapMaybe (either (const Nothing) Just) - -ping :: Address ip => NodeAddr ip -> DHT ip (NodeInfo ip) -ping addr = do - (nid, Ping) <- queryNode addr Ping - return (NodeInfo nid addr) -- cgit v1.2.3