Hook up HTTP storage for servers listening on .onion addresses

This commit is contained in:
Itamar Turner-Trauring 2023-06-06 12:06:51 -04:00
parent 74a121da74
commit e8744f91e5
3 changed files with 21 additions and 6 deletions

View File

@ -102,8 +102,15 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
for location_hint in chain.from_iterable(
hints.split(",") for hints in cls.tub.locationHints
):
if location_hint.startswith("tcp:"):
_, hostname, port = location_hint.split(":")
if location_hint.startswith("tcp:") or location_hint.startswith("tor:"):
scheme, hostname, port = location_hint.split(":")
if scheme == "tcp":
subscheme = None
else:
subscheme = "tor"
# If we're listening on Tor, the hostname needs to have an
# .onion TLD.
assert hostname.endswith(".onion")
port = int(port)
storage_nurls.add(
build_nurl(
@ -111,9 +118,10 @@ class _FoolscapOrHttps(Protocol, metaclass=_PretendToBeNegotiation):
port,
str(swissnum, "ascii"),
cls.tub.myCertificate.original.to_cryptography(),
subscheme
)
)
# TODO this is probably where we'll have to support Tor and I2P?
# TODO this is where we'll have to support Tor and I2P as well.
# See https://tahoe-lafs.org/trac/tahoe-lafs/ticket/3888#comment:9
# for discussion (there will be separate tickets added for those at
# some point.)

View File

@ -369,7 +369,7 @@ class StorageClientFactory:
if handler == "tcp":
return Agent(reactor, tls_context_factory, pool=pool)
if handler == "tor": # TODO or nurl.scheme == "pb+tor":
if handler == "tor" or nurl.scheme == "pb+tor":
assert self._tor_provider is not None
if self._tor_instance is None:
self._tor_instance = await self._tor_provider.get_tor_instance(reactor)

View File

@ -995,13 +995,20 @@ class _TLSEndpointWrapper(object):
def build_nurl(
hostname: str, port: int, swissnum: str, certificate: CryptoCertificate
hostname: str,
port: int,
swissnum: str,
certificate: CryptoCertificate,
subscheme: Optional[str] = None,
) -> DecodedURL:
"""
Construct a HTTPS NURL, given the hostname, port, server swissnum, and x509
certificate for the server. Clients can then connect to the server using
this NURL.
"""
scheme = "pb"
if subscheme is not None:
scheme = f"{scheme}+{subscheme}"
return DecodedURL().replace(
fragment="v=1", # how we know this NURL is HTTP-based (i.e. not Foolscap)
host=hostname,
@ -1013,7 +1020,7 @@ def build_nurl(
"ascii",
),
),
scheme="pb",
scheme=scheme,
)