def __init__(self, hs): super(RoomListHandler, self).__init__(hs) self.enable_room_list_search = hs.config.enable_room_list_search self.response_cache = ResponseCache(hs, "room_list") self.remote_response_cache = ResponseCache(hs, "remote_room_list", timeout_ms=30 * 1000)
def __init__(self, hs): super().__init__(hs) self.auth = hs.get_auth() self.handler = hs.get_handlers().federation_handler self.state = hs.get_state_handler() self.device_handler = hs.get_device_handler() self._federation_ratelimiter = hs.get_federation_ratelimiter() self._server_linearizer = Linearizer("fed_server") self._transaction_linearizer = Linearizer("fed_txn_handler") # We cache results for transaction with the same ID self._transaction_resp_cache = ResponseCache(hs, "fed_txn_handler", timeout_ms=30000) self.transaction_actions = TransactionActions(self.store) self.registry = hs.get_federation_registry() # We cache responses to state queries, as they take a while and often # come in waves. self._state_resp_cache = ResponseCache(hs, "state_resp", timeout_ms=30000) self._state_ids_resp_cache = ResponseCache(hs, "state_ids_resp", timeout_ms=30000) self._federation_metrics_domains = ( hs.get_config().federation.federation_metrics_domains)
def __init__(self, hs): super(RoomListHandler, self).__init__(hs) self.response_cache = ResponseCache() self.remote_list_request_cache = ResponseCache() self.remote_list_cache = {} self.fetch_looping_call = hs.get_clock().looping_call( self.fetch_all_remote_lists, REMOTE_ROOM_LIST_POLL_INTERVAL) self.fetch_all_remote_lists()
def __init__(self, hs: "HomeServer"): super().__init__(hs) self.enable_room_list_search = hs.config.enable_room_list_search self.response_cache = ResponseCache( hs.get_clock(), "room_list" ) # type: ResponseCache[Tuple[Optional[int], Optional[str], ThirdPartyInstanceID]] self.remote_response_cache = ResponseCache( hs.get_clock(), "remote_room_list", timeout_ms=30 * 1000 ) # type: ResponseCache[Tuple[str, Optional[int], Optional[str], bool, Optional[str]]]
def __init__(self, hs: "HomeServer"): self.store = hs.get_datastore() self.hs = hs self.enable_room_list_search = hs.config.roomdirectory.enable_room_list_search self.response_cache: ResponseCache[ Tuple[Optional[int], Optional[str], Optional[ThirdPartyInstanceID]] ] = ResponseCache(hs.get_clock(), "room_list") self.remote_response_cache: ResponseCache[ Tuple[str, Optional[int], Optional[str], bool, Optional[str]] ] = ResponseCache(hs.get_clock(), "remote_room_list", timeout_ms=30 * 1000)
def __init__(self, hs): self.store = hs.get_datastore() self.notifier = hs.get_notifier() self.presence_handler = hs.get_presence_handler() self.event_sources = hs.get_event_sources() self.clock = hs.get_clock() self.response_cache = ResponseCache()
def __init__(self, hs): super().__init__(hs) self.clock = hs.get_clock() self.protocol_meta_cache = ResponseCache( hs.get_clock(), "as_protocol_meta", timeout_ms=HOUR_IN_MS) # type: ResponseCache[Tuple[str, str]]
def __init__(self, hs): super(ApplicationServiceApi, self).__init__(hs) self.clock = hs.get_clock() self.protocol_meta_cache = ResponseCache(hs, "as_protocol_meta", timeout_ms=HOUR_IN_MS)
def __init__(self, hs): if self.CACHE: self.response_cache = ResponseCache(hs, "repl." + self.NAME, timeout_ms=30 * 60 * 1000) assert self.METHOD in ("PUT", "POST", "GET")
def __init__(self, hs: "HomeServer"): super().__init__(hs) self.handler = hs.get_federation_handler() self._federation_event_handler = hs.get_federation_event_handler() self.state = hs.get_state_handler() self._event_auth_handler = hs.get_event_auth_handler() self.device_handler = hs.get_device_handler() # Ensure the following handlers are loaded since they register callbacks # with FederationHandlerRegistry. hs.get_directory_handler() self._server_linearizer = Linearizer("fed_server") # origins that we are currently processing a transaction from. # a dict from origin to txn id. self._active_transactions: Dict[str, str] = {} # We cache results for transaction with the same ID self._transaction_resp_cache: ResponseCache[Tuple[str, str]] = ResponseCache( hs.get_clock(), "fed_txn_handler", timeout_ms=30000 ) self.transaction_actions = TransactionActions(self.store) self.registry = hs.get_federation_registry() # We cache responses to state queries, as they take a while and often # come in waves. self._state_resp_cache: ResponseCache[ Tuple[str, Optional[str]] ] = ResponseCache(hs.get_clock(), "state_resp", timeout_ms=30000) self._state_ids_resp_cache: ResponseCache[Tuple[str, str]] = ResponseCache( hs.get_clock(), "state_ids_resp", timeout_ms=30000 ) self._federation_metrics_domains = ( hs.config.federation.federation_metrics_domains ) self._room_prejoin_state_types = hs.config.api.room_prejoin_state # Whether we have started handling old events in the staging area. self._started_handling_of_staged_events = False
def __init__(self, hs): super(ReplicationSendEventRestServlet, self).__init__() self.event_creation_handler = hs.get_event_creation_handler() self.store = hs.get_datastore() self.clock = hs.get_clock() # The responses are tiny, so we may as well cache them for a while self.response_cache = ResponseCache(hs, timeout_ms=30 * 60 * 1000)
def __init__(self, hs): super(RoomCreationHandler, self).__init__(hs) self.spam_checker = hs.get_spam_checker() self.event_creation_handler = hs.get_event_creation_handler() self.room_member_handler = hs.get_room_member_handler() self.config = hs.config # Room state based off defined presets self._presets_dict = { RoomCreationPreset.PRIVATE_CHAT: { "join_rules": JoinRules.INVITE, "history_visibility": "shared", "original_invitees_have_ops": False, "guest_can_join": True, "power_level_content_override": { "invite": 0 }, }, RoomCreationPreset.TRUSTED_PRIVATE_CHAT: { "join_rules": JoinRules.INVITE, "history_visibility": "shared", "original_invitees_have_ops": True, "guest_can_join": True, "power_level_content_override": { "invite": 0 }, }, RoomCreationPreset.PUBLIC_CHAT: { "join_rules": JoinRules.PUBLIC, "history_visibility": "shared", "original_invitees_have_ops": False, "guest_can_join": False, "power_level_content_override": {}, }, } # Modify presets to selectively enable encryption by default per homeserver config for preset_name, preset_config in self._presets_dict.items(): encrypted = ( preset_name in self.config.encryption_enabled_by_default_for_room_presets) preset_config["encrypted"] = encrypted self._replication = hs.get_replication_data_handler() # linearizer to stop two upgrades happening at once self._upgrade_linearizer = Linearizer("room_upgrade_linearizer") # If a user tries to update the same room multiple times in quick # succession, only process the first attempt and return its result to # subsequent requests self._upgrade_response_cache = ResponseCache( hs, "room_upgrade", timeout_ms=FIVE_MINUTES_IN_MS) self._server_notices_mxid = hs.config.server_notices_mxid self.third_party_event_rules = hs.get_third_party_event_rules()
def __init__(self, hs): super(FederationServer, self).__init__(hs) self.auth = hs.get_auth() self._server_linearizer = Linearizer("fed_server") # We cache responses to state queries, as they take a while and often # come in waves. self._state_resp_cache = ResponseCache(hs, timeout_ms=30000)
def __init__(self, hs: "HomeServer"): super(InitialSyncHandler, self).__init__(hs) self.hs = hs self.state = hs.get_state_handler() self.clock = hs.get_clock() self.validator = EventValidator() self.snapshot_cache = ResponseCache(hs, "initial_sync_cache") self._event_serializer = hs.get_event_client_serializer() self.storage = hs.get_storage() self.state_store = self.storage.state
def __init__(self, hs: "HomeServer"): super().__init__(hs) self.hs = hs self.state = hs.get_state_handler() self.clock = hs.get_clock() self.validator = EventValidator() self.snapshot_cache = ResponseCache( hs, "initial_sync_cache" ) # type: ResponseCache[Tuple[str, Optional[StreamToken], Optional[StreamToken], str, Optional[int], bool, bool]] self._event_serializer = hs.get_event_client_serializer() self.storage = hs.get_storage() self.state_store = self.storage.state
def __init__(self, hs: "HomeServer"): super().__init__(hs) self.auth = hs.get_auth() self.handler = hs.get_federation_handler() self.state = hs.get_state_handler() self.device_handler = hs.get_device_handler() # Ensure the following handlers are loaded since they register callbacks # with FederationHandlerRegistry. hs.get_directory_handler() self._server_linearizer = Linearizer("fed_server") # origins that we are currently processing a transaction from. # a dict from origin to txn id. self._active_transactions = {} # type: Dict[str, str] # We cache results for transaction with the same ID self._transaction_resp_cache = ResponseCache( hs.get_clock(), "fed_txn_handler", timeout_ms=30000 ) # type: ResponseCache[Tuple[str, str]] self.transaction_actions = TransactionActions(self.store) self.registry = hs.get_federation_registry() # We cache responses to state queries, as they take a while and often # come in waves. self._state_resp_cache = ResponseCache( hs.get_clock(), "state_resp", timeout_ms=30000 ) # type: ResponseCache[Tuple[str, str]] self._state_ids_resp_cache = ResponseCache( hs.get_clock(), "state_ids_resp", timeout_ms=30000 ) # type: ResponseCache[Tuple[str, str]] self._federation_metrics_domains = ( hs.get_config().federation.federation_metrics_domains )
def __init__(self, hs): super(FederationServer, self).__init__(hs) self.auth = hs.get_auth() self.handler = hs.get_handlers().federation_handler self.state = hs.get_state_handler() self.device_handler = hs.get_device_handler() self._server_linearizer = Linearizer("fed_server") self._transaction_linearizer = Linearizer("fed_txn_handler") self.transaction_actions = TransactionActions(self.store) self.registry = hs.get_federation_registry() # We cache responses to state queries, as they take a while and often # come in waves. self._state_resp_cache = ResponseCache(hs, "state_resp", timeout_ms=30000) self._state_ids_resp_cache = ResponseCache(hs, "state_ids_resp", timeout_ms=30000)
def __init__(self, hs: "HomeServer"): self._event_auth_handler = hs.get_event_auth_handler() self._store = hs.get_datastore() self._event_serializer = hs.get_event_client_serializer() self._server_name = hs.hostname self._federation_client = hs.get_federation_client() # If a user tries to fetch the same page multiple times in quick succession, # only process the first attempt and return its result to subsequent requests. self._pagination_response_cache: ResponseCache[ Tuple[str, bool, Optional[int], Optional[int], Optional[str]]] = ResponseCache( hs.get_clock(), "get_room_hierarchy", )
def __init__(self, hs): if self.CACHE: self.response_cache = ResponseCache(hs, "repl." + self.NAME, timeout_ms=30 * 60 * 1000) # We reserve `instance_name` as a parameter to sending requests, so we # assert here that sub classes don't try and use the name. assert ("instance_name" not in self.PATH_ARGS ), "`instance_name` is a reserved parameter name" assert ("instance_name" not in signature(self.__class__._serialize_payload).parameters ), "`instance_name` is a reserved parameter name" assert self.METHOD in ("PUT", "POST", "GET")
def __init__(self, hs: "HomeServer"): self.store = hs.get_datastores().main self.auth = hs.get_auth() self.state_handler = hs.get_state_handler() self.hs = hs self.state = hs.get_state_handler() self.clock = hs.get_clock() self.validator = EventValidator() self.snapshot_cache: ResponseCache[Tuple[str, Optional[StreamToken], Optional[StreamToken], str, Optional[int], bool, bool, ]] = ResponseCache( hs.get_clock(), "initial_sync_cache") self._event_serializer = hs.get_event_client_serializer() self._storage_controllers = hs.get_storage_controllers() self._state_storage_controller = self._storage_controllers.state
def __init__(self, hs: "HomeServer"): if self.CACHE: self.response_cache: ResponseCache[str] = ResponseCache( hs.get_clock(), "repl." + self.NAME, timeout_ms=30 * 60 * 1000) # We reserve `instance_name` as a parameter to sending requests, so we # assert here that sub classes don't try and use the name. assert ("instance_name" not in self.PATH_ARGS ), "`instance_name` is a reserved parameter name" assert ("instance_name" not in signature(self.__class__._serialize_payload).parameters ), "`instance_name` is a reserved parameter name" assert self.METHOD in ("PUT", "POST", "GET") self._replication_secret = None if hs.config.worker.worker_replication_secret: self._replication_secret = hs.config.worker.worker_replication_secret
def __init__(self, hs): super(RoomCreationHandler, self).__init__(hs) self.spam_checker = hs.get_spam_checker() self.event_creation_handler = hs.get_event_creation_handler() self.room_member_handler = hs.get_room_member_handler() self.config = hs.config # linearizer to stop two upgrades happening at once self._upgrade_linearizer = Linearizer("room_upgrade_linearizer") # If a user tries to update the same room multiple times in quick # succession, only process the first attempt and return its result to # subsequent requests self._upgrade_response_cache = ResponseCache( hs, "room_upgrade", timeout_ms=FIVE_MINUTES_IN_MS) self._server_notices_mxid = hs.config.server_notices_mxid self.third_party_event_rules = hs.get_third_party_event_rules()
def __init__(self, hs: "HomeServer"): self._event_auth_handler = hs.get_event_auth_handler() self._store = hs.get_datastores().main self._storage_controllers = hs.get_storage_controllers() self._event_serializer = hs.get_event_client_serializer() self._server_name = hs.hostname self._federation_client = hs.get_federation_client() self._ratelimiter = Ratelimiter(store=self._store, clock=hs.get_clock(), rate_hz=5, burst_count=10) # If a user tries to fetch the same page multiple times in quick succession, # only process the first attempt and return its result to subsequent requests. self._pagination_response_cache: ResponseCache[ Tuple[str, str, bool, Optional[int], Optional[int], Optional[str]]] = ResponseCache( hs.get_clock(), "get_room_hierarchy", ) self._msc3266_enabled = hs.config.experimental.msc3266_enabled
def __init__(self, hs): super(RoomListHandler, self).__init__(hs) self.response_cache = ResponseCache(hs) self.remote_response_cache = ResponseCache(hs, timeout_ms=30 * 1000)
def with_cache(self, name: str, ms: int = 0) -> ResponseCache: return ResponseCache(self.clock, name, timeout_ms=ms)