expandTopicName expands session specific topic name to global name Returns topic: session-specific topic name the message recipient should see routeTo: routable global topic name err: *ServerComMessage with an error to return to the sender
(msg *ClientComMessage)
| 1325 | // routeTo: routable global topic name |
| 1326 | // err: *ServerComMessage with an error to return to the sender |
| 1327 | func (s *Session) expandTopicName(msg *ClientComMessage) (string, *ServerComMessage) { |
| 1328 | if msg.Original == "" { |
| 1329 | logs.Warn.Println("s.etn: empty topic name", s.sid) |
| 1330 | return "", ErrMalformed(msg.Id, "", msg.Timestamp) |
| 1331 | } |
| 1332 | |
| 1333 | // Expanded name of the topic to route to i.e. rcptto: or s.subs[routeTo] |
| 1334 | var routeTo string |
| 1335 | if msg.Original == "me" { |
| 1336 | routeTo = msg.AsUser |
| 1337 | } else if msg.Original == "fnd" { |
| 1338 | routeTo = types.ParseUserId(msg.AsUser).FndName() |
| 1339 | } else if msg.Original == "slf" { |
| 1340 | routeTo = types.ParseUserId(msg.AsUser).SlfName() |
| 1341 | } else if strings.HasPrefix(msg.Original, "usr") { |
| 1342 | // p2p topic |
| 1343 | uid1 := types.ParseUserId(msg.AsUser) |
| 1344 | uid2 := types.ParseUserId(msg.Original) |
| 1345 | if uid2.IsZero() { |
| 1346 | // Ensure the user id is valid. |
| 1347 | logs.Warn.Println("s.etn: failed to parse p2p topic name", s.sid) |
| 1348 | return "", ErrMalformed(msg.Id, msg.Original, msg.Timestamp) |
| 1349 | } else if uid2 == uid1 { |
| 1350 | // Use 'me' to access self-topic. |
| 1351 | logs.Warn.Println("s.etn: invalid p2p self-subscription", s.sid) |
| 1352 | return "", ErrPermissionDeniedReply(msg, msg.Timestamp) |
| 1353 | } |
| 1354 | routeTo = uid1.P2PName(uid2) |
| 1355 | } else if tmp := types.ChnToGrp(msg.Original); tmp != "" { |
| 1356 | routeTo = tmp |
| 1357 | } else { |
| 1358 | routeTo = msg.Original |
| 1359 | } |
| 1360 | |
| 1361 | return routeTo, nil |
| 1362 | } |
| 1363 | |
| 1364 | func (s *Session) serializeAndUpdateStats(msg *ServerComMessage) any { |
| 1365 | dataSize, data := s.serialize(msg) |
no test coverage detected