diff options
author | Kegsay <kegan@matrix.org> | 2020-07-30 11:15:46 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-30 11:15:46 +0100 |
commit | 9355fb5ac8c911bdbde6dcc0f279f716d8a8f60b (patch) | |
tree | c6a155f7b65e25c8ab4abaf7413fbb0531a02b12 /keyserver | |
parent | 0fdd4f14d123e76bd3d0368947d3aab84a787946 (diff) |
Hook up device list updates to the sync notifier (#1231)
* WIP hooking up key changes
* Fix import cycle, get tests passing and binary compiling
* Linting and update whitelist
Diffstat (limited to 'keyserver')
-rw-r--r-- | keyserver/api/api.go | 2 | ||||
-rw-r--r-- | keyserver/internal/internal.go | 4 | ||||
-rw-r--r-- | keyserver/producers/keychange.go | 9 |
3 files changed, 15 insertions, 0 deletions
diff --git a/keyserver/api/api.go b/keyserver/api/api.go index 406a252d..c9afb09c 100644 --- a/keyserver/api/api.go +++ b/keyserver/api/api.go @@ -143,6 +143,8 @@ type QueryKeyChangesRequest struct { type QueryKeyChangesResponse struct { // The set of users who have had their keys change. UserIDs []string + // The partition being served - useful if the partition is unknown at request time + Partition int32 // The latest offset represented in this response. Offset int64 // Set if there was a problem handling the request. diff --git a/keyserver/internal/internal.go b/keyserver/internal/internal.go index 240a5640..9a41e44f 100644 --- a/keyserver/internal/internal.go +++ b/keyserver/internal/internal.go @@ -41,6 +41,9 @@ type KeyInternalAPI struct { } func (a *KeyInternalAPI) QueryKeyChanges(ctx context.Context, req *api.QueryKeyChangesRequest, res *api.QueryKeyChangesResponse) { + if req.Partition < 0 { + req.Partition = a.Producer.DefaultPartition() + } userIDs, latest, err := a.DB.KeyChanges(ctx, req.Partition, req.Offset) if err != nil { res.Error = &api.KeyError{ @@ -48,6 +51,7 @@ func (a *KeyInternalAPI) QueryKeyChanges(ctx context.Context, req *api.QueryKeyC } } res.Offset = latest + res.Partition = req.Partition res.UserIDs = userIDs } diff --git a/keyserver/producers/keychange.go b/keyserver/producers/keychange.go index d59dd200..c51d9f55 100644 --- a/keyserver/producers/keychange.go +++ b/keyserver/producers/keychange.go @@ -31,6 +31,15 @@ type KeyChange struct { DB storage.Database } +// DefaultPartition returns the default partition this process is sending key changes to. +// NB: A keyserver MUST send key changes to only 1 partition or else query operations will +// become inconsistent. Partitions can be sharded (e.g by hash of user ID of key change) but +// then all keyservers must be queried to calculate the entire set of key changes between +// two sync tokens. +func (p *KeyChange) DefaultPartition() int32 { + return 0 +} + // ProduceKeyChanges creates new change events for each key func (p *KeyChange) ProduceKeyChanges(keys []api.DeviceKeys) error { for _, key := range keys { |