diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 47d561a75..a9babc8aa 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -1102,6 +1102,12 @@ func Setup( if r := rateLimits.rateLimit(req); r != nil { return *r } + if !cfg.Matrix.PresenceEnabled { + return util.JSONResponse{ + Code: http.StatusOK, + JSON: struct{}{}, + } + } vars, err := httputil.URLDecodeMapValues(mux.Vars(req)) if err != nil { return util.ErrorResponse(err) @@ -1115,7 +1121,12 @@ func Setup( if err != nil { return util.ErrorResponse(err) } - + if !cfg.Matrix.PresenceEnabled { + return util.JSONResponse{ + Code: http.StatusOK, + JSON: struct{}{}, + } + } return GetPresence(req, userAPI, vars["userId"], rsAPI, device) }), ).Methods(http.MethodGet, http.MethodOptions) diff --git a/dendrite-config.yaml b/dendrite-config.yaml index 7feb908e3..3d882a97f 100644 --- a/dendrite-config.yaml +++ b/dendrite-config.yaml @@ -48,6 +48,9 @@ global: # - private_key: old_matrix_key.pem # expired_at: 1601024554498 + # Enable/Disable presence. Enabling presence might cause a high load on your server. + presence_enabled: false + # How long a remote server can cache our server signing key before requesting it # again. Increasing this number will reduce the number of requests made by other # servers for our key but increases the period that a compromised key will be diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index 056ce05c9..fbdc9aae1 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -168,16 +168,17 @@ func Send( servers federationAPI.ServersInRoomProvider, ) util.JSONResponse { t := txnReq{ - rsAPI: rsAPI, - eduAPI: eduAPI, - userAPI: userAPI, - keys: keys, - federation: federation, - hadEvents: make(map[string]bool), - haveEvents: make(map[string]*gomatrixserverlib.HeaderedEvent), - servers: servers, - keyAPI: keyAPI, - roomsMu: mu, + rsAPI: rsAPI, + eduAPI: eduAPI, + userAPI: userAPI, + keys: keys, + federation: federation, + hadEvents: make(map[string]bool), + haveEvents: make(map[string]*gomatrixserverlib.HeaderedEvent), + servers: servers, + keyAPI: keyAPI, + roomsMu: mu, + presenceEnabled: cfg.Matrix.PresenceEnabled, } var txnEvents struct { @@ -244,6 +245,7 @@ type txnReq struct { haveEvents map[string]*gomatrixserverlib.HeaderedEvent haveEventsMutex sync.Mutex work string // metrics + presenceEnabled bool } func (t *txnReq) hadEvent(eventID string, had bool) { @@ -508,7 +510,9 @@ func (t *txnReq) processEDUs(ctx context.Context) { } } case gomatrixserverlib.MPresence: - t.handlePresence(ctx, e) + if t.presenceEnabled { + t.handlePresence(ctx, e) + } case eduserverAPI.MSigningKeyUpdate: var updatePayload eduserverAPI.CrossSigningKeyUpdate if err := json.Unmarshal(e.Content, &updatePayload); err != nil { diff --git a/setup/config/config_global.go b/setup/config/config_global.go index 90a92f2bc..aefb4fc5e 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -38,6 +38,9 @@ type Global struct { // to other servers and the federation API will not be exposed. DisableFederation bool `yaml:"disable_federation"` + // Enable/Disable presence. Defaults to false + PresenceEnabled bool `yaml:"presence_enabled"` + // List of domains that the server will trust as identity servers to // verify third-party identifiers. // Defaults to an empty array.