From 1b78cae637fa28001214697ca042e907b9f5af4f Mon Sep 17 00:00:00 2001 From: James Crayne Date: Thu, 31 May 2018 12:15:30 +0000 Subject: remove dumb else clause on duplicate packet case --- src/Network/Tox/Crypto/Handlers.hs | 39 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 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 307efb22..0dc7f08d 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs @@ -662,6 +662,11 @@ runUponHandshake netCryptoSession0 addr pktoq = do Nothing -> return () -- | Called when we get a handshake, but there's already a session entry. +-- +-- 1) duplicate packet ... ignore +-- 2) handshake for new session (old session is lost?) + +-- 3) we initiated, this a response updateCryptoSession :: NetCryptoSessions -> SockAddr -> HandshakeParams -> NetCryptoSession -> Handshake Encrypted -> IO () updateCryptoSession sessions addr hp session handshake = do ncState0 <- atomically $ readTVar (ncState session) @@ -680,25 +685,25 @@ updateCryptoSession sessions addr hp session handshake = do dput XNetCrypto (" ncTheirDHTKey=" ++ show (ncTheirDHTKey session) ++ bool "{/=}" "{==}" (ncTheirDHTKey session == HaveDHTKey (hpCookieRemoteDhtkey hp)) ++ "hpCookieRemoteDhtkey=" ++ show (hpCookieRemoteDhtkey hp)) - if ( -- Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp -- XXX: Do we really want to compare base nonce here? + when ( -- Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp -- XXX: Do we really want to compare base nonce here? -- || ncTheirDHTKey session /= HaveDHTKey (hpCookieRemoteDhtkey hp) - ) then freshCryptoSession sessions addr hp - else do - atomically $ do - writeTVar (ncTheirBaseNonce session) (frmMaybe (hpTheirBaseNonce hp)) - writeTVar (ncTheirSessionPublic session) (frmMaybe (hpTheirSessionKeyPublic hp)) - writeTVar (ncHandShake session) (HaveHandshake handshake) - case ncOutgoingQueue session of - NeedHandshake -> do - case hpTheirSessionKeyPublic hp of - Just sessionpubkey -> do - pktoq <- createNetCryptoOutQueue sessions (ncSessionSecret session) sessionpubkey - (ncPacketQueue session) (ncMyPacketNonce session) (ncOutgoingIdMap session) - case pktoq of - NeedHandshake -> dput XNetCrypto "Unexpectedly missing ncOutgoingQueue" - HaveHandshake pktoq -> runUponHandshake session addr pktoq - HaveHandshake pktoq -> runUponHandshake session addr pktoq + ) $ freshCryptoSession sessions addr hp + -- else do + -- atomically $ do + -- writeTVar (ncTheirBaseNonce session) (frmMaybe (hpTheirBaseNonce hp)) + -- writeTVar (ncTheirSessionPublic session) (frmMaybe (hpTheirSessionKeyPublic hp)) + -- writeTVar (ncHandShake session) (HaveHandshake handshake) + -- case ncOutgoingQueue session of + -- NeedHandshake -> do + -- case hpTheirSessionKeyPublic hp of + -- Just sessionpubkey -> do + -- pktoq <- createNetCryptoOutQueue sessions (ncSessionSecret session) sessionpubkey + -- (ncPacketQueue session) (ncMyPacketNonce session) (ncOutgoingIdMap session) + -- case pktoq of + -- NeedHandshake -> dput XNetCrypto "Unexpectedly missing ncOutgoingQueue" + -- HaveHandshake pktoq -> runUponHandshake session addr pktoq + -- HaveHandshake pktoq -> runUponHandshake session addr pktoq else do dput XNetCrypto "updateCryptoSession else clause" dput XNetCrypto (" ncTheirBaseNonce0=" ++ show ncTheirBaseNonce0 -- cgit v1.2.3