Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c442a72
Start implementing federation.
fancycode Jun 5, 2024
e08ce21
Include original id in request to join federated room so client can m…
fancycode Jul 17, 2024
43b8ea5
Rewrite more session ids for proxied federated events.
fancycode Jul 17, 2024
148c779
federation: Send "bye" before closing, use message id for error respo…
fancycode Jul 17, 2024
6243ef1
Make sure response to federated room leave contains id from request.
fancycode Jul 17, 2024
f271faa
Add tests for federation code.
fancycode Jul 17, 2024
0451cea
Fix missing events if federated session leaves and joins again.
fancycode Jul 18, 2024
c055b12
Support different federated room ids.
fancycode Jul 18, 2024
4f95416
Send websocket close message before closing connection and don't log …
fancycode Jul 18, 2024
cf2e3aa
Return details for errors while creating federated clients.
fancycode Jul 18, 2024
deb7f71
Add option to disable certificate validation for federation
fancycode Jul 18, 2024
1ec09d6
Support timeouts for federation connections.
fancycode Jul 18, 2024
1873d15
Add information on federation to documentation.
fancycode Jul 18, 2024
c3d24b6
Expect base signaling url for federation requests.
fancycode Jul 18, 2024
ffa70f3
Add missing error handling.
fancycode Jul 18, 2024
a256789
Support reconnecting the internal federated connection.
fancycode Jul 24, 2024
fd651d7
Check for capability feature "federation-v2" for federated connections.
fancycode Jul 24, 2024
8672134
Include "federated" in "join" events for fed. sessions.
fancycode Jul 25, 2024
2f76dea
Detect duplicate join requests for federated clients.
fancycode Jul 25, 2024
f4b6f23
Support switching federated rooms while reusing internal connections.
fancycode Jul 25, 2024
347abb2
Ignore already closed connections when closing websocket.
fancycode Jul 25, 2024
b8b6f37
Use different NATS servers for federation tests.
fancycode Jul 31, 2024
c83c42c
Add special handling for "forceMute" control event.
fancycode Jul 31, 2024
11a1f36
Convert actorId / actorType in participants updates for federated users.
fancycode Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rewrite more session ids for proxied federated events.
  • Loading branch information
fancycode committed Aug 6, 2024
commit 43b8ea546e901578bd3e9d2b4e0973fe0cbc24f5
97 changes: 94 additions & 3 deletions federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,103 @@ func (c *FederationClient) joinRoom() error {
})
}

func (c *FederationClient) updateEventUsers(users []map[string]interface{}, localSessionId string, remoteSessionId string) {
for _, u := range users {
key := "sessionId"
sid, found := u[key]
if !found {
key := "sessionid"
sid, found = u[key]
}
if found {
if sid, ok := sid.(string); ok && sid == remoteSessionId {
u[key] = localSessionId
break
}
}
}
}

func (c *FederationClient) updateRecipient(recipient *MessageClientMessageRecipient, localSessionId string, remoteSessionId string) {
if recipient != nil && recipient.Type == RecipientTypeSession && remoteSessionId != "" && recipient.SessionId == remoteSessionId {
recipient.SessionId = localSessionId
}
}

func (c *FederationClient) updateSender(sender *MessageServerMessageSender, localSessionId string, remoteSessionId string) {
if sender != nil && sender.Type == RecipientTypeSession && remoteSessionId != "" && sender.SessionId == remoteSessionId {
sender.SessionId = localSessionId
}
}

func (c *FederationClient) processMessage(msg *ServerMessage) {
hello := c.hello.Load()
localSessionId := c.session.PublicId()
var remoteSessionId string
if hello := c.hello.Load(); hello != nil {
remoteSessionId = hello.SessionId
}
switch msg.Type {
case "control":
c.updateRecipient(msg.Control.Recipient, localSessionId, remoteSessionId)
c.updateSender(msg.Control.Sender, localSessionId, remoteSessionId)
case "event":
switch msg.Event.Target {
case "participants":
switch msg.Event.Type {
case "update":
if remoteSessionId != "" {
c.updateEventUsers(msg.Event.Update.Changed, localSessionId, remoteSessionId)
c.updateEventUsers(msg.Event.Update.Users, localSessionId, remoteSessionId)
}
case "flags":
if remoteSessionId != "" && msg.Event.Flags.SessionId == remoteSessionId {
msg.Event.Flags.SessionId = localSessionId
}
}
case "room":
switch msg.Event.Type {
case "join":
if remoteSessionId != "" {
for _, j := range msg.Event.Join {
if j.SessionId == remoteSessionId {
j.SessionId = localSessionId
break
}
}
}
case "leave":
if remoteSessionId != "" {
for idx, j := range msg.Event.Leave {
if j == remoteSessionId {
msg.Event.Leave[idx] = localSessionId
break
}
}
}
}
}
case "message":
if r := msg.Message.Recipient; r != nil && r.Type == RecipientTypeSession && hello != nil && r.SessionId == hello.SessionId {
msg.Message.Recipient.SessionId = c.session.PublicId()
c.updateRecipient(msg.Message.Recipient, localSessionId, remoteSessionId)
c.updateSender(msg.Message.Sender, localSessionId, remoteSessionId)
if remoteSessionId != "" && len(msg.Message.Data) > 0 {
var ao AnswerOfferMessage
if json.Unmarshal(msg.Message.Data, &ao) == nil && (ao.Type == "offer" || ao.Type == "answer") {
changed := false
if ao.From == remoteSessionId {
ao.From = localSessionId
changed = true
}
if ao.To == remoteSessionId {
ao.To = localSessionId
changed = true
}

if changed {
if data, err := json.Marshal(ao); err == nil {
msg.Message.Data = data
}
}
}
}
}
c.session.SendMessage(msg)
Expand Down