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

Commit

Permalink
Merge pull request #1795 from matrix-org/erikj/port_defaults
Browse files Browse the repository at this point in the history
Restore default bind address
  • Loading branch information
erikjohnston authored Jan 13, 2017
2 parents 6f5e41e + b1dfd20 commit 641ccdb
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 84 deletions.
12 changes: 2 additions & 10 deletions synapse/app/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def setup(self):

def _listen_http(self, listener_config):
port = listener_config["port"]
bind_address = listener_config.get("bind_address", None)
bind_addresses = listener_config.get("bind_addresses", [])
bind_addresses = listener_config["bind_addresses"]
site_tag = listener_config.get("tag", port)
resources = {}
for res in listener_config["resources"]:
Expand All @@ -87,9 +86,6 @@ def _listen_http(self, listener_config):

root_resource = create_resource_tree(resources, Resource())

if bind_address is not None:
bind_addresses.append(bind_address)

for address in bind_addresses:
reactor.listenTCP(
port,
Expand All @@ -109,11 +105,7 @@ def start_listening(self, listeners):
if listener["type"] == "http":
self._listen_http(listener)
elif listener["type"] == "manhole":
bind_address = listener.get("bind_address", None)
bind_addresses = listener.get("bind_addresses", [])

if bind_address is not None:
bind_addresses.append(bind_address)
bind_addresses = listener["bind_addresses"]

for address in bind_addresses:
reactor.listenTCP(
Expand Down
12 changes: 2 additions & 10 deletions synapse/app/client_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ def setup(self):

def _listen_http(self, listener_config):
port = listener_config["port"]
bind_address = listener_config.get("bind_address", None)
bind_addresses = listener_config.get("bind_addresses", [])
bind_addresses = listener_config["bind_addresses"]
site_tag = listener_config.get("tag", port)
resources = {}
for res in listener_config["resources"]:
Expand All @@ -110,9 +109,6 @@ def _listen_http(self, listener_config):

root_resource = create_resource_tree(resources, Resource())

if bind_address is not None:
bind_addresses.append(bind_address)

for address in bind_addresses:
reactor.listenTCP(
port,
Expand All @@ -132,11 +128,7 @@ def start_listening(self, listeners):
if listener["type"] == "http":
self._listen_http(listener)
elif listener["type"] == "manhole":
bind_address = listener.get("bind_address", None)
bind_addresses = listener.get("bind_addresses", [])

if bind_address is not None:
bind_addresses.append(bind_address)
bind_addresses = listener["bind_addresses"]

for address in bind_addresses:
reactor.listenTCP(
Expand Down
12 changes: 2 additions & 10 deletions synapse/app/federation_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def setup(self):

def _listen_http(self, listener_config):
port = listener_config["port"]
bind_address = listener_config.get("bind_address", None)
bind_addresses = listener_config.get("bind_addresses", [])
bind_addresses = listener_config["bind_addresses"]
site_tag = listener_config.get("tag", port)
resources = {}
for res in listener_config["resources"]:
Expand All @@ -101,9 +100,6 @@ def _listen_http(self, listener_config):

root_resource = create_resource_tree(resources, Resource())

if bind_address is not None:
bind_addresses.append(bind_address)

for address in bind_addresses:
reactor.listenTCP(
port,
Expand All @@ -123,11 +119,7 @@ def start_listening(self, listeners):
if listener["type"] == "http":
self._listen_http(listener)
elif listener["type"] == "manhole":
bind_address = listener.get("bind_address", None)
bind_addresses = listener.get("bind_addresses", [])

if bind_address is not None:
bind_addresses.append(bind_address)
bind_addresses = listener["bind_addresses"]

for address in bind_addresses:
reactor.listenTCP(
Expand Down
12 changes: 2 additions & 10 deletions synapse/app/federation_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def setup(self):

def _listen_http(self, listener_config):
port = listener_config["port"]
bind_address = listener_config.get("bind_address", None)
bind_addresses = listener_config.get("bind_addresses", [])
bind_addresses = listener_config["bind_addresses"]
site_tag = listener_config.get("tag", port)
resources = {}
for res in listener_config["resources"]:
Expand All @@ -93,9 +92,6 @@ def _listen_http(self, listener_config):

root_resource = create_resource_tree(resources, Resource())

if bind_address is not None:
bind_addresses.append(bind_address)

for address in bind_addresses:
reactor.listenTCP(
port,
Expand All @@ -115,11 +111,7 @@ def start_listening(self, listeners):
if listener["type"] == "http":
self._listen_http(listener)
elif listener["type"] == "manhole":
bind_address = listener.get("bind_address", None)
bind_addresses = listener.get("bind_addresses", [])

if bind_address is not None:
bind_addresses.append(bind_address)
bind_addresses = listener["bind_addresses"]

for address in bind_addresses:
reactor.listenTCP(
Expand Down
12 changes: 2 additions & 10 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ def build_resource_for_web_client(hs):
class SynapseHomeServer(HomeServer):
def _listener_http(self, config, listener_config):
port = listener_config["port"]
bind_address = listener_config.get("bind_address", None)
bind_addresses = listener_config.get("bind_addresses", [])
bind_addresses = listener_config["bind_addresses"]
tls = listener_config.get("tls", False)
site_tag = listener_config.get("tag", port)

Expand Down Expand Up @@ -175,9 +174,6 @@ def _listener_http(self, config, listener_config):

root_resource = create_resource_tree(resources, root_resource)

if bind_address is not None:
bind_addresses.append(bind_address)

if tls:
for address in bind_addresses:
reactor.listenSSL(
Expand Down Expand Up @@ -212,11 +208,7 @@ def start_listening(self):
if listener["type"] == "http":
self._listener_http(config, listener)
elif listener["type"] == "manhole":
bind_address = listener.get("bind_address", None)
bind_addresses = listener.get("bind_addresses", [])

if bind_address is not None:
bind_addresses.append(bind_address)
bind_addresses = listener["bind_addresses"]

for address in bind_addresses:
reactor.listenTCP(
Expand Down
12 changes: 2 additions & 10 deletions synapse/app/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def setup(self):

def _listen_http(self, listener_config):
port = listener_config["port"]
bind_address = listener_config.get("bind_address", None)
bind_addresses = listener_config.get("bind_addresses", [])
bind_addresses = listener_config["bind_addresses"]
site_tag = listener_config.get("tag", port)
resources = {}
for res in listener_config["resources"]:
Expand All @@ -107,9 +106,6 @@ def _listen_http(self, listener_config):

root_resource = create_resource_tree(resources, Resource())

if bind_address is not None:
bind_addresses.append(bind_address)

for address in bind_addresses:
reactor.listenTCP(
port,
Expand All @@ -129,11 +125,7 @@ def start_listening(self, listeners):
if listener["type"] == "http":
self._listen_http(listener)
elif listener["type"] == "manhole":
bind_address = listener.get("bind_address", None)
bind_addresses = listener.get("bind_addresses", [])

if bind_address is not None:
bind_addresses.append(bind_address)
bind_addresses = listener["bind_addresses"]

for address in bind_addresses:
reactor.listenTCP(
Expand Down
12 changes: 2 additions & 10 deletions synapse/app/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def remove_pusher(self, app_id, push_key, user_id):

def _listen_http(self, listener_config):
port = listener_config["port"]
bind_address = listener_config.get("bind_address", None)
bind_addresses = listener_config.get("bind_addresses", [])
bind_addresses = listener_config["bind_addresses"]
site_tag = listener_config.get("tag", port)
resources = {}
for res in listener_config["resources"]:
Expand All @@ -132,9 +131,6 @@ def _listen_http(self, listener_config):

root_resource = create_resource_tree(resources, Resource())

if bind_address is not None:
bind_addresses.append(bind_address)

for address in bind_addresses:
reactor.listenTCP(
port,
Expand All @@ -154,11 +150,7 @@ def start_listening(self, listeners):
if listener["type"] == "http":
self._listen_http(listener)
elif listener["type"] == "manhole":
bind_address = listener.get("bind_address", None)
bind_addresses = listener.get("bind_addresses", [])

if bind_address is not None:
bind_addresses.append(bind_address)
bind_addresses = listener["bind_addresses"]

for address in bind_addresses:
reactor.listenTCP(
Expand Down
12 changes: 2 additions & 10 deletions synapse/app/synchrotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ def setup(self):

def _listen_http(self, listener_config):
port = listener_config["port"]
bind_address = listener_config.get("bind_address", None)
bind_addresses = listener_config.get("bind_addresses", [])
bind_addresses = listener_config["bind_addresses"]
site_tag = listener_config.get("tag", port)
resources = {}
for res in listener_config["resources"]:
Expand All @@ -312,9 +311,6 @@ def _listen_http(self, listener_config):

root_resource = create_resource_tree(resources, Resource())

if bind_address is not None:
bind_addresses.append(bind_address)

for address in bind_addresses:
reactor.listenTCP(
port,
Expand All @@ -334,11 +330,7 @@ def start_listening(self, listeners):
if listener["type"] == "http":
self._listen_http(listener)
elif listener["type"] == "manhole":
bind_address = listener.get("bind_address", None)
bind_addresses = listener.get("bind_addresses", [])

if bind_address is not None:
bind_addresses.append(bind_address)
bind_addresses = listener["bind_addresses"]

for address in bind_addresses:
reactor.listenTCP(
Expand Down
17 changes: 13 additions & 4 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def read_config(self, config):

self.listeners = config.get("listeners", [])

for listener in self.listeners:
bind_address = listener.pop("bind_address", None)
bind_addresses = listener.setdefault("bind_addresses", [])

if bind_address:
bind_addresses.append(bind_address)
elif not bind_addresses:
bind_addresses.append('')

self.gc_thresholds = read_gc_thresholds(config.get("gc_thresholds", None))

bind_port = config.get("bind_port")
Expand All @@ -54,7 +63,7 @@ def read_config(self, config):

self.listeners.append({
"port": bind_port,
"bind_address": bind_host,
"bind_addresses": [bind_host],
"tls": True,
"type": "http",
"resources": [
Expand All @@ -73,7 +82,7 @@ def read_config(self, config):
if unsecure_port:
self.listeners.append({
"port": unsecure_port,
"bind_address": bind_host,
"bind_addresses": [bind_host],
"tls": False,
"type": "http",
"resources": [
Expand All @@ -92,15 +101,15 @@ def read_config(self, config):
if manhole:
self.listeners.append({
"port": manhole,
"bind_address": "127.0.0.1",
"bind_addresses": ["127.0.0.1"],
"type": "manhole",
})

metrics_port = config.get("metrics_port")
if metrics_port:
self.listeners.append({
"port": metrics_port,
"bind_address": config.get("metrics_bind_host", "127.0.0.1"),
"bind_addresses": [config.get("metrics_bind_host", "127.0.0.1")],
"tls": False,
"type": "http",
"resources": [
Expand Down

0 comments on commit 641ccdb

Please sign in to comment.