From 46c096abcb269407b0927587520dda644aca9b51 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Sun, 22 Dec 2019 12:05:26 -0500 Subject: WIP: fixing TCP relay chat. --- dht/ToxManager.hs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dht/ToxManager.hs b/dht/ToxManager.hs index 0363f7f0..f5a8fd15 100644 --- a/dht/ToxManager.hs +++ b/dht/ToxManager.hs @@ -276,6 +276,10 @@ cycled :: [x] -> [x] cycled [] = [] cycled (x:xs) = xs ++ [x] +-- Notes: +-- send cookieRequest OOB +-- request relay session +-- send handshake OOB connectViaRelay :: ToxToXMPP -> PublicKey -> Tox.DHTPublicKey -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ()) connectViaRelay tx theirKey theirDhtKey ann tkey now = do @@ -291,10 +295,11 @@ connectViaRelay tx theirKey theirDhtKey ann tkey now = do tkey = akeyConnectTCP (txAnnouncer tx) me theirKey go = do let Tox.SendNodes ns = Tox.dhtpkNodes theirDhtKey - mcon <- foldr (\action next -> action >>= maybe next (return . Just)) - (return Nothing) - $ map (Multi.tcpConnectionRequest (txTCP tx) theirKey) ns - forM_ mcon $ \ni -> do + mcons <- forM ns $ \ni -> do + mcon <- Multi.tcpConnectionRequest (txTCP tx) (Tox.dhtpk theirDhtKey) ni + return mcon + let oobs = [ Multi.TCP ==> TCP.ViaRelay Nothing (Tox.key2id $ Tox.dhtpk theirDhtKey) ni | ni <- ns ] + forM_ (catMaybes mcons ++ oobs) $ \ni -> do cookieRequest (toxCryptoKeys $ txTox tx) (toxDHT $ txTox tx) myPublicKey ni >>= \case Nothing -> return () Just cookie -> do @@ -665,6 +670,8 @@ startConnecting0 tx them contact reason = do , friendRequestText = "XMPP friend request" } sendMessage tr route (mypub,Tox.OnionFriendRequest fr) + -- Seearch for friend's tox-id rendezvous and use the results to + -- send our dht key. scheduleSearch announcer akey meth them startConnecting :: ToxToXMPP -> PublicKey -> String -> IO () @@ -743,6 +750,7 @@ getStatus me them a c hs = do cookieIsPending <- getPendingCookieFlag hs me them return $ statusLogic astat policy mdht maddr cookieIsPending +-- TODO: recognize TCP status statusLogic :: Status ToxProgress -> Policy -> Maybe dhtkey -> Maybe addr -> Bool -> Status ToxProgress statusLogic astat policy mdht maddr cookieIsPending = case () of () | Established <- astat -> Established -- cgit v1.2.3