diff options
author | joe <joe@jerkface.net> | 2017-11-21 13:41:32 -0500 |
---|---|---|
committer | joe <joe@jerkface.net> | 2017-11-21 13:41:32 -0500 |
commit | 83df973a1f81a9c227a6704c03b8eeb0f17c5dcf (patch) | |
tree | 5ec33e47579f7a736763ea380119f3a5ab8a4782 /src/Network/Tox/Crypto/Handlers.hs | |
parent | be968e3f3fb15bfcc1f2f58b04bf55c883c42bb1 (diff) |
addtoNonce24: unsafeDupablePerformIO at def, not call sites.
Diffstat (limited to 'src/Network/Tox/Crypto/Handlers.hs')
-rw-r--r-- | src/Network/Tox/Crypto/Handlers.hs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/Network/Tox/Crypto/Handlers.hs b/src/Network/Tox/Crypto/Handlers.hs index 6e1623de..13ee0ed2 100644 --- a/src/Network/Tox/Crypto/Handlers.hs +++ b/src/Network/Tox/Crypto/Handlers.hs | |||
@@ -24,7 +24,6 @@ import qualified Data.PacketQueue as PQ | |||
24 | import Data.Serialize as S | 24 | import Data.Serialize as S |
25 | import Data.Word | 25 | import Data.Word |
26 | import qualified Data.Word64Map as W64 | 26 | import qualified Data.Word64Map as W64 |
27 | import GHC.Conc (unsafeIOToSTM) | ||
28 | import qualified Data.Set as Set | 27 | import qualified Data.Set as Set |
29 | import qualified Data.Array.Unboxed as A | 28 | import qualified Data.Array.Unboxed as A |
30 | import SensibleDir | 29 | import SensibleDir |
@@ -36,7 +35,6 @@ import System.Directory | |||
36 | import System.Random -- for ping fuzz | 35 | import System.Random -- for ping fuzz |
37 | import Control.Concurrent | 36 | import Control.Concurrent |
38 | import GHC.Conc (labelThread) | 37 | import GHC.Conc (labelThread) |
39 | import System.IO.Unsafe(unsafeDupablePerformIO {- unsafeIOToSTM -}) | ||
40 | import PingMachine | 38 | import PingMachine |
41 | 39 | ||
42 | -- util, todo: move to another module | 40 | -- util, todo: move to another module |
@@ -341,7 +339,7 @@ freshCryptoSession sessions | |||
341 | f <- lookupNonceFunction crypto newsession theirSessionKey | 339 | f <- lookupNonceFunction crypto newsession theirSessionKey |
342 | atomically $ do | 340 | atomically $ do |
343 | n24 <- readTVar ncMyPacketNonce0 | 341 | n24 <- readTVar ncMyPacketNonce0 |
344 | let n24plus1 = unsafeDupablePerformIO (incrementNonce24 n24) | 342 | let n24plus1 = incrementNonce24 n24 |
345 | writeTVar ncMyPacketNonce0 n24plus1 | 343 | writeTVar ncMyPacketNonce0 n24plus1 |
346 | return (return (f n24, n24, ncOutgoingIdMap0)) | 344 | return (return (f n24, n24, ncOutgoingIdMap0)) |
347 | pktoq <- atomically $ PQ.newOutGoing pktq ncToWire toWireIO 0 (outboundQueueCapacity sessions) 0 | 345 | pktoq <- atomically $ PQ.newOutGoing pktq ncToWire toWireIO 0 (outboundQueueCapacity sessions) 0 |
@@ -488,8 +486,8 @@ cryptoNetHandler sessions addr (NetCrypto (CryptoPacket nonce16 encrypted)) = do | |||
488 | theirBaseNonce <- atomically $ readTVar ncTheirBaseNonce | 486 | theirBaseNonce <- atomically $ readTVar ncTheirBaseNonce |
489 | -- Try to decrypt message | 487 | -- Try to decrypt message |
490 | let diff :: Word16 | 488 | let diff :: Word16 |
491 | diff = nonce16 - fromIntegral (last2Bytes theirBaseNonce) -- truncating to Word16 | 489 | diff = nonce16 - fromIntegral (last2Bytes theirBaseNonce) -- truncating to Word16 |
492 | tempNonce <- addtoNonce24 theirBaseNonce (fromIntegral diff) -- expanding to Word | 490 | tempNonce = addtoNonce24 theirBaseNonce (fromIntegral diff) -- expanding to Word |
493 | lr <- fmap join $ sequence $ do -- Either Monad -- | 491 | lr <- fmap join $ sequence $ do -- Either Monad -- |
494 | pubkey <- maybeToEither ncTheirSessionPublic | 492 | pubkey <- maybeToEither ncTheirSessionPublic |
495 | Right $ do -- IO Monad | 493 | Right $ do -- IO Monad |
@@ -508,8 +506,7 @@ cryptoNetHandler sessions addr (NetCrypto (CryptoPacket nonce16 encrypted)) = do | |||
508 | when (diff > 2 * dATA_NUM_THRESHOLD)$ | 506 | when (diff > 2 * dATA_NUM_THRESHOLD)$ |
509 | atomically $ do | 507 | atomically $ do |
510 | y <- readTVar ncTheirBaseNonce | 508 | y <- readTVar ncTheirBaseNonce |
511 | -- all because Storable forces IO... | 509 | let x = addtoNonce24 y (fromIntegral dATA_NUM_THRESHOLD) |
512 | x <- unsafeIOToSTM $ addtoNonce24 y (fromIntegral dATA_NUM_THRESHOLD) | ||
513 | writeTVar ncTheirBaseNonce y | 510 | writeTVar ncTheirBaseNonce y |
514 | -- then set session confirmed, | 511 | -- then set session confirmed, |
515 | atomically $ writeTVar ncState Confirmed | 512 | atomically $ writeTVar ncState Confirmed |