From ed237b0dba674a7bac023163542cd6d904e20d77 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Wed, 29 Mar 2023 09:26:13 -0400 Subject: [PATCH] improve the Listener protocol somewhat --- src/allmydata/listeners.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/allmydata/listeners.py b/src/allmydata/listeners.py index 00ac9df4d..34b447868 100644 --- a/src/allmydata/listeners.py +++ b/src/allmydata/listeners.py @@ -6,11 +6,13 @@ detect when it is possible to use it, etc. from __future__ import annotations -from typing import Any, Protocol +from typing import Any, Awaitable, Protocol, Sequence, Mapping, Optional +from typing_extensions import Literal -from attrs import frozen +from attrs import frozen, define from .interfaces import IAddressFamily +from .util.iputil import allocate_tcp_port @frozen class ListenerConfig: @@ -19,14 +21,12 @@ class ListenerConfig: :ivar tub_locations: Entries to merge into ``[node]tub.location``. - :ivar node_config: Entries to merge into the overall Tahoe-LAFS - configuration. XXX Note: Sections currently merge by overwriting - existing items with overlapping keys. In the future it would be nice - to merge every item sensibly (or error). + :ivar node_config: Entries to add into the overall Tahoe-LAFS + configuration beneath a section named after this listener. """ - tub_ports: list[str] - tub_locations: list[str] - node_config: dict[str, dict[str, str]] + tub_ports: Sequence[str] + tub_locations: Sequence[str] + node_config: Mapping[str, Sequence[tuple[str, str]]] class Listener(Protocol): """ @@ -45,7 +45,7 @@ class Listener(Protocol): node's public internet address from peers? """ - def create_config(self, reactor: Any, cli_config: Any) -> ListenerConfig: + async def create_config(self, reactor: Any, cli_config: Any) -> Optional[ListenerConfig]: """ Set up an instance of this listener according to the given configuration parameters. @@ -56,7 +56,7 @@ class Listener(Protocol): overall *tahoe.cfg* configuration file. """ - def create(self, config: Any, reactor: Any) -> IAddressFamily: + def create(self, reactor: Any, config: Any) -> IAddressFamily: """ Instantiate this listener according to the given previously-generated configuration.