diff options
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 9 |
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 | |||
54 | maybeToEither (Just x) = Right x | 54 | maybeToEither (Just x) = Right x |
55 | maybeToEither Nothing = Left "maybeToEither" | 55 | maybeToEither Nothing = Left "maybeToEither" |
56 | 56 | ||
57 | data NetCryptoSessionStatus = Unaccepted | Accepted | Confirmed | 57 | data 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 | |||
540 | updateCryptoSession sessions addr hp session = do | 540 | updateCryptoSession 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 | ||
570 | cryptoNetHandler :: NetCryptoSessions -> SockAddr -> NetCrypto -> IO (Maybe (NetCrypto -> NetCrypto)) | 571 | cryptoNetHandler :: 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 |