summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-16 23:59:52 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-16 23:59:52 +0400
commit677c54a4ed4e4ecb185b46a8272add4c6df04b0b (patch)
tree542e2a49e3c1d25d893e2254cb88ff54bbdc2b98
parent81fb820ce0469a7ff3677e278ed5e3b3c491f569 (diff)
Move ping function to Query module
-rw-r--r--src/Network/BitTorrent/DHT.hs2
-rw-r--r--src/Network/BitTorrent/DHT/Query.hs8
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs6
3 files changed, 9 insertions, 7 deletions
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
136 $(logInfoS) "bootstrap" "Start node bootstrapping" 136 $(logInfoS) "bootstrap" "Start node bootstrapping"
137 nid <- asks thisNodeId 137 nid <- asks thisNodeId
138 -- TODO filter duplicated in startNodes list 138 -- TODO filter duplicated in startNodes list
139 aliveNodes <- queryParallel (ping <$> startNodes) 139 aliveNodes <- queryParallel (pingQ <$> startNodes)
140 _ <- sourceList [aliveNodes] $= search nid (findNodeQ nid) $$ C.consume 140 _ <- sourceList [aliveNodes] $= search nid (findNodeQ nid) $$ C.consume
141 $(logInfoS) "bootstrap" "Node bootstrapping finished" 141 $(logInfoS) "bootstrap" "Node bootstrapping finished"
142 142
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
11 -- * Search 11 -- * Search
12 -- ** Step 12 -- ** Step
13 , Iteration 13 , Iteration
14 , pingQ
14 , findNodeQ 15 , findNodeQ
15 , getPeersQ 16 , getPeersQ
16 , announceQ 17 , announceQ
@@ -85,6 +86,13 @@ handlers = [pingH, findNodeH, getPeersH, announceH]
85 86
86type Iteration ip o = NodeInfo ip -> DHT ip (Either [NodeInfo ip] [o ip]) 87type Iteration ip o = NodeInfo ip -> DHT ip (Either [NodeInfo ip] [o ip])
87 88
89-- | The most basic query. May be used to check if the given node is
90-- alive or get its 'NodeId'.
91pingQ :: Address ip => NodeAddr ip -> DHT ip (NodeInfo ip)
92pingQ addr = do
93 (nid, Ping) <- queryNode addr Ping
94 return (NodeInfo nid addr)
95
88-- TODO match with expected node id 96-- TODO match with expected node id
89findNodeQ :: Address ip => NodeId -> Iteration ip NodeInfo 97findNodeQ :: Address ip => NodeId -> Iteration ip NodeInfo
90findNodeQ nid NodeInfo {..} = do 98findNodeQ 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
55 , queryNode 55 , queryNode
56 , queryParallel 56 , queryParallel
57 , (<@>) 57 , (<@>)
58 , ping
59 ) where 58 ) where
60 59
61import Prelude hiding (ioError) 60import Prelude hiding (ioError)
@@ -463,8 +462,3 @@ queryParallel queries = do
463 where 462 where
464 cleanup :: [Either QueryFailure a] -> [a] 463 cleanup :: [Either QueryFailure a] -> [a]
465 cleanup = mapMaybe (either (const Nothing) Just) 464 cleanup = mapMaybe (either (const Nothing) Just)
466
467ping :: Address ip => NodeAddr ip -> DHT ip (NodeInfo ip)
468ping addr = do
469 (nid, Ping) <- queryNode addr Ping
470 return (NodeInfo nid addr)