@@ -354,9 +354,9 @@ setConnShortLinkAsync :: AgentClient -> ACorrId -> ConnId -> UserConnLinkData 'C
354354setConnShortLinkAsync c = withAgentEnv c .:: setConnShortLinkAsync' c
355355{-# INLINE setConnShortLinkAsync #-}
356356
357- -- | Get and verify data from short link (LGET/LKEY command) asynchronously, synchronous response is new connection id
358- getConnShortLinkAsync :: AgentClient -> UserId -> ACorrId -> ConnShortLink 'CMContact -> AE ConnId
359- getConnShortLinkAsync c = withAgentEnv c .:. getConnShortLinkAsync' c
357+ -- | Get and verify data from short link (LGET/LKEY command) asynchronously, synchronous response is new/passed connection id
358+ getConnShortLinkAsync :: AgentClient -> UserId -> ACorrId -> Maybe ConnId -> ConnShortLink 'CMContact -> AE ConnId
359+ getConnShortLinkAsync c = withAgentEnv c .:: getConnShortLinkAsync' c
360360{-# INLINE getConnShortLinkAsync #-}
361361
362362-- | Join SMP agent connection (JOIN command) asynchronously, synchronous response is new connection id.
@@ -1001,14 +1001,22 @@ setConnShortLinkAsync' c corrId connId userLinkData clientData =
10011001 _ -> throwE $ CMD PROHIBITED " setConnShortLinkAsync: invalid connection or mode"
10021002 enqueueCommand c corrId connId (Just srv) $ AClientCommand $ LSET userLinkData clientData
10031003
1004- getConnShortLinkAsync' :: AgentClient -> UserId -> ACorrId -> ConnShortLink 'CMContact -> AM ConnId
1005- getConnShortLinkAsync' c userId corrId shortLink@ (CSLContact _ _ srv _) = do
1006- g <- asks random
1007- connId <- withStore c $ \ db -> do
1008- -- server is created so the command is processed in server queue,
1009- -- not blocking other "no server" commands
1010- void $ createServer db srv
1011- prepareNewConn db g
1004+ getConnShortLinkAsync' :: AgentClient -> UserId -> ACorrId -> Maybe ConnId -> ConnShortLink 'CMContact -> AM ConnId
1005+ getConnShortLinkAsync' c userId corrId connId_ shortLink@ (CSLContact _ _ srv _) = do
1006+ connId <- case connId_ of
1007+ Just existingConnId -> do
1008+ -- connId and srv can be unrelated: connId is used as "mailbox" for LDATA delivery,
1009+ -- while srv is the short link's server for the LGET request.
1010+ -- E.g., owner's relay connection (connId, on server A) fetches relay's group link data (srv = server B).
1011+ -- This works because enqueueCommand stores (connId, srv) independently in the commands table,
1012+ -- the network request targets srv, and event delivery uses connId via corrId correlation.
1013+ withStore' c $ \ db -> void $ createServer db srv
1014+ pure existingConnId
1015+ Nothing -> do
1016+ g <- asks random
1017+ withStore c $ \ db -> do
1018+ void $ createServer db srv
1019+ prepareNewConn db g
10121020 enqueueCommand c corrId connId (Just srv) $ AClientCommand $ LGET shortLink
10131021 pure connId
10141022 where
0 commit comments