Nicer API.
This commit is contained in:
parent
d918135a0d
commit
5d53cd4a17
|
@ -55,7 +55,7 @@ from allmydata.util.yamlutil import (
|
||||||
from . import (
|
from . import (
|
||||||
__full_version__,
|
__full_version__,
|
||||||
)
|
)
|
||||||
from .protocol_switch import support_foolscap_and_https
|
from .protocol_switch import create_tub_with_https_support
|
||||||
|
|
||||||
|
|
||||||
def _common_valid_config():
|
def _common_valid_config():
|
||||||
|
@ -708,8 +708,10 @@ def create_tub(tub_options, default_connection_handlers, foolscap_connection_han
|
||||||
:param dict tub_options: every key-value pair in here will be set in
|
:param dict tub_options: every key-value pair in here will be set in
|
||||||
the new Tub via `Tub.setOption`
|
the new Tub via `Tub.setOption`
|
||||||
"""
|
"""
|
||||||
tub = Tub(**kwargs)
|
# We listen simulataneously for both Foolscap and HTTPS on the same port,
|
||||||
support_foolscap_and_https(tub)
|
# so we have to create a special Foolscap Tub for that to work:
|
||||||
|
tub = create_tub_with_https_support(**kwargs)
|
||||||
|
|
||||||
for (name, value) in list(tub_options.items()):
|
for (name, value) in list(tub_options.items()):
|
||||||
tub.setOption(name, value)
|
tub.setOption(name, value)
|
||||||
handlers = default_connection_handlers.copy()
|
handlers = default_connection_handlers.copy()
|
||||||
|
|
|
@ -6,10 +6,11 @@ simple as possible, with no extra configuration needed. Listening on the same
|
||||||
port means a user upgrading Tahoe-LAFS will automatically get HTTPS working
|
port means a user upgrading Tahoe-LAFS will automatically get HTTPS working
|
||||||
with no additional changes.
|
with no additional changes.
|
||||||
|
|
||||||
Use ``support_foolscap_and_https()`` to create a new subclass for a ``Tub``
|
Use ``create_tub_with_https_support()`` creates a new ``Tub`` that has its
|
||||||
instance, and then ``add_storage_server()`` on the resulting class to add the
|
``negotiationClass`` modified to be a new subclass tied to that specific
|
||||||
relevant information for a storage server once it becomes available later in
|
``Tub`` instance. Calling ``tub.negotiationClass.add_storage_server(...)``
|
||||||
the configuration process.
|
then adds relevant information for a storage server once it becomes available
|
||||||
|
later in the configuration process.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
@ -193,14 +194,17 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
|
||||||
self.__dict__ = protocol.__dict__
|
self.__dict__ = protocol.__dict__
|
||||||
|
|
||||||
|
|
||||||
def support_foolscap_and_https(tub: Tub):
|
def create_tub_with_https_support(**kwargs) -> Tub:
|
||||||
"""
|
"""
|
||||||
Create a new Foolscap-or-HTTPS protocol class for a specific ``Tub``
|
Create a new Tub that also supports HTTPS.
|
||||||
|
|
||||||
|
This involves creating a new protocol switch class for the specific ``Tub``
|
||||||
instance.
|
instance.
|
||||||
"""
|
"""
|
||||||
the_tub = tub
|
the_tub = Tub(**kwargs)
|
||||||
|
|
||||||
class FoolscapOrHttpForTub(_FoolscapOrHttps):
|
class FoolscapOrHttpForTub(_FoolscapOrHttps):
|
||||||
tub = the_tub
|
tub = the_tub
|
||||||
|
|
||||||
tub.negotiationClass = FoolscapOrHttpForTub # type: ignore
|
the_tub.negotiationClass = FoolscapOrHttpForTub # type: ignore
|
||||||
|
return the_tub
|
||||||
|
|
Loading…
Reference in New Issue