summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJames Crayne <jim.crayne@gmail.com>2018-05-30 02:47:14 +0000
committerJames Crayne <jim.crayne@gmail.com>2018-05-30 02:47:14 +0000
commit1afb9ea88c52e7face6293ef1c837837c1c9b2ef (patch)
treed07ecab21e41051e9f783619639bfda2b0233a55 /src
parentbce19c5eaf5e07501b322811d7cc2be53db9e451 (diff)
comment showing relation between old and new crypto session status types
Diffstat (limited to 'src')
-rw-r--r--src/Network/Tox/Crypto/Handlers.hs9
1 files changed, 5 insertions, 4 deletions
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
54maybeToEither (Just x) = Right x 54maybeToEither (Just x) = Right x
55maybeToEither Nothing = Left "maybeToEither" 55maybeToEither Nothing = Left "maybeToEither"
56 56
57data NetCryptoSessionStatus = Unaccepted | Accepted | Confirmed 57data NetCryptoSessionStatus = Unaccepted | Accepted {- InProgress AwaitingSessionPacket -} | Confirmed {- Established -}
58 deriving (Eq,Ord,Show,Enum) 58 deriving (Eq,Ord,Show,Enum)
59 59
60 60
@@ -420,7 +420,7 @@ freshCryptoSession sessions
420 x <- readTVar (nextSessionId sessions) 420 x <- readTVar (nextSessionId sessions)
421 modifyTVar (nextSessionId sessions) (+1) 421 modifyTVar (nextSessionId sessions) (+1)
422 return x 422 return x
423 ncState0 <- atomically $ newTVar Accepted 423 ncState0 <- atomically $ newTVar Accepted -- (InProgress AwaitingSessionPacket)
424 ncTheirBaseNonce0 <- atomically $ newTVar theirBaseNonce 424 ncTheirBaseNonce0 <- atomically $ newTVar theirBaseNonce
425 n24 <- atomically $ transportNewNonce crypto 425 n24 <- atomically $ transportNewNonce crypto
426 state <- lookupSharedSecret crypto key remotePublicKey n24 426 state <- lookupSharedSecret crypto key remotePublicKey n24
@@ -540,6 +540,7 @@ updateCryptoSession :: NetCryptoSessions -> SockAddr -> HandshakeParams -> NetCr
540updateCryptoSession sessions addr hp session = do 540updateCryptoSession sessions addr hp session = do
541 ncState0 <- atomically $ readTVar (ncState session) 541 ncState0 <- atomically $ readTVar (ncState session)
542 ncTheirBaseNonce0 <- atomically $ readTVar (ncTheirBaseNonce session) 542 ncTheirBaseNonce0 <- atomically $ readTVar (ncTheirBaseNonce session)
543 -- if (ncState0 >= InProgress AwaitingSessionPacket)
543 if (ncState0 >= Accepted) 544 if (ncState0 >= Accepted)
544 -- If the nonce in the handshake and the dht key are both the same as 545 -- If the nonce in the handshake and the dht key are both the same as
545 -- the ones we have saved, assume we already handled this and this is a 546 -- the ones we have saved, assume we already handled this and this is a
@@ -564,7 +565,7 @@ updateCryptoSession sessions addr hp session = do
564 ++ "hpTheirBaseNonce=" ++ show (hpTheirBaseNonce hp)) 565 ++ "hpTheirBaseNonce=" ++ show (hpTheirBaseNonce hp))
565 if ( Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp) 566 if ( Just ncTheirBaseNonce0 /= hpTheirBaseNonce hp)
566 then freshCryptoSession sessions addr hp -- basenonce mismatch, trigger refresh 567 then freshCryptoSession sessions addr hp -- basenonce mismatch, trigger refresh
567 else atomically $ writeTVar (ncState session) Accepted 568 else atomically $ writeTVar (ncState session) Accepted -- (InProgress AwaitingSessionPacket)
568 569
569 570
570cryptoNetHandler :: NetCryptoSessions -> SockAddr -> NetCrypto -> IO (Maybe (NetCrypto -> NetCrypto)) 571cryptoNetHandler :: NetCryptoSessions -> SockAddr -> NetCrypto -> IO (Maybe (NetCrypto -> NetCrypto))
@@ -678,7 +679,7 @@ cryptoNetHandler sessions addr (NetCrypto (CryptoPacket nonce16 encrypted)) = do
678 let x = addtoNonce24 y (fromIntegral dATA_NUM_THRESHOLD) 679 let x = addtoNonce24 y (fromIntegral dATA_NUM_THRESHOLD)
679 writeTVar ncTheirBaseNonce y 680 writeTVar ncTheirBaseNonce y
680 -- then set session confirmed, 681 -- then set session confirmed,
681 atomically $ writeTVar ncState Confirmed 682 atomically $ writeTVar ncState Confirmed {-Established-}
682 -- bump ping machine 683 -- bump ping machine
683 case ncPingMachine of 684 case ncPingMachine of
684 Just pingMachine -> pingBump pingMachine 685 Just pingMachine -> pingBump pingMachine