diff options
author | Joe Crayne <joe@jerkface.net> | 2019-12-22 12:05:26 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-01 23:28:00 -0500 |
commit | 46c096abcb269407b0927587520dda644aca9b51 (patch) | |
tree | c9dd2dc67261bae09f49c2ce15c6e9f6e155b4e3 | |
parent | af2d131e01fed76205c2c0c32a2f29bab8cceb84 (diff) |
WIP: fixing TCP relay chat.
-rw-r--r-- | dht/ToxManager.hs | 16 |
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] | |||
276 | cycled [] = [] | 276 | cycled [] = [] |
277 | cycled (x:xs) = xs ++ [x] | 277 | cycled (x:xs) = xs ++ [x] |
278 | 278 | ||
279 | -- Notes: | ||
280 | -- send cookieRequest OOB | ||
281 | -- request relay session | ||
282 | -- send handshake OOB | ||
279 | connectViaRelay :: ToxToXMPP -> PublicKey -> Tox.DHTPublicKey | 283 | connectViaRelay :: ToxToXMPP -> PublicKey -> Tox.DHTPublicKey |
280 | -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ()) | 284 | -> Announcer -> AnnounceKey -> POSIXTime -> STM (IO ()) |
281 | connectViaRelay tx theirKey theirDhtKey ann tkey now = do | 285 | connectViaRelay 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 | ||
670 | startConnecting :: ToxToXMPP -> PublicKey -> String -> IO () | 677 | startConnecting :: 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 | ||
746 | statusLogic :: Status ToxProgress -> Policy -> Maybe dhtkey -> Maybe addr -> Bool -> Status ToxProgress | 754 | statusLogic :: Status ToxProgress -> Policy -> Maybe dhtkey -> Maybe addr -> Bool -> Status ToxProgress |
747 | statusLogic astat policy mdht maddr cookieIsPending = case () of | 755 | statusLogic astat policy mdht maddr cookieIsPending = case () of |
748 | () | Established <- astat -> Established | 756 | () | Established <- astat -> Established |