mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-20 17:52:50 +00:00
Improve factoring.
This commit is contained in:
parent
21bb9e50f6
commit
822b652d99
@ -37,7 +37,6 @@ import allmydata
|
||||
from allmydata.crypto import rsa, ed25519
|
||||
from allmydata.crypto.util import remove_prefix
|
||||
from allmydata.storage.server import StorageServer, FoolscapStorageServer
|
||||
from allmydata.storage.http_server import build_nurl
|
||||
from allmydata import storage_client
|
||||
from allmydata.immutable.upload import Uploader
|
||||
from allmydata.immutable.offloaded import Helper
|
||||
@ -660,10 +659,10 @@ class _Client(node.Node, pollmixin.PollMixin):
|
||||
self.init_web(webport) # strports string
|
||||
|
||||
# TODO this may be the wrong location for now? but as temporary measure
|
||||
# it allows us to get NURLs for testing in test_istorageserver.py Will
|
||||
# eventually get fixed one way or another in
|
||||
# it allows us to get NURLs for testing in test_istorageserver.py. This
|
||||
# will eventually get fixed one way or another in
|
||||
# https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3901
|
||||
self.storage_nurls = []
|
||||
self.storage_nurls = set()
|
||||
|
||||
def init_stats_provider(self):
|
||||
self.stats_provider = StatsProvider(self)
|
||||
@ -826,17 +825,9 @@ class _Client(node.Node, pollmixin.PollMixin):
|
||||
furl_file = self.config.get_private_path("storage.furl").encode(get_filesystem_encoding())
|
||||
furl = self.tub.registerReference(FoolscapStorageServer(ss), furlFile=furl_file)
|
||||
(_, _, swissnum) = furl.rpartition("/")
|
||||
self.tub.negotiationClass.add_storage_server(ss, swissnum.encode("ascii"))
|
||||
for location_hint in self.tub.locationHints:
|
||||
if location_hint.startswith("tcp:"):
|
||||
_, hostname, port = location_hint.split(":")
|
||||
port = int(port)
|
||||
self.storage_nurls.append(
|
||||
build_nurl(
|
||||
hostname, port, swissnum, self.tub.myCertificate.original.to_cryptography()
|
||||
)
|
||||
)
|
||||
|
||||
self.storage_nurls.update(
|
||||
self.tub.negotiationClass.add_storage_server(ss, swissnum.encode("ascii"))
|
||||
)
|
||||
announcement["anonymous-storage-FURL"] = furl
|
||||
|
||||
enabled_storage_servers = self._enable_storage_servers(
|
||||
|
@ -12,6 +12,8 @@ relevant information for a storage server once it becomes available later in
|
||||
the configuration process.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from twisted.internet.protocol import Protocol
|
||||
from twisted.internet.interfaces import IDelayedCall
|
||||
from twisted.internet.ssl import CertificateOptions
|
||||
@ -19,10 +21,11 @@ from twisted.web.server import Site
|
||||
from twisted.protocols.tls import TLSMemoryBIOFactory
|
||||
from twisted.internet import reactor
|
||||
|
||||
from hyperlink import DecodedURL
|
||||
from foolscap.negotiate import Negotiation
|
||||
from foolscap.api import Tub
|
||||
|
||||
from .storage.http_server import HTTPServer
|
||||
from .storage.http_server import HTTPServer, build_nurl
|
||||
from .storage.server import StorageServer
|
||||
|
||||
|
||||
@ -45,7 +48,9 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
|
||||
since these are created by Foolscap's ``Tub``, by setting this to be the
|
||||
tub's ``negotiationClass``.
|
||||
|
||||
Do not use directly; this needs to be subclassed per ``Tub``.
|
||||
Do not use directly, use ``support_foolscap_and_https(tub)`` instead. The
|
||||
way this class works is that a new subclass is created for a specific
|
||||
``Tub`` instance.
|
||||
"""
|
||||
|
||||
# These will be set by support_foolscap_and_https() and add_storage_server().
|
||||
@ -61,10 +66,14 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
|
||||
_timeout: IDelayedCall
|
||||
|
||||
@classmethod
|
||||
def add_storage_server(cls, storage_server: StorageServer, swissnum):
|
||||
def add_storage_server(
|
||||
cls, storage_server: StorageServer, swissnum: bytes
|
||||
) -> set[DecodedURL]:
|
||||
"""
|
||||
Add the various storage server-related attributes needed by a
|
||||
``Tub``-specific ``_FoolscapOrHttps`` subclass.
|
||||
|
||||
Returns the resulting NURLs.
|
||||
"""
|
||||
# Tub.myCertificate is a twisted.internet.ssl.PrivateCertificate
|
||||
# instance.
|
||||
@ -80,6 +89,21 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
|
||||
Site(cls.http_storage_server.get_resource()),
|
||||
)
|
||||
|
||||
storage_nurls = set()
|
||||
for location_hint in cls.tub.locationHints:
|
||||
if location_hint.startswith("tcp:"):
|
||||
_, hostname, port = location_hint.split(":")
|
||||
port = int(port)
|
||||
storage_nurls.add(
|
||||
build_nurl(
|
||||
hostname,
|
||||
port,
|
||||
str(swissnum, "ascii"),
|
||||
cls.tub.myCertificate.original.to_cryptography(),
|
||||
)
|
||||
)
|
||||
return storage_nurls
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._foolscap: Negotiation = Negotiation(*args, **kwargs)
|
||||
self._buffer: bytes = b""
|
||||
|
@ -1085,7 +1085,7 @@ class _HTTPMixin(_SharedMixin):
|
||||
"""Run tests on the HTTP version of ``IStorageServer``."""
|
||||
|
||||
def _get_istorage_server(self):
|
||||
nurl = self.clients[0].storage_nurls[0]
|
||||
nurl = list(self.clients[0].storage_nurls)[0]
|
||||
|
||||
# Create HTTP client with non-persistent connections, so we don't leak
|
||||
# state across tests:
|
||||
|
Loading…
x
Reference in New Issue
Block a user