summaryrefslogtreecommitdiff
path: root/src/Network/Tox/DHT
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-18 00:49:38 -0400
committerjoe <joe@jerkface.net>2018-06-18 00:49:38 -0400
commit07b1494c9d5c692371c9689a8f78f4cf7ee58732 (patch)
treeaac158efc14bdb210717018704c43f2542804bf8 /src/Network/Tox/DHT
parent6de7e6d299254010ebe2fd3fc5fb7c7fd6c89fc6 (diff)
Tox: Added timestamps to dhtkey and sockaddr information.
Diffstat (limited to 'src/Network/Tox/DHT')
-rw-r--r--src/Network/Tox/DHT/Handlers.hs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/Network/Tox/DHT/Handlers.hs b/src/Network/Tox/DHT/Handlers.hs
index 6a80b4a4..7e986fdd 100644
--- a/src/Network/Tox/DHT/Handlers.hs
+++ b/src/Network/Tox/DHT/Handlers.hs
@@ -117,8 +117,8 @@ classify client msg = fromMaybe (IsUnknown "unknown")
117data NodeInfoCallback = NodeInfoCallback 117data NodeInfoCallback = NodeInfoCallback
118 { interestingNodeId :: NodeId 118 { interestingNodeId :: NodeId
119 , listenerId :: Int 119 , listenerId :: Int
120 , observedAddress :: NodeInfo -> STM () 120 , observedAddress :: POSIXTime -> NodeInfo -> STM ()
121 , rumoredAddress :: SockAddr -> NodeInfo -> STM () 121 , rumoredAddress :: POSIXTime -> SockAddr -> NodeInfo -> STM ()
122 } 122 }
123 123
124data Routing = Routing 124data Routing = Routing
@@ -405,22 +405,24 @@ getNodes client cbvar nid addr = do
405 -- hPutStrLn stderr $ show addr ++ " -sendnodes-> " ++ show reply 405 -- hPutStrLn stderr $ show addr ++ " -sendnodes-> " ++ show reply
406 forM_ (join reply) $ \(SendNodes ns) -> 406 forM_ (join reply) $ \(SendNodes ns) ->
407 forM_ ns $ \n -> do 407 forM_ ns $ \n -> do
408 now <- getPOSIXTime
408 atomically $ do 409 atomically $ do
409 mcbs <- HashMap.lookup (nodeId n) <$> readTVar cbvar 410 mcbs <- HashMap.lookup (nodeId n) <$> readTVar cbvar
410 forM_ mcbs $ \cbs -> do 411 forM_ mcbs $ \cbs -> do
411 forM_ cbs $ \cb -> do 412 forM_ cbs $ \cb -> do
412 rumoredAddress cb (nodeAddr addr) n 413 rumoredAddress cb now (nodeAddr addr) n
413 return $ fmap unwrapNodes $ join reply 414 return $ fmap unwrapNodes $ join reply
414 415
415updateRouting :: Client -> Routing -> OnionRouter -> NodeInfo -> Message -> IO () 416updateRouting :: Client -> Routing -> OnionRouter -> NodeInfo -> Message -> IO ()
416updateRouting client routing orouter naddr msg 417updateRouting client routing orouter naddr msg
417 | PacketKind 0x21 <- msgType msg = dput XLan "(tox)updateRouting: ignoring lan discovery" -- ignore lan discovery 418 | PacketKind 0x21 <- msgType msg = dput XLan "(tox)updateRouting: ignoring lan discovery" -- ignore lan discovery
418 | otherwise = do 419 | otherwise = do
420 now <- getPOSIXTime
419 atomically $ do 421 atomically $ do
420 m <- HashMap.lookup (nodeId naddr) <$> readTVar (nodesOfInterest routing) 422 m <- HashMap.lookup (nodeId naddr) <$> readTVar (nodesOfInterest routing)
421 forM_ m $ mapM_ $ \NodeInfoCallback{interestingNodeId,observedAddress} -> do 423 forM_ m $ mapM_ $ \NodeInfoCallback{interestingNodeId,observedAddress} -> do
422 when (interestingNodeId == nodeId naddr) 424 when (interestingNodeId == nodeId naddr)
423 $ observedAddress naddr 425 $ observedAddress now naddr
424 case prefer4or6 naddr Nothing of 426 case prefer4or6 naddr Nothing of
425 Want_IP4 -> updateTable client naddr orouter (committee4 routing) (refresher4 routing) 427 Want_IP4 -> updateTable client naddr orouter (committee4 routing) (refresher4 routing)
426 Want_IP6 -> updateTable client naddr orouter (committee6 routing) (refresher6 routing) 428 Want_IP6 -> updateTable client naddr orouter (committee6 routing) (refresher6 routing)