diff options
author | jim@bo <jim@bo> | 2018-06-22 04:35:21 -0400 |
---|---|---|
committer | jim@bo <jim@bo> | 2018-06-22 04:40:30 -0400 |
commit | 716f51cce4ab52b3f67567b405e6455f0752e10c (patch) | |
tree | 69436750d602fdbf294ef355df910d601d427c29 /src/Network/Tox/Crypto | |
parent | 2ffb6b2b7f5d4c935770689a3afe763cb537d750 (diff) |
call destroySession before freshCrpytoSession on Reset-handshake
Diffstat (limited to 'src/Network/Tox/Crypto')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 14 |
1 files changed, 6 insertions, 8 deletions
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 | |||
779 | dput XNetCrypto $ "Dequeued::" ++ show (bufferData cd) ++ " now running hook..." | 779 | dput XNetCrypto $ "Dequeued::" ++ show (bufferData cd) ++ " now running hook..." |
780 | void $ runCryptoHook netCryptoSession0 (bufferData cd) | 780 | void $ runCryptoHook netCryptoSession0 (bufferData cd) |
781 | loop | 781 | loop |
782 | atomically $ writeTVar (ncDequeueThread netCryptoSession0) (Just threadid) | ||
783 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr | 782 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoDequeue." ++ show (key2id remotePublicKey) ++ sidStr |
784 | 783 | ||
785 | -- launch request thread | 784 | -- launch request thread |
@@ -800,7 +799,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
800 | PQ.OGSuccess -> return () | 799 | PQ.OGSuccess -> return () |
801 | _ -> retry | 800 | _ -> retry |
802 | loop | 801 | loop |
803 | atomically $ writeTVar (ncRequestThread netCryptoSession0) (Just reqthreadId) | ||
804 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr | 802 | dput XNetCrypto $ "runUponHandshake: " ++ show threadid ++ " = NetCryptoRequest." ++ show (key2id remotePublicKey) ++ sidStr |
805 | 803 | ||
806 | -- launch dequeueOutgoing thread | 804 | -- launch dequeueOutgoing thread |
@@ -813,7 +811,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
813 | dput XNetCrypto "NetCryptoDequeueOutgoing thread... Sending encrypted Packet" | 811 | dput XNetCrypto "NetCryptoDequeueOutgoing thread... Sending encrypted Packet" |
814 | sendSessionPacket sessions addr pkt | 812 | sendSessionPacket sessions addr pkt |
815 | loop | 813 | loop |
816 | atomically $ writeTVar (ncDequeueOutGoingThread netCryptoSession0) (Just threadidOutgoing) | ||
817 | dput XNetCrypto $ "runUponHandshake: " ++ show threadidOutgoing ++ " = NetCryptoDequeueOutgoing." ++ show (key2id remotePublicKey) ++ sidStr | 814 | dput XNetCrypto $ "runUponHandshake: " ++ show threadidOutgoing ++ " = NetCryptoDequeueOutgoing." ++ show (key2id remotePublicKey) ++ sidStr |
818 | 815 | ||
819 | -- launch ping Machine thread | 816 | -- launch ping Machine thread |
@@ -833,7 +830,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
833 | Left s -> dput XNetCrypto $ "(pingThread session: " ++ show (ncSessionId netCryptoSession0) ++ ") " ++ s | 830 | Left s -> dput XNetCrypto $ "(pingThread session: " ++ show (ncSessionId netCryptoSession0) ++ ") " ++ s |
834 | Right _ -> return () | 831 | Right _ -> return () |
835 | loop | 832 | loop |
836 | atomically $ writeTVar (ncPingThread netCryptoSession0) (Just pingThreadId) | ||
837 | 833 | ||
838 | -- launch IdleEvent thread | 834 | -- launch IdleEvent thread |
839 | idleThreadId <- forkIO $ do | 835 | idleThreadId <- forkIO $ do |
@@ -846,7 +842,6 @@ runUponHandshake netCryptoSession0 addr pktoq = do | |||
846 | hooks <- atomically (readTVar (ncIdleEventHooks netCryptoSession0)) | 842 | hooks <- atomically (readTVar (ncIdleEventHooks netCryptoSession0)) |
847 | mapM_ (($ netCryptoSession0) . snd) hooks | 843 | mapM_ (($ netCryptoSession0) . snd) hooks |
848 | PingTimeOut -> destroySession netCryptoSession0 | 844 | PingTimeOut -> destroySession netCryptoSession0 |
849 | atomically $ writeTVar (ncIdleEventThread netCryptoSession0) (Just idleThreadId) | ||
850 | 845 | ||
851 | -- update session with thread ids | 846 | -- update session with thread ids |
852 | let netCryptoSession = netCryptoSession0 | 847 | let netCryptoSession = netCryptoSession0 |
@@ -886,8 +881,8 @@ destroySession session = do | |||
886 | $ Map.map (filter ((/=sid) . ncSessionId)) | 881 | $ Map.map (filter ((/=sid) . ncSessionId)) |
887 | modifyTVar (netCryptoSessions allsessions) | 882 | modifyTVar (netCryptoSessions allsessions) |
888 | $ Map.filterWithKey (\k v -> ncSessionId v /= sid) | 883 | $ Map.filterWithKey (\k v -> ncSessionId v /= sid) |
889 | stopThread (ncPingThread session) | ||
890 | stopMachine (ncPingMachine session) | 884 | stopMachine (ncPingMachine session) |
885 | stopThread (ncPingThread session) | ||
891 | stopThread (ncDequeueThread session) | 886 | stopThread (ncDequeueThread session) |
892 | stopThread (ncDequeueOutGoingThread session) | 887 | stopThread (ncDequeueOutGoingThread session) |
893 | stopThread (ncRequestThread session) | 888 | stopThread (ncRequestThread session) |
@@ -923,7 +918,9 @@ updateCryptoSession sessions addr newsession timestamp hp session handshake = do | |||
923 | || | 918 | || |
924 | ncTheirDHTKey session /= HaveDHTKey (hpCookieRemoteDhtkey hp) | 919 | ncTheirDHTKey session /= HaveDHTKey (hpCookieRemoteDhtkey hp) |
925 | ) | 920 | ) |
926 | then freshCryptoSession sessions addr newsession timestamp hp | 921 | then do |
922 | (r,action) <- freshCryptoSession sessions addr newsession timestamp hp | ||
923 | return (r,destroySession session >> action) | ||
927 | else return (Nothing,return ()) | 924 | else return (Nothing,return ()) |
928 | else do | 925 | else do |
929 | dmsg "updateCryptoSession else clause" | 926 | dmsg "updateCryptoSession else clause" |
@@ -952,7 +949,8 @@ updateCryptoSession sessions addr newsession timestamp hp session handshake = do | |||
952 | (toMaybe mbpktoq)) | 949 | (toMaybe mbpktoq)) |
953 | HaveHandshake _ -> do | 950 | HaveHandshake _ -> do |
954 | dmsg "basenonce mismatch, trigger refresh" | 951 | dmsg "basenonce mismatch, trigger refresh" |
955 | freshCryptoSession sessions addr newsession timestamp hp -- basenonce mismatch, trigger refresh | 952 | (r,action) <- freshCryptoSession sessions addr newsession timestamp hp -- basenonce mismatch, trigger refresh |
953 | return (r, destroySession session >> action) | ||
956 | _ -> do | 954 | _ -> do |
957 | dmsg "updateCryptoSession -- unexpected condition! have hpTheirSessionKeyPublic but missing hpTheirBaseNonce?" | 955 | dmsg "updateCryptoSession -- unexpected condition! have hpTheirSessionKeyPublic but missing hpTheirBaseNonce?" |
958 | return (Nothing,return ()) | 956 | return (Nothing,return ()) |