mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-11 15:32:39 +00:00
Make Tor provider available at the right place to enable it for HTTP storage
client connections.
This commit is contained in:
parent
6a6d4d7e02
commit
f83b73b5f3
@ -10,7 +10,6 @@ import weakref
|
|||||||
from typing import Optional, Iterable
|
from typing import Optional, Iterable
|
||||||
from base64 import urlsafe_b64encode
|
from base64 import urlsafe_b64encode
|
||||||
from functools import partial
|
from functools import partial
|
||||||
# On Python 2 this will be the backported package:
|
|
||||||
from configparser import NoSectionError
|
from configparser import NoSectionError
|
||||||
|
|
||||||
from foolscap.furl import (
|
from foolscap.furl import (
|
||||||
@ -47,7 +46,7 @@ from allmydata.util.encodingutil import get_filesystem_encoding
|
|||||||
from allmydata.util.abbreviate import parse_abbreviated_size
|
from allmydata.util.abbreviate import parse_abbreviated_size
|
||||||
from allmydata.util.time_format import parse_duration, parse_date
|
from allmydata.util.time_format import parse_duration, parse_date
|
||||||
from allmydata.util.i2p_provider import create as create_i2p_provider
|
from allmydata.util.i2p_provider import create as create_i2p_provider
|
||||||
from allmydata.util.tor_provider import create as create_tor_provider
|
from allmydata.util.tor_provider import create as create_tor_provider, _Provider as TorProvider
|
||||||
from allmydata.stats import StatsProvider
|
from allmydata.stats import StatsProvider
|
||||||
from allmydata.history import History
|
from allmydata.history import History
|
||||||
from allmydata.interfaces import (
|
from allmydata.interfaces import (
|
||||||
@ -268,7 +267,7 @@ def create_client_from_config(config, _client_factory=None, _introducer_factory=
|
|||||||
introducer_clients = create_introducer_clients(config, main_tub, _introducer_factory)
|
introducer_clients = create_introducer_clients(config, main_tub, _introducer_factory)
|
||||||
storage_broker = create_storage_farm_broker(
|
storage_broker = create_storage_farm_broker(
|
||||||
config, default_connection_handlers, foolscap_connection_handlers,
|
config, default_connection_handlers, foolscap_connection_handlers,
|
||||||
tub_options, introducer_clients
|
tub_options, introducer_clients, tor_provider
|
||||||
)
|
)
|
||||||
|
|
||||||
client = _client_factory(
|
client = _client_factory(
|
||||||
@ -464,7 +463,7 @@ def create_introducer_clients(config, main_tub, _introducer_factory=None):
|
|||||||
return introducer_clients
|
return introducer_clients
|
||||||
|
|
||||||
|
|
||||||
def create_storage_farm_broker(config: _Config, default_connection_handlers, foolscap_connection_handlers, tub_options, introducer_clients):
|
def create_storage_farm_broker(config: _Config, default_connection_handlers, foolscap_connection_handlers, tub_options, introducer_clients, tor_provider: Optional[TorProvider]):
|
||||||
"""
|
"""
|
||||||
Create a StorageFarmBroker object, for use by Uploader/Downloader
|
Create a StorageFarmBroker object, for use by Uploader/Downloader
|
||||||
(and everybody else who wants to use storage servers)
|
(and everybody else who wants to use storage servers)
|
||||||
@ -500,6 +499,7 @@ def create_storage_farm_broker(config: _Config, default_connection_handlers, foo
|
|||||||
tub_maker=tub_creator,
|
tub_maker=tub_creator,
|
||||||
node_config=config,
|
node_config=config,
|
||||||
storage_client_config=storage_client_config,
|
storage_client_config=storage_client_config,
|
||||||
|
tor_provider=tor_provider,
|
||||||
)
|
)
|
||||||
for ic in introducer_clients:
|
for ic in introducer_clients:
|
||||||
sb.use_introducer(ic)
|
sb.use_introducer(ic)
|
||||||
|
@ -77,6 +77,7 @@ from allmydata.grid_manager import (
|
|||||||
from allmydata.crypto import (
|
from allmydata.crypto import (
|
||||||
ed25519,
|
ed25519,
|
||||||
)
|
)
|
||||||
|
from allmydata.util.tor_provider import _Provider as TorProvider
|
||||||
from allmydata.util import log, base32, connection_status
|
from allmydata.util import log, base32, connection_status
|
||||||
from allmydata.util.assertutil import precondition
|
from allmydata.util.assertutil import precondition
|
||||||
from allmydata.util.observer import ObserverList
|
from allmydata.util.observer import ObserverList
|
||||||
@ -202,6 +203,7 @@ class StorageFarmBroker(service.MultiService):
|
|||||||
tub_maker,
|
tub_maker,
|
||||||
node_config: _Config,
|
node_config: _Config,
|
||||||
storage_client_config=None,
|
storage_client_config=None,
|
||||||
|
tor_provider: Optional[TorProvider]=None,
|
||||||
):
|
):
|
||||||
service.MultiService.__init__(self)
|
service.MultiService.__init__(self)
|
||||||
assert permute_peers # False not implemented yet
|
assert permute_peers # False not implemented yet
|
||||||
@ -223,6 +225,7 @@ class StorageFarmBroker(service.MultiService):
|
|||||||
self.introducer_client = None
|
self.introducer_client = None
|
||||||
self._threshold_listeners : list[tuple[float,defer.Deferred[Any]]]= [] # tuples of (threshold, Deferred)
|
self._threshold_listeners : list[tuple[float,defer.Deferred[Any]]]= [] # tuples of (threshold, Deferred)
|
||||||
self._connected_high_water_mark = 0
|
self._connected_high_water_mark = 0
|
||||||
|
self._tor_provider = tor_provider
|
||||||
|
|
||||||
@log_call(action_type=u"storage-client:broker:set-static-servers")
|
@log_call(action_type=u"storage-client:broker:set-static-servers")
|
||||||
def set_static_servers(self, servers):
|
def set_static_servers(self, servers):
|
||||||
@ -315,6 +318,7 @@ class StorageFarmBroker(service.MultiService):
|
|||||||
server_id,
|
server_id,
|
||||||
server["ann"],
|
server["ann"],
|
||||||
grid_manager_verifier=gm_verifier,
|
grid_manager_verifier=gm_verifier,
|
||||||
|
tor_provider=tor_provider
|
||||||
)
|
)
|
||||||
s.on_status_changed(lambda _: self._got_connection())
|
s.on_status_changed(lambda _: self._got_connection())
|
||||||
return s
|
return s
|
||||||
@ -1049,7 +1053,7 @@ class HTTPNativeStorageServer(service.MultiService):
|
|||||||
"connected".
|
"connected".
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, server_id: bytes, announcement, reactor=reactor, grid_manager_verifier=None):
|
def __init__(self, server_id: bytes, announcement, reactor=reactor, grid_manager_verifier=None, tor_provider: Optional[TorProvider]=None):
|
||||||
service.MultiService.__init__(self)
|
service.MultiService.__init__(self)
|
||||||
assert isinstance(server_id, bytes)
|
assert isinstance(server_id, bytes)
|
||||||
self._server_id = server_id
|
self._server_id = server_id
|
||||||
@ -1057,6 +1061,8 @@ class HTTPNativeStorageServer(service.MultiService):
|
|||||||
self._on_status_changed = ObserverList()
|
self._on_status_changed = ObserverList()
|
||||||
self._reactor = reactor
|
self._reactor = reactor
|
||||||
self._grid_manager_verifier = grid_manager_verifier
|
self._grid_manager_verifier = grid_manager_verifier
|
||||||
|
self._tor_provider = tor_provider
|
||||||
|
|
||||||
furl = announcement["anonymous-storage-FURL"].encode("utf-8")
|
furl = announcement["anonymous-storage-FURL"].encode("utf-8")
|
||||||
(
|
(
|
||||||
self._nickname,
|
self._nickname,
|
||||||
@ -1242,6 +1248,8 @@ class HTTPNativeStorageServer(service.MultiService):
|
|||||||
pool = HTTPConnectionPool(reactor, persistent=False)
|
pool = HTTPConnectionPool(reactor, persistent=False)
|
||||||
pool.retryAutomatically = False
|
pool.retryAutomatically = False
|
||||||
return StorageClientGeneral(
|
return StorageClientGeneral(
|
||||||
|
# TODO if Tor client connections are enabled, use an Agent
|
||||||
|
# created via tor.
|
||||||
StorageClient.from_nurl(nurl, reactor, pool)
|
StorageClient.from_nurl(nurl, reactor, pool)
|
||||||
).get_version()
|
).get_version()
|
||||||
|
|
||||||
@ -1249,6 +1257,8 @@ class HTTPNativeStorageServer(service.MultiService):
|
|||||||
|
|
||||||
# If we've gotten this far, we've found a working NURL.
|
# If we've gotten this far, we've found a working NURL.
|
||||||
self._istorage_server = _HTTPStorageServer.from_http_client(
|
self._istorage_server = _HTTPStorageServer.from_http_client(
|
||||||
|
# TODO if Tor client connections are enabled, use an Agent
|
||||||
|
# created via tor.
|
||||||
StorageClient.from_nurl(nurl, reactor)
|
StorageClient.from_nurl(nurl, reactor)
|
||||||
)
|
)
|
||||||
return self._istorage_server
|
return self._istorage_server
|
||||||
|
@ -2,14 +2,10 @@
|
|||||||
"""
|
"""
|
||||||
Ported to Python 3.
|
Ported to Python 3.
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import, print_function, with_statement
|
|
||||||
from __future__ import division
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
from future.utils import PY2
|
from __future__ import annotations
|
||||||
if PY2:
|
|
||||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from zope.interface import (
|
from zope.interface import (
|
||||||
@ -41,7 +37,7 @@ def _import_txtorcon():
|
|||||||
except ImportError: # pragma: no cover
|
except ImportError: # pragma: no cover
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def create(reactor, config, import_tor=None, import_txtorcon=None):
|
def create(reactor, config, import_tor=None, import_txtorcon=None) -> Optional[_Provider]:
|
||||||
"""
|
"""
|
||||||
Create a new _Provider service (this is an IService so must be
|
Create a new _Provider service (this is an IService so must be
|
||||||
hooked up to a parent or otherwise started).
|
hooked up to a parent or otherwise started).
|
||||||
|
Loading…
Reference in New Issue
Block a user