summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorjim@bo <jim@bo>2018-06-24 19:16:46 -0400
committerjim@bo <jim@bo>2018-06-24 19:16:46 -0400
commitf78efaaf6fd64c77c0fd778a7666c40782ce9ec4 (patch)
tree9d2f919678575e0b5e6015317213836e60fd0dad /src/Network
parent47637306b8c19b0b7363f9a2642c7190470a2c93 (diff)
ensure setTerminated not called if there is another NetCryptoSessoin on same key
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/Tox.hs17
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
68import qualified Data.Map.Strict as Map 68import qualified Data.Map.Strict as Map
69import DPut 69import DPut
70import Network.Tox.Avahi 70import Network.Tox.Avahi
71import Text.Printf
72import Data.List
71 73
72newCrypto :: IO TransportCrypto 74newCrypto :: IO TransportCrypto
73newCrypto = do 75newCrypto = 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