Skip to content

Commit

Permalink
Don't listen on all interfaces if empty reg URL
Browse files Browse the repository at this point in the history
  • Loading branch information
hifi committed Nov 1, 2023
1 parent f85b83e commit 06d2d44
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions heisenbridge/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,9 @@ async def run(self, listen_address, listen_port, homeserver_url, owner, safe_mod
url = urllib.parse.urlparse(homeserver_url)
ws = None
if url.scheme in ["ws", "wss"]:
print("Using websockets to receive transactions. Listening is still enabled.")
print(
f"Using websockets to receive transactions. Listening is still enabled on http://{listen_address}:{listen_port}"
)
ws = AppserviceWebsocket(homeserver_url, self.registration["as_token"], self._on_mx_event)
homeserver_url = url._replace(scheme=("https" if url.scheme == "wss" else "http")).geturl()
print(f"Connecting to HS at {homeserver_url}")
Expand Down Expand Up @@ -941,18 +943,24 @@ async def async_main():
listen_port = args.listen_port

if not listen_address:
listen_address = "127.0.0.1"

try:
url = urllib.parse.urlparse(service.registration["url"])
listen_address = url.hostname
if url.hostname:
listen_address = url.hostname
except Exception:
listen_address = "127.0.0.1"
pass

if not listen_port:
listen_port = 9898

try:
url = urllib.parse.urlparse(service.registration["url"])
listen_port = url.port
if url.port:
listen_port = url.port
except Exception:
listen_port = 9898
pass

await service.run(listen_address, listen_port, args.homeserver, args.owner, args.safe_mode)

Expand Down

0 comments on commit 06d2d44

Please sign in to comment.