summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/DHT/Query.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/DHT/Query.hs')
-rw-r--r--src/Network/BitTorrent/DHT/Query.hs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/Network/BitTorrent/DHT/Query.hs b/src/Network/BitTorrent/DHT/Query.hs
index e067ab52..44083d81 100644
--- a/src/Network/BitTorrent/DHT/Query.hs
+++ b/src/Network/BitTorrent/DHT/Query.hs
@@ -232,7 +232,7 @@ refreshNodes nid = do
232 232
233-- | This operation do not block but acquire exclusive access to 233-- | This operation do not block but acquire exclusive access to
234-- routing table. 234-- routing table.
235insertNode :: Address ip => NodeInfo ip -> Maybe ReflectedIP -> DHT ip ThreadId 235insertNode :: forall ip. Address ip => NodeInfo ip -> Maybe ReflectedIP -> DHT ip ThreadId
236insertNode info witnessed_ip0 = fork $ do 236insertNode info witnessed_ip0 = fork $ do
237 var <- asks routingInfo 237 var <- asks routingInfo
238 tm <- getTimestamp 238 tm <- getTimestamp
@@ -247,23 +247,24 @@ insertNode info witnessed_ip0 = fork $ do
247 fallbackid <- asks tentativeNodeId 247 fallbackid <- asks tentativeNodeId
248 let atomicInsert arrival witnessed_ip = do 248 let atomicInsert arrival witnessed_ip = do
249 minfo <- readTVar var 249 minfo <- readTVar var
250 let change ip = fromMaybe fallbackid 250 let change ip0 = fromMaybe fallbackid $ do
251 $ listToMaybe 251 ip <- fromSockAddr ip0 :: Maybe ip
252 $ rank id (nodeId $ foreignNode arrival) 252 listToMaybe
253 $ bep42s ip fallbackid 253 $ rank id (nodeId $ foreignNode arrival)
254 $ bep42s ip fallbackid
254 case minfo of 255 case minfo of
255 Just inf -> do 256 Just inf -> do
256 (ps,t') <- R.insert tm arrival $ myBuckets inf 257 (ps,t') <- R.insert tm arrival $ myBuckets inf
257 writeTVar var $ Just $ inf { myBuckets = t' } 258 writeTVar var $ Just $ inf { myBuckets = t' }
258 return $ do 259 return $ do
259 case witnessed_ip of 260 case witnessed_ip of
260 Just (ReflectedIP ip0) 261 Just (ReflectedIP ip)
261 | fromSockAddr ip0 /= Just (myAddress inf) 262 | ip /= myAddress inf
262 -> $(logInfo) ( T.pack $ L.unwords 263 -> $(logInfo) ( T.pack $ L.unwords
263 $ [ "Possible NAT?" 264 $ [ "Possible NAT?"
264 , show (toSockAddr $ nodeAddr $ foreignNode arrival) 265 , show (toSockAddr $ nodeAddr $ foreignNode arrival)
265 , "reports my address:" 266 , "reports my address:"
266 , show ip0 ] ) 267 , show ip ] )
267 -- TODO: Let routing table vote on my IP/NodeId. 268 -- TODO: Let routing table vote on my IP/NodeId.
268 _ -> return () 269 _ -> return ()
269 return ps 270 return ps
@@ -275,8 +276,7 @@ insertNode info witnessed_ip0 = fork $ do
275 <> T.pack (show (toSockAddr $ nodeAddr $ foreignNode arrival))) 276 <> T.pack (show (toSockAddr $ nodeAddr $ foreignNode arrival)))
276 return [] 277 return []
277 in fromMaybe dropped $ do 278 in fromMaybe dropped $ do
278 ReflectedIP ip0 <- witnessed_ip 279 ReflectedIP ip <- witnessed_ip
279 ip <- fromSockAddr ip0
280 let nil = nullTable (change ip) maxbuckets 280 let nil = nullTable (change ip) maxbuckets
281 return $ do 281 return $ do
282 (ps,t') <- R.insert tm arrival nil 282 (ps,t') <- R.insert tm arrival nil
@@ -285,7 +285,7 @@ insertNode info witnessed_ip0 = fork $ do
285 return $ do 285 return $ do
286 $(logInfo) ( T.pack $ L.unwords 286 $(logInfo) ( T.pack $ L.unwords
287 [ "External IP address:" 287 [ "External IP address:"
288 , show ip0 288 , show ip
289 , "(reported by" 289 , "(reported by"
290 , show (toSockAddr $ nodeAddr $ foreignNode arrival) 290 , show (toSockAddr $ nodeAddr $ foreignNode arrival)
291 <> ")" 291 <> ")"