Fix federationclient whitelist checks, improve performance

This commit is contained in:
enaix 2025-01-17 14:55:11 +03:00
parent 94deed77ec
commit b5ea31ff5c
2 changed files with 32 additions and 25 deletions

View file

@ -112,10 +112,11 @@ func NewFederationInternalAPI(
}
}
// IsWhitelistedOrAny checks if the server is whitelisted or the whitelist is disabled, so we can connect to any server
// IsWhitelistedOrAny checks if the server is whitelisted or the whitelist is disabled (we can connect to any server)
func (a *FederationInternalAPI) IsWhitelistedOrAny(s spec.ServerName) bool {
stats := a.statistics.ForServer(s)
return stats.Whitelisted() || !a.cfg.EnableWhitelist
// Thread-safe, since DB access is performed in mutex and stats.Whitelisted is constant
stats := a.statistics.ForServer(s) // Calls mutex if the stats do not exist yet
return !a.cfg.EnableWhitelist || stats.Whitelisted() // Lazy eval
}
func (a *FederationInternalAPI) IsBlacklistedOrBackingOff(s spec.ServerName) (*statistics.ServerStatistics, error) {