Skip to content

Commit c59cfea

Browse files
committed
change short link encoding
1 parent c3bb5c2 commit c59cfea

3 files changed

Lines changed: 19 additions & 20 deletions

File tree

simplexmq.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 1.12
22

33
name: simplexmq
4-
version: 6.3.200.0
4+
version: 6.3.1.0
55
synopsis: SimpleXMQ message broker
66
description: This package includes <./docs/Simplex-Messaging-Server.html server>,
77
<./docs/Simplex-Messaging-Client.html client> and

src/Simplex/Messaging/Agent/Protocol.hs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,15 +1407,16 @@ instance ConnectionModeI m => FromJSON (ConnectionLink m) where
14071407

14081408
instance ConnectionModeI m => StrEncoding (ConnShortLink m) where
14091409
strEncode = \case
1410-
CSLInvitation srv (SMP.EntityId lnkId) (LinkKey k) -> encLink srv (lnkId <> k) 'i'
1411-
CSLContact ct srv (LinkKey k) -> encLink srv k $ toLower $ ctTypeChar ct
1410+
CSLInvitation srv (SMP.EntityId lnkId) (LinkKey k) -> encLink srv lnkId k 'i'
1411+
CSLContact ct srv (LinkKey k) -> encLink srv "" k $ toLower $ ctTypeChar ct
14121412
where
1413-
encLink (SMPServer (h :| hs) port (C.KeyHash kh)) linkUri linkType =
1414-
B.concat ["https://", strEncode h, port', "/", B.singleton linkType, "#", khStr, hosts, B64.encodeUnpadded linkUri]
1413+
encLink (SMPServer (h :| hs) port (C.KeyHash kh)) lnkId k linkType =
1414+
B.concat ["https://", strEncode h, port', "/", B.singleton linkType, "#", khStr, hosts, lnkIdStr, B64.encodeUnpadded k]
14151415
where
14161416
port' = if null port then "" else B.pack (':' : port)
1417+
khStr = if B.null kh then "" else B64.encodeUnpadded kh <> "&"
14171418
hosts = if null hs then "" else strEncode (TransportHosts_ hs) <> "/"
1418-
khStr = if B.null kh then "" else B64.encodeUnpadded kh <> "@"
1419+
lnkIdStr = if B.null lnkId then "" else B64.encodeUnpadded lnkId <> "."
14191420
strP = (\(ACSL _ l) -> checkConnMode l) <$?> strP
14201421
{-# INLINE strP #-}
14211422

@@ -1426,19 +1427,17 @@ instance StrEncoding AConnShortLink where
14261427
h <- "https://" *> strP
14271428
port <- A.char ':' *> (B.unpack <$> A.takeWhile1 isDigit) <|> pure ""
14281429
contactType <- A.char '/' *> contactTypeP
1429-
keyHash <- optional (A.char '/') *> A.char '#' *> (strP <* A.char '@' <|> pure (C.KeyHash ""))
1430+
keyHash <- optional (A.char '/') *> A.char '#' *> (strP <* A.char '&' <|> pure (C.KeyHash ""))
14301431
TransportHosts_ hs <- strP <* "/" <|> pure (TransportHosts_ [])
1431-
linkUri <- strP
14321432
let srv = SMPServer (h :| hs) port keyHash
14331433
case contactType of
1434-
Nothing
1435-
| B.length linkUri == 56 ->
1436-
let (lnkId, k) = B.splitAt 24 linkUri
1437-
in pure $ ACSL SCMInvitation $ CSLInvitation srv (SMP.EntityId lnkId) (LinkKey k)
1438-
| otherwise -> fail "bad ConnShortLink: incorrect linkID and key length"
1439-
Just ct
1440-
| B.length linkUri == 32 -> pure $ ACSL SCMContact $ CSLContact ct srv (LinkKey linkUri)
1441-
| otherwise -> fail "bad ConnShortLink: incorrect key length"
1434+
Nothing -> do
1435+
lnkId <- strP <* A.char '.'
1436+
k <- strP
1437+
pure $ ACSL SCMInvitation $ CSLInvitation srv (SMP.EntityId lnkId) (LinkKey k)
1438+
Just ct -> do
1439+
k <- strP
1440+
pure $ ACSL SCMContact $ CSLContact ct srv (LinkKey k)
14421441
where
14431442
contactTypeP = do
14441443
Just <$> (A.anyChar >>= ctTypeP . toUpper)

tests/AgentTests/ConnectionRequestTests.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ connectionRequestTests =
279279
smpEncodingTest contactAddressV2
280280
smpEncodingTest contactAddressClientData
281281
it "should serialize / parse short links" $ do
282-
CSLContact CCTContact srv (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im:5223/a#1234-w@jjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion/MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
283-
CSLContact CCTGroup srv (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im:5223/g#1234-w@jjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion/MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
282+
CSLContact CCTContact srv (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im:5223/a#1234-w&jjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion/MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
283+
CSLContact CCTGroup srv (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im:5223/g#1234-w&jjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion/MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
284284
CSLContact CCTContact shortSrv (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im/a#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
285-
CSLInvitation srv (EntityId "0123456789abcdef01234567") (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im:5223/i#1234-w@jjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion/MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
286-
CSLInvitation shortSrv (EntityId "0123456789abcdef01234567") (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im/i#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
285+
CSLInvitation srv (EntityId "0123456789abcdef01234567") (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im:5223/i#1234-w&jjbyvoemxysm7qxap7m5d5m35jzv5qq6gnlv7s4rsn7tdwwmuqciwpid.onion/MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3.MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
286+
CSLInvitation shortSrv (EntityId "0123456789abcdef01234567") (LinkKey "0123456789abcdef0123456789abcdef") #==# "https://smp.simplex.im/i#MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3.MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY"
287287
it "should shorten / restore short links" $ do
288288
shortenShortLink [srv] (CSLContact CCTContact srv (LinkKey "0123456789abcdef0123456789abcdef"))
289289
`shouldBe` CSLContact CCTContact shortSrv (LinkKey "0123456789abcdef0123456789abcdef")

0 commit comments

Comments
 (0)