mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-19 07:48:11 +00:00
A nicer API.
This commit is contained in:
@ -64,7 +64,6 @@ from allmydata.interfaces import (
|
|||||||
from allmydata.nodemaker import NodeMaker
|
from allmydata.nodemaker import NodeMaker
|
||||||
from allmydata.blacklist import Blacklist
|
from allmydata.blacklist import Blacklist
|
||||||
from allmydata import node
|
from allmydata import node
|
||||||
from .protocol_switch import update_foolscap_or_http_class
|
|
||||||
|
|
||||||
|
|
||||||
KiB=1024
|
KiB=1024
|
||||||
@ -820,7 +819,9 @@ class _Client(node.Node, pollmixin.PollMixin):
|
|||||||
furl_file = self.config.get_private_path("storage.furl").encode(get_filesystem_encoding())
|
furl_file = self.config.get_private_path("storage.furl").encode(get_filesystem_encoding())
|
||||||
furl = self.tub.registerReference(FoolscapStorageServer(ss), furlFile=furl_file)
|
furl = self.tub.registerReference(FoolscapStorageServer(ss), furlFile=furl_file)
|
||||||
(_, _, swissnum) = furl.rpartition("/")
|
(_, _, swissnum) = furl.rpartition("/")
|
||||||
update_foolscap_or_http_class(self.tub.negotiationClass, self.tub.myCertificate, ss, swissnum.encode("ascii"))
|
self.tub.negotiationClass.add_storage_server(
|
||||||
|
self.tub.myCertificate, ss, swissnum.encode("ascii")
|
||||||
|
)
|
||||||
|
|
||||||
announcement["anonymous-storage-FURL"] = furl
|
announcement["anonymous-storage-FURL"] = furl
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ from allmydata.util.yamlutil import (
|
|||||||
from . import (
|
from . import (
|
||||||
__full_version__,
|
__full_version__,
|
||||||
)
|
)
|
||||||
from .protocol_switch import create_foolscap_or_http_class
|
from .protocol_switch import support_foolscap_and_https
|
||||||
|
|
||||||
|
|
||||||
def _common_valid_config():
|
def _common_valid_config():
|
||||||
@ -709,7 +709,7 @@ def create_tub(tub_options, default_connection_handlers, foolscap_connection_han
|
|||||||
the new Tub via `Tub.setOption`
|
the new Tub via `Tub.setOption`
|
||||||
"""
|
"""
|
||||||
tub = Tub(**kwargs)
|
tub = Tub(**kwargs)
|
||||||
tub.negotiationClass = create_foolscap_or_http_class()
|
support_foolscap_and_https(tub)
|
||||||
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,9 +6,10 @@ 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 ``create_foolscap_or_http_class()`` to create a new subclass per ``Tub``,
|
Use ``support_foolscap_and_https()`` to create a new subclass for a ``Tub``
|
||||||
and then ``update_foolscap_or_http_class()`` to add the relevant information to
|
instance, and then ``add_storage_server()`` on the resulting class to add the
|
||||||
the subclass once it becomes available later in the configuration process.
|
relevant information for a storage server once it becomes available later in
|
||||||
|
the configuration process.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from twisted.internet.protocol import Protocol
|
from twisted.internet.protocol import Protocol
|
||||||
@ -19,6 +20,7 @@ from twisted.protocols.tls import TLSMemoryBIOFactory
|
|||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
|
|
||||||
from foolscap.negotiate import Negotiation
|
from foolscap.negotiate import Negotiation
|
||||||
|
from foolscap.api import Tub
|
||||||
|
|
||||||
from .storage.http_server import HTTPServer
|
from .storage.http_server import HTTPServer
|
||||||
from .storage.server import StorageServer
|
from .storage.server import StorageServer
|
||||||
@ -54,6 +56,16 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
|
|||||||
|
|
||||||
_timeout: IDelayedCall
|
_timeout: IDelayedCall
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def add_storage_server(cls, certificate, storage_server, swissnum):
|
||||||
|
"""
|
||||||
|
Add the various parameters needed by a ``Tub``-specific
|
||||||
|
``_FoolscapOrHttps`` subclass.
|
||||||
|
"""
|
||||||
|
cls.certificate = certificate
|
||||||
|
cls.storage_server = storage_server
|
||||||
|
cls.swissnum = swissnum
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self._foolscap: Negotiation = Negotiation(*args, **kwargs)
|
self._foolscap: Negotiation = Negotiation(*args, **kwargs)
|
||||||
self._buffer: bytes = b""
|
self._buffer: bytes = b""
|
||||||
@ -124,7 +136,7 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
|
|||||||
self.__dict__ = protocol.__dict__
|
self.__dict__ = protocol.__dict__
|
||||||
|
|
||||||
|
|
||||||
def create_foolscap_or_http_class():
|
def support_foolscap_and_https(tub: Tub):
|
||||||
"""
|
"""
|
||||||
Create a new Foolscap-or-HTTPS protocol class for a specific ``Tub``
|
Create a new Foolscap-or-HTTPS protocol class for a specific ``Tub``
|
||||||
instance.
|
instance.
|
||||||
@ -133,14 +145,4 @@ def create_foolscap_or_http_class():
|
|||||||
class FoolscapOrHttpWithCert(_FoolscapOrHttps):
|
class FoolscapOrHttpWithCert(_FoolscapOrHttps):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return FoolscapOrHttpWithCert
|
tub.negotiationClass = FoolscapOrHttpWithCert # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def update_foolscap_or_http_class(cls, certificate, storage_server, swissnum):
|
|
||||||
"""
|
|
||||||
Add the various parameters needed by a ``Tub``-specific
|
|
||||||
``_FoolscapOrHttps`` subclass.
|
|
||||||
"""
|
|
||||||
cls.certificate = certificate
|
|
||||||
cls.storage_server = storage_server
|
|
||||||
cls.swissnum = swissnum
|
|
||||||
|
Reference in New Issue
Block a user