diff options
author | joe <joe@jerkface.net> | 2017-01-22 01:22:18 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-01-22 01:22:18 -0500 |
commit | aab30811698a3b97173043e56e97f46cd3a91776 (patch) | |
tree | 1ddf1e98538e420dce12780bdca173fb879ad725 /src/Network/BitTorrent/DHT | |
parent | 21e1fdde98a2e263bf8dfc34a2545b0635e358c8 (diff) |
Store external port number, as well as IP.
Diffstat (limited to 'src/Network/BitTorrent/DHT')
-rw-r--r-- | src/Network/BitTorrent/DHT/Query.hs | 22 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Routing.hs | 4 | ||||
-rw-r--r-- | src/Network/BitTorrent/DHT/Session.hs | 2 |
3 files changed, 14 insertions, 14 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. |
235 | insertNode :: Address ip => NodeInfo ip -> Maybe ReflectedIP -> DHT ip ThreadId | 235 | insertNode :: forall ip. Address ip => NodeInfo ip -> Maybe ReflectedIP -> DHT ip ThreadId |
236 | insertNode info witnessed_ip0 = fork $ do | 236 | insertNode 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 | <> ")" |
diff --git a/src/Network/BitTorrent/DHT/Routing.hs b/src/Network/BitTorrent/DHT/Routing.hs index f9d64eea..c230929e 100644 --- a/src/Network/BitTorrent/DHT/Routing.hs +++ b/src/Network/BitTorrent/DHT/Routing.hs | |||
@@ -327,11 +327,11 @@ defaultBucketCount = 20 | |||
327 | data Info ip = Info | 327 | data Info ip = Info |
328 | { myBuckets :: Table ip | 328 | { myBuckets :: Table ip |
329 | , myNodeId :: NodeId | 329 | , myNodeId :: NodeId |
330 | , myAddress :: ip | 330 | , myAddress :: SockAddr |
331 | } | 331 | } |
332 | deriving (Eq, Show, Generic) | 332 | deriving (Eq, Show, Generic) |
333 | 333 | ||
334 | instance (Eq ip, Serialize ip) => Serialize (Info ip) | 334 | -- instance (Eq ip, Serialize ip) => Serialize (Info ip) |
335 | 335 | ||
336 | -- | The routing table covers the entire 'NodeId' space from 0 to 2 ^ | 336 | -- | The routing table covers the entire 'NodeId' space from 0 to 2 ^ |
337 | -- 160. The routing table is subdivided into 'Bucket's that each cover | 337 | -- 160. The routing table is subdivided into 'Bucket's that each cover |
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs index c8545bfd..b85e97fa 100644 --- a/src/Network/BitTorrent/DHT/Session.hs +++ b/src/Network/BitTorrent/DHT/Session.hs | |||
@@ -373,7 +373,7 @@ checkToken addr questionableToken = do | |||
373 | -----------------------------------------------------------------------} | 373 | -----------------------------------------------------------------------} |
374 | 374 | ||
375 | -- | This nodes externally routable address reported by remote peers. | 375 | -- | This nodes externally routable address reported by remote peers. |
376 | routableAddress :: DHT ip (Maybe ip) | 376 | routableAddress :: DHT ip (Maybe SockAddr) |
377 | routableAddress = do | 377 | routableAddress = do |
378 | info <- asks routingInfo >>= liftIO . atomically . readTVar | 378 | info <- asks routingInfo >>= liftIO . atomically . readTVar |
379 | return $ myAddress <$> info | 379 | return $ myAddress <$> info |