narrow the type of cli_config a bit

This has unfortunate interactions with the "stdout" attribute but I'm punting
on that.
This commit is contained in:
Jean-Paul Calderone 2023-07-20 14:19:12 -04:00
parent 40665d824d
commit 57facc6335
3 changed files with 14 additions and 7 deletions

View File

@ -10,6 +10,7 @@ from typing import Any, Protocol, Sequence, Mapping, Optional, Union, Awaitable
from typing_extensions import Literal
from attrs import frozen
from twisted.python.usage import Options
from .interfaces import IAddressFamily
from .util.iputil import allocate_tcp_port
@ -45,7 +46,7 @@ class Listener(Protocol):
node's public internet address from peers?
"""
async def create_config(self, reactor: Any, cli_config: Any) -> Optional[ListenerConfig]:
async def create_config(self, reactor: Any, cli_config: Options) -> Optional[ListenerConfig]:
"""
Set up an instance of this listener according to the given
configuration parameters.
@ -75,7 +76,7 @@ class TCPProvider:
def can_hide_ip(self) -> Literal[False]:
return False
async def create_config(self, reactor: Any, cli_config: Any) -> ListenerConfig:
async def create_config(self, reactor: Any, cli_config: Options) -> ListenerConfig:
tub_ports = []
tub_locations = []
if cli_config["port"]: # --port/--location are a pair
@ -110,7 +111,7 @@ class StaticProvider:
def can_hide_ip(self) -> bool:
return self._hide_ip
async def create_config(self, reactor: Any, cli_config: Any) -> Optional[ListenerConfig]:
async def create_config(self, reactor: Any, cli_config: Options) -> Optional[ListenerConfig]:
if self._config is None or isinstance(self._config, ListenerConfig):
return self._config
return await self._config

View File

@ -15,6 +15,7 @@ from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.endpoints import clientFromString
from twisted.internet.error import ConnectionRefusedError, ConnectError
from twisted.application import service
from twisted.python.usage import Options
from ..listeners import ListenerConfig
from ..interfaces import (
@ -108,7 +109,7 @@ def _connect_to_i2p(reactor, cli_config, txi2p):
else:
raise ValueError("unable to reach any default I2P SAM port")
async def create_config(reactor: Any, cli_config: Any) -> ListenerConfig:
async def create_config(reactor: Any, cli_config: Options) -> ListenerConfig:
"""
For a given set of command-line options, construct an I2P listener.
@ -120,7 +121,9 @@ async def create_config(reactor: Any, cli_config: Any) -> ListenerConfig:
"Please 'pip install tahoe-lafs[i2p]' to fix this.")
tahoe_config_i2p = [] # written into tahoe.cfg:[i2p]
private_dir = os.path.abspath(os.path.join(cli_config["basedir"], "private"))
stdout = cli_config.stdout
# XXX We shouldn't carry stdout around by jamming it into the Options
# value. See https://tahoe-lafs.org/trac/tahoe-lafs/ticket/4048
stdout = cli_config.stdout # type: ignore[attr-defined]
if cli_config["i2p-launch"]:
raise NotImplementedError("--i2p-launch is under development.")
else:

View File

@ -13,6 +13,7 @@ from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.endpoints import clientFromString, TCP4ServerEndpoint
from twisted.internet.error import ConnectionRefusedError, ConnectError
from twisted.application import service
from twisted.python.usage import Options
from .observer import OneShotObserverList
from .iputil import allocate_tcp_port
@ -154,14 +155,16 @@ def _connect_to_tor(reactor, cli_config, txtorcon):
else:
raise ValueError("unable to reach any default Tor control port")
async def create_config(reactor: Any, cli_config: Any) -> ListenerConfig:
async def create_config(reactor: Any, cli_config: Options) -> ListenerConfig:
txtorcon = _import_txtorcon()
if not txtorcon:
raise ValueError("Cannot create onion without txtorcon. "
"Please 'pip install tahoe-lafs[tor]' to fix this.")
tahoe_config_tor = [] # written into tahoe.cfg:[tor]
private_dir = os.path.abspath(os.path.join(cli_config["basedir"], "private"))
stdout = cli_config.stdout
# XXX We shouldn't carry stdout around by jamming it into the Options
# value. See https://tahoe-lafs.org/trac/tahoe-lafs/ticket/4048
stdout = cli_config.stdout # type: ignore[attr-defined]
if cli_config["tor-launch"]:
tahoe_config_tor.append(("launch", "true"))
tor_executable = cli_config["tor-executable"]