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.
 
 
 
 
 
 

82 lines
3.2 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 Optional
  15. from synapse.config._base import Config
  16. from synapse.config._util import validate_config
  17. class FederationConfig(Config):
  18. section = "federation"
  19. def read_config(self, config, **kwargs):
  20. # FIXME: federation_domain_whitelist needs sytests
  21. self.federation_domain_whitelist = None # type: Optional[dict]
  22. federation_domain_whitelist = config.get("federation_domain_whitelist", None)
  23. if federation_domain_whitelist is not None:
  24. # turn the whitelist into a hash for speed of lookup
  25. self.federation_domain_whitelist = {}
  26. for domain in federation_domain_whitelist:
  27. self.federation_domain_whitelist[domain] = True
  28. federation_metrics_domains = config.get("federation_metrics_domains") or []
  29. validate_config(
  30. _METRICS_FOR_DOMAINS_SCHEMA,
  31. federation_metrics_domains,
  32. ("federation_metrics_domains",),
  33. )
  34. self.federation_metrics_domains = set(federation_metrics_domains)
  35. self.allow_profile_lookup_over_federation = config.get(
  36. "allow_profile_lookup_over_federation", True
  37. )
  38. def generate_config_section(self, config_dir_path, server_name, **kwargs):
  39. return """\
  40. ## Federation ##
  41. # Restrict federation to the following whitelist of domains.
  42. # N.B. we recommend also firewalling your federation listener to limit
  43. # inbound federation traffic as early as possible, rather than relying
  44. # purely on this application-layer restriction. If not specified, the
  45. # default is to whitelist everything.
  46. #
  47. #federation_domain_whitelist:
  48. # - lon.example.com
  49. # - nyc.example.com
  50. # - syd.example.com
  51. # Report prometheus metrics on the age of PDUs being sent to and received from
  52. # the following domains. This can be used to give an idea of "delay" on inbound
  53. # and outbound federation, though be aware that any delay can be due to problems
  54. # at either end or with the intermediate network.
  55. #
  56. # By default, no domains are monitored in this way.
  57. #
  58. #federation_metrics_domains:
  59. # - matrix.org
  60. # - example.com
  61. # Uncomment to disable profile lookup over federation. By default, the
  62. # Federation API allows other homeservers to obtain profile data of any user
  63. # on this homeserver. Defaults to 'true'.
  64. #
  65. #allow_profile_lookup_over_federation: false
  66. """
  67. _METRICS_FOR_DOMAINS_SCHEMA = {"type": "array", "items": {"type": "string"}}