summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-16 23:53:11 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-16 23:53:11 +0400
commit81fb820ce0469a7ff3677e278ed5e3b3c491f569 (patch)
treee0c7cba820d9d89404dd50f687e74e87264c0fe1 /src/Network/BitTorrent
parent3d2408eb3f680117d841e5f90e120ff018009f03 (diff)
Remove getNodeId function
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/DHT.hs3
-rw-r--r--src/Network/BitTorrent/DHT/Query.hs2
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs21
3 files changed, 15 insertions, 11 deletions
diff --git a/src/Network/BitTorrent/DHT.hs b/src/Network/BitTorrent/DHT.hs
index b5dc868d..92d1ec63 100644
--- a/src/Network/BitTorrent/DHT.hs
+++ b/src/Network/BitTorrent/DHT.hs
@@ -53,6 +53,7 @@ module Network.BitTorrent.DHT
53 53
54import Control.Applicative 54import Control.Applicative
55import Control.Monad.Logger 55import Control.Monad.Logger
56import Control.Monad.Reader
56import Control.Monad.Trans 57import Control.Monad.Trans
57import Data.ByteString as BS 58import Data.ByteString as BS
58import Data.Conduit as C 59import Data.Conduit as C
@@ -133,7 +134,7 @@ resolveHostName NodeAddr {..} = do
133bootstrap :: Address ip => [NodeAddr ip] -> DHT ip () 134bootstrap :: Address ip => [NodeAddr ip] -> DHT ip ()
134bootstrap startNodes = do 135bootstrap startNodes = do
135 $(logInfoS) "bootstrap" "Start node bootstrapping" 136 $(logInfoS) "bootstrap" "Start node bootstrapping"
136 nid <- getNodeId 137 nid <- asks thisNodeId
137 -- TODO filter duplicated in startNodes list 138 -- TODO filter duplicated in startNodes list
138 aliveNodes <- queryParallel (ping <$> startNodes) 139 aliveNodes <- queryParallel (ping <$> startNodes)
139 _ <- sourceList [aliveNodes] $= search nid (findNodeQ nid) $$ C.consume 140 _ <- sourceList [aliveNodes] $= search nid (findNodeQ nid) $$ C.consume
diff --git a/src/Network/BitTorrent/DHT/Query.hs b/src/Network/BitTorrent/DHT/Query.hs
index 627bc096..724c07e6 100644
--- a/src/Network/BitTorrent/DHT/Query.hs
+++ b/src/Network/BitTorrent/DHT/Query.hs
@@ -54,7 +54,7 @@ nodeHandler action = handler $ \ sockAddr (Query remoteId q) -> do
54 Nothing -> throwIO BadAddress 54 Nothing -> throwIO BadAddress
55 Just naddr -> do 55 Just naddr -> do
56 insertNode (NodeInfo remoteId naddr) 56 insertNode (NodeInfo remoteId naddr)
57 Response <$> getNodeId <*> action naddr q 57 Response <$> asks thisNodeId <*> action naddr q
58 58
59pingH :: Address ip => NodeHandler ip 59pingH :: Address ip => NodeHandler ip
60pingH = nodeHandler $ \ _ Ping -> do 60pingH = nodeHandler $ \ _ Ping -> do
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index cbdc9ff8..11e1c81a 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -23,12 +23,16 @@ module Network.BitTorrent.DHT.Session
23 -- * Session 23 -- * Session
24 , Node 24 , Node
25 , options 25 , options
26 , thisNodeId
27
28 -- ** Initialization
26 , LogFun 29 , LogFun
27 , NodeHandler 30 , NodeHandler
28 , startNode 31 , startNode
29 32
30 -- * DHT 33 -- * DHT
31 -- | Use @asks options@ to get options passed to 'startNode'. 34 -- | Use @asks options@ to get options passed to 'startNode'
35 -- or @asks thisNodeId@ to get id of locally running node.
32 , DHT 36 , DHT
33 , runDHT 37 , runDHT
34 38
@@ -38,7 +42,6 @@ module Network.BitTorrent.DHT.Session
38 42
39 -- * Routing table 43 -- * Routing table
40 , getTable 44 , getTable
41 , getNodeId
42 , getClosest 45 , getClosest
43 , insertNode 46 , insertNode
44 47
@@ -225,8 +228,12 @@ type LogFun = Loc -> LogSource -> LogLevel -> LogStr -> IO ()
225 228
226-- | DHT session keep track state of /this/ node. 229-- | DHT session keep track state of /this/ node.
227data Node ip = Node 230data Node ip = Node
228 { options :: !Options -- ^ session configuration; 231 { -- | Session configuration;
229 , thisNodeId :: !NodeId -- ^ session identifier; 232 options :: !Options
233
234 -- | Pseudo-unique self-assigned session identifier. This value is
235 -- constant during DHT session and (optionally) between sessions.
236 , thisNodeId :: !NodeId
230 , manager :: !(Manager (DHT ip)) -- ^ RPC manager; 237 , manager :: !(Manager (DHT ip)) -- ^ RPC manager;
231 , routingTable :: !(MVar (Table ip)) -- ^ search table; 238 , routingTable :: !(MVar (Table ip)) -- ^ search table;
232 , contactInfo :: !(TVar (PeerStore ip)) -- ^ published by other nodes; 239 , contactInfo :: !(TVar (PeerStore ip)) -- ^ published by other nodes;
@@ -361,10 +368,6 @@ getTable = do
361 var <- asks routingTable 368 var <- asks routingTable
362 liftIO (readMVar var) 369 liftIO (readMVar var)
363 370
364-- | Get id of /this/ node. This value is constant during DHT session.
365getNodeId :: DHT ip NodeId
366getNodeId = asks thisNodeId
367
368-- | Find a set of closest nodes from routing table of this node. (in 371-- | Find a set of closest nodes from routing table of this node. (in
369-- no particular order) 372-- no particular order)
370-- 373--
@@ -440,7 +443,7 @@ deleteTopic ih p = do
440queryNode :: forall a b ip. Address ip => KRPC (Query a) (Response b) 443queryNode :: forall a b ip. Address ip => KRPC (Query a) (Response b)
441 => NodeAddr ip -> a -> DHT ip (NodeId, b) 444 => NodeAddr ip -> a -> DHT ip (NodeId, b)
442queryNode addr q = do 445queryNode addr q = do
443 nid <- getNodeId 446 nid <- asks thisNodeId
444 Response remoteId r <- query (toSockAddr addr) (Query nid q) 447 Response remoteId r <- query (toSockAddr addr) (Query nid q)
445 insertNode (NodeInfo remoteId addr) 448 insertNode (NodeInfo remoteId addr)
446 return (remoteId, r) 449 return (remoteId, r)