diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2022-02-22 13:35:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-22 13:35:06 +0000 |
commit | 600fbae31f1b0b6919bb9045958b932071de6737 (patch) | |
tree | 53ed98d54bfd44d16ba9564308079ded12f9eb59 /keyserver | |
parent | bbe7d37928194d411d99079055cdcec9dbdd4959 (diff) |
Only emit key change notifications from federation when changes are made (#2217)
* Only emit key changes when poked over federation
* Remove logging
* Fix unit test possibly
Diffstat (limited to 'keyserver')
-rw-r--r-- | keyserver/internal/device_list_update.go | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/keyserver/internal/device_list_update.go b/keyserver/internal/device_list_update.go index c5a5d40c..b208f0ce 100644 --- a/keyserver/internal/device_list_update.go +++ b/keyserver/internal/device_list_update.go @@ -241,14 +241,33 @@ func (u *DeviceListUpdater) update(ctx context.Context, event gomatrixserverlib. StreamID: event.StreamID, }, } + + // DeviceKeysJSON will side-effect modify this, so it needs + // to be a copy, not sharing any pointers with the above. + deviceKeysCopy := *keys[0].DeviceKeys + deviceKeysCopy.KeyJSON = nil + existingKeys := []api.DeviceMessage{ + { + Type: keys[0].Type, + DeviceKeys: &deviceKeysCopy, + StreamID: keys[0].StreamID, + }, + } + + // fetch what keys we had already and only emit changes + if err = u.db.DeviceKeysJSON(ctx, existingKeys); err != nil { + // non-fatal, log and continue + util.GetLogger(ctx).WithError(err).WithField("user_id", event.UserID).Errorf( + "failed to query device keys json for calculating diffs", + ) + } + err = u.db.StoreRemoteDeviceKeys(ctx, keys, nil) if err != nil { return false, fmt.Errorf("failed to store remote device keys for %s (%s): %w", event.UserID, event.DeviceID, err) } - // ALWAYS emit key changes when we've been poked over federation even if there's no change - // just in case this poke is important for something. - err = u.producer.ProduceKeyChanges(keys) - if err != nil { + + if err = emitDeviceKeyChanges(u.producer, existingKeys, keys); err != nil { return false, fmt.Errorf("failed to produce device key changes for %s (%s): %w", event.UserID, event.DeviceID, err) } return false, nil |