From 1afb9ea88c52e7face6293ef1c837837c1c9b2ef Mon Sep 17 00:00:00 2001 From: James Crayne Date: Wed, 30 May 2018 02:47:14 +0000 Subject: comment showing relation between old and new crypto session status types --- src/Network/Tox/Crypto/Handlers.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index e9368731..d02fc6aa 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs @@ -54,7 +54,7 @@ maybeToEither :: Maybe b -> Either String b maybeToEither (Just x) = Right x maybeToEither Nothing = Left "maybeToEither" -data NetCryptoSessionStatus = Unaccepted | Accepted | Confirmed +data NetCryptoSessionStatus = Unaccepted | Accepted {- InProgress AwaitingSessionPacket -} | Confirmed {- Established -} deriving (Eq,Ord,Show,Enum) @@ -420,7 +420,7 @@ freshCryptoSession sessions x <- readTVar (nextSessionId sessions) modifyTVar (nextSessionId sessions) (+1) return x - ncState0 <- atomically $ newTVar Accepted + ncState0 <- atomically $ newTVar Accepted -- (InProgress AwaitingSessionPacket) ncTheirBaseNonce0 <- atomically $ newTVar theirBaseNonce n24 <- atomically $ transportNewNonce crypto state <- lookupSharedSecret crypto key remotePublicKey n24 @@ -540,6 +540,7 @@ updateCryptoSession :: NetCryptoSessions -> SockAddr -> HandshakeParams -> NetCr updateCryptoSession sessions addr hp session = do ncState0 <- atomically $ readTVar (ncState session) ncTheirBaseNonce0 <- atomically $ readTVar (ncTheirBaseNonce session) + -- if (ncState0 >= InProgress AwaitingSessionPacket) if (ncState0 >= Accepted) -- If the nonce in the handshake and the dht key are both the same as -- the ones we have saved, assume we already handled this and this is a @@ -564,7 +565,7 @@ updateCryptoSession sessions addr hp session = do ++ "hpTheirBaseNonce=" ++ show (hpTheirBaseNonce hp)) if ( Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp) then freshCryptoSession sessions addr hp -- basenonce mismatch, trigger refresh - else atomically $ writeTVar (ncState session) Accepted + else atomically $ writeTVar (ncState session) Accepted -- (InProgress AwaitingSessionPacket) cryptoNetHandler :: NetCryptoSessions -> SockAddr -> NetCrypto -> IO (Maybe (NetCrypto -> NetCrypto)) @@ -678,7 +679,7 @@ cryptoNetHandler sessions addr (NetCrypto (CryptoPacket nonce16 encrypted)) = do let x = addtoNonce24 y (fromIntegral dATA_NUM_THRESHOLD) writeTVar ncTheirBaseNonce y -- then set session confirmed, - atomically $ writeTVar ncState Confirmed + atomically $ writeTVar ncState Confirmed {-Established-} -- bump ping machine case ncPingMachine of Just pingMachine -> pingBump pingMachine -- cgit v1.2.3