Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Use direct references for configuration variables (part 6). #10916

Merged
merged 7 commits into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10916.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use direct references to config flags.
8 changes: 4 additions & 4 deletions synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def start_worker_reactor(appname, config, run_command=reactor.run):

start_reactor(
appname,
soft_file_limit=config.soft_file_limit,
gc_thresholds=config.gc_thresholds,
soft_file_limit=config.server.soft_file_limit,
gc_thresholds=config.server.gc_thresholds,
pid_file=config.worker.worker_pid_file,
daemonize=config.worker.worker_daemonize,
print_pidfile=config.print_pidfile,
print_pidfile=config.server.print_pidfile,
logger=logger,
run_command=run_command,
)
Expand Down Expand Up @@ -298,7 +298,7 @@ def refresh_certificate(hs):
Refresh the TLS certificates that Synapse is using by re-reading them from
disk and updating the TLS context factories to use them.
"""
if not hs.config.has_tls_listener():
if not hs.config.server.has_tls_listener():
return

hs.config.read_certificate_from_disk()
Expand Down
4 changes: 2 additions & 2 deletions synapse/app/admin_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ def start(config_options):
config.logging.no_redirect_stdio = True

# Explicitly disable background processes
config.update_user_directory = False
config.server.update_user_directory = False
config.worker.run_background_tasks = False
config.start_pushers = False
config.pusher_shard_config.instances = []
config.send_federation = False
config.federation_shard_config.instances = []

synapse.events.USE_FROZEN_DICTS = config.use_frozen_dicts
synapse.events.USE_FROZEN_DICTS = config.server.use_frozen_dicts

ss = AdminCmdServer(
config.server.server_name,
Expand Down
2 changes: 1 addition & 1 deletion synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def start(config_options):
# For other worker types we force this to off.
config.server.update_user_directory = False

synapse.events.USE_FROZEN_DICTS = config.use_frozen_dicts
synapse.events.USE_FROZEN_DICTS = config.server.use_frozen_dicts
synapse.util.caches.TRACK_MEMORY_USAGE = config.caches.track_memory_usage

if config.server.gc_seconds:
Expand Down
14 changes: 7 additions & 7 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _configure_named_resource(self, name, compress=False):
resources[SERVER_KEY_V2_PREFIX] = KeyApiV2Resource(self)

if name == "webclient":
webclient_loc = self.config.web_client_location
webclient_loc = self.config.server.web_client_location

if webclient_loc is None:
logger.warning(
Expand Down Expand Up @@ -343,7 +343,7 @@ def setup(config_options):
# generating config files and shouldn't try to continue.
sys.exit(0)

events.USE_FROZEN_DICTS = config.use_frozen_dicts
events.USE_FROZEN_DICTS = config.server.use_frozen_dicts
synapse.util.caches.TRACK_MEMORY_USAGE = config.caches.track_memory_usage

if config.server.gc_seconds:
Expand Down Expand Up @@ -439,11 +439,11 @@ def profiled(*args, **kargs):

_base.start_reactor(
"synapse-homeserver",
soft_file_limit=hs.config.soft_file_limit,
gc_thresholds=hs.config.gc_thresholds,
pid_file=hs.config.pid_file,
daemonize=hs.config.daemonize,
print_pidfile=hs.config.print_pidfile,
soft_file_limit=hs.config.server.soft_file_limit,
gc_thresholds=hs.config.server.gc_thresholds,
pid_file=hs.config.server.pid_file,
daemonize=hs.config.server.daemonize,
print_pidfile=hs.config.server.print_pidfile,
logger=logger,
)

Expand Down
8 changes: 4 additions & 4 deletions synapse/app/phone_stats_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def phone_stats_home(hs, stats, stats_process=_stats_process):
store = hs.get_datastore()

stats["homeserver"] = hs.config.server.server_name
stats["server_context"] = hs.config.server_context
stats["server_context"] = hs.config.server.server_context
stats["timestamp"] = now
stats["uptime_seconds"] = uptime
version = sys.version_info
Expand Down Expand Up @@ -171,7 +171,7 @@ async def generate_monthly_active_users():
current_mau_count_by_service = {}
reserved_users = ()
store = hs.get_datastore()
if hs.config.limit_usage_by_mau or hs.config.mau_stats_only:
if hs.config.server.limit_usage_by_mau or hs.config.server.mau_stats_only:
current_mau_count = await store.get_monthly_active_count()
current_mau_count_by_service = (
await store.get_monthly_active_count_by_service()
Expand All @@ -183,9 +183,9 @@ async def generate_monthly_active_users():
current_mau_by_service_gauge.labels(app_service).set(float(count))

registered_reserved_users_mau_gauge.set(float(len(reserved_users)))
max_mau_gauge.set(float(hs.config.max_mau_value))
max_mau_gauge.set(float(hs.config.server.max_mau_value))

if hs.config.limit_usage_by_mau or hs.config.mau_stats_only:
if hs.config.server.limit_usage_by_mau or hs.config.server.mau_stats_only:
generate_monthly_active_users()
clock.looping_call(generate_monthly_active_users, 5 * 60 * 1000)
# End of monthly active user settings
Expand Down
2 changes: 1 addition & 1 deletion synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def __getattr__(self, item: str) -> Any:
"""
Redirect lookups on this object either to config objects, or values on
config objects, so that `config.tls.blah` works, as well as legacy uses
of things like `config.server_name`. It will first look up the config
of things like `config.server.server_name`. It will first look up the config
section name, and then values on those config classes.
"""
if item in self._configs.keys():
Expand Down
4 changes: 1 addition & 3 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Copyright 2014-2016 OpenMarket Ltd
# Copyright 2017-2018 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
# Copyright 2014-2021 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions synapse/events/presence_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def load_legacy_presence_router(hs: "HomeServer"):
configuration, and registers the hooks they implement.
"""

