aboutsummaryrefslogtreecommitdiff
path: root/roomserver
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2022-02-28 14:51:40 +0000
committerGitHub <noreply@github.com>2022-02-28 14:51:40 +0000
commita23fda662607e9160230335503e912f626abf616 (patch)
tree82f287510bcb89e2c93de63d329dd8dbe9bf4ed4 /roomserver
parentac77732185a2473dd39984669ea3f454548aa7f5 (diff)
Update `Events` call-sites which now don't return an error, update `parsedRespState` to sort (#2227)
* Topologically sort with `SendEventWithState`, so that earlier events should satisfy auth for later ones * Revert "Topologically sort with `SendEventWithState`, so that earlier events should satisfy auth for later ones" This reverts commit b0cd706012b4c9b6724b11e16f19c4cb732ab286. * Update to matrix-org/gomatrixserverlib#293 * `Events` no longer returns an error, other tweaks * Make sure `Events` is sorted for `parsedRespState` too
Diffstat (limited to 'roomserver')
-rw-r--r--roomserver/api/wrapper.go8
-rw-r--r--roomserver/internal/input/input_missing.go22
2 files changed, 19 insertions, 11 deletions
diff --git a/roomserver/api/wrapper.go b/roomserver/api/wrapper.go
index 012094c6..5491d36b 100644
--- a/roomserver/api/wrapper.go
+++ b/roomserver/api/wrapper.go
@@ -51,12 +51,8 @@ func SendEventWithState(
state *gomatrixserverlib.RespState, event *gomatrixserverlib.HeaderedEvent,
origin gomatrixserverlib.ServerName, haveEventIDs map[string]bool, async bool,
) error {
- outliers, err := state.Events(event.RoomVersion)
- if err != nil {
- return err
- }
-
- var ires []InputRoomEvent
+ outliers := state.Events(event.RoomVersion)
+ ires := make([]InputRoomEvent, 0, len(outliers))
for _, outlier := range outliers {
if haveEventIDs[outlier.EventID()] {
continue
diff --git a/roomserver/internal/input/input_missing.go b/roomserver/internal/input/input_missing.go
index 4655e92a..a7da9b06 100644
--- a/roomserver/internal/input/input_missing.go
+++ b/roomserver/internal/input/input_missing.go
@@ -23,6 +23,21 @@ type parsedRespState struct {
StateEvents []*gomatrixserverlib.Event
}
+func (p *parsedRespState) Events() []*gomatrixserverlib.Event {
+ eventsByID := make(map[string]*gomatrixserverlib.Event, len(p.AuthEvents)+len(p.StateEvents))
+ for i, event := range p.AuthEvents {
+ eventsByID[event.EventID()] = p.AuthEvents[i]
+ }
+ for i, event := range p.StateEvents {
+ eventsByID[event.EventID()] = p.StateEvents[i]
+ }
+ allEvents := make([]*gomatrixserverlib.Event, 0, len(eventsByID))
+ for _, event := range eventsByID {
+ allEvents = append(allEvents, event)
+ }
+ return gomatrixserverlib.ReverseTopologicalOrdering(allEvents, gomatrixserverlib.TopologicalOrderByAuthEvents)
+}
+
type missingStateReq struct {
origin gomatrixserverlib.ServerName
db storage.Database
@@ -124,11 +139,8 @@ func (t *missingStateReq) processEventWithMissingState(
t.hadEventsMutex.Unlock()
sendOutliers := func(resolvedState *parsedRespState) error {
- outliers, oerr := gomatrixserverlib.OrderAuthAndStateEvents(resolvedState.AuthEvents, resolvedState.StateEvents, roomVersion)
- if oerr != nil {
- return fmt.Errorf("gomatrixserverlib.OrderAuthAndStateEvents: %w", oerr)
- }
- var outlierRoomEvents []api.InputRoomEvent
+ outliers := resolvedState.Events()
+ outlierRoomEvents := make([]api.InputRoomEvent, 0, len(outliers))
for _, outlier := range outliers {
if hadEvents[outlier.EventID()] {
continue