|
|
|
@@ -22,7 +22,7 @@ batchingTests :: Spec
|
|
|
|
|
batchingTests = do
|
|
|
|
|
describe "batchTransmissions" $ do
|
|
|
|
|
describe "SMP v7 (current)" $ do
|
|
|
|
|
it "should batch with 109 subscriptions per batch" $ testBatchSubscriptions
|
|
|
|
|
it "should batch with 109 subscriptions per batch" testBatchSubscriptions
|
|
|
|
|
it "should break on message that does not fit" testBatchWithMessage
|
|
|
|
|
it "should break on large message" testBatchWithLargeMessage
|
|
|
|
|
describe "v8 (next)" $ do
|
|
|
|
@@ -42,14 +42,14 @@ batchingTests = do
|
|
|
|
|
testBatchSubscriptions :: IO ()
|
|
|
|
|
testBatchSubscriptions = do
|
|
|
|
|
sessId <- atomically . C.randomBytes 32 =<< C.newRandom
|
|
|
|
|
subs <- replicateM 250 $ randomSUB sessId
|
|
|
|
|
subs <- replicateM 300 $ randomSUB sessId
|
|
|
|
|
let batches1 = batchTransmissions False smpBlockSize $ L.fromList subs
|
|
|
|
|
all lenOk1 batches1 `shouldBe` True
|
|
|
|
|
length batches1 `shouldBe` 250
|
|
|
|
|
length batches1 `shouldBe` 300
|
|
|
|
|
let batches = batchTransmissions True smpBlockSize $ L.fromList subs
|
|
|
|
|
length batches `shouldBe` 3
|
|
|
|
|
[TBTransmissions s1 n1 _, TBTransmissions s2 n2 _, TBTransmissions s3 n3 _] <- pure batches
|
|
|
|
|
(n1, n2, n3) `shouldBe` (32, 109, 109)
|
|
|
|
|
(n1, n2, n3) `shouldBe` (28, 136, 136)
|
|
|
|
|
all lenOk [s1, s2, s3] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testBatchSubscriptionsV8 :: IO ()
|
|
|
|
@@ -62,7 +62,7 @@ testBatchSubscriptionsV8 = do
|
|
|
|
|
let batches = batchTransmissions True smpBlockSize $ L.fromList subs
|
|
|
|
|
length batches `shouldBe` 3
|
|
|
|
|
[TBTransmissions s1 n1 _, TBTransmissions s2 n2 _, TBTransmissions s3 n3 _] <- pure batches
|
|
|
|
|
(n1, n2, n3) `shouldBe` (16, 142, 142)
|
|
|
|
|
(n1, n2, n3) `shouldBe` (28, 136, 136)
|
|
|
|
|
all lenOk [s1, s2, s3] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testBatchWithMessage :: IO ()
|
|
|
|
@@ -78,7 +78,7 @@ testBatchWithMessage = do
|
|
|
|
|
let batches = batchTransmissions True smpBlockSize $ L.fromList cmds
|
|
|
|
|
length batches `shouldBe` 2
|
|
|
|
|
[TBTransmissions s1 n1 _, TBTransmissions s2 n2 _] <- pure batches
|
|
|
|
|
(n1, n2) `shouldBe` (45, 56)
|
|
|
|
|
(n1, n2) `shouldBe` (32, 69)
|
|
|
|
|
all lenOk [s1, s2] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testBatchWithMessageV8 :: IO ()
|
|
|
|
@@ -94,26 +94,26 @@ testBatchWithMessageV8 = do
|
|
|
|
|
let batches = batchTransmissions True smpBlockSize $ L.fromList cmds
|
|
|
|
|
length batches `shouldBe` 2
|
|
|
|
|
[TBTransmissions s1 n1 _, TBTransmissions s2 n2 _] <- pure batches
|
|
|
|
|
(n1, n2) `shouldBe` (29, 72)
|
|
|
|
|
(n1, n2) `shouldBe` (32, 69)
|
|
|
|
|
all lenOk [s1, s2] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testBatchWithLargeMessage :: IO ()
|
|
|
|
|
testBatchWithLargeMessage = do
|
|
|
|
|
sessId <- atomically . C.randomBytes 32 =<< C.newRandom
|
|
|
|
|
subs1 <- replicateM 60 $ randomSUB sessId
|
|
|
|
|
subs1 <- replicateM 50 $ randomSUB sessId
|
|
|
|
|
send <- randomSEND sessId 17000
|
|
|
|
|
subs2 <- replicateM 120 $ randomSUB sessId
|
|
|
|
|
subs2 <- replicateM 150 $ randomSUB sessId
|
|
|
|
|
let cmds = subs1 <> [send] <> subs2
|
|
|
|
|
batches1 = batchTransmissions False smpBlockSize $ L.fromList cmds
|
|
|
|
|
all lenOk1 batches1 `shouldBe` False
|
|
|
|
|
length batches1 `shouldBe` 181
|
|
|
|
|
let batches1' = take 60 batches1 <> drop 61 batches1
|
|
|
|
|
length batches1 `shouldBe` 201
|
|
|
|
|
let batches1' = take 50 batches1 <> drop 51 batches1
|
|
|
|
|
all lenOk1 batches1' `shouldBe` True
|
|
|
|
|
length batches1' `shouldBe` 180
|
|
|
|
|
length batches1' `shouldBe` 200
|
|
|
|
|
let batches = batchTransmissions True smpBlockSize $ L.fromList cmds
|
|
|
|
|
length batches `shouldBe` 4
|
|
|
|
|
[TBTransmissions s1 n1 _, TBError TELargeMsg _, TBTransmissions s2 n2 _, TBTransmissions s3 n3 _] <- pure batches
|
|
|
|
|
(n1, n2, n3) `shouldBe` (60, 11, 109)
|
|
|
|
|
(n1, n2, n3) `shouldBe` (50, 14, 136)
|
|
|
|
|
all lenOk [s1, s2, s3] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testBatchWithLargeMessageV8 :: IO ()
|
|
|
|
@@ -132,21 +132,20 @@ testBatchWithLargeMessageV8 = do
|
|
|
|
|
let batches = batchTransmissions True smpBlockSize $ L.fromList cmds
|
|
|
|
|
length batches `shouldBe` 4
|
|
|
|
|
[TBTransmissions s1 n1 _, TBError TELargeMsg _, TBTransmissions s2 n2 _, TBTransmissions s3 n3 _] <- pure batches
|
|
|
|
|
(n1, n2, n3) `shouldBe` (60, 8, 142)
|
|
|
|
|
(n1, n2, n3) `shouldBe` (60, 14, 136)
|
|
|
|
|
all lenOk [s1, s2, s3] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testClientBatchSubscriptions :: IO ()
|
|
|
|
|
testClientBatchSubscriptions = do
|
|
|
|
|
sessId <- atomically . C.randomBytes 32 =<< C.newRandom
|
|
|
|
|
client <- atomically $ clientStub sessId currentClientSMPRelayVersion Nothing
|
|
|
|
|
subs <- replicateM 250 $ randomSUBCmd client
|
|
|
|
|
client <- testClientStub
|
|
|
|
|
subs <- replicateM 300 $ randomSUBCmd client
|
|
|
|
|
let batches1 = batchTransmissions' False smpBlockSize $ L.fromList subs
|
|
|
|
|
all lenOk1 batches1 `shouldBe` True
|
|
|
|
|
let batches = batchTransmissions' True smpBlockSize $ L.fromList subs
|
|
|
|
|
length batches `shouldBe` 3
|
|
|
|
|
[TBTransmissions s1 n1 rs1, TBTransmissions s2 n2 rs2, TBTransmissions s3 n3 rs3] <- pure batches
|
|
|
|
|
(n1, n2, n3) `shouldBe` (31, 110, 109)
|
|
|
|
|
(length rs1, length rs2, length rs3) `shouldBe` (31, 110, 109)
|
|
|
|
|
(n1, n2, n3) `shouldBe` (28, 136, 136)
|
|
|
|
|
(length rs1, length rs2, length rs3) `shouldBe` (28, 136, 136)
|
|
|
|
|
all lenOk [s1, s2, s3] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testClientBatchSubscriptionsV8 :: IO ()
|
|
|
|
@@ -158,14 +157,13 @@ testClientBatchSubscriptionsV8 = do
|
|
|
|
|
let batches = batchTransmissions' True smpBlockSize $ L.fromList subs
|
|
|
|
|
length batches `shouldBe` 3
|
|
|
|
|
[TBTransmissions s1 n1 rs1, TBTransmissions s2 n2 rs2, TBTransmissions s3 n3 rs3] <- pure batches
|
|
|
|
|
(n1, n2, n3) `shouldBe` (16, 142, 142)
|
|
|
|
|
(length rs1, length rs2, length rs3) `shouldBe` (16, 142, 142)
|
|
|
|
|
(n1, n2, n3) `shouldBe` (28, 136, 136)
|
|
|
|
|
(length rs1, length rs2, length rs3) `shouldBe` (28, 136, 136)
|
|
|
|
|
all lenOk [s1, s2, s3] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testClientBatchWithMessage :: IO ()
|
|
|
|
|
testClientBatchWithMessage = do
|
|
|
|
|
sessId <- atomically . C.randomBytes 32 =<< C.newRandom
|
|
|
|
|
client <- atomically $ clientStub sessId currentClientSMPRelayVersion Nothing
|
|
|
|
|
client <- testClientStub
|
|
|
|
|
subs1 <- replicateM 60 $ randomSUBCmd client
|
|
|
|
|
send <- randomSENDCmd client 8000
|
|
|
|
|
subs2 <- replicateM 40 $ randomSUBCmd client
|
|
|
|
@@ -176,8 +174,8 @@ testClientBatchWithMessage = do
|
|
|
|
|
let batches = batchTransmissions' True smpBlockSize $ L.fromList cmds
|
|
|
|
|
length batches `shouldBe` 2
|
|
|
|
|
[TBTransmissions s1 n1 rs1, TBTransmissions s2 n2 rs2] <- pure batches
|
|
|
|
|
(n1, n2) `shouldBe` (45, 56)
|
|
|
|
|
(length rs1, length rs2) `shouldBe` (45, 56)
|
|
|
|
|
(n1, n2) `shouldBe` (32, 69)
|
|
|
|
|
(length rs1, length rs2) `shouldBe` (32, 69)
|
|
|
|
|
all lenOk [s1, s2] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testClientBatchWithMessageV8 :: IO ()
|
|
|
|
@@ -193,38 +191,37 @@ testClientBatchWithMessageV8 = do
|
|
|
|
|
let batches = batchTransmissions' True smpBlockSize $ L.fromList cmds
|
|
|
|
|
length batches `shouldBe` 2
|
|
|
|
|
[TBTransmissions s1 n1 rs1, TBTransmissions s2 n2 rs2] <- pure batches
|
|
|
|
|
(n1, n2) `shouldBe` (28, 73)
|
|
|
|
|
(length rs1, length rs2) `shouldBe` (28, 73)
|
|
|
|
|
(n1, n2) `shouldBe` (32, 69)
|
|
|
|
|
(length rs1, length rs2) `shouldBe` (32, 69)
|
|
|
|
|
all lenOk [s1, s2] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testClientBatchWithLargeMessage :: IO ()
|
|
|
|
|
testClientBatchWithLargeMessage = do
|
|
|
|
|
sessId <- atomically . C.randomBytes 32 =<< C.newRandom
|
|
|
|
|
client <- atomically $ clientStub sessId currentClientSMPRelayVersion Nothing
|
|
|
|
|
subs1 <- replicateM 60 $ randomSUBCmd client
|
|
|
|
|
client <- testClientStub
|
|
|
|
|
subs1 <- replicateM 50 $ randomSUBCmd client
|
|
|
|
|
send <- randomSENDCmd client 17000
|
|
|
|
|
subs2 <- replicateM 120 $ randomSUBCmd client
|
|
|
|
|
subs2 <- replicateM 150 $ randomSUBCmd client
|
|
|
|
|
let cmds = subs1 <> [send] <> subs2
|
|
|
|
|
batches1 = batchTransmissions' False smpBlockSize $ L.fromList cmds
|
|
|
|
|
all lenOk1 batches1 `shouldBe` False
|
|
|
|
|
length batches1 `shouldBe` 181
|
|
|
|
|
let batches1' = take 60 batches1 <> drop 61 batches1
|
|
|
|
|
length batches1 `shouldBe` 201
|
|
|
|
|
let batches1' = take 50 batches1 <> drop 51 batches1
|
|
|
|
|
all lenOk1 batches1' `shouldBe` True
|
|
|
|
|
length batches1' `shouldBe` 180
|
|
|
|
|
length batches1' `shouldBe` 200
|
|
|
|
|
--
|
|
|
|
|
let batches = batchTransmissions' True smpBlockSize $ L.fromList cmds
|
|
|
|
|
length batches `shouldBe` 4
|
|
|
|
|
[TBTransmissions s1 n1 rs1, TBError TELargeMsg _, TBTransmissions s2 n2 rs2, TBTransmissions s3 n3 rs3] <- pure batches
|
|
|
|
|
(n1, n2, n3) `shouldBe` (60, 11, 109)
|
|
|
|
|
(length rs1, length rs2, length rs3) `shouldBe` (60, 11, 109)
|
|
|
|
|
(n1, n2, n3) `shouldBe` (50, 14, 136)
|
|
|
|
|
(length rs1, length rs2, length rs3) `shouldBe` (50, 14, 136)
|
|
|
|
|
all lenOk [s1, s2, s3] `shouldBe` True
|
|
|
|
|
--
|
|
|
|
|
let cmds' = [send] <> subs1 <> subs2
|
|
|
|
|
let batches' = batchTransmissions' True smpBlockSize $ L.fromList cmds'
|
|
|
|
|
length batches' `shouldBe` 3
|
|
|
|
|
[TBError TELargeMsg _, TBTransmissions s1' n1' rs1', TBTransmissions s2' n2' rs2'] <- pure batches'
|
|
|
|
|
(n1', n2') `shouldBe` (71, 109)
|
|
|
|
|
(length rs1', length rs2') `shouldBe` (71, 109)
|
|
|
|
|
(n1', n2') `shouldBe` (64, 136)
|
|
|
|
|
(length rs1', length rs2') `shouldBe` (64, 136)
|
|
|
|
|
all lenOk [s1', s2'] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testClientBatchWithLargeMessageV8 :: IO ()
|
|
|
|
@@ -244,37 +241,43 @@ testClientBatchWithLargeMessageV8 = do
|
|
|
|
|
let batches = batchTransmissions' True smpBlockSize $ L.fromList cmds
|
|
|
|
|
length batches `shouldBe` 4
|
|
|
|
|
[TBTransmissions s1 n1 rs1, TBError TELargeMsg _, TBTransmissions s2 n2 rs2, TBTransmissions s3 n3 rs3] <- pure batches
|
|
|
|
|
(n1, n2, n3) `shouldBe` (60, 8, 142)
|
|
|
|
|
(length rs1, length rs2, length rs3) `shouldBe` (60, 8, 142)
|
|
|
|
|
(n1, n2, n3) `shouldBe` (60, 14, 136)
|
|
|
|
|
(length rs1, length rs2, length rs3) `shouldBe` (60, 14, 136)
|
|
|
|
|
all lenOk [s1, s2, s3] `shouldBe` True
|
|
|
|
|
--
|
|
|
|
|
let cmds' = [send] <> subs1 <> subs2
|
|
|
|
|
let batches' = batchTransmissions' True smpBlockSize $ L.fromList cmds'
|
|
|
|
|
length batches' `shouldBe` 3
|
|
|
|
|
[TBError TELargeMsg _, TBTransmissions s1' n1' rs1', TBTransmissions s2' n2' rs2'] <- pure batches'
|
|
|
|
|
(n1', n2') `shouldBe` (68, 142)
|
|
|
|
|
(length rs1', length rs2') `shouldBe` (68, 142)
|
|
|
|
|
(n1', n2') `shouldBe` (74, 136)
|
|
|
|
|
(length rs1', length rs2') `shouldBe` (74, 136)
|
|
|
|
|
all lenOk [s1', s2'] `shouldBe` True
|
|
|
|
|
|
|
|
|
|
testClientStub :: IO (ProtocolClient ErrorType BrokerMsg)
|
|
|
|
|
testClientStub = do
|
|
|
|
|
g <- C.newRandom
|
|
|
|
|
sessId <- atomically $ C.randomBytes 32 g
|
|
|
|
|
atomically $ clientStub g sessId currentClientSMPRelayVersion Nothing
|
|
|
|
|
|
|
|
|
|
clientStubV8 :: IO (ProtocolClient ErrorType BrokerMsg)
|
|
|
|
|
clientStubV8 = do
|
|
|
|
|
g <- C.newRandom
|
|
|
|
|
sessId <- atomically $ C.randomBytes 32 g
|
|
|
|
|
(rKey, _) <- atomically $ C.generateAuthKeyPair C.SX25519 g
|
|
|
|
|
thAuth_ <- testTHandleAuth authEncryptCmdsSMPVersion g rKey
|
|
|
|
|
atomically $ clientStub sessId authEncryptCmdsSMPVersion thAuth_
|
|
|
|
|
atomically $ clientStub g sessId authEncryptCmdsSMPVersion thAuth_
|
|
|
|
|
|
|
|
|
|
randomSUB :: ByteString -> IO (Either TransportError (Maybe TransmissionAuth, ByteString))
|
|
|
|
|
randomSUB = randomSUB_ C.SEd448 currentClientSMPRelayVersion
|
|
|
|
|
randomSUB = randomSUB_ C.SEd25519 currentClientSMPRelayVersion
|
|
|
|
|
|
|
|
|
|
randomSUBv8 :: ByteString -> IO (Either TransportError (Maybe TransmissionAuth, ByteString))
|
|
|
|
|
randomSUBv8 = randomSUB_ C.SX25519 authEncryptCmdsSMPVersion
|
|
|
|
|
randomSUBv8 = randomSUB_ C.SEd25519 authEncryptCmdsSMPVersion
|
|
|
|
|
|
|
|
|
|
randomSUB_ :: (C.AlgorithmI a, C.AuthAlgorithm a) => C.SAlgorithm a -> Version -> ByteString -> IO (Either TransportError (Maybe TransmissionAuth, ByteString))
|
|
|
|
|
randomSUB_ a v sessId = do
|
|
|
|
|
g <- C.newRandom
|
|
|
|
|
rId <- atomically $ C.randomBytes 24 g
|
|
|
|
|
corrId <- atomically $ CorrId <$> C.randomBytes 3 g
|
|
|
|
|
corrId <- atomically $ CorrId <$> C.randomBytes 24 g
|
|
|
|
|
(rKey, rpKey) <- atomically $ C.generateAuthKeyPair a g
|
|
|
|
|
thAuth_ <- testTHandleAuth v g rKey
|
|
|
|
|
let thParams = testTHandleParams v sessId
|
|
|
|
@@ -282,10 +285,10 @@ randomSUB_ a v sessId = do
|
|
|
|
|
pure $ (,tToSend) <$> authTransmission thAuth_ (Just rpKey) corrId tForAuth
|
|
|
|
|
|
|
|
|
|
randomSUBCmd :: ProtocolClient ErrorType BrokerMsg -> IO (PCTransmission ErrorType BrokerMsg)
|
|
|
|
|
randomSUBCmd = randomSUBCmd_ C.SEd448
|
|
|
|
|
randomSUBCmd = randomSUBCmd_ C.SEd25519
|
|
|
|
|
|
|
|
|
|
randomSUBCmdV8 :: ProtocolClient ErrorType BrokerMsg -> IO (PCTransmission ErrorType BrokerMsg)
|
|
|
|
|
randomSUBCmdV8 = randomSUBCmd_ C.SX25519
|
|
|
|
|
randomSUBCmdV8 = randomSUBCmd_ C.SEd25519 -- same as v7
|
|
|
|
|
|
|
|
|
|
randomSUBCmd_ :: (C.AlgorithmI a, C.AuthAlgorithm a) => C.SAlgorithm a -> ProtocolClient ErrorType BrokerMsg -> IO (PCTransmission ErrorType BrokerMsg)
|
|
|
|
|
randomSUBCmd_ a c = do
|
|
|
|
@@ -295,7 +298,7 @@ randomSUBCmd_ a c = do
|
|
|
|
|
mkTransmission c (Just rpKey, rId, Cmd SRecipient SUB)
|
|
|
|
|
|
|
|
|
|
randomSEND :: ByteString -> Int -> IO (Either TransportError (Maybe TransmissionAuth, ByteString))
|
|
|
|
|
randomSEND = randomSEND_ C.SEd448 currentClientSMPRelayVersion
|
|
|
|
|
randomSEND = randomSEND_ C.SEd25519 currentClientSMPRelayVersion
|
|
|
|
|
|
|
|
|
|
randomSENDv8 :: ByteString -> Int -> IO (Either TransportError (Maybe TransmissionAuth, ByteString))
|
|
|
|
|
randomSENDv8 = randomSEND_ C.SX25519 authEncryptCmdsSMPVersion
|
|
|
|
@@ -305,12 +308,12 @@ randomSEND_ a v sessId len = do
|
|
|
|
|
g <- C.newRandom
|
|
|
|
|
sId <- atomically $ C.randomBytes 24 g
|
|
|
|
|
corrId <- atomically $ CorrId <$> C.randomBytes 3 g
|
|
|
|
|
(rKey, rpKey) <- atomically $ C.generateAuthKeyPair a g
|
|
|
|
|
thAuth_ <- testTHandleAuth v g rKey
|
|
|
|
|
(sKey, spKey) <- atomically $ C.generateAuthKeyPair a g
|
|
|
|
|
thAuth_ <- testTHandleAuth v g sKey
|
|
|
|
|
msg <- atomically $ C.randomBytes len g
|
|
|
|
|
let thParams = testTHandleParams v sessId
|
|
|
|
|
ClntTransmission {tForAuth, tToSend} = encodeClntTransmission thParams (corrId, sId, Cmd SSender $ SEND noMsgFlags msg)
|
|
|
|
|
pure $ (,tToSend) <$> authTransmission thAuth_ (Just rpKey) corrId tForAuth
|
|
|
|
|
pure $ (,tToSend) <$> authTransmission thAuth_ (Just spKey) corrId tForAuth
|
|
|
|
|
|
|
|
|
|
testTHandleParams :: Version -> ByteString -> THandleParams
|
|
|
|
|
testTHandleParams v sessionId =
|
|
|
|
@@ -331,7 +334,7 @@ testTHandleAuth v g (C.APublicAuthKey a k) = case a of
|
|
|
|
|
_ -> pure Nothing
|
|
|
|
|
|
|
|
|
|
randomSENDCmd :: ProtocolClient ErrorType BrokerMsg -> Int -> IO (PCTransmission ErrorType BrokerMsg)
|
|
|
|
|
randomSENDCmd = randomSENDCmd_ C.SEd448
|
|
|
|
|
randomSENDCmd = randomSENDCmd_ C.SEd25519
|
|
|
|
|
|
|
|
|
|
randomSENDCmdV8 :: ProtocolClient ErrorType BrokerMsg -> Int -> IO (PCTransmission ErrorType BrokerMsg)
|
|
|
|
|
randomSENDCmdV8 = randomSENDCmd_ C.SX25519
|
|
|
|
|