summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs39
1 files changed, 22 insertions, 17 deletions
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
662 Nothing -> return () 662 Nothing -> return ()
663 663
664-- | Called when we get a handshake, but there's already a session entry. 664-- | Called when we get a handshake, but there's already a session entry.
665--
666-- 1) duplicate packet ... ignore
667-- 2) handshake for new session (old session is lost?)
668
669-- 3) we initiated, this a response
665updateCryptoSession :: NetCryptoSessions -> SockAddr -> HandshakeParams -> NetCryptoSession -> Handshake Encrypted -> IO () 670updateCryptoSession :: NetCryptoSessions -> SockAddr -> HandshakeParams -> NetCryptoSession -> Handshake Encrypted -> IO ()
666updateCryptoSession sessions addr hp session handshake = do 671updateCryptoSession sessions addr hp session handshake = do
667 ncState0 <- atomically $ readTVar (ncState session) 672 ncState0 <- atomically $ readTVar (ncState session)
@@ -680,25 +685,25 @@ updateCryptoSession sessions addr hp session handshake = do
680 dput XNetCrypto (" ncTheirDHTKey=" ++ show (ncTheirDHTKey session) 685 dput XNetCrypto (" ncTheirDHTKey=" ++ show (ncTheirDHTKey session)
681 ++ bool "{/=}" "{==}" (ncTheirDHTKey session == HaveDHTKey (hpCookieRemoteDhtkey hp)) 686 ++ bool "{/=}" "{==}" (ncTheirDHTKey session == HaveDHTKey (hpCookieRemoteDhtkey hp))
682 ++ "hpCookieRemoteDhtkey=" ++ show (hpCookieRemoteDhtkey hp)) 687 ++ "hpCookieRemoteDhtkey=" ++ show (hpCookieRemoteDhtkey hp))
683 if ( -- Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp -- XXX: Do we really want to compare base nonce here? 688 when ( -- Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp -- XXX: Do we really want to compare base nonce here?
684 -- || 689 -- ||
685 ncTheirDHTKey session /= HaveDHTKey (hpCookieRemoteDhtkey hp) 690 ncTheirDHTKey session /= HaveDHTKey (hpCookieRemoteDhtkey hp)
686 ) then freshCryptoSession sessions addr hp 691 ) $ freshCryptoSession sessions addr hp
687 else do 692 -- else do
688 atomically $ do 693 -- atomically $ do
689 writeTVar (ncTheirBaseNonce session) (frmMaybe (hpTheirBaseNonce hp)) 694 -- writeTVar (ncTheirBaseNonce session) (frmMaybe (hpTheirBaseNonce hp))
690 writeTVar (ncTheirSessionPublic session) (frmMaybe (hpTheirSessionKeyPublic hp)) 695 -- writeTVar (ncTheirSessionPublic session) (frmMaybe (hpTheirSessionKeyPublic hp))
691 writeTVar (ncHandShake session) (HaveHandshake handshake) 696 -- writeTVar (ncHandShake session) (HaveHandshake handshake)
692 case ncOutgoingQueue session of 697 -- case ncOutgoingQueue session of
693 NeedHandshake -> do 698 -- NeedHandshake -> do
694 case hpTheirSessionKeyPublic hp of 699 -- case hpTheirSessionKeyPublic hp of
695 Just sessionpubkey -> do 700 -- Just sessionpubkey -> do
696 pktoq <- createNetCryptoOutQueue sessions (ncSessionSecret session) sessionpubkey 701 -- pktoq <- createNetCryptoOutQueue sessions (ncSessionSecret session) sessionpubkey
697 (ncPacketQueue session) (ncMyPacketNonce session) (ncOutgoingIdMap session) 702 -- (ncPacketQueue session) (ncMyPacketNonce session) (ncOutgoingIdMap session)
698 case pktoq of 703 -- case pktoq of
699 NeedHandshake -> dput XNetCrypto "Unexpectedly missing ncOutgoingQueue" 704 -- NeedHandshake -> dput XNetCrypto "Unexpectedly missing ncOutgoingQueue"
700 HaveHandshake pktoq -> runUponHandshake session addr pktoq 705 -- HaveHandshake pktoq -> runUponHandshake session addr pktoq
701 HaveHandshake pktoq -> runUponHandshake session addr pktoq 706 -- HaveHandshake pktoq -> runUponHandshake session addr pktoq
702 else do 707 else do
703 dput XNetCrypto "updateCryptoSession else clause" 708 dput XNetCrypto "updateCryptoSession else clause"
704 dput XNetCrypto (" ncTheirBaseNonce0=" ++ show ncTheirBaseNonce0 709 dput XNetCrypto (" ncTheirBaseNonce0=" ++ show ncTheirBaseNonce0