summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-12-20 01:07:27 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 23:27:24 -0500
commit6863cc64e606dd753d57aa1a124584bcb4416de4 (patch)
tree23076a5d547e33721fdd02320c743b9912c9c644
parent3a03ba64a8d60708a43959cb0a5d97056afe056e (diff)
Use tcp table as fallback nodes for onion search.
-rw-r--r--dht/ToxManager.hs23
-rw-r--r--dht/src/Network/Tox/TCP.hs2
2 files changed, 18 insertions, 7 deletions
diff --git a/dht/ToxManager.hs b/dht/ToxManager.hs
index 403167c2..0363f7f0 100644
--- a/dht/ToxManager.hs
+++ b/dht/ToxManager.hs
@@ -35,6 +35,7 @@ import DebugTag
35import Foreign.Storable 35import Foreign.Storable
36import HandshakeCache 36import HandshakeCache
37import Network.Address 37import Network.Address
38import Network.Kademlia.Bootstrap
38import qualified Network.Kademlia.Routing as R 39import qualified Network.Kademlia.Routing as R
39 ;import Network.Kademlia.Routing as R 40 ;import Network.Kademlia.Routing as R
40import Network.Kademlia.Search 41import Network.Kademlia.Search
@@ -51,7 +52,7 @@ import Network.Tox.NodeId
51import qualified Network.Tox.Onion.Handlers as Tox 52import qualified Network.Tox.Onion.Handlers as Tox
52import qualified Network.Tox.Onion.Transport as Tox 53import qualified Network.Tox.Onion.Transport as Tox
53 ;import Network.Tox.Onion.Transport (OnionData (..)) 54 ;import Network.Tox.Onion.Transport (OnionData (..))
54import Network.Tox.Onion.Routes (tcpKademliaClient) 55import Network.Tox.Onion.Routes (tcpKademliaClient,tcpBucketRefresher)
55import qualified Network.Tox.TCP as TCP 56import qualified Network.Tox.TCP as TCP
56import Presence 57import Presence
57import Text.Read 58import Text.Read
@@ -310,6 +311,11 @@ connectViaRelay tx theirKey theirDhtKey ann tkey now = do
310 311
311gotDhtPubkey :: Tox.DHTPublicKey -> ToxToXMPP -> PublicKey -> IO () 312gotDhtPubkey :: Tox.DHTPublicKey -> ToxToXMPP -> PublicKey -> IO ()
312gotDhtPubkey theirDhtKey tx theirKey = do 313gotDhtPubkey theirDhtKey tx theirKey = do
314 dput XNetCrypto $ unlines $
315 [ "Recieved DHTKey from " ++ show (Tox.key2id theirKey)
316 , " DHT: " ++ show target
317 ] ++ let Tox.SendNodes ns = Tox.dhtpkNodes theirDhtKey
318 in [ " relay " ++ show n | n <- ns ]
313 contact <- atomically $ getContact theirKey (txAccount tx) >>= mapM (readTVar . contactLastSeenAddr) 319 contact <- atomically $ getContact theirKey (txAccount tx) >>= mapM (readTVar . contactLastSeenAddr)
314 forM_ contact $ \lastSeen -> do 320 forM_ contact $ \lastSeen -> do
315 case lastSeen of 321 case lastSeen of
@@ -591,13 +597,18 @@ checkSoliciting presence me them contact = do
591 597
592nearNodes :: Tox extra -> NodeId -> STM [NodeInfo] 598nearNodes :: Tox extra -> NodeId -> STM [NodeInfo]
593nearNodes tox nid = do 599nearNodes tox nid = do
600 let refresher = tcpBucketRefresher $ toxOnionRoutes tox
594 bkts4 <- readTVar $ routing4 $ toxRouting tox 601 bkts4 <- readTVar $ routing4 $ toxRouting tox
595 bkts6 <- readTVar $ routing6 $ toxRouting tox 602 bkts6 <- readTVar $ routing6 $ toxRouting tox
596 let nss = 603 bktsTCP <- readTVar $ refreshBuckets refresher
597 map 604 let udpSpace = searchSpace $ toxQSearch tox
598 (R.kclosest (searchSpace $ toxQSearch tox) (searchK $ toxQSearch tox) nid) 605 k = searchK $ toxQSearch tox
599 [bkts4, bkts6] 606 nss = map (R.kclosest udpSpace k nid) [bkts4, bkts6]
600 return $ foldr interweave [] nss 607 ns_UDP = foldr interweave [] nss
608 ns_TCP = case refresher of
609 BucketRefresher{refreshSearch=sch}
610 -> R.kclosest (searchSpace sch) k nid bktsTCP
611 return $ ns_UDP ++ map TCP.udpNodeInfo ns_TCP
601 612
602startConnecting0 :: ToxToXMPP -> PublicKey -> Contact -> String -> IO () 613startConnecting0 :: ToxToXMPP -> PublicKey -> Contact -> String -> IO ()
603startConnecting0 tx them contact reason = do 614startConnecting0 tx them contact reason = do
diff --git a/dht/src/Network/Tox/TCP.hs b/dht/src/Network/Tox/TCP.hs
index 04119164..9f0af976 100644
--- a/dht/src/Network/Tox/TCP.hs
+++ b/dht/src/Network/Tox/TCP.hs
@@ -349,7 +349,7 @@ newClient crypto store load lookupSender getRoute = do
349 OOBRecv k bs -> IsUnsolicited $ handleOOB k bs 349 OOBRecv k bs -> IsUnsolicited $ handleOOB k bs
350 wut -> IsUnknown (show wut) 350 wut -> IsUnknown (show wut)
351 , lookupHandler = \case 351 , lookupHandler = \case
352 PingPacket -> trace ("tcp-received-ping") $ Just MethodHandler 352 PingPacket -> Just MethodHandler
353 { methodParse = \case (_,RelayPing n8) -> Right () 353 { methodParse = \case (_,RelayPing n8) -> Right ()
354 _ -> trace ("tcp-non-ping") $ Left "TCP: Non-ping?" 354 _ -> trace ("tcp-non-ping") $ Left "TCP: Non-ping?"
355 , methodSerialize = \n8 src dst () -> {- trace ("tcp-made-pong-"++show n8) -} (False, RelayPong n8) 355 , methodSerialize = \n8 src dst () -> {- trace ("tcp-made-pong-"++show n8) -} (False, RelayPong n8)