From d2e220c86325b55e22409b1a7da12b06a8052e76 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sat, 25 Jan 2020 04:45:19 -0500 Subject: Received DHT-key: Try our relays too (not just theirs). --- dht/ToxManager.hs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/dht/ToxManager.hs b/dht/ToxManager.hs index 19db77ec..545dbd6c 100644 --- a/dht/ToxManager.hs +++ b/dht/ToxManager.hs @@ -52,7 +52,8 @@ import Network.Tox.NodeId import qualified Network.Tox.Onion.Handlers as Tox import qualified Network.Tox.Onion.Transport as Tox ;import Network.Tox.Onion.Transport (OnionData (..)) -import Network.Tox.Onion.Routes (tcpKademliaClient,tcpBucketRefresher) +import Network.Tox.Onion.Routes (tcpKademliaClient,tcpBucketRefresher,tcpRelayPinger) +import Network.Tox.RelayPinger import qualified Network.Tox.TCP as TCP import Presence import Text.Read @@ -136,7 +137,6 @@ toxman ssvar announcer tox presence = ToxManager forkIO $ do accountWatcher ssvar - (TCP.tcpClient $ tcpKademliaClient $ toxOnionRoutes tox) acnt tox presence @@ -267,6 +267,7 @@ data ToxToXMPP = ToxToXMPP , txTox :: Tox JabberClients , txSessions :: TVar (Map.Map Uniq24 AggregateSession) , txTCP :: TCP.RelayClient + , txRelayPinger :: RelayPinger } default_nospam :: Word32 @@ -310,13 +311,16 @@ connectViaRelay tx theirKey theirDhtKey ann tkey now = do me = key2id myPublicKey tkey = akeyConnectTCP (txAnnouncer tx) me theirKey go ns = do + (_,relays) <- atomically $ currentRelays (txRelayPinger tx) + let ns' = ns ++ relays + oobs = [ Multi.TCP ==> TCP.ViaRelay Nothing (Tox.key2id $ Tox.dhtpk theirDhtKey) ni | ni <- ns' ] mapM_ (TCP.sendConnectionRequest (txTCP tx) $ Tox.dhtpk theirDhtKey) - (filter ((/= 0) . TCP.tcpPort) ns) - let oobs = [ Multi.TCP ==> TCP.ViaRelay Nothing (Tox.key2id $ Tox.dhtpk theirDhtKey) ni | ni <- ns ] + (filter ((/= 0) . TCP.tcpPort) ns') + -- currentRelays :: RelayPinger -> STM (Int,[TCP.NodeInfo]) dput XMan $ "connectViaRelay: address count is " ++ show (length oobs) forM_ oobs $ \ni -> do cookieRequest (toxCryptoKeys $ txTox tx) (toxDHT $ txTox tx) myPublicKey ni >>= \case - Nothing -> dput XMan $ "connectViaRelay: no cookie from " ++ show ni + Nothing -> dput XMan $ "connectViaRelay: no cookie from " ++ Multi.summarizeNodeInfo ni Just cookie -> do cookieCreationStamp <- getPOSIXTime let their_nid = key2id $ dhtpk theirDhtKey @@ -648,7 +652,6 @@ startConnecting0 tx them contact reason = do onResult theirkey rendezvous = do mTheirDHTKey <- atomically $ fmap ((,) (txTCP tx)) <$> contactDHTKey contact dkey <- Tox.getContactInfo mTheirDHTKey tox - let tr = Tox.toxToRoute tox route = Tox.AnnouncedRendezvous theirkey rendezvous dput XMan $ unwords [ take 8 (show $ key2id theirkey) @@ -708,10 +711,11 @@ closeSessions me them ssvar = do closeAll ag accountWatcher :: TVar (Map.Map Uniq24 AggregateSession) - -> TCP.RelayClient -> Account JabberClients -> Tox JabberClients -> PresenceState Pending -> Announcer -> IO () -accountWatcher ssvar tcp acc tox st announcer = do +accountWatcher ssvar acc tox st announcer = do let me = key2id $ toPublic $ userSecret acc + tcp = TCP.tcpClient $ tcpKademliaClient $ toxOnionRoutes tox + pinger = tcpRelayPinger $ toxOnionRoutes tox dput XMan $ "accountWatcher(" ++ show me ++") started" myThreadId >>= flip labelThread ("online:" ++ show (key2id $ toPublic $ userSecret acc)) @@ -725,6 +729,7 @@ accountWatcher ssvar tcp acc tox st announcer = do , txTox = tox , txSessions = ssvar , txTCP = tcp + , txRelayPinger = pinger } forM_ (HashMap.toList cs) $ \(them,c) -> do startConnecting0 tx (id2key them) c "enabled account" -- cgit v1.2.3