summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2018-06-18 23:51:47 -0400
committerjoe <joe@jerkface.net>2018-06-18 23:51:47 -0400
commit403cf5dad13bbe0ff757a80c651adc071df0dbc4 (patch)
tree64bfb8426f8b0e45a5cb57a64822a36a88e559ec
parentcb99e428d75ef89bbe7a6b2a2e5dbacdc1e1c641 (diff)
Automatically cancel searches when we log-out of xmpp.
-rw-r--r--ToxManager.hs2
-rw-r--r--ToxToXMPP.hs13
2 files changed, 11 insertions, 4 deletions
diff --git a/ToxManager.hs b/ToxManager.hs
index 1e9c618d..460b2fe5 100644
--- a/ToxManager.hs
+++ b/ToxManager.hs
@@ -111,8 +111,8 @@ toxman announcer toxbkts tox presence = ToxManager
111 -- Stop the recurring search for that contact 111 -- Stop the recurring search for that contact
112 -- 112 --
113 -- Stop recurring announce. 113 -- Stop recurring announce.
114 akey <- packAnnounceKey announcer ("toxid:" ++ show pubid)
114 fmap Just $ forM toxbkts $ \(nm,bkts) -> do 115 fmap Just $ forM toxbkts $ \(nm,bkts) -> do
115 akey <- packAnnounceKey announcer (nm ++ "id:" ++ show pubid)
116 return (akey,bkts) 116 return (akey,bkts)
117 else return Nothing 117 else return Nothing
118 forM_ bStopped $ \kbkts -> do 118 forM_ bStopped $ \kbkts -> do
diff --git a/ToxToXMPP.hs b/ToxToXMPP.hs
index ace4e041..c61764ef 100644
--- a/ToxToXMPP.hs
+++ b/ToxToXMPP.hs
@@ -111,7 +111,8 @@ dispatch :: ToxToXMPP -> ContactEvent -> IO ()
111dispatch tx (SessionEstablished theirKey) = stopConnecting tx theirKey 111dispatch tx (SessionEstablished theirKey) = stopConnecting tx theirKey
112dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey 112dispatch tx (SessionTerminated theirKey) = startConnecting tx theirKey
113dispatch tx (AddrChange theirkey saddr) = return () -- todo 113dispatch tx (AddrChange theirkey saddr) = return () -- todo
114dispatch tx (PolicyChange theirkey policy ) = return () -- todo 114dispatch tx (PolicyChange theirkey TryingToConnect ) = startConnecting tx theirkey
115dispatch tx (PolicyChange theirkey policy ) = stopConnecting tx theirkey
115dispatch tx (OnionRouted theirkey (OnionDHTPublicKey pkey)) = return () -- todo 116dispatch tx (OnionRouted theirkey (OnionDHTPublicKey pkey)) = return () -- todo
116dispatch tx (OnionRouted theirkey (OnionFriendRequest fr) ) = do 117dispatch tx (OnionRouted theirkey (OnionFriendRequest fr) ) = do
117 let ToxToXMPP { txAnnouncer = acr 118 let ToxToXMPP { txAnnouncer = acr
@@ -198,6 +199,7 @@ startConnecting tx them = do
198 199
199stopConnecting :: ToxToXMPP -> PublicKey -> IO () 200stopConnecting :: ToxToXMPP -> PublicKey -> IO ()
200stopConnecting ToxToXMPP{txAnnouncer=announcer,txAccount=acnt} them = do 201stopConnecting ToxToXMPP{txAnnouncer=announcer,txAccount=acnt} them = do
202 hPutStrLn stderr $ "STOP CONNECTING " ++ show (key2id them)
201 let pub = toPublic $ userSecret acnt 203 let pub = toPublic $ userSecret acnt
202 me = key2id pub 204 me = key2id pub
203 akey <- akeyDHTKeyShare announcer me them 205 akey <- akeyDHTKeyShare announcer me them
@@ -207,7 +209,7 @@ forkAccountWatcher :: Account -> Tox -> PresenceState -> Announcer -> IO ThreadI
207forkAccountWatcher acc tox st announcer = forkIO $ do 209forkAccountWatcher acc tox st announcer = forkIO $ do
208 myThreadId >>= flip labelThread ("tox-xmpp:" 210 myThreadId >>= flip labelThread ("tox-xmpp:"
209 ++ show (key2id $ toPublic $ userSecret acc)) 211 ++ show (key2id $ toPublic $ userSecret acc))
210 (chan,contacts) <- atomically $ do 212 (chan,cs) <- atomically $ do
211 chan <- dupTChan $ eventChan acc -- duplicate broadcast channel for reading. 213 chan <- dupTChan $ eventChan acc -- duplicate broadcast channel for reading.
212 contacts <- readTVar (contacts acc) 214 contacts <- readTVar (contacts acc)
213 return (chan,contacts) 215 return (chan,contacts)
@@ -216,7 +218,7 @@ forkAccountWatcher acc tox st announcer = forkIO $ do
216 , txPresence = st 218 , txPresence = st
217 , txTox = tox 219 , txTox = tox
218 } 220 }
219 forM_ (HashMap.toList contacts) $ \(them,c) -> do 221 forM_ (HashMap.toList cs) $ \(them,c) -> do
220 startConnecting0 tx (id2key them) c 222 startConnecting0 tx (id2key them) c
221 223
222 -- Loop endlessly until clientRefs is null. 224 -- Loop endlessly until clientRefs is null.
@@ -230,6 +232,11 @@ forkAccountWatcher acc tox st announcer = forkIO $ do
230 232
231 forM_ mev $ \ev -> dispatch tx ev >> loop 233 forM_ mev $ \ev -> dispatch tx ev >> loop
232 234
235 cs <- atomically $ readTVar (contacts acc)
236 forM_ (HashMap.toList cs) $ \(them,c) -> do
237 stopConnecting tx (id2key them)
238
239
233toxQSearch :: Tox.Tox -> Search Tox.NodeId (IP, PortNumber) Nonce32 Tox.NodeInfo Tox.Rendezvous 240toxQSearch :: Tox.Tox -> Search Tox.NodeId (IP, PortNumber) Nonce32 Tox.NodeInfo Tox.Rendezvous
234toxQSearch tox = Tox.toxidSearch (Tox.onionTimeout tox) (Tox.toxCryptoKeys tox) (Tox.toxOnion tox) 241toxQSearch tox = Tox.toxidSearch (Tox.onionTimeout tox) (Tox.toxCryptoKeys tox) (Tox.toxOnion tox)
235 242