diff options
Diffstat (limited to 'dht/ToxManager.hs')
-rw-r--r-- | dht/ToxManager.hs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/dht/ToxManager.hs b/dht/ToxManager.hs index 25a4f0f2..126efa36 100644 --- a/dht/ToxManager.hs +++ b/dht/ToxManager.hs | |||
@@ -134,7 +134,8 @@ toxman ssvar announcer tox presence = ToxManager | |||
134 | toxAnnounceInterval) | 134 | toxAnnounceInterval) |
135 | pub | 135 | pub |
136 | 136 | ||
137 | forkAccountWatcher ssvar | 137 | forkIO $ do |
138 | accountWatcher ssvar | ||
138 | (TCP.tcpClient $ tcpKademliaClient $ toxOnionRoutes tox) | 139 | (TCP.tcpClient $ tcpKademliaClient $ toxOnionRoutes tox) |
139 | acnt | 140 | acnt |
140 | tox | 141 | tox |
@@ -155,6 +156,11 @@ toxman ssvar announcer tox presence = ToxManager | |||
155 | -- Remove this xmpp client /k/ from the set holding this | 156 | -- Remove this xmpp client /k/ from the set holding this |
156 | -- account active. | 157 | -- account active. |
157 | modifyTVar' (accountExtra acnt) $ Map.delete k | 158 | modifyTVar' (accountExtra acnt) $ Map.delete k |
159 | is_last <- Map.null <$> readTVar (accountExtra acnt) | ||
160 | when is_last $ do | ||
161 | -- Forget secret key if this was the last client. | ||
162 | -- This ensures that incoming connections are rejected. | ||
163 | modifyTVar' accounts $ HashMap.delete pubid | ||
158 | return rs | 164 | return rs |
159 | return $ | 165 | return $ |
160 | if (Map.null $ Map.delete k refs) then | 166 | if (Map.null $ Map.delete k refs) then |
@@ -165,7 +171,7 @@ toxman ssvar announcer tox presence = ToxManager | |||
165 | let Just pubid = mpubid | 171 | let Just pubid = mpubid |
166 | pub = Tox.id2key pubid | 172 | pub = Tox.id2key pubid |
167 | -- Stop the announce-toxid task for this account. Note that other | 173 | -- Stop the announce-toxid task for this account. Note that other |
168 | -- announced tasks will be stopped by the forkAccountWatcher thread | 174 | -- announced tasks will be stopped by the accountWatcher thread |
169 | -- when it terminates. | 175 | -- when it terminates. |
170 | cancel announcer akey | 176 | cancel announcer akey |
171 | 177 | ||
@@ -705,12 +711,12 @@ closeSessions me them ssvar = do | |||
705 | -- Just True <- checkCompatible ag (id2key me) (id2key them) | 711 | -- Just True <- checkCompatible ag (id2key me) (id2key them) |
706 | closeAll ag | 712 | closeAll ag |
707 | 713 | ||
708 | forkAccountWatcher :: TVar (Map.Map Uniq24 AggregateSession) | 714 | accountWatcher :: TVar (Map.Map Uniq24 AggregateSession) |
709 | -> TCP.RelayClient | 715 | -> TCP.RelayClient |
710 | -> Account JabberClients -> Tox JabberClients -> PresenceState Pending -> Announcer -> IO ThreadId | 716 | -> Account JabberClients -> Tox JabberClients -> PresenceState Pending -> Announcer -> IO () |
711 | forkAccountWatcher ssvar tcp acc tox st announcer = forkIO $ do | 717 | accountWatcher ssvar tcp acc tox st announcer = do |
712 | let me = key2id $ toPublic $ userSecret acc | 718 | let me = key2id $ toPublic $ userSecret acc |
713 | dput XMan $ "forkAccountWatcher(" ++ show me ++") started" | 719 | dput XMan $ "accountWatcher(" ++ show me ++") started" |
714 | myThreadId >>= flip labelThread ("online:" | 720 | myThreadId >>= flip labelThread ("online:" |
715 | ++ show (key2id $ toPublic $ userSecret acc)) | 721 | ++ show (key2id $ toPublic $ userSecret acc)) |
716 | (chan,cs) <- atomically $ do | 722 | (chan,cs) <- atomically $ do |
@@ -743,7 +749,7 @@ forkAccountWatcher ssvar tcp acc tox st announcer = forkIO $ do | |||
743 | forM_ (HashMap.toList cs) $ \(them,c) -> do | 749 | forM_ (HashMap.toList cs) $ \(them,c) -> do |
744 | stopConnecting tx (id2key them) "disabled account" | 750 | stopConnecting tx (id2key them) "disabled account" |
745 | closeSessions me them ssvar | 751 | closeSessions me them ssvar |
746 | dput XMan $ "forkAccountWatcher(" ++ show me ++") stopped" | 752 | dput XMan $ "accountWatcher(" ++ show me ++") stopped" |
747 | 753 | ||
748 | 754 | ||
749 | toxAnnounceInterval :: POSIXTime | 755 | toxAnnounceInterval :: POSIXTime |