From a4e7d471af7e2cf902404f6740f0932a088cb660 Mon Sep 17 00:00:00 2001 From: S7evinK <2353100+S7evinK@users.noreply.github.com> Date: Fri, 11 Feb 2022 18:15:44 +0100 Subject: [PATCH] Remove FederationDisabled error type (#2174) --- federationapi/consumers/roomserver.go | 30 +++++++++++---------------- federationapi/queue/queue.go | 27 ++++++++---------------- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/federationapi/consumers/roomserver.go b/federationapi/consumers/roomserver.go index ac29f930b..173dcff01 100644 --- a/federationapi/consumers/roomserver.go +++ b/federationapi/consumers/roomserver.go @@ -19,6 +19,10 @@ import ( "encoding/json" "fmt" + "github.com/matrix-org/gomatrixserverlib" + "github.com/nats-io/nats.go" + log "github.com/sirupsen/logrus" + "github.com/matrix-org/dendrite/federationapi/queue" "github.com/matrix-org/dendrite/federationapi/storage" "github.com/matrix-org/dendrite/federationapi/types" @@ -26,9 +30,6 @@ import ( "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/jetstream" "github.com/matrix-org/dendrite/setup/process" - "github.com/matrix-org/gomatrixserverlib" - "github.com/nats-io/nats.go" - log "github.com/sirupsen/logrus" ) // OutputRoomEventConsumer consumes events that originated in the room server. @@ -97,21 +98,14 @@ func (s *OutputRoomEventConsumer) onMessage(ctx context.Context, msg *nats.Msg) } if err := s.processMessage(*output.NewRoomEvent); err != nil { - switch err.(type) { - case *queue.ErrorFederationDisabled: - log.WithField("error", output.Type).Info( - err.Error(), - ) - default: - // panic rather than continue with an inconsistent database - log.WithFields(log.Fields{ - "event_id": ev.EventID(), - "event": string(ev.JSON()), - "add": output.NewRoomEvent.AddsStateEventIDs, - "del": output.NewRoomEvent.RemovesStateEventIDs, - log.ErrorKey: err, - }).Panicf("roomserver output log: write room event failure") - } + // panic rather than continue with an inconsistent database + log.WithFields(log.Fields{ + "event_id": ev.EventID(), + "event": string(ev.JSON()), + "add": output.NewRoomEvent.AddsStateEventIDs, + "del": output.NewRoomEvent.RemovesStateEventIDs, + log.ErrorKey: err, + }).Panicf("roomserver output log: write room event failure") } case api.OutputTypeNewInboundPeek: diff --git a/federationapi/queue/queue.go b/federationapi/queue/queue.go index 8a6ad1555..dcd090856 100644 --- a/federationapi/queue/queue.go +++ b/federationapi/queue/queue.go @@ -22,15 +22,16 @@ import ( "sync" "time" + "github.com/matrix-org/gomatrixserverlib" + "github.com/prometheus/client_golang/prometheus" + log "github.com/sirupsen/logrus" + "github.com/tidwall/gjson" + "github.com/matrix-org/dendrite/federationapi/statistics" "github.com/matrix-org/dendrite/federationapi/storage" "github.com/matrix-org/dendrite/federationapi/storage/shared" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/setup/process" - "github.com/matrix-org/gomatrixserverlib" - "github.com/prometheus/client_golang/prometheus" - log "github.com/sirupsen/logrus" - "github.com/tidwall/gjson" ) // OutgoingQueues is a collection of queues for sending transactions to other @@ -182,23 +183,14 @@ func (oqs *OutgoingQueues) clearQueue(oq *destinationQueue) { destinationQueueTotal.Dec() } -type ErrorFederationDisabled struct { - Message string -} - -func (e *ErrorFederationDisabled) Error() string { - return e.Message -} - // SendEvent sends an event to the destinations func (oqs *OutgoingQueues) SendEvent( ev *gomatrixserverlib.HeaderedEvent, origin gomatrixserverlib.ServerName, destinations []gomatrixserverlib.ServerName, ) error { if oqs.disabled { - return &ErrorFederationDisabled{ - Message: "Federation disabled", - } + log.Trace("Federation is disabled, not sending event") + return nil } if origin != oqs.origin { // TODO: Support virtual hosting; gh issue #577. @@ -262,9 +254,8 @@ func (oqs *OutgoingQueues) SendEDU( destinations []gomatrixserverlib.ServerName, ) error { if oqs.disabled { - return &ErrorFederationDisabled{ - Message: "Federation disabled", - } + log.Trace("Federation is disabled, not sending EDU") + return nil } if origin != oqs.origin { // TODO: Support virtual hosting; gh issue #577.