You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

88 line
3.6 KiB

  1. # Copyright 2020 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from typing import Any, Optional
  15. from synapse.config._base import Config
  16. from synapse.config._util import validate_config
  17. from synapse.types import JsonDict
  18. class FederationConfig(Config):
  19. section = "federation"
  20. def read_config(self, config: JsonDict, **kwargs: Any) -> None:
  21. federation_config = config.setdefault("federation", {})
  22. # FIXME: federation_domain_whitelist needs sytests
  23. self.federation_domain_whitelist: Optional[dict] = None
  24. federation_domain_whitelist = config.get("federation_domain_whitelist", None)
  25. if federation_domain_whitelist is not None:
  26. # turn the whitelist into a hash for speed of lookup
  27. self.federation_domain_whitelist = {}
  28. for domain in federation_domain_whitelist:
  29. self.federation_domain_whitelist[domain] = True
  30. federation_metrics_domains = config.get("federation_metrics_domains") or []
  31. validate_config(
  32. _METRICS_FOR_DOMAINS_SCHEMA,
  33. federation_metrics_domains,
  34. ("federation_metrics_domains",),
  35. )
  36. self.federation_metrics_domains = set(federation_metrics_domains)
  37. self.allow_profile_lookup_over_federation = config.get(
  38. "allow_profile_lookup_over_federation", True
  39. )
  40. self.allow_device_name_lookup_over_federation = config.get(
  41. "allow_device_name_lookup_over_federation", False
  42. )
  43. # Allow for the configuration of timeout, max request retries
  44. # and min/max retry delays in the matrix federation client.
  45. self.client_timeout_ms = Config.parse_duration(
  46. federation_config.get("client_timeout", "60s")
  47. )
  48. self.max_long_retry_delay_ms = Config.parse_duration(
  49. federation_config.get("max_long_retry_delay", "60s")
  50. )
  51. self.max_short_retry_delay_ms = Config.parse_duration(
  52. federation_config.get("max_short_retry_delay", "2s")
  53. )
  54. self.max_long_retries = federation_config.get("max_long_retries", 10)
  55. self.max_short_retries = federation_config.get("max_short_retries", 3)
  56. # Allow for the configuration of the backoff algorithm used
  57. # when trying to reach an unavailable destination.
  58. # Unlike previous configuration those values applies across
  59. # multiple requests and the state of the backoff is stored on DB.
  60. self.destination_min_retry_interval_ms = Config.parse_duration(
  61. federation_config.get("destination_min_retry_interval", "10m")
  62. )
  63. self.destination_retry_multiplier = federation_config.get(
  64. "destination_retry_multiplier", 2
  65. )
  66. self.destination_max_retry_interval_ms = min(
  67. Config.parse_duration(
  68. federation_config.get("destination_max_retry_interval", "7d")
  69. ),
  70. # Set a hard-limit to not overflow the database column.
  71. 2**62,
  72. )
  73. _METRICS_FOR_DOMAINS_SCHEMA = {"type": "array", "items": {"type": "string"}}