From e15970a484031cb2d4673c03f06b314a19c25b43 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Wed, 29 Mar 2023 09:26:59 -0400 Subject: [PATCH] Add a couple simple Listeners that we need --- src/allmydata/listeners.py | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/src/allmydata/listeners.py b/src/allmydata/listeners.py index 34b447868..149721bbc 100644 --- a/src/allmydata/listeners.py +++ b/src/allmydata/listeners.py @@ -64,3 +64,54 @@ class Listener(Protocol): :return: A handle on the listener which can be used to integrate it into the Tahoe-LAFS node. """ + +class TCPProvider: + """ + Support plain TCP connections. + """ + def is_available(self) -> Literal[True]: + return True + + def can_hide_ip(self) -> Literal[False]: + return False + + async def create_config(self, reactor: Any, cli_config: Any) -> ListenerConfig: + tub_ports = [] + tub_locations = [] + if cli_config["port"]: # --port/--location are a pair + tub_ports.append(cli_config["port"]) + tub_locations.append(cli_config["location"]) + else: + assert "hostname" in cli_config + hostname = cli_config["hostname"] + new_port = allocate_tcp_port() + tub_ports.append(f"tcp:{new_port}") + tub_locations.append(f"tcp:{hostname}:{new_port}") + + return ListenerConfig(tub_ports, tub_locations, {}) + + def create(self, reactor: Any, config: Any) -> IAddressFamily: + raise NotImplementedError() + + +@define +class StaticProvider: + """ + A provider that uses all pre-computed values. + """ + _available: bool + _hide_ip: bool + _config: Any + _address: IAddressFamily + + def is_available(self) -> bool: + return self._available + + def can_hide_ip(self) -> bool: + return self._hide_ip + + async def create_config(self, reactor: Any, cli_config: Any) -> None: + return await self._config + + def create(self, reactor: Any, config: Any) -> IAddressFamily: + return self._address