if hs.config.presence_router_module_class is None:
if hs.config.server.presence_router_module_class is None:
return

module = hs.config.presence_router_module_class
config = hs.config.presence_router_config
module = hs.config.server.presence_router_module_class
config = hs.config.server.presence_router_config
api = hs.get_module_api()

presence_router = module(config=config, module_api=api)
Expand Down
2 changes: 1 addition & 1 deletion synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ class EventClientSerializer:
def __init__(self, hs):
self.store = hs.get_datastore()
self.experimental_msc1849_support_enabled = (
hs.config.experimental_msc1849_support_enabled
hs.config.server.experimental_msc1849_support_enabled
)

async def serialize_event(
Expand Down
2 changes: 1 addition & 1 deletion synapse/federation/transport/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __init__(
):
super().__init__(hs, authenticator, ratelimiter, server_name)
self.handler = hs.get_room_list_handler()
self.allow_access = hs.config.allow_public_rooms_over_federation
self.allow_access = hs.config.server.allow_public_rooms_over_federation

async def on_GET(
self, origin: str, content: Literal[None], query: Dict[bytes, List[bytes]]
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, hs: "HomeServer"):
self.store = hs.get_datastore()
self.config = hs.config
self.enable_room_list_search = hs.config.roomdirectory.enable_room_list_search
self.require_membership = hs.config.require_membership_for_aliases
self.require_membership = hs.config.server.require_membership_for_aliases
self.third_party_event_rules = hs.get_third_party_event_rules()

self.federation = hs.get_federation_client()
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ async def on_invite_request(
if is_blocked:
raise SynapseError(403, "This room has been blocked on this server")

if self.hs.config.block_non_admin_invites:
if self.hs.config.server.block_non_admin_invites:
raise SynapseError(403, "This server does not accept room invites")

if not await self.spam_checker.user_may_invite(
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, hs: "HomeServer"):
self.http_client = SimpleHttpClient(hs)
# An HTTP client for contacting identity servers specified by clients.
self.blacklisting_http_client = SimpleHttpClient(
hs, ip_blacklist=hs.config.federation_ip_range_blacklist
hs, ip_blacklist=hs.config.server.federation_ip_range_blacklist
)
self.federation_http_client = hs.get_federation_http_client()
self.hs = hs
Expand Down
14 changes: 8 additions & 6 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, hs: "HomeServer"):
self.storage = hs.get_storage()
self.state_store = self.storage.state
self._event_serializer = hs.get_event_client_serializer()
self._ephemeral_events_enabled = hs.config.enable_ephemeral_messages
self._ephemeral_events_enabled = hs.config.server.enable_ephemeral_messages

# The scheduled call to self._expire_event. None if no call is currently
# scheduled.
Expand Down Expand Up @@ -413,7 +413,9 @@ def __init__(self, hs: "HomeServer"):
self.server_name = hs.hostname
self.notifier = hs.get_notifier()
self.config = hs.config
self.require_membership_for_aliases = hs.config.require_membership_for_aliases
self.require_membership_for_aliases = (
hs.config.server.require_membership_for_aliases
)
self._events_shard_config = self.config.worker.events_shard_config
self._instance_name = hs.get_instance_name()

Expand All @@ -423,7 +425,7 @@ def __init__(self, hs: "HomeServer"):
Membership.JOIN,
Membership.KNOCK,
}
if self.hs.config.include_profile_data_on_invite:
if self.hs.config.server.include_profile_data_on_invite:
self.membership_types_to_include_profile_data_in.add(Membership.INVITE)

