summaryrefslogtreecommitdiff
path: root/dht/src/Network/Tox/DHT
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-12-19 16:49:18 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 23:27:24 -0500
commit89c516018e51c4f15ace02d974a7a959f8c219a9 (patch)
tree5b6a0ad4adbe4d36c0230370697b41bae3ddab0c /dht/src/Network/Tox/DHT
parentffaae666cf69e7555d0f47324d0afabc0347829c (diff)
Minor refactor.
Diffstat (limited to 'dht/src/Network/Tox/DHT')
-rw-r--r--dht/src/Network/Tox/DHT/Handlers.hs27
1 files changed, 15 insertions, 12 deletions
diff --git a/dht/src/Network/Tox/DHT/Handlers.hs b/dht/src/Network/Tox/DHT/Handlers.hs
index 5156ec44..73bc2229 100644
--- a/dht/src/Network/Tox/DHT/Handlers.hs
+++ b/dht/src/Network/Tox/DHT/Handlers.hs
@@ -445,30 +445,33 @@ updateRouting client routing orouter naddr0 msg
445 forM_ m $ mapM_ $ \NodeInfoCallback{interestingNodeId,observedAddress} -> do 445 forM_ m $ mapM_ $ \NodeInfoCallback{interestingNodeId,observedAddress} -> do
446 when (interestingNodeId == nodeId naddr) 446 when (interestingNodeId == nodeId naddr)
447 $ observedAddress now naddr 447 $ observedAddress now naddr
448 case prefer4or6 (Multi.UDP ==> naddr) Nothing of 448 updateTable client routing orouter naddr
449 Want_IP4 -> updateTable client naddr orouter (committee4 routing) (refresher4 routing)
450 Want_IP6 -> updateTable client naddr orouter (committee6 routing) (refresher6 routing)
451 Want_Both -> do dput XMisc "BUG:unreachable"
452 error $ "BUG:unreachable at " ++ __FILE__ ++ ":" ++ show __LINE__
453 449
454updateTable :: Client -> NodeInfo 450updateTable :: Client -> Routing
455 -> (TVar (R.BucketList NodeInfo) -> RoutingTransition NodeInfo -> STM ()) 451 -> (TVar (R.BucketList NodeInfo) -> RoutingTransition NodeInfo -> STM ())
456 -> TriadCommittee NodeId SockAddr 452 -> NodeInfo
457 -> BucketRefresher NodeId NodeInfo
458 -> IO () 453 -> IO ()
459updateTable client naddr orouter committee refresher = do 454updateTable client routing orouter naddr = do
455 case prefer4or6 (Multi.UDP ==> naddr) Nothing of
456 Want_IP4 -> go (committee4 routing) (refresher4 routing)
457 Want_IP6 -> go (committee6 routing) (refresher6 routing)
458 Want_Both -> do dput XMisc "BUG:unreachable"
459 error $ "BUG:unreachable at " ++ __FILE__ ++ ":" ++ show __LINE__
460 where
461 go :: TriadCommittee NodeId SockAddr -> BucketRefresher NodeId NodeInfo -> IO ()
462 go committee refresher = do
460 self <- atomically $ R.thisNode <$> readTVar (refreshBuckets refresher) 463 self <- atomically $ R.thisNode <$> readTVar (refreshBuckets refresher)
461 -- dput XMisc $ "(tox)updateRouting: " ++ show (nodeIP self, nodeIP naddr) 464 -- dput XMisc $ "(tox)updateRouting: " ++ show (nodeIP self, nodeIP naddr)
462 when (self /= naddr) $ do 465 when (self /= naddr) $ do
463 -- TODO: IP address vote? 466 -- TODO: IP address vote?
464 insertNode (toxKademlia client committee orouter refresher) naddr 467 insertNode (toxKademlia client orouter committee refresher) naddr
465 468
466toxKademlia :: Client 469toxKademlia :: Client
467 -> TriadCommittee NodeId SockAddr
468 -> (TVar (R.BucketList NodeInfo) -> RoutingTransition NodeInfo -> STM ()) 470 -> (TVar (R.BucketList NodeInfo) -> RoutingTransition NodeInfo -> STM ())
471 -> TriadCommittee NodeId SockAddr
469 -> BucketRefresher NodeId NodeInfo 472 -> BucketRefresher NodeId NodeInfo
470 -> Kademlia NodeId NodeInfo 473 -> Kademlia NodeId NodeInfo
471toxKademlia client committee orouter refresher 474toxKademlia client orouter committee refresher
472 = Kademlia quietInsertions 475 = Kademlia quietInsertions
473 toxSpace 476 toxSpace
474 (vanillaIO (refreshBuckets refresher) $ pingUDP client) 477 (vanillaIO (refreshBuckets refresher) $ pingUDP client)