@@ -112,6 +112,7 @@ module Simplex.Messaging.Agent.Protocol
112112 ServiceScheme ,
113113 FixedLinkData (.. ),
114114 ConnLinkData (.. ),
115+ AUserConnLinkData (.. ),
115116 UserConnLinkData (.. ),
116117 UserContactData (.. ),
117118 UserLinkData (.. ),
@@ -436,7 +437,7 @@ deriving instance Show AEvtTag
436437
437438data ACommand
438439 = NEW Bool AConnectionMode InitialKeys SubscriptionMode -- response INV
439- | LSET AConnectionMode AUserConnLinkData (Maybe CRClientData ) -- response LINK
440+ | LSET AUserConnLinkData (Maybe CRClientData ) -- response LINK
440441 | JOIN Bool AConnectionRequestUri PQSupport SubscriptionMode ConnInfo
441442 | LET ConfirmationId ConnInfo -- ConnInfo is from client
442443 | ACK AgentMsgId (Maybe MsgReceiptInfo )
@@ -1709,17 +1710,30 @@ data UserContactData = UserContactData
17091710 relays :: [ConnShortLink 'CMContact],
17101711 userData :: UserLinkData
17111712 }
1713+ deriving (Eq , Show )
17121714
17131715newtype UserLinkData = UserLinkData ByteString
1716+ deriving (Eq , Show )
17141717
17151718data AConnLinkData = forall m . ConnectionModeI m => ACLD (SConnectionMode m ) (ConnLinkData m )
17161719
17171720data UserConnLinkData c where
17181721 UserInvLinkData :: UserLinkData -> UserConnLinkData 'CMInvitation
17191722 UserContactLinkData :: UserContactData -> UserConnLinkData 'CMContact
17201723
1724+ deriving instance Eq (UserConnLinkData m )
1725+
1726+ deriving instance Show (UserConnLinkData m )
1727+
17211728data AUserConnLinkData = forall m . ConnectionModeI m => AUCLD (SConnectionMode m ) (UserConnLinkData m )
17221729
1730+ instance Eq AUserConnLinkData where
1731+ AUCLD m d == AUCLD m' d' = case testEquality m m' of
1732+ Just Refl -> d == d'
1733+ Nothing -> False
1734+
1735+ deriving instance Show AUserConnLinkData
1736+
17231737linkUserData :: ConnLinkData c -> UserLinkData
17241738linkUserData = \ case
17251739 InvitationLinkData _ d -> d
@@ -1746,6 +1760,7 @@ data OwnerAuth = OwnerAuth
17461760 -- Owner validation should detect and reject loops.
17471761 authOwnerSig :: C. Signature 'C.Ed25519
17481762 }
1763+ deriving (Eq , Show )
17491764
17501765instance Encoding OwnerAuth where
17511766 smpEncode OwnerAuth {ownerId, ownerKey, ownerSig, authOwnerId, authOwnerSig} =
@@ -1785,9 +1800,35 @@ instance Encoding AConnLinkData where
17851800 let cd = UserContactData {direct, owners, relays, userData}
17861801 pure $ ACLD SCMContact $ ContactLinkData vr cd
17871802
1803+ instance ConnectionModeI c => Encoding (UserConnLinkData c ) where
1804+ smpEncode = \ case
1805+ UserInvLinkData userData -> smpEncode (CMInvitation , userData)
1806+ UserContactLinkData UserContactData {direct, owners, relays, userData} ->
1807+ B. concat [smpEncode (CMContact , direct), smpEncodeList owners, smpEncodeList relays, smpEncode userData]
1808+ smpP = (\ (AUCLD _ d) -> checkConnMode d) <$?> smpP
1809+ {-# INLINE smpP #-}
1810+
17881811instance Encoding AUserConnLinkData where
1789- smpEncode = undefined
1790- smpP = undefined
1812+ smpEncode (AUCLD _ d) = smpEncode d
1813+ {-# INLINE smpEncode #-}
1814+ smpP =
1815+ smpP >>= \ case
1816+ CMInvitation -> do
1817+ userData <- smpP <* A. takeByteString -- ignoring tail for forward compatibility with the future link data encoding
1818+ pure $ AUCLD SCMInvitation $ UserInvLinkData userData
1819+ CMContact -> do
1820+ direct <- smpP
1821+ owners <- smpListP
1822+ relays <- smpListP
1823+ userData <- smpP <* A. takeByteString -- ignoring tail for forward compatibility with the future link data encoding
1824+ let cd = UserContactData {direct, owners, relays, userData}
1825+ pure $ AUCLD SCMContact $ UserContactLinkData cd
1826+
1827+ instance StrEncoding AUserConnLinkData where
1828+ strEncode = smpEncode
1829+ {-# INLINE strEncode #-}
1830+ strP = smpP
1831+ {-# INLINE strP #-}
17911832
17921833instance Encoding UserLinkData where
17931834 smpEncode (UserLinkData s) = if B. length s <= 254 then smpEncode s else smpEncode ('\ 255 ', Large s)
@@ -2009,7 +2050,7 @@ commandP binaryP =
20092050 strP
20102051 >>= \ case
20112052 NEW_ -> s (NEW <$> strP_ <*> strP_ <*> pqIKP <*> (strP <|> pure SMP. SMSubscribe ))
2012- LSET_ -> undefined
2053+ LSET_ -> s ( LSET <$> strP <*> optional ( A. space *> strP))
20132054 JOIN_ -> s (JOIN <$> strP_ <*> strP_ <*> pqSupP <*> (strP_ <|> pure SMP. SMSubscribe ) <*> binaryP)
20142055 LET_ -> s (LET <$> A. takeTill (== ' ' ) <* A. space <*> binaryP)
20152056 ACK_ -> s (ACK <$> A. decimal <*> optional (A. space *> binaryP))
@@ -2027,7 +2068,7 @@ commandP binaryP =
20272068serializeCommand :: ACommand -> ByteString
20282069serializeCommand = \ case
20292070 NEW ntfs cMode pqIK subMode -> s (NEW_ , ntfs, cMode, pqIK, subMode)
2030- LSET {} -> undefined
2071+ LSET uld cd_ -> s ( LSET_ , uld) <> maybe " " ( B. cons ' ' . s) cd_
20312072 JOIN ntfs cReq pqSup subMode cInfo -> s (JOIN_ , ntfs, cReq, pqSup, subMode, Str $ serializeBinary cInfo)
20322073 LET confId cInfo -> B. unwords [s LET_ , confId, serializeBinary cInfo]
20332074 ACK mId rcptInfo_ -> s (ACK_ , mId) <> maybe " " (B. cons ' ' . serializeBinary) rcptInfo_
0 commit comments