More cleanups.

This commit is contained in:
Itamar Turner-Trauring 2022-07-29 10:12:24 -04:00
parent 34518f9d0d
commit 1cd2185be7
1 changed files with 17 additions and 12 deletions

View File

@ -48,21 +48,20 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
since these are created by Foolscap's ``Tub``, by setting this to be the since these are created by Foolscap's ``Tub``, by setting this to be the
tub's ``negotiationClass``. tub's ``negotiationClass``.
Do not use directly, use ``support_foolscap_and_https(tub)`` instead. The Do not instantiate directly, use ``support_foolscap_and_https(tub)``
way this class works is that a new subclass is created for a specific instead. The way this class works is that a new subclass is created for a
``Tub`` instance. specific ``Tub`` instance.
""" """
# These will be set by support_foolscap_and_https() and add_storage_server(). # These are class attributes; they will be set by
# support_foolscap_and_https() and add_storage_server().
# The HTTP storage server API we're exposing. # The Twisted HTTPS protocol factory wrapping the storage server HTTP API:
http_storage_server: HTTPServer
# The Twisted HTTPS protocol factory wrapping the storage server API:
https_factory: TLSMemoryBIOFactory https_factory: TLSMemoryBIOFactory
# The tub that created us: # The tub that created us:
tub: Tub tub: Tub
# This will be created by the instance in connectionMade(): # This is an instance attribute; it will be set in connectionMade().
_timeout: IDelayedCall _timeout: IDelayedCall
@classmethod @classmethod
@ -70,11 +69,17 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
cls, storage_server: StorageServer, swissnum: bytes cls, storage_server: StorageServer, swissnum: bytes
) -> set[DecodedURL]: ) -> set[DecodedURL]:
""" """
Add the various storage server-related attributes needed by a Update a ``_FoolscapOrHttps`` subclass for a specific ``Tub`` instance
``Tub``-specific ``_FoolscapOrHttps`` subclass. with the class attributes it requires for a specific storage server.
Returns the resulting NURLs. Returns the resulting NURLs.
""" """
# We need to be a subclass:
assert cls != _FoolscapOrHttps
# The tub instance must already be set:
assert hasattr(cls, "tub")
assert isinstance(cls.tub, Tub)
# Tub.myCertificate is a twisted.internet.ssl.PrivateCertificate # Tub.myCertificate is a twisted.internet.ssl.PrivateCertificate
# instance. # instance.
certificate_options = CertificateOptions( certificate_options = CertificateOptions(
@ -82,11 +87,11 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
certificate=cls.tub.myCertificate.original, certificate=cls.tub.myCertificate.original,
) )
cls.http_storage_server = HTTPServer(storage_server, swissnum) http_storage_server = HTTPServer(storage_server, swissnum)
cls.https_factory = TLSMemoryBIOFactory( cls.https_factory = TLSMemoryBIOFactory(
certificate_options, certificate_options,
False, False,
Site(cls.http_storage_server.get_resource()), Site(http_storage_server.get_resource()),
) )
storage_nurls = set() storage_nurls = set()