diff options
author | Joe Crayne <joe@jerkface.net> | 2020-01-25 04:45:19 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2020-01-25 19:18:12 -0500 |
commit | d2e220c86325b55e22409b1a7da12b06a8052e76 (patch) | |
tree | 061bc4d7d97135b9890e75d16683533201295c0e /dht/ToxManager.hs | |
parent | c20841ec96a8432d74c111db0a88b7437395b532 (diff) |
Received DHT-key: Try our relays too (not just theirs).
Diffstat (limited to 'dht/ToxManager.hs')
-rw-r--r-- | dht/ToxManager.hs | 21 |
1 files 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 | |||
52 | import qualified Network.Tox.Onion.Handlers as Tox | 52 | import qualified Network.Tox.Onion.Handlers as Tox |
53 | import qualified Network.Tox.Onion.Transport as Tox | 53 | import qualified Network.Tox.Onion.Transport as Tox |
54 | ;import Network.Tox.Onion.Transport (OnionData (..)) | 54 | ;import Network.Tox.Onion.Transport (OnionData (..)) |
55 | import Network.Tox.Onion.Routes (tcpKademliaClient,tcpBucketRefresher) | 55 | import Network.Tox.Onion.Routes (tcpKademliaClient,tcpBucketRefresher,tcpRelayPinger) |
56 | import Network.Tox.RelayPinger | ||
56 | import qualified Network.Tox.TCP as TCP | 57 | import qualified Network.Tox.TCP as TCP |
57 | import Presence | 58 | import Presence |
58 | import Text.Read | 59 | import Text.Read |
@@ -136,7 +137,6 @@ toxman ssvar announcer tox presence = ToxManager | |||
136 | 137 | ||
137 | forkIO $ do | 138 | forkIO $ do |
138 | accountWatcher ssvar | 139 | accountWatcher ssvar |
139 | (TCP.tcpClient $ tcpKademliaClient $ toxOnionRoutes tox) | ||
140 | acnt | 140 | acnt |
141 | tox | 141 | tox |
142 | presence | 142 | presence |
@@ -267,6 +267,7 @@ data ToxToXMPP = ToxToXMPP | |||
267 | , txTox :: Tox JabberClients | 267 | , txTox :: Tox JabberClients |
268 | , txSessions :: TVar (Map.Map Uniq24 AggregateSession) | 268 | , txSessions :: TVar (Map.Map Uniq24 AggregateSession) |
269 | , txTCP :: TCP.RelayClient | 269 | , txTCP :: TCP.RelayClient |
270 | , txRelayPinger :: RelayPinger | ||
270 | } | 271 | } |
271 | 272 | ||
272 | default_nospam :: Word32 | 273 | default_nospam :: Word32 |
@@ -310,13 +311,16 @@ connectViaRelay tx theirKey theirDhtKey ann tkey now = do | |||
310 | me = key2id myPublicKey | 311 | me = key2id myPublicKey |
311 | tkey = akeyConnectTCP (txAnnouncer tx) me theirKey | 312 | tkey = akeyConnectTCP (txAnnouncer tx) me theirKey |
312 | go ns = do | 313 | go ns = do |
314 | (_,relays) <- atomically $ currentRelays (txRelayPinger tx) | ||
315 | let ns' = ns ++ relays | ||
316 | oobs = [ Multi.TCP ==> TCP.ViaRelay Nothing (Tox.key2id $ Tox.dhtpk theirDhtKey) ni | ni <- ns' ] | ||
313 | mapM_ (TCP.sendConnectionRequest (txTCP tx) $ Tox.dhtpk theirDhtKey) | 317 | mapM_ (TCP.sendConnectionRequest (txTCP tx) $ Tox.dhtpk theirDhtKey) |
314 | (filter ((/= 0) . TCP.tcpPort) ns) | 318 | (filter ((/= 0) . TCP.tcpPort) ns') |
315 | let oobs = [ Multi.TCP ==> TCP.ViaRelay Nothing (Tox.key2id $ Tox.dhtpk theirDhtKey) ni | ni <- ns ] | 319 | -- currentRelays :: RelayPinger -> STM (Int,[TCP.NodeInfo])<Paste> |
316 | dput XMan $ "connectViaRelay: address count is " ++ show (length oobs) | 320 | dput XMan $ "connectViaRelay: address count is " ++ show (length oobs) |
317 | forM_ oobs $ \ni -> do | 321 | forM_ oobs $ \ni -> do |
318 | cookieRequest (toxCryptoKeys $ txTox tx) (toxDHT $ txTox tx) myPublicKey ni >>= \case | 322 | cookieRequest (toxCryptoKeys $ txTox tx) (toxDHT $ txTox tx) myPublicKey ni >>= \case |
319 | Nothing -> dput XMan $ "connectViaRelay: no cookie from " ++ show ni | 323 | Nothing -> dput XMan $ "connectViaRelay: no cookie from " ++ Multi.summarizeNodeInfo ni |
320 | Just cookie -> do | 324 | Just cookie -> do |
321 | cookieCreationStamp <- getPOSIXTime | 325 | cookieCreationStamp <- getPOSIXTime |
322 | let their_nid = key2id $ dhtpk theirDhtKey | 326 | let their_nid = key2id $ dhtpk theirDhtKey |
@@ -648,7 +652,6 @@ startConnecting0 tx them contact reason = do | |||
648 | onResult theirkey rendezvous = do | 652 | onResult theirkey rendezvous = do |
649 | mTheirDHTKey <- atomically $ fmap ((,) (txTCP tx)) <$> contactDHTKey contact | 653 | mTheirDHTKey <- atomically $ fmap ((,) (txTCP tx)) <$> contactDHTKey contact |
650 | dkey <- Tox.getContactInfo mTheirDHTKey tox | 654 | dkey <- Tox.getContactInfo mTheirDHTKey tox |
651 | |||
652 | let tr = Tox.toxToRoute tox | 655 | let tr = Tox.toxToRoute tox |
653 | route = Tox.AnnouncedRendezvous theirkey rendezvous | 656 | route = Tox.AnnouncedRendezvous theirkey rendezvous |
654 | dput XMan $ unwords [ take 8 (show $ key2id theirkey) | 657 | dput XMan $ unwords [ take 8 (show $ key2id theirkey) |
@@ -708,10 +711,11 @@ closeSessions me them ssvar = do | |||
708 | closeAll ag | 711 | closeAll ag |
709 | 712 | ||
710 | accountWatcher :: TVar (Map.Map Uniq24 AggregateSession) | 713 | accountWatcher :: TVar (Map.Map Uniq24 AggregateSession) |
711 | -> TCP.RelayClient | ||
712 | -> Account JabberClients -> Tox JabberClients -> PresenceState Pending -> Announcer -> IO () | 714 | -> Account JabberClients -> Tox JabberClients -> PresenceState Pending -> Announcer -> IO () |
713 | accountWatcher ssvar tcp acc tox st announcer = do | 715 | accountWatcher ssvar acc tox st announcer = do |
714 | let me = key2id $ toPublic $ userSecret acc | 716 | let me = key2id $ toPublic $ userSecret acc |
717 | tcp = TCP.tcpClient $ tcpKademliaClient $ toxOnionRoutes tox | ||
718 | pinger = tcpRelayPinger $ toxOnionRoutes tox | ||
715 | dput XMan $ "accountWatcher(" ++ show me ++") started" | 719 | dput XMan $ "accountWatcher(" ++ show me ++") started" |
716 | myThreadId >>= flip labelThread ("online:" | 720 | myThreadId >>= flip labelThread ("online:" |
717 | ++ show (key2id $ toPublic $ userSecret acc)) | 721 | ++ show (key2id $ toPublic $ userSecret acc)) |
@@ -725,6 +729,7 @@ accountWatcher ssvar tcp acc tox st announcer = do | |||
725 | , txTox = tox | 729 | , txTox = tox |
726 | , txSessions = ssvar | 730 | , txSessions = ssvar |
727 | , txTCP = tcp | 731 | , txTCP = tcp |
732 | , txRelayPinger = pinger | ||
728 | } | 733 | } |
729 | forM_ (HashMap.toList cs) $ \(them,c) -> do | 734 | forM_ (HashMap.toList cs) $ \(them,c) -> do |
730 | startConnecting0 tx (id2key them) c "enabled account" | 735 | startConnecting0 tx (id2key them) c "enabled account" |