From c3866287f929e153a00293d3c548b26c7e910b9b Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 12 Jan 2020 22:57:39 -0500 Subject: Configure connection requests before having contact's dhtkey. --- dht/ToxManager.hs | 2 +- dht/examples/dhtd.hs | 6 +++++- dht/src/Network/Tox.hs | 12 ++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dht/ToxManager.hs b/dht/ToxManager.hs index 4d8910e2..dd8f5940 100644 --- a/dht/ToxManager.hs +++ b/dht/ToxManager.hs @@ -646,7 +646,7 @@ startConnecting0 tx them contact reason = do let meth = SearchMethod (toxQSearch tox) onResult (nearNodes tox) (key2id them) 30 where onResult theirkey rendezvous = do - dkey <- Tox.getContactInfo tox + dkey <- Tox.getContactInfo (Just (txTCP tx,them)) tox let tr = Tox.toxToRoute tox route = Tox.AnnouncedRendezvous theirkey rendezvous dput XMan $ unwords [ take 8 (show $ key2id theirkey) diff --git a/dht/examples/dhtd.hs b/dht/examples/dhtd.hs index c36508ef..d7c817ca 100644 --- a/dht/examples/dhtd.hs +++ b/dht/examples/dhtd.hs @@ -1581,7 +1581,11 @@ initTox runio opts ssvar keysdb mbxmpp invc = case porttox opts of -- -- > a +dhtkey KWoEx1XQHrluIoW.3nK6BFb6XCebKWr3nDDt3V7CcoJ , ("dhtkey", DHTAnnouncable { announceSendData = Left ("toxid", readEither, \me them addr -> do - dkey <- Tox.getContactInfo tox + -- let mthem = Just ( TCP.tcpClient + -- $ tcpKademliaClient + -- $ toxOnionRoutes tox + -- , them ) + dkey <- Tox.getContactInfo Nothing tox sendMessage (Tox.toxToRoute tox) (Tox.AnnouncedRendezvous them addr) diff --git a/dht/src/Network/Tox.hs b/dht/src/Network/Tox.hs index f136ab96..fca0f9e0 100644 --- a/dht/src/Network/Tox.hs +++ b/dht/src/Network/Tox.hs @@ -72,7 +72,7 @@ import qualified Network.Tox.Onion.Transport as Onion import Network.Tox.RelayPinger import System.Global6 import Network.Tox.Transport -import Network.Tox.TCP (tcpClient) +import Network.Tox.TCP (tcpClient, RelayClient) import Network.Tox.Onion.Routes import Network.Tox.ContactInfo import Text.XXD @@ -199,8 +199,8 @@ data Tox extra = Tox -- | Create a DHTPublicKey packet to send to a remote contact. -getContactInfo :: Tox extra -> IO DHT.DHTPublicKey -getContactInfo Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically $ do +getContactInfo :: Maybe (RelayClient,PublicKey) -> Tox extra -> IO DHT.DHTPublicKey +getContactInfo mthem Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically $ do (rcnt,relays) <- currentRelays (tcpRelayPinger toxOnionRoutes) r4 <- readTVar $ DHT.routing4 toxRouting r6 <- readTVar $ DHT.routing6 toxRouting @@ -212,12 +212,16 @@ getContactInfo Tox{toxCryptoKeys,toxRouting,toxOnionRoutes} = join $ atomically n6s = R.kclosest DHT.toxSpace 4 self r6 ns = filter (DHT.isGlobal . nodeIP) [n4,n6] ++ concat (zipWith (\a b -> [a,b]) n4s n6s) + sending_ns = take 4 $ relays ++ map TCP.fromUDPNode ns return $ do + forM_ mthem $ \(tcp,them) -> + forM_ (filter (\n -> TCP.tcpPort n /= 0) sending_ns) $ \ni -> do + Multi.tcpConnectionRequest tcp them ni timestamp <- round . (* 1000000) <$> getPOSIXTime return DHT.DHTPublicKey { dhtpkNonce = timestamp , dhtpk = id2key self - , dhtpkNodes = DHT.SendNodes $ take 4 $ relays ++ map TCP.fromUDPNode ns + , dhtpkNodes = DHT.SendNodes sending_ns } isLocalHost :: SockAddr -> Bool -- cgit v1.2.3