improve the Listener protocol somewhat

This commit is contained in:
Jean-Paul Calderone 2023-03-29 09:26:13 -04:00
parent cbfbfe8b1e
commit ed237b0dba

View File

@ -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.