From ccdd8e1775cf4a96063701ab6bcd9fa987a4f169 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sun, 13 Apr 2025 13:43:27 +0100 Subject: [PATCH] agent: additional encodings for short links --- src/Simplex/Messaging/Agent/Protocol.hs | 17 +++++++++++++++++ tests/AgentTests/SchemaDump.hs | 3 +-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Protocol.hs b/src/Simplex/Messaging/Agent/Protocol.hs index 157ea6a86..43cceb376 100644 --- a/src/Simplex/Messaging/Agent/Protocol.hs +++ b/src/Simplex/Messaging/Agent/Protocol.hs @@ -123,6 +123,7 @@ module Simplex.Messaging.Agent.Protocol ShortLinkScheme (..), LinkKey (..), sameConnReqContact, + sameShortLinkContact, simplexChat, connReqUriP', simplexConnReqUri, @@ -1413,6 +1414,11 @@ deriving instance Show ACreatedConnLink data AConnectionLink = forall m. ConnectionModeI m => ACL (SConnectionMode m) (ConnectionLink m) +instance Eq AConnectionLink where + ACL m cl == ACL m' cl' = case testEquality m m' of + Just Refl -> cl == cl' + _ -> False + deriving instance Show AConnectionLink instance ConnectionModeI m => StrEncoding (ConnectionLink m) where @@ -1436,6 +1442,13 @@ instance ConnectionModeI m => ToJSON (ConnectionLink m) where instance ConnectionModeI m => FromJSON (ConnectionLink m) where parseJSON = strParseJSON "ConnectionLink" +instance ToJSON AConnectionLink where + toEncoding = strToJEncoding + toJSON = strToJSON + +instance FromJSON AConnectionLink where + parseJSON = strParseJSON "AConnectionLink" + instance ConnectionModeI m => StrEncoding (ConnShortLink m) where strEncode = \case CSLInvitation sch srv (SMP.EntityId lnkId) (LinkKey k) -> slEncode sch srv 'i' lnkId k @@ -1569,6 +1582,10 @@ sameConnReqContact (CRContactUri ConnReqUriData {crSmpQueues = qs}) (CRContactUr where same (q, q') = sameQAddress (qAddress q) (qAddress q') +sameShortLinkContact :: ConnShortLink 'CMContact -> ConnShortLink 'CMContact -> Bool +sameShortLinkContact (CSLContact _ ct srv k) (CSLContact _ ct' srv' k') = + ct == ct' && sameSrvAddr srv srv' && k == k' + checkConnMode :: forall t m m'. (ConnectionModeI m, ConnectionModeI m') => t m' -> Either String (t m) checkConnMode c = case testEquality (sConnectionMode @m) (sConnectionMode @m') of Just Refl -> Right c diff --git a/tests/AgentTests/SchemaDump.hs b/tests/AgentTests/SchemaDump.hs index 882dd685c..736863364 100644 --- a/tests/AgentTests/SchemaDump.hs +++ b/tests/AgentTests/SchemaDump.hs @@ -4,7 +4,6 @@ module AgentTests.SchemaDump where import Control.DeepSeq -import Control.Exception (bracket_) import Control.Monad (unless, void) import Data.List (dropWhileEnd) import Data.Maybe (fromJust, isJust) @@ -17,7 +16,7 @@ import Simplex.Messaging.Agent.Store.SQLite.DB (TrackQueries (..)) import qualified Simplex.Messaging.Agent.Store.SQLite.Migrations as Migrations import Simplex.Messaging.Agent.Store.Shared (Migration (..), MigrationConfirmation (..), MigrationsToRun (..), toDownMigration) import Simplex.Messaging.Util (ifM) -import System.Directory (createDirectoryIfMissing, doesFileExist, removeDirectoryRecursive, removeFile) +import System.Directory (doesFileExist, removeFile) import System.Process (readCreateProcess, shell) import Test.Hspec