summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/DHT/Message.hs8
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs7
2 files changed, 8 insertions, 7 deletions
diff --git a/src/Network/BitTorrent/DHT/Message.hs b/src/Network/BitTorrent/DHT/Message.hs
index ac4889fe..acecf8b1 100644
--- a/src/Network/BitTorrent/DHT/Message.hs
+++ b/src/Network/BitTorrent/DHT/Message.hs
@@ -106,13 +106,13 @@ node_id_key = "id"
106-- | All queries have an \"id\" key and value containing the node ID 106-- | All queries have an \"id\" key and value containing the node ID
107-- of the querying node. 107-- of the querying node.
108data Query a = Query 108data Query a = Query
109 { thisNodeId :: NodeId -- ^ node id of /quering/ node; 109 { queringNodeId :: NodeId -- ^ node id of /quering/ node;
110 , queryParams :: a -- ^ query parameters. 110 , queryParams :: a -- ^ query parameters.
111 } deriving (Show, Eq, Typeable) 111 } deriving (Show, Eq, Typeable)
112 112
113instance BEncode a => BEncode (Query a) where 113instance BEncode a => BEncode (Query a) where
114 toBEncode Query {..} = toDict $ 114 toBEncode Query {..} = toDict $
115 node_id_key .=! thisNodeId .: endDict 115 node_id_key .=! queringNodeId .: endDict
116 <> 116 <>
117 dict (toBEncode queryParams) 117 dict (toBEncode queryParams)
118 where 118 where
@@ -126,7 +126,7 @@ instance BEncode a => BEncode (Query a) where
126-- | All responses have an \"id\" key and value containing the node ID 126-- | All responses have an \"id\" key and value containing the node ID
127-- of the responding node. 127-- of the responding node.
128data Response a = Response 128data Response a = Response
129 { remoteNodeId :: NodeId -- ^ node id of /quered/ node; 129 { queredNodeId :: NodeId -- ^ node id of /quered/ node;
130 , responseVals :: a -- ^ query result. 130 , responseVals :: a -- ^ query result.
131 } deriving (Show, Eq, Typeable) 131 } deriving (Show, Eq, Typeable)
132 132
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index a4f10bb1..3c37ea9a 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -152,6 +152,7 @@ invalidateTokens curTime ts @ SessionTokens {..}
152 152
153data Node ip = Node 153data Node ip = Node
154 { options :: !Options 154 { options :: !Options
155 , thisNodeId :: !NodeId
155 , manager :: !(Manager (DHT ip)) 156 , manager :: !(Manager (DHT ip))
156 , routingTable :: !(MVar (Table ip)) 157 , routingTable :: !(MVar (Table ip))
157 , contactInfo :: !(TVar (PeerStore ip)) 158 , contactInfo :: !(TVar (PeerStore ip))
@@ -196,7 +197,7 @@ runDHT handlers opts naddr action = runResourceT $ do
196 let nodeAddr = toSockAddr naddr 197 let nodeAddr = toSockAddr naddr
197 (_, m) <- allocate (newManager rpcOpts nodeAddr handlers) closeManager 198 (_, m) <- allocate (newManager rpcOpts nodeAddr handlers) closeManager
198 myId <- liftIO genNodeId 199 myId <- liftIO genNodeId
199 node <- liftIO $ Node opts m 200 node <- liftIO $ Node opts myId m
200 <$> newMVar (nullTable myId (optBucketCount opts)) 201 <$> newMVar (nullTable myId (optBucketCount opts))
201 <*> newTVarIO def 202 <*> newTVarIO def
202 <*> (newTVarIO =<< nullSessionTokens) 203 <*> (newTVarIO =<< nullSessionTokens)
@@ -270,9 +271,9 @@ getTable = do
270 var <- asks routingTable 271 var <- asks routingTable
271 liftIO (readMVar var) 272 liftIO (readMVar var)
272 273
273-- FIXME no blocking 274-- | Get id of /this/ node. This value is constant during DHT session.
274getNodeId :: DHT ip NodeId 275getNodeId :: DHT ip NodeId
275getNodeId = thisId <$> getTable 276getNodeId = asks thisNodeId
276 277
277getClosest :: Eq ip => NodeId -> DHT ip [NodeInfo ip] 278getClosest :: Eq ip => NodeId -> DHT ip [NodeInfo ip]
278getClosest nid = do 279getClosest nid = do