(m api.DeviceMessage)
| 156 | } |
| 157 | |
| 158 | func (t *KeyChangeConsumer) onCrossSigningMessage(m api.DeviceMessage) bool { |
| 159 | output := m.CrossSigningKeyUpdate |
| 160 | _, host, err := gomatrixserverlib.SplitID('@', output.UserID) |
| 161 | if err != nil { |
| 162 | logrus.WithError(err).Errorf("fedsender key change consumer: user ID parse failure") |
| 163 | return true |
| 164 | } |
| 165 | if host != gomatrixserverlib.ServerName(t.serverName) { |
| 166 | // Ignore any messages that didn't originate locally, otherwise we'll |
| 167 | // end up parroting information we received from other servers. |
| 168 | return true |
| 169 | } |
| 170 | logger := logrus.WithField("user_id", output.UserID) |
| 171 | |
| 172 | var queryRes roomserverAPI.QueryRoomsForUserResponse |
| 173 | err = t.rsAPI.QueryRoomsForUser(t.ctx, &roomserverAPI.QueryRoomsForUserRequest{ |
| 174 | UserID: output.UserID, |
| 175 | WantMembership: "join", |
| 176 | }, &queryRes) |
| 177 | if err != nil { |
| 178 | logger.WithError(err).Error("fedsender key change consumer: failed to calculate joined rooms for user") |
| 179 | return true |
| 180 | } |
| 181 | // send this key change to all servers who share rooms with this user. |
| 182 | destinations, err := t.db.GetJoinedHostsForRooms(t.ctx, queryRes.RoomIDs, true) |
| 183 | if err != nil { |
| 184 | logger.WithError(err).Error("fedsender key change consumer: failed to calculate joined hosts for rooms user is in") |
| 185 | return true |
| 186 | } |
| 187 | |
| 188 | if len(destinations) == 0 { |
| 189 | return true |
| 190 | } |
| 191 | |
| 192 | // Pack the EDU and marshal it |
| 193 | edu := &gomatrixserverlib.EDU{ |
| 194 | Type: types.MSigningKeyUpdate, |
| 195 | Origin: string(t.serverName), |
| 196 | } |
| 197 | if edu.Content, err = json.Marshal(output); err != nil { |
| 198 | logger.WithError(err).Error("fedsender key change consumer: failed to marshal output, dropping") |
| 199 | return true |
| 200 | } |
| 201 | |
| 202 | logger.Debugf("Sending cross-signing update message to %q", destinations) |
| 203 | err = t.queues.SendEDU(edu, t.serverName, destinations) |
| 204 | return err == nil |
| 205 | } |
| 206 | |
| 207 | func prevID(streamID int64) []int64 { |
| 208 | if streamID <= 1 { |
no test coverage detected