diff options
Diffstat (limited to 'src/Network/Tox.hs')
-rw-r--r-- | src/Network/Tox.hs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/Network/Tox.hs b/src/Network/Tox.hs index 26488657..93d42eca 100644 --- a/src/Network/Tox.hs +++ b/src/Network/Tox.hs | |||
@@ -68,6 +68,8 @@ import qualified Data.HashMap.Strict as HashMap | |||
68 | import qualified Data.Map.Strict as Map | 68 | import qualified Data.Map.Strict as Map |
69 | import DPut | 69 | import DPut |
70 | import Network.Tox.Avahi | 70 | import Network.Tox.Avahi |
71 | import Text.Printf | ||
72 | import Data.List | ||
71 | 73 | ||
72 | newCrypto :: IO TransportCrypto | 74 | newCrypto :: IO TransportCrypto |
73 | newCrypto = do | 75 | newCrypto = do |
@@ -361,7 +363,20 @@ mkDefaultDestroyHook roster = \session -> do | |||
361 | accounts <- readTVar (accounts roster) -- :: STM (HashMap NodeId (Account extra) | 363 | accounts <- readTVar (accounts roster) -- :: STM (HashMap NodeId (Account extra) |
362 | let mbAccount = HashMap.lookup (key2id $ ncMyPublicKey session) accounts -- :: STM (Maybe (Account extra) | 364 | let mbAccount = HashMap.lookup (key2id $ ncMyPublicKey session) accounts -- :: STM (Maybe (Account extra) |
363 | case mbAccount of | 365 | case mbAccount of |
364 | Just account -> Right <$> setTerminated now (ncTheirPublicKey session) account | 366 | Just account -> do |
367 | mp <- readTVar (netCryptoSessionsByKey (ncAllSessions session)) | ||
368 | case Map.lookup (ncTheirPublicKey session) mp of | ||
369 | Just sessionsWithThisPublicKey | ||
370 | | relevantSessions <- filter ((/=ncSessionId session) . ncSessionId) sessionsWithThisPublicKey | ||
371 | , not (null relevantSessions) | ||
372 | -> do | ||
373 | let showsession x = printf "%x" (ncSessionId x) | ||
374 | return . Left $ "Not calling setTerminated on " ++ show (key2id (ncTheirPublicKey session)) | ||
375 | ++" despite session(" ++ showsession session | ||
376 | ++ ") failure. (Still have sessions: [" | ||
377 | ++ Data.List.intercalate "," (map showsession relevantSessions) | ||
378 | ++ "]" | ||
379 | _ -> Right <$> setTerminated now (ncTheirPublicKey session) account | ||
365 | Nothing -> return . Left $ "(defaultDestroyHook) their is no account! pubkey=" ++ show (key2id (ncTheirPublicKey session)) | 380 | Nothing -> return . Left $ "(defaultDestroyHook) their is no account! pubkey=" ++ show (key2id (ncTheirPublicKey session)) |
366 | case r of | 381 | case r of |
367 | Left msg -> dput XMan msg | 382 | Left msg -> dput XMan msg |