summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-12-22 12:05:26 -0500
committerJoe Crayne <joe@jerkface.net>2020-01-01 23:28:00 -0500
commit46c096abcb269407b0927587520dda644aca9b51 (patch)
treec9dd2dc67261bae09f49c2ce15c6e9f6e155b4e3
parentaf2d131e01fed76205c2c0c32a2f29bab8cceb84 (diff)
WIP: fixing TCP relay chat.
-rw-r--r--dht/ToxManager.hs16
1 files 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]
276cycled [] = [] 276cycled [] = []
277cycled (x:xs) = xs ++ [x] 277cycled (x:xs) = xs ++ [x]
278 278
279-- Notes:
280-- send cookieRequest OOB
281-- request relay session
282-- send handshake OOB
279connectViaRelay :: ToxToXMPP -> PublicKey -> Tox.DHTPublicKey 283connectViaRelay :: ToxToXMPP -> PublicKey -> Tox.DHTPublicKey
280 -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ()) 284 -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ())
281connectViaRelay tx theirKey theirDhtKey ann tkey now = do 285connectViaRelay tx theirKey theirDhtKey ann tkey now = do
@@ -291,10 +295,11 @@ connectViaRelay tx theirKey theirDhtKey ann tkey now = do
291 tkey = akeyConnectTCP (txAnnouncer tx) me theirKey 295 tkey = akeyConnectTCP (txAnnouncer tx) me theirKey
292 go = do 296 go = do
293 let Tox.SendNodes ns = Tox.dhtpkNodes theirDhtKey 297 let Tox.SendNodes ns = Tox.dhtpkNodes theirDhtKey
294 mcon <- foldr (\action next -> action >>= maybe next (return . Just)) 298 mcons <- forM ns $ \ni -> do
295 (return Nothing) 299 mcon <- Multi.tcpConnectionRequest (txTCP tx) (Tox.dhtpk theirDhtKey) ni
296 $ map (Multi.tcpConnectionRequest (txTCP tx) theirKey) ns 300 return mcon
297 forM_ mcon $ \ni -> do 301 let oobs = [ Multi.TCP ==> TCP.ViaRelay Nothing (Tox.key2id $ Tox.dhtpk theirDhtKey) ni | ni <- ns ]
302 forM_ (catMaybes mcons ++ oobs) $ \ni -> do
298 cookieRequest (toxCryptoKeys $ txTox tx) (toxDHT $ txTox tx) myPublicKey ni >>= \case 303 cookieRequest (toxCryptoKeys $ txTox tx) (toxDHT $ txTox tx) myPublicKey ni >>= \case
299 Nothing -> return () 304 Nothing -> return ()
300 Just cookie -> do 305 Just cookie -> do
@@ -665,6 +670,8 @@ startConnecting0 tx them contact reason = do
665 , friendRequestText = "XMPP friend request" 670 , friendRequestText = "XMPP friend request"
666 } 671 }
667 sendMessage tr route (mypub,Tox.OnionFriendRequest fr) 672 sendMessage tr route (mypub,Tox.OnionFriendRequest fr)
673 -- Seearch for friend's tox-id rendezvous and use the results to
674 -- send our dht key.
668 scheduleSearch announcer akey meth them 675 scheduleSearch announcer akey meth them
669 676
670startConnecting :: ToxToXMPP -> PublicKey -> String -> IO () 677startConnecting :: ToxToXMPP -> PublicKey -> String -> IO ()
@@ -743,6 +750,7 @@ getStatus me them a c hs = do
743 cookieIsPending <- getPendingCookieFlag hs me them 750 cookieIsPending <- getPendingCookieFlag hs me them
744 return $ statusLogic astat policy mdht maddr cookieIsPending 751 return $ statusLogic astat policy mdht maddr cookieIsPending
745 752
753-- TODO: recognize TCP status
746statusLogic :: Status ToxProgress -> Policy -> Maybe dhtkey -> Maybe addr -> Bool -> Status ToxProgress 754statusLogic :: Status ToxProgress -> Policy -> Maybe dhtkey -> Maybe addr -> Bool -> Status ToxProgress
747statusLogic astat policy mdht maddr cookieIsPending = case () of 755statusLogic astat policy mdht maddr cookieIsPending = case () of
748 () | Established <- astat -> Established 756 () | Established <- astat -> Established