Use event origin failing all else

This commit is contained in:
Neil Alexander 2021-12-15 14:05:35 +00:00
parent 2203dd9d8a
commit 2a46752d0b
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 8 additions and 11 deletions

View file

@ -183,7 +183,7 @@ func (r *Inputer) processRoomEvent(
} }
if input.Origin == "" { if input.Origin == "" {
return "", fmt.Errorf("expected an origin") input.Origin = event.Origin()
} }
if len(missingRes.MissingPrevEventIDs) > 0 { if len(missingRes.MissingPrevEventIDs) > 0 {

View file

@ -250,7 +250,7 @@ func (t *missingStateReq) lookupStateAfterEventLocally(ctx context.Context, room
// set the event from the haveEvents cache - this means we will share pointers with other prev_event branches for this // set the event from the haveEvents cache - this means we will share pointers with other prev_event branches for this
// processEvent request, which is better for memory. // processEvent request, which is better for memory.
stateEvents[i] = t.cacheAndReturn(ev) stateEvents[i] = t.cacheAndReturn(ev)
t.hadEvent(ev.EventID(), true) t.hadEvent(ev.EventID())
} }
// we should never access res.StateEvents again so we delete it here to make GC faster // we should never access res.StateEvents again so we delete it here to make GC faster
res.StateEvents = nil res.StateEvents = nil
@ -285,7 +285,7 @@ func (t *missingStateReq) lookupStateAfterEventLocally(ctx context.Context, room
} }
for i, ev := range queryRes.Events { for i, ev := range queryRes.Events {
authEvents = append(authEvents, t.cacheAndReturn(queryRes.Events[i]).Unwrap()) authEvents = append(authEvents, t.cacheAndReturn(queryRes.Events[i]).Unwrap())
t.hadEvent(ev.EventID(), true) t.hadEvent(ev.EventID())
} }
queryRes.Events = nil queryRes.Events = nil
} }
@ -362,7 +362,7 @@ func (t *missingStateReq) getMissingEvents(ctx context.Context, e *gomatrixserve
latestEvents := make([]string, len(res.LatestEvents)) latestEvents := make([]string, len(res.LatestEvents))
for i, ev := range res.LatestEvents { for i, ev := range res.LatestEvents {
latestEvents[i] = res.LatestEvents[i].EventID latestEvents[i] = res.LatestEvents[i].EventID
t.hadEvent(ev.EventID, true) t.hadEvent(ev.EventID)
} }
var missingResp *gomatrixserverlib.RespMissingEvents var missingResp *gomatrixserverlib.RespMissingEvents
@ -497,7 +497,7 @@ func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roo
} }
for i, ev := range queryRes.Events { for i, ev := range queryRes.Events {
queryRes.Events[i] = t.cacheAndReturn(queryRes.Events[i]) queryRes.Events[i] = t.cacheAndReturn(queryRes.Events[i])
t.hadEvent(ev.EventID(), true) t.hadEvent(ev.EventID())
evID := queryRes.Events[i].EventID() evID := queryRes.Events[i].EventID()
if missing[evID] { if missing[evID] {
delete(missing, evID) delete(missing, evID)
@ -681,15 +681,12 @@ func checkAllowedByState(e *gomatrixserverlib.Event, stateEvents []*gomatrixserv
return gomatrixserverlib.Allowed(e, &authUsingState) return gomatrixserverlib.Allowed(e, &authUsingState)
} }
func (t *missingStateReq) hadEvent(eventID string, had bool) { func (t *missingStateReq) hadEvent(eventID string) {
t.hadEventsMutex.Lock() t.hadEventsMutex.Lock()
defer t.hadEventsMutex.Unlock() defer t.hadEventsMutex.Unlock()
t.hadEvents[eventID] = had t.hadEvents[eventID] = true
} }
type roomNotFoundError struct {
roomID string
}
type verifySigError struct { type verifySigError struct {
eventID string eventID string
err error err error
@ -699,7 +696,6 @@ type missingPrevEventsError struct {
err error err error
} }
func (e roomNotFoundError) Error() string { return fmt.Sprintf("room %q not found", e.roomID) }
func (e verifySigError) Error() string { func (e verifySigError) Error() string {
return fmt.Sprintf("unable to verify signature of event %q: %s", e.eventID, e.err) return fmt.Sprintf("unable to verify signature of event %q: %s", e.eventID, e.err)
} }

View file

@ -139,6 +139,7 @@ func (r *Leaver) performLeaveRoomByID(
{ {
Kind: api.KindNew, Kind: api.KindNew,
Event: event.Headered(buildRes.RoomVersion), Event: event.Headered(buildRes.RoomVersion),
Origin: event.Origin(),
AuthEventIDs: event.AuthEventIDs(), AuthEventIDs: event.AuthEventIDs(),
SendAsServer: string(r.Cfg.Matrix.ServerName), SendAsServer: string(r.Cfg.Matrix.ServerName),
}, },