onMessage is called when the federation server receives a new event from the room server output log. It is unsafe to call this with messages for the same room in multiple gorountines because updates it will likely fail with a types.EventIDMismatchError when it realises that it cannot update the room
(ctx context.Context, msg *nats.Msg)
| 78 | // because updates it will likely fail with a types.EventIDMismatchError when it |
| 79 | // realises that it cannot update the room state using the deltas. |
| 80 | func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msg *nats.Msg) bool { |
| 81 | // Parse out the event JSON |
| 82 | var output api.OutputEvent |
| 83 | if err := json.Unmarshal(msg.Data, &output); err != nil { |
| 84 | // If the message was invalid, log it and move on to the next message in the stream |
| 85 | log.WithError(err).Errorf("roomserver output log: message parse failure") |
| 86 | return true |
| 87 | } |
| 88 | |
| 89 | switch output.Type { |
| 90 | case api.OutputTypeNewRoomEvent: |
| 91 | ev := output.NewRoomEvent.Event |
| 92 | if err := s.processMessage(*output.NewRoomEvent, output.NewRoomEvent.RewritesState); err != nil { |
| 93 | // panic rather than continue with an inconsistent database |
| 94 | log.WithFields(log.Fields{ |
| 95 | "event_id": ev.EventID(), |
| 96 | "event": string(ev.JSON()), |
| 97 | "add": output.NewRoomEvent.AddsStateEventIDs, |
| 98 | "del": output.NewRoomEvent.RemovesStateEventIDs, |
| 99 | log.ErrorKey: err, |
| 100 | }).Panicf("roomserver output log: write room event failure") |
| 101 | } |
| 102 | |
| 103 | case api.OutputTypeNewInboundPeek: |
| 104 | if err := s.processInboundPeek(*output.NewInboundPeek); err != nil { |
| 105 | log.WithFields(log.Fields{ |
| 106 | "event": output.NewInboundPeek, |
| 107 | log.ErrorKey: err, |
| 108 | }).Panicf("roomserver output log: remote peek event failure") |
| 109 | return false |
| 110 | } |
| 111 | |
| 112 | default: |
| 113 | log.WithField("type", output.Type).Debug( |
| 114 | "roomserver output log: ignoring unknown output type", |
| 115 | ) |
| 116 | } |
| 117 | |
| 118 | return true |
| 119 | } |
| 120 | |
| 121 | // processInboundPeek starts tracking a new federated inbound peek (replacing the existing one if any) |
| 122 | // causing the federationapi to start sending messages to the peeking server |
nothing calls this directly
no test coverage detected