Add option to disable presence

This commit is contained in:
Till Faelligen 2021-08-23 12:11:34 +02:00
parent 0973a4e346
commit a073a21d71
4 changed files with 33 additions and 12 deletions

View file

@ -1102,6 +1102,12 @@ func Setup(
if r := rateLimits.rateLimit(req); r != nil { if r := rateLimits.rateLimit(req); r != nil {
return *r return *r
} }
if !cfg.Matrix.PresenceEnabled {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct{}{},
}
}
vars, err := httputil.URLDecodeMapValues(mux.Vars(req)) vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
@ -1115,7 +1121,12 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
if !cfg.Matrix.PresenceEnabled {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct{}{},
}
}
return GetPresence(req, userAPI, vars["userId"], rsAPI, device) return GetPresence(req, userAPI, vars["userId"], rsAPI, device)
}), }),
).Methods(http.MethodGet, http.MethodOptions) ).Methods(http.MethodGet, http.MethodOptions)

View file

@ -48,6 +48,9 @@ global:
# - private_key: old_matrix_key.pem # - private_key: old_matrix_key.pem
# expired_at: 1601024554498 # 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 # 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 # 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 # servers for our key but increases the period that a compromised key will be

View file

@ -178,6 +178,7 @@ func Send(
servers: servers, servers: servers,
keyAPI: keyAPI, keyAPI: keyAPI,
roomsMu: mu, roomsMu: mu,
presenceEnabled: cfg.Matrix.PresenceEnabled,
} }
var txnEvents struct { var txnEvents struct {
@ -244,6 +245,7 @@ type txnReq struct {
haveEvents map[string]*gomatrixserverlib.HeaderedEvent haveEvents map[string]*gomatrixserverlib.HeaderedEvent
haveEventsMutex sync.Mutex haveEventsMutex sync.Mutex
work string // metrics work string // metrics
presenceEnabled bool
} }
func (t *txnReq) hadEvent(eventID string, had bool) { func (t *txnReq) hadEvent(eventID string, had bool) {
@ -508,7 +510,9 @@ func (t *txnReq) processEDUs(ctx context.Context) {
} }
} }
case gomatrixserverlib.MPresence: case gomatrixserverlib.MPresence:
if t.presenceEnabled {
t.handlePresence(ctx, e) t.handlePresence(ctx, e)
}
case eduserverAPI.MSigningKeyUpdate: case eduserverAPI.MSigningKeyUpdate:
var updatePayload eduserverAPI.CrossSigningKeyUpdate var updatePayload eduserverAPI.CrossSigningKeyUpdate
if err := json.Unmarshal(e.Content, &updatePayload); err != nil { if err := json.Unmarshal(e.Content, &updatePayload); err != nil {

View file

@ -38,6 +38,9 @@ type Global struct {
// to other servers and the federation API will not be exposed. // to other servers and the federation API will not be exposed.
DisableFederation bool `yaml:"disable_federation"` 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 // List of domains that the server will trust as identity servers to
// verify third-party identifiers. // verify third-party identifiers.
// Defaults to an empty array. // Defaults to an empty array.