diff options
author | Joe Crayne <joe@jerkface.net> | 2018-11-04 04:26:47 -0500 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-11-04 04:26:47 -0500 |
commit | e0fc956953100a375ef1e325d8e5d53b96de0749 (patch) | |
tree | 953ca18f7f834ece22562344d07a35e916a37967 /ToxManager.hs | |
parent | c5ae81e491af14ff3f6608e284eb33bc9f124745 (diff) |
Fixed redundant session close and memory leak.
Diffstat (limited to 'ToxManager.hs')
-rw-r--r-- | ToxManager.hs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/ToxManager.hs b/ToxManager.hs index 40377b62..01403d9d 100644 --- a/ToxManager.hs +++ b/ToxManager.hs | |||
@@ -221,10 +221,13 @@ toxman ssvar announcer toxbkts tox presence = ToxManager | |||
221 | themid <- readMaybe $ T.unpack them | 221 | themid <- readMaybe $ T.unpack them |
222 | return (id2key meid, id2key themid) | 222 | return (id2key meid, id2key themid) |
223 | forM m $ \(me,them) -> do | 223 | forM m $ \(me,them) -> do |
224 | u <- xor24 <$> hash24 me <*> hash24 them | 224 | u <- meAndThem me them |
225 | return $ addrToPeerKey $ Remote $ peerAddress $ uniqueAsKey u | 225 | return $ addrToPeerKey $ Remote $ peerAddress $ uniqueAsKey u |
226 | } | 226 | } |
227 | 227 | ||
228 | meAndThem :: PublicKey -> PublicKey -> IO Uniq24 | ||
229 | meAndThem me them = xor24 <$> hash24 me <*> hash24 them | ||
230 | |||
228 | key2jid :: Word32 -> PublicKey -> Text | 231 | key2jid :: Word32 -> PublicKey -> Text |
229 | key2jid nospam key = T.pack $ show $ NoSpamId nsp key | 232 | key2jid nospam key = T.pack $ show $ NoSpamId nsp key |
230 | where | 233 | where |
@@ -656,6 +659,14 @@ stopConnecting ToxToXMPP{txAnnouncer=announcer,txAccount=acnt} them reason = do | |||
656 | cancel announcer akeyC | 659 | cancel announcer akeyC |
657 | cancel announcer akeyD | 660 | cancel announcer akeyD |
658 | 661 | ||
662 | closeSessions :: NodeId{-me-} -> NodeId{-them-} -> TVar (Map.Map Uniq24 AggregateSession) -> IO () | ||
663 | closeSessions me them ssvar = do | ||
664 | m <- atomically $ readTVar ssvar | ||
665 | u <- meAndThem (id2key me) (id2key them) | ||
666 | forM_ (Map.lookup u m) $ \ag -> do | ||
667 | -- Just True <- checkCompatible ag (id2key me) (id2key them) | ||
668 | closeAll ag | ||
669 | |||
659 | forkAccountWatcher :: TVar (Map.Map Uniq24 AggregateSession) | 670 | forkAccountWatcher :: TVar (Map.Map Uniq24 AggregateSession) |
660 | -> Account JabberClients -> Tox JabberClients -> PresenceState Pending -> Announcer -> IO ThreadId | 671 | -> Account JabberClients -> Tox JabberClients -> PresenceState Pending -> Announcer -> IO ThreadId |
661 | forkAccountWatcher ssvar acc tox st announcer = forkIO $ do | 672 | forkAccountWatcher ssvar acc tox st announcer = forkIO $ do |
@@ -676,19 +687,21 @@ forkAccountWatcher ssvar acc tox st announcer = forkIO $ do | |||
676 | 687 | ||
677 | -- Loop endlessly until accountExtra is null. | 688 | -- Loop endlessly until accountExtra is null. |
678 | fix $ \loop -> do | 689 | fix $ \loop -> do |
679 | mev <- atomically $ | 690 | mev <- atomically $ |
680 | (Just <$> readTChan chan) | 691 | (Just <$> readTChan chan) |
681 | `orElse` do | 692 | `orElse` do |
682 | refs <- readTVar $ accountExtra acc | 693 | refs <- readTVar $ accountExtra acc |
683 | check $ Map.null refs | 694 | check $ Map.null refs |
684 | return Nothing | 695 | return Nothing |
685 | 696 | ||
686 | forM_ mev $ \ev -> dispatch tx ev >> loop | 697 | forM_ mev $ \ev -> dispatch tx ev >> loop |
687 | 698 | ||
699 | -- Stop tasks associated with each contact for this account. | ||
688 | cs <- atomically $ readTVar (contacts acc) | 700 | cs <- atomically $ readTVar (contacts acc) |
701 | let me = key2id $ toPublic $ userSecret acc | ||
689 | forM_ (HashMap.toList cs) $ \(them,c) -> do | 702 | forM_ (HashMap.toList cs) $ \(them,c) -> do |
690 | stopConnecting tx (id2key them) "disabled account" | 703 | stopConnecting tx (id2key them) "disabled account" |
691 | -- TODO: closeAll for each relevant session in ssvar. | 704 | closeSessions me them ssvar |
692 | 705 | ||
693 | 706 | ||
694 | toxAnnounceInterval :: POSIXTime | 707 | toxAnnounceInterval :: POSIXTime |