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

Tiny .well-known fixes #4521

Merged
merged 3 commits into from
Jan 30, 2019
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/4521.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement MSC1708 (.well-known routing for server-server federation)
20 changes: 11 additions & 9 deletions synapse/http/federation/matrix_federation_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,18 @@ def _get_well_known(self, server_name):
response = yield make_deferred_yieldable(
self._well_known_agent.request(b"GET", uri),
)
body = yield make_deferred_yieldable(readBody(response))
if response.code != 200:
raise Exception("Non-200 response %s" % (response.code, ))
except Exception as e:
logger.info("Connection error fetching %s: %s", uri_str, e)
self._well_known_cache.set(server_name, None, WELL_KNOWN_INVALID_CACHE_PERIOD)
defer.returnValue(None)
logger.info("Error fetching %s: %s", uri_str, e)

body = yield make_deferred_yieldable(readBody(response))
# add some randomness to the TTL to avoid a stampeding herd every hour
# after startup
cache_period = WELL_KNOWN_INVALID_CACHE_PERIOD
cache_period += random.uniform(0, WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER)

if response.code != 200:
logger.info("Error response %i from %s", response.code, uri_str)
self._well_known_cache.set(server_name, None, WELL_KNOWN_INVALID_CACHE_PERIOD)
self._well_known_cache.set(server_name, None, cache_period)
defer.returnValue(None)

try:
Expand All @@ -326,8 +328,8 @@ def _get_well_known(self, server_name):
)
if cache_period is None:
cache_period = WELL_KNOWN_DEFAULT_CACHE_PERIOD
# add some randomness to the TTL to avoid a stampeding herd every hour after
# startup
# add some randomness to the TTL to avoid a stampeding herd every 24 hours
# after startup
cache_period += random.uniform(0, WELL_KNOWN_DEFAULT_CACHE_PERIOD_JITTER)
else:
cache_period = min(cache_period, WELL_KNOWN_MAX_CACHE_PERIOD)
Expand Down