@@ -365,9 +365,9 @@ setConnShortLinkAsync :: AgentClient -> ACorrId -> ConnId -> UserConnLinkData 'C
365365setConnShortLinkAsync c = withAgentEnv c .:: setConnShortLinkAsync' c
366366{-# INLINE setConnShortLinkAsync #-}
367367
368- -- | Get and verify data from short link (LGET/LKEY command) asynchronously, synchronous response is new connection id
369- getConnShortLinkAsync :: AgentClient -> UserId -> ACorrId -> ConnShortLink 'CMContact -> AE ConnId
370- getConnShortLinkAsync c = withAgentEnv c .:. getConnShortLinkAsync' c
368+ -- | Get and verify data from short link (LGET/LKEY command) asynchronously, synchronous response is new/passed connection id
369+ getConnShortLinkAsync :: AgentClient -> UserId -> ACorrId -> Maybe ConnId -> ConnShortLink 'CMContact -> AE ConnId
370+ getConnShortLinkAsync c = withAgentEnv c .:: getConnShortLinkAsync' c
371371{-# INLINE getConnShortLinkAsync #-}
372372
373373-- | Join SMP agent connection (JOIN command) asynchronously, synchronous response is new connection id.
@@ -1041,14 +1041,22 @@ setConnShortLinkAsync' c corrId connId userLinkData clientData =
10411041 _ -> throwE $ CMD PROHIBITED " setConnShortLinkAsync: invalid connection or mode"
10421042 enqueueCommand c corrId connId (Just srv) $ AClientCommand $ LSET userLinkData clientData
10431043
1044- getConnShortLinkAsync' :: AgentClient -> UserId -> ACorrId -> ConnShortLink 'CMContact -> AM ConnId
1045- getConnShortLinkAsync' c userId corrId shortLink@ (CSLContact _ _ srv _) = do
1046- g <- asks random
1047- connId <- withStore c $ \ db -> do
1048- -- server is created so the command is processed in server queue,
1049- -- not blocking other "no server" commands
1050- void $ createServer db srv
1051- prepareNewConn db g
1044+ getConnShortLinkAsync' :: AgentClient -> UserId -> ACorrId -> Maybe ConnId -> ConnShortLink 'CMContact -> AM ConnId
1045+ getConnShortLinkAsync' c userId corrId connId_ shortLink@ (CSLContact _ _ srv _) = do
1046+ connId <- case connId_ of
1047+ Just existingConnId -> do
1048+ -- connId and srv can be unrelated: connId is used as "mailbox" for LDATA delivery,
1049+ -- while srv is the short link's server for the LGET request.
1050+ -- E.g., owner's relay connection (connId, on server A) fetches relay's group link data (srv = server B).
1051+ -- This works because enqueueCommand stores (connId, srv) independently in the commands table,
1052+ -- the network request targets srv, and event delivery uses connId via corrId correlation.
1053+ withStore' c $ \ db -> void $ createServer db srv
1054+ pure existingConnId
1055+ Nothing -> do
1056+ g <- asks random
1057+ withStore c $ \ db -> do
1058+ void $ createServer db srv
1059+ prepareNewConn db g
10521060 enqueueCommand c corrId connId (Just srv) $ AClientCommand $ LGET shortLink
10531061 pure connId
10541062 where
0 commit comments