From 716f51cce4ab52b3f67567b405e6455f0752e10c Mon Sep 17 00:00:00 2001 From: "jim@bo" Date: Fri, 22 Jun 2018 04:35:21 -0400 Subject: call destroySession before freshCrpytoSession on Reset-handshake --- src/Network/Tox/Crypto/Handlers.hs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/Network/Tox/Crypto/Handlers.hs') diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index bd421ea3..7a7567cf 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs @@ -779,7 +779,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do dput XNetCrypto $ "Dequeued::" ++ show (bufferData cd) ++ " now running hook..." void $ runCryptoHook netCryptoSession0 (bufferData cd) loop - atomically $ writeTVar (ncDequeueThread netCryptoSession0) (Just threadid) dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr -- launch request thread @@ -800,7 +799,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do PQ.OGSuccess -> return () _ -> retry loop - atomically $ writeTVar (ncRequestThread netCryptoSession0) (Just reqthreadId) dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr -- launch dequeueOutgoing thread @@ -813,7 +811,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do dput XNetCrypto "NetCryptoDequeueOutgoing thread... Sending encrypted Packet" sendSessionPacket sessions addr pkt loop - atomically $ writeTVar (ncDequeueOutGoingThread netCryptoSession0) (Just threadidOutgoing) dput XNetCrypto $ "runUponHandshake: " ++ show threadidOutgoing ++ " = NetCryptoDequeueOutgoing." ++ show (key2id remotePublicKey) ++ sidStr -- launch ping Machine thread @@ -833,7 +830,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do Left s -> dput XNetCrypto $ "(pingThread session: " ++ show (ncSessionId netCryptoSession0) ++ ") " ++ s Right _ -> return () loop - atomically $ writeTVar (ncPingThread netCryptoSession0) (Just pingThreadId) -- launch IdleEvent thread idleThreadId <- forkIO $ do @@ -846,7 +842,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do hooks <- atomically (readTVar (ncIdleEventHooks netCryptoSession0)) mapM_ (($ netCryptoSession0) . snd) hooks PingTimeOut -> destroySession netCryptoSession0 - atomically $ writeTVar (ncIdleEventThread netCryptoSession0) (Just idleThreadId) -- update session with thread ids let netCryptoSession = netCryptoSession0 @@ -886,8 +881,8 @@ destroySession session = do $ Map.map (filter ((/=sid) . ncSessionId)) modifyTVar (netCryptoSessions allsessions) $ Map.filterWithKey (\k v -> ncSessionId v /= sid) - stopThread (ncPingThread session) stopMachine (ncPingMachine session) + stopThread (ncPingThread session) stopThread (ncDequeueThread session) stopThread (ncDequeueOutGoingThread session) stopThread (ncRequestThread session) @@ -923,7 +918,9 @@ updateCryptoSession sessions addr newsession timestamp hp session handshake = do || ncTheirDHTKey session /= HaveDHTKey (hpCookieRemoteDhtkey hp) ) - then freshCryptoSession sessions addr newsession timestamp hp + then do + (r,action) <- freshCryptoSession sessions addr newsession timestamp hp + return (r,destroySession session >> action) else return (Nothing,return ()) else do dmsg "updateCryptoSession else clause" @@ -952,7 +949,8 @@ updateCryptoSession sessions addr newsession timestamp hp session handshake = do (toMaybe mbpktoq)) HaveHandshake _ -> do dmsg "basenonce mismatch, trigger refresh" - freshCryptoSession sessions addr newsession timestamp hp -- basenonce mismatch, trigger refresh + (r,action) <- freshCryptoSession sessions addr newsession timestamp hp -- basenonce mismatch, trigger refresh + return (r, destroySession session >> action) _ -> do dmsg "updateCryptoSession -- unexpected condition! have hpTheirSessionKeyPublic but missing hpTheirBaseNonce?" return (Nothing,return ()) -- cgit v1.2.3