self.send_event = ReplicationSendEventRestServlet.make_client(hs)
Expand Down Expand Up @@ -459,11 +461,11 @@ def __init__(self, hs: "HomeServer"):
#
self._rooms_to_exclude_from_dummy_event_insertion: Dict[str, int] = {}
# The number of forward extremeities before a dummy event is sent.
self._dummy_events_threshold = hs.config.dummy_events_threshold
self._dummy_events_threshold = hs.config.server.dummy_events_threshold

if (
self.config.worker.run_background_tasks
and self.config.cleanup_extremities_with_dummy_events
and self.config.server.cleanup_extremities_with_dummy_events
):
self.clock.looping_call(
lambda: run_as_background_process(
Expand All @@ -475,7 +477,7 @@ def __init__(self, hs: "HomeServer"):

self._message_handler = hs.get_message_handler()

self._ephemeral_events_enabled = hs.config.enable_ephemeral_messages
self._ephemeral_events_enabled = hs.config.server.enable_ephemeral_messages

self._external_cache = hs.get_external_cache()

Expand Down
14 changes: 10 additions & 4 deletions synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ def __init__(self, hs: "HomeServer"):
self._purges_by_id: Dict[str, PurgeStatus] = {}
self._event_serializer = hs.get_event_client_serializer()

self._retention_default_max_lifetime = hs.config.retention_default_max_lifetime
self._retention_default_max_lifetime = (
hs.config.server.retention_default_max_lifetime
)

self._retention_allowed_lifetime_min = hs.config.retention_allowed_lifetime_min
self._retention_allowed_lifetime_max = hs.config.retention_allowed_lifetime_max
self._retention_allowed_lifetime_min = (
hs.config.server.retention_allowed_lifetime_min
)
self._retention_allowed_lifetime_max = (
hs.config.server.retention_allowed_lifetime_max
)

if hs.config.worker.run_background_tasks and hs.config.retention_enabled:
if hs.config.worker.run_background_tasks and hs.config.server.retention_enabled:
# Run the purge jobs described in the configuration file.
for job in hs.config.server.retention_purge_jobs:
logger.info("Setting up purge job with config: %s", job)
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ async def check_profile_query_allowed(
# when building a membership event. In this case, we must allow the
# lookup.
if (
not self.hs.config.limit_profile_requests_to_users_who_share_rooms
not self.hs.config.server.limit_profile_requests_to_users_who_share_rooms
or not requester
):
return
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ async def post_registration_actions(
# Necessary due to auth checks prior to the threepid being
# written to the db
if is_threepid_reserved(
self.hs.config.mau_limits_reserved_threepids, threepid
self.hs.config.server.mau_limits_reserved_threepids, threepid
):
await self.store.upsert_monthly_active_user(user_id)

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ async def create_room(
await self.ratelimit(requester)

room_version_id = config.get(
"room_version", self.config.default_room_version.identifier
"room_version", self.config.server.default_room_version.identifier
)

if not isinstance(room_version_id, str):
Expand Down
14 changes: 7 additions & 7 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, hs: "HomeServer"):
self.third_party_event_rules = hs.get_third_party_event_rules()
self._server_notices_mxid = self.config.servernotices.server_notices_mxid
self._enable_lookup = hs.config.enable_3pid_lookup
self.allow_per_room_profiles = self.config.allow_per_room_profiles
self.allow_per_room_profiles = self.config.server.allow_per_room_profiles

self._join_rate_limiter_local = Ratelimiter(
store=self.store,
Expand Down Expand Up @@ -617,7 +617,7 @@ async def update_membership_locked(
is_requester_admin = await self.auth.is_server_admin(requester.user)

if not is_requester_admin:
if self.config.block_non_admin_invites:
if self.config.server.block_non_admin_invites:
logger.info(
"Blocking invite: user is not admin and non-admin "
"invites disabled"
Expand Down Expand Up @@ -1222,7 +1222,7 @@ async def do_3pid_invite(
Raises:
ShadowBanError if the requester has been shadow-banned.
"""
if self.config.block_non_admin_invites:
if self.config.server.block_non_admin_invites:
is_requester_admin = await self.auth.is_server_admin(requester.user)
if not is_requester_admin:
raise SynapseError(
Expand Down Expand Up @@ -1420,7 +1420,7 @@ async def _is_remote_room_too_complex(
Returns: bool of whether the complexity is too great, or None
if unable to be fetched
"""
max_complexity = self.hs.config.limit_remote_rooms.complexity
max_complexity = self.hs.config.server.limit_remote_rooms.complexity
complexity = await self.federation_handler.get_room_complexity(
remote_room_hosts, room_id
)
Expand All @@ -1436,7 +1436,7 @@ async def _is_local_room_too_complex(self, room_id: str) -> bool:
Args:
room_id: The room ID to check for complexity.
"""
max_complexity = self.hs.config.limit_remote_rooms.complexity
max_complexity = self.hs.config.server.limit_remote_rooms.complexity
complexity = await self.store.get_room_complexity(room_id)

return complexity["v1"] > max_complexity
Expand Down Expand Up @@ -1472,7 +1472,7 @@ async def _remote_join(
if too_complex is True:
raise SynapseError(
code=400,
msg=self.hs.config.limit_remote_rooms.complexity_error,
msg=self.hs.config.server.limit_remote_rooms.complexity_error,
errcode=Codes.RESOURCE_LIMIT_EXCEEDED,
)

Expand Down Expand Up @@ -1507,7 +1507,7 @@ async def _remote_join(
)
raise SynapseError(
code=400,
msg=self.hs.config.limit_remote_rooms.complexity_error,
msg=self.hs.config.server.limit_remote_rooms.complexity_error,
errcode=Codes.RESOURCE_LIMIT_EXCEEDED,
)

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def search(
dict to be returned to the client with results of search
"""

if not self.hs.config.enable_search:
if not self.hs.config.server.enable_search:
raise SynapseError(400, "Search is disabled on this homeserver")

batch_group = None
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, hs: "HomeServer"):
self.clock = hs.get_clock()
self.notifier = hs.get_notifier()
self.is_mine_id = hs.is_mine_id
self.update_user_directory = hs.config.update_user_directory
self.update_user_directory = hs.config.server.update_user_directory
self.search_all_users = hs.config.userdirectory.user_directory_search_all_users
self.spam_checker = hs.get_spam_checker()
# The current position in the current_state_delta stream
Expand Down
Loading