diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-09-29 13:40:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-29 13:40:29 +0100 |
commit | 738b829a23d4e50e68f98acb72f7d10a16009f8b (patch) | |
tree | be4f86b0a3b39f10856499d869721c914d56b65f /roomserver/internal/query | |
parent | 4ff7ac7b6574d6adec775057dc2c798a1fe10248 (diff) |
Fetch missing auth events, implement QueryMissingAuthPrevEvents, try other servers in room for /event and /get_missing_events (#1450)
* Try to ask other servers in the room for missing events if the origin won't provide them
* Logging
* More logging
* Implement QueryMissingAuthPrevEvents
* Try to get missing auth events badly
* Use processEvent
* Logging
* Update QueryMissingAuthPrevEvents
* Try to find missing auth events
* Patchy fix for test
* Logging tweaks
* Send auth events as outliers
* Update check in QueryMissingAuthPrevEvents
* Error responses
* More return codes
* Don't return error on reject/soft-fail since it was ultimately handled
* More tweaks
* More error tweaks
Diffstat (limited to 'roomserver/internal/query')
-rw-r--r-- | roomserver/internal/query/query.go | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/roomserver/internal/query/query.go b/roomserver/internal/query/query.go index 58cb4493..73660421 100644 --- a/roomserver/internal/query/query.go +++ b/roomserver/internal/query/query.go @@ -98,6 +98,38 @@ func (r *Queryer) QueryStateAfterEvents( return nil } +// QueryMissingAuthPrevEvents implements api.RoomserverInternalAPI +func (r *Queryer) QueryMissingAuthPrevEvents( + ctx context.Context, + request *api.QueryMissingAuthPrevEventsRequest, + response *api.QueryMissingAuthPrevEventsResponse, +) error { + info, err := r.DB.RoomInfo(ctx, request.RoomID) + if err != nil { + return err + } + if info == nil { + return errors.New("room doesn't exist") + } + + response.RoomExists = !info.IsStub + response.RoomVersion = info.RoomVersion + + for _, authEventID := range request.AuthEventIDs { + if nids, err := r.DB.EventNIDs(ctx, []string{authEventID}); err != nil || len(nids) == 0 { + response.MissingAuthEventIDs = append(response.MissingAuthEventIDs, authEventID) + } + } + + for _, prevEventID := range request.PrevEventIDs { + if nids, err := r.DB.EventNIDs(ctx, []string{prevEventID}); err != nil || len(nids) == 0 { + response.MissingPrevEventIDs = append(response.MissingPrevEventIDs, prevEventID) + } + } + + return nil +} + // QueryEventsByID implements api.RoomserverInternalAPI func (r *Queryer) QueryEventsByID( ctx context.Context, @@ -255,19 +287,24 @@ func (r *Queryer) QueryServerJoinedToRoom( return fmt.Errorf("r.DB.Events: %w", err) } + servers := map[gomatrixserverlib.ServerName]struct{}{} for _, e := range events { if e.Type() == gomatrixserverlib.MRoomMember && e.StateKey() != nil { _, serverName, err := gomatrixserverlib.SplitID('@', *e.StateKey()) if err != nil { continue } + servers[serverName] = struct{}{} if serverName == request.ServerName { response.IsInRoom = true - break } } } + for server := range servers { + response.ServerNames = append(response.ServerNames, server) + } + return nil } |