diff --git a/src/Simplex/Messaging/Client.hs b/src/Simplex/Messaging/Client.hs index ed179a8d9..1a1536968 100644 --- a/src/Simplex/Messaging/Client.hs +++ b/src/Simplex/Messaging/Client.hs @@ -155,7 +155,7 @@ clientStub sessionId = do { action = Nothing, sessionId, sessionTs = undefined, - thVersion = currentSMPServerVersion, + thVersion = currentClientSMPRelayVersion, thAuth = Nothing, timeoutPerBlock = undefined, blockSize = smpBlockSize, @@ -268,7 +268,7 @@ defaultClientConfig serverVRange = } defaultSMPClientConfig :: ProtocolClientConfig -defaultSMPClientConfig = defaultClientConfig supportedSMPServerVRange +defaultSMPClientConfig = defaultClientConfig supportedClientSMPRelayVRange data Request err msg = Request { entityId :: EntityId, diff --git a/src/Simplex/Messaging/Notifications/Client.hs b/src/Simplex/Messaging/Notifications/Client.hs index 879339fe1..d69114b68 100644 --- a/src/Simplex/Messaging/Notifications/Client.hs +++ b/src/Simplex/Messaging/Notifications/Client.hs @@ -10,7 +10,7 @@ import Data.Word (Word16) import Simplex.Messaging.Client import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Notifications.Protocol -import Simplex.Messaging.Notifications.Transport (supportedNTFServerVRange) +import Simplex.Messaging.Notifications.Transport (supportedClientNTFVRange) import Simplex.Messaging.Protocol (ErrorType) import Simplex.Messaging.Util (bshow) @@ -19,7 +19,7 @@ type NtfClient = ProtocolClient ErrorType NtfResponse type NtfClientError = ProtocolClientError ErrorType defaultNTFClientConfig :: ProtocolClientConfig -defaultNTFClientConfig = defaultClientConfig supportedNTFServerVRange +defaultNTFClientConfig = defaultClientConfig supportedClientNTFVRange ntfRegisterToken :: NtfClient -> C.APrivateAuthKey -> NewNtfEntity 'Token -> ExceptT NtfClientError IO (NtfTokenId, C.PublicKeyX25519) ntfRegisterToken c pKey newTkn = diff --git a/src/Simplex/Messaging/Notifications/Server/Main.hs b/src/Simplex/Messaging/Notifications/Server/Main.hs index f3b73f8f4..a915bdbee 100644 --- a/src/Simplex/Messaging/Notifications/Server/Main.hs +++ b/src/Simplex/Messaging/Notifications/Server/Main.hs @@ -19,7 +19,7 @@ import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Notifications.Server (runNtfServer) import Simplex.Messaging.Notifications.Server.Env (NtfServerConfig (..), defaultInactiveClientExpiration) import Simplex.Messaging.Notifications.Server.Push.APNS (defaultAPNSPushClientConfig) -import Simplex.Messaging.Notifications.Transport (supportedNTFServerVRange) +import Simplex.Messaging.Notifications.Transport (supportedServerNTFVRange) import Simplex.Messaging.Protocol (ProtoServerWithAuth (..), pattern NtfServer) import Simplex.Messaging.Server.CLI import Simplex.Messaging.Server.Expiration @@ -136,7 +136,7 @@ ntfServerCLI cfgPath logPath = logStatsStartTime = 0, -- seconds from 00:00 UTC serverStatsLogFile = combine logPath "ntf-server-stats.daily.log", serverStatsBackupFile = logStats $> combine logPath "ntf-server-stats.log", - ntfServerVRange = supportedNTFServerVRange, + ntfServerVRange = supportedServerNTFVRange, transportConfig = defaultTransportServerConfig { logTLSErrors = fromMaybe False $ iniOnOff "TRANSPORT" "log_tls_errors" ini diff --git a/src/Simplex/Messaging/Notifications/Transport.hs b/src/Simplex/Messaging/Notifications/Transport.hs index c0c3e2b73..af78152a3 100644 --- a/src/Simplex/Messaging/Notifications/Transport.hs +++ b/src/Simplex/Messaging/Notifications/Transport.hs @@ -21,11 +21,17 @@ ntfBlockSize = 512 authEncryptCmdsNTFVersion :: Version authEncryptCmdsNTFVersion = 2 -currentNTFServerVersion :: Version -currentNTFServerVersion = 1 +currentClientNTFVersion :: Version +currentClientNTFVersion = 1 -supportedNTFServerVRange :: VersionRange -supportedNTFServerVRange = mkVersionRange 1 currentNTFServerVersion +currentServerNTFVersion :: Version +currentServerNTFVersion = 1 + +supportedClientNTFVRange :: VersionRange +supportedClientNTFVRange = mkVersionRange 1 currentClientNTFVersion + +supportedServerNTFVRange :: VersionRange +supportedServerNTFVRange = mkVersionRange 1 currentServerNTFVersion data NtfServerHandshake = NtfServerHandshake { ntfVersionRange :: VersionRange, diff --git a/src/Simplex/Messaging/Server/Main.hs b/src/Simplex/Messaging/Server/Main.hs index e02256aab..ea5ff2f5f 100644 --- a/src/Simplex/Messaging/Server/Main.hs +++ b/src/Simplex/Messaging/Server/Main.hs @@ -25,7 +25,7 @@ import Simplex.Messaging.Server (runSMPServer) import Simplex.Messaging.Server.CLI import Simplex.Messaging.Server.Env.STM (ServerConfig (..), defMsgExpirationDays, defaultInactiveClientExpiration, defaultMessageExpiration) import Simplex.Messaging.Server.Expiration -import Simplex.Messaging.Transport (simplexMQVersion, supportedSMPServerVRange) +import Simplex.Messaging.Transport (simplexMQVersion, supportedServerSMPRelayVRange) import Simplex.Messaging.Transport.Client (TransportHost (..)) import Simplex.Messaging.Transport.Server (TransportServerConfig (..), defaultTransportServerConfig) import Simplex.Messaging.Util (safeDecodeUtf8) @@ -200,7 +200,7 @@ smpServerCLI cfgPath logPath = logStatsStartTime = 0, -- seconds from 00:00 UTC serverStatsLogFile = combine logPath "smp-server-stats.daily.log", serverStatsBackupFile = logStats $> combine logPath "smp-server-stats.log", - smpServerVRange = supportedSMPServerVRange, + smpServerVRange = supportedServerSMPRelayVRange, transportConfig = defaultTransportServerConfig { logTLSErrors = fromMaybe False $ iniOnOff "TRANSPORT" "log_tls_errors" ini diff --git a/src/Simplex/Messaging/Transport.hs b/src/Simplex/Messaging/Transport.hs index 99b5e4eed..c20037684 100644 --- a/src/Simplex/Messaging/Transport.hs +++ b/src/Simplex/Messaging/Transport.hs @@ -27,8 +27,10 @@ -- See https://github.com/simplex-chat/simplexmq/blob/master/protocol/simplex-messaging.md#appendix-a module Simplex.Messaging.Transport ( -- * SMP transport parameters - supportedSMPServerVRange, - currentSMPServerVersion, + supportedClientSMPRelayVRange, + supportedServerSMPRelayVRange, + currentClientSMPRelayVersion, + currentServerSMPRelayVersion, basicAuthSMPVersion, subModeSMPVersion, authEncryptCmdsSMPVersion, @@ -121,13 +123,19 @@ subModeSMPVersion = 6 authEncryptCmdsSMPVersion :: Version authEncryptCmdsSMPVersion = 7 -currentSMPServerVersion :: Version -currentSMPServerVersion = 6 +currentClientSMPRelayVersion :: Version +currentClientSMPRelayVersion = 6 + +currentServerSMPRelayVersion :: Version +currentServerSMPRelayVersion = 6 -- minimal supported protocol version is 4 -- TODO remove code that supports sending commands without batching -supportedSMPServerVRange :: VersionRange -supportedSMPServerVRange = mkVersionRange batchCmdsSMPVersion currentSMPServerVersion +supportedClientSMPRelayVRange :: VersionRange +supportedClientSMPRelayVRange = mkVersionRange batchCmdsSMPVersion currentClientSMPRelayVersion + +supportedServerSMPRelayVRange :: VersionRange +supportedServerSMPRelayVRange = mkVersionRange batchCmdsSMPVersion currentServerSMPRelayVersion simplexMQVersion :: String simplexMQVersion = showVersion SMQ.version diff --git a/tests/AgentTests/FunctionalAPITests.hs b/tests/AgentTests/FunctionalAPITests.hs index b4884a406..347ec75f4 100644 --- a/tests/AgentTests/FunctionalAPITests.hs +++ b/tests/AgentTests/FunctionalAPITests.hs @@ -383,6 +383,7 @@ testMatrix2 t runTest = do it "v7" $ withSmpServerV7 t $ runTestCfg2 agentCfgV7 agentCfgV7 3 runTest it "v7 to current" $ withSmpServerV7 t $ runTestCfg2 agentCfgV7 agentCfg 3 runTest it "current to v7" $ withSmpServerV7 t $ runTestCfg2 agentCfg agentCfgV7 3 runTest + it "current with v7 server" $ withSmpServerV7 t $ runTestCfg2 agentCfg agentCfg 3 runTest it "current" $ withSmpServer t $ runTestCfg2 agentCfg agentCfg 3 runTest it "prev" $ withSmpServer t $ runTestCfg2 agentCfgVPrev agentCfgVPrev 3 runTest it "prev to current" $ withSmpServer t $ runTestCfg2 agentCfgVPrev agentCfg 3 runTest diff --git a/tests/CoreTests/BatchingTests.hs b/tests/CoreTests/BatchingTests.hs index f12fe0755..01826e4c4 100644 --- a/tests/CoreTests/BatchingTests.hs +++ b/tests/CoreTests/BatchingTests.hs @@ -11,7 +11,6 @@ import Simplex.Messaging.Client import qualified Simplex.Messaging.Crypto as C import Simplex.Messaging.Protocol import Simplex.Messaging.Transport -import Simplex.Messaging.Version (VersionRange (..)) import Test.Hspec batchingTests :: Spec @@ -141,7 +140,7 @@ randomSUB sessId = do rId <- atomically $ C.randomBytes 24 g corrId <- atomically $ CorrId <$> C.randomBytes 3 g (_, rpKey) <- atomically $ C.generateSignatureKeyPair C.SEd448 g - let s = encodeTransmission (maxVersion supportedSMPServerVRange) sessId (corrId, rId, Cmd SRecipient SUB) + let s = encodeTransmission currentClientSMPRelayVersion sessId (corrId, rId, Cmd SRecipient SUB) pure $ Right (Just . TASignature $ C.sign rpKey s, s) randomSUBCmd :: ProtocolClient ErrorType BrokerMsg -> IO (PCTransmission ErrorType BrokerMsg) @@ -158,7 +157,7 @@ randomSEND sessId len = do corrId <- atomically $ CorrId <$> C.randomBytes 3 g (_, rpKey) <- atomically $ C.generateSignatureKeyPair C.SEd448 g msg <- atomically $ C.randomBytes len g - let s = encodeTransmission (maxVersion supportedSMPServerVRange) sessId (corrId, sId, Cmd SSender $ SEND noMsgFlags msg) + let s = encodeTransmission currentClientSMPRelayVersion sessId (corrId, sId, Cmd SSender $ SEND noMsgFlags msg) pure $ Right (Just . TASignature $ C.sign rpKey s, s) randomSENDCmd :: ProtocolClient ErrorType BrokerMsg -> Int -> IO (PCTransmission ErrorType BrokerMsg) diff --git a/tests/NtfClient.hs b/tests/NtfClient.hs index 7a6dcfe01..9eb53c036 100644 --- a/tests/NtfClient.hs +++ b/tests/NtfClient.hs @@ -76,7 +76,7 @@ testNtfClient client = do runTransportClient defaultTransportClientConfig Nothing host ntfTestPort (Just testKeyHash) $ \h -> do g <- liftIO C.newRandom ks <- atomically $ C.generateKeyPair g - liftIO (runExceptT $ ntfClientHandshake h ks testKeyHash supportedNTFServerVRange) >>= \case + liftIO (runExceptT $ ntfClientHandshake h ks testKeyHash supportedClientNTFVRange) >>= \case Right th -> client th Left e -> error $ show e @@ -107,7 +107,7 @@ ntfServerCfg = logStatsStartTime = 0, serverStatsLogFile = "tests/ntf-server-stats.daily.log", serverStatsBackupFile = Nothing, - ntfServerVRange = supportedNTFServerVRange, + ntfServerVRange = supportedServerNTFVRange, transportConfig = defaultTransportServerConfig } diff --git a/tests/SMPClient.hs b/tests/SMPClient.hs index 369738f83..740d9dcc7 100644 --- a/tests/SMPClient.hs +++ b/tests/SMPClient.hs @@ -73,7 +73,7 @@ testSMPClient client = do runTransportClient defaultTransportClientConfig Nothing useHost testPort (Just testKeyHash) $ \h -> do g <- liftIO C.newRandom ks <- atomically $ C.generateKeyPair g - liftIO (runExceptT $ smpClientHandshake h ks testKeyHash supportedSMPServerVRange) >>= \case + liftIO (runExceptT $ smpClientHandshake h ks testKeyHash supportedClientSMPRelayVRange) >>= \case Right th -> client th Left e -> error $ show e @@ -100,7 +100,7 @@ cfg = caCertificateFile = "tests/fixtures/ca.crt", privateKeyFile = "tests/fixtures/server.key", certificateFile = "tests/fixtures/server.crt", - smpServerVRange = supportedSMPServerVRange, + smpServerVRange = supportedServerSMPRelayVRange, transportConfig = defaultTransportServerConfig, controlPort = Nothing }