From 77f912721a0b0b381a4663abd916e80113e178ed Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 10 Dec 2021 09:30:14 +0000 Subject: [PATCH] Fix lint errors --- federationapi/internal/query.go | 12 +++---- federationapi/routing/send.go | 55 --------------------------------- 2 files changed, 6 insertions(+), 61 deletions(-) diff --git a/federationapi/internal/query.go b/federationapi/internal/query.go index 44305b23..794a513f 100644 --- a/federationapi/internal/query.go +++ b/federationapi/internal/query.go @@ -36,11 +36,11 @@ func (f *FederationInternalAPI) QueryEventAuthFromFederation( } tryHost := func(serverName gomatrixserverlib.ServerName) error { - ctx, cancel := context.WithTimeout(ctx, time.Second*30) + reqctx, cancel := context.WithTimeout(ctx, time.Second*30) defer cancel() ires, err := f.doRequest(serverName, func() (interface{}, error) { return f.federation.GetEventAuth( - ctx, + reqctx, serverName, request.RoomID, request.EventID, @@ -76,11 +76,11 @@ func (f *FederationInternalAPI) QueryStateIDsFromFederation( } tryHost := func(serverName gomatrixserverlib.ServerName) error { - ctx, cancel := context.WithTimeout(ctx, time.Second*30) + reqctx, cancel := context.WithTimeout(ctx, time.Second*30) defer cancel() ires, err := f.doRequest(serverName, func() (interface{}, error) { return f.federation.LookupStateIDs( - ctx, + reqctx, serverName, request.RoomID, request.EventID, @@ -117,11 +117,11 @@ func (f *FederationInternalAPI) QueryStateFromFederation( } tryHost := func(serverName gomatrixserverlib.ServerName) error { - ctx, cancel := context.WithTimeout(ctx, time.Second*30) + reqctx, cancel := context.WithTimeout(ctx, time.Second*30) defer cancel() ires, err := f.doRequest(serverName, func() (interface{}, error) { return f.federation.LookupState( - ctx, + reqctx, serverName, request.RoomID, request.EventID, diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index 59aea5f9..5f0d4865 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -697,61 +697,6 @@ func (t *txnReq) processEvent(ctx context.Context, e *gomatrixserverlib.Event) e ) } -func (t *txnReq) retrieveMissingAuthEvents( - ctx context.Context, e *gomatrixserverlib.Event, stateResp *api.QueryMissingAuthPrevEventsResponse, -) error { - logger := util.GetLogger(ctx).WithField("event_id", e.EventID()).WithField("room_id", e.RoomID()) - - missingAuthEvents := make(map[string]struct{}) - for _, missingAuthEventID := range stateResp.MissingAuthEventIDs { - missingAuthEvents[missingAuthEventID] = struct{}{} - } - -withNextEvent: - for missingAuthEventID := range missingAuthEvents { - withNextServer: - for _, server := range t.getServers(ctx, e.RoomID(), e) { - logger.Infof("Retrieving missing auth event %q from %q", missingAuthEventID, server) - tx, err := t.federation.GetEvent(ctx, server, missingAuthEventID) - if err != nil { - logger.WithError(err).Warnf("Failed to retrieve auth event %q", missingAuthEventID) - if errors.Is(err, context.DeadlineExceeded) { - return err - } - continue withNextServer - } - ev, err := gomatrixserverlib.NewEventFromUntrustedJSON(tx.PDUs[0], stateResp.RoomVersion) - if err != nil { - logger.WithError(err).Warnf("Failed to unmarshal auth event %q", missingAuthEventID) - continue withNextServer - } - if err = api.SendInputRoomEvents( - context.Background(), - t.rsAPI, - []api.InputRoomEvent{ - { - Kind: api.KindOutlier, - Event: ev.Headered(stateResp.RoomVersion), - AuthEventIDs: ev.AuthEventIDs(), - SendAsServer: api.DoNotSendToOtherServers, - }, - }, - ); err != nil { - return fmt.Errorf("api.SendEvents: %w", err) - } - t.hadEvent(ev.EventID(), true) // if the roomserver didn't know about the event before, it does now - t.cacheAndReturn(ev.Headered(stateResp.RoomVersion)) - delete(missingAuthEvents, missingAuthEventID) - continue withNextEvent - } - } - - if missing := len(missingAuthEvents); missing > 0 { - return fmt.Errorf("event refers to %d auth_events which we failed to fetch", missing) - } - return nil -} - func checkAllowedByState(e *gomatrixserverlib.Event, stateEvents []*gomatrixserverlib.Event) error { authUsingState := gomatrixserverlib.NewAuthEvents(nil) for i := range stateEvents {