2016-07-20 00:22:12 +00:00
|
|
|
import os, stat, time, weakref
|
2016-01-27 06:49:23 +00:00
|
|
|
from base64 import urlsafe_b64encode
|
2018-01-31 01:04:08 +00:00
|
|
|
from functools import partial
|
2018-09-11 17:14:41 +00:00
|
|
|
from errno import ENOENT, EPERM
|
2020-08-26 14:53:02 +00:00
|
|
|
try:
|
|
|
|
from ConfigParser import NoSectionError
|
|
|
|
except ImportError:
|
|
|
|
from configparser import NoSectionError
|
2006-11-30 23:23:39 +00:00
|
|
|
|
2019-06-27 19:29:37 +00:00
|
|
|
from foolscap.furl import (
|
|
|
|
decode_furl,
|
|
|
|
)
|
|
|
|
|
2019-06-14 20:34:10 +00:00
|
|
|
import attr
|
2017-02-27 17:56:49 +00:00
|
|
|
from zope.interface import implementer
|
2019-06-17 18:29:43 +00:00
|
|
|
|
2019-06-14 20:34:10 +00:00
|
|
|
from twisted.plugin import (
|
|
|
|
getPlugins,
|
|
|
|
)
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
from twisted.internet import reactor, defer
|
2010-08-04 07:27:02 +00:00
|
|
|
from twisted.application import service
|
2007-05-25 00:34:42 +00:00
|
|
|
from twisted.application.internet import TimerService
|
2016-05-10 20:19:35 +00:00
|
|
|
from twisted.python.filepath import FilePath
|
2006-11-30 22:14:47 +00:00
|
|
|
|
2007-04-26 19:01:25 +00:00
|
|
|
import allmydata
|
2019-06-14 04:17:58 +00:00
|
|
|
from allmydata.crypto import rsa, ed25519
|
2019-07-08 18:46:22 +00:00
|
|
|
from allmydata.crypto.util import remove_prefix
|
2009-02-18 21:46:55 +00:00
|
|
|
from allmydata.storage.server import StorageServer
|
2009-06-01 21:06:04 +00:00
|
|
|
from allmydata import storage_client
|
2008-07-16 20:14:39 +00:00
|
|
|
from allmydata.immutable.upload import Uploader
|
2009-01-07 04:48:22 +00:00
|
|
|
from allmydata.immutable.offloaded import Helper
|
2007-03-08 02:16:06 +00:00
|
|
|
from allmydata.control import ControlServer
|
2008-06-18 19:24:16 +00:00
|
|
|
from allmydata.introducer.client import IntroducerClient
|
2019-06-17 20:44:17 +00:00
|
|
|
from allmydata.util import (
|
|
|
|
hashutil, base32, pollmixin, log, idlib,
|
|
|
|
yamlutil, configutil,
|
|
|
|
)
|
2016-07-20 00:22:12 +00:00
|
|
|
from allmydata.util.encodingutil import (get_filesystem_encoding,
|
|
|
|
from_utf8_or_none)
|
2008-12-02 00:24:21 +00:00
|
|
|
from allmydata.util.abbreviate import parse_abbreviated_size
|
2009-03-19 01:00:09 +00:00
|
|
|
from allmydata.util.time_format import parse_duration, parse_date
|
2018-01-30 06:51:49 +00:00
|
|
|
from allmydata.util.i2p_provider import create as create_i2p_provider
|
|
|
|
from allmydata.util.tor_provider import create as create_tor_provider
|
stats: add a simple stats gathering system
We have a desire to collect runtime statistics from multiple nodes primarily
for server monitoring purposes. This implements a simple implementation of
such a system, as a skeleton to build more sophistication upon.
Each client now looks for a 'stats_gatherer.furl' config file. If it has
been configured to use a stats gatherer, then it instantiates internally
a StatsProvider. This is a central place for code which wishes to offer
stats up for monitoring to report them to, either by calling
stats_provider.count('stat.name', value) to increment a counter, or by
registering a class as a stats producer with sp.register_producer(obj).
The StatsProvider connects to the StatsGatherer server and provides its
provider upon startup. The StatsGatherer is then responsible for polling
the attached providers periodically to retrieve the data provided.
The provider queries each registered producer when the gatherer queries
the provider. Both the internal 'counters' and the queried 'stats' are
then reported to the gatherer.
This provides a simple gatherer app, (c.f. make stats-gatherer-run)
which prints its furl and listens for incoming connections. Once a
minute, the gatherer polls all connected providers, and writes the
retrieved data into a pickle file.
Also included is a munin plugin which knows how to read the gatherer's
stats.pickle and output data munin can interpret. this plugin,
tahoe-stats.py can be symlinked as multiple different names within
munin's 'plugins' directory, and inspects argv to determine which
data to display, doing a lookup in a table within that file.
It looks in the environment for 'statsfile' to determine the path to
the gatherer's stats.pickle. An example plugins-conf.d file is
provided.
2008-01-31 03:11:07 +00:00
|
|
|
from allmydata.stats import StatsProvider
|
2009-01-14 23:14:24 +00:00
|
|
|
from allmydata.history import History
|
2019-06-14 20:34:10 +00:00
|
|
|
from allmydata.interfaces import (
|
|
|
|
IStatsProducer,
|
|
|
|
SDMF_VERSION,
|
|
|
|
MDMF_VERSION,
|
|
|
|
DEFAULT_MAX_SEGMENT_SIZE,
|
|
|
|
IFoolscapStoragePlugin,
|
|
|
|
IAnnounceableStorageServer,
|
|
|
|
)
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
from allmydata.nodemaker import NodeMaker
|
2011-08-24 15:59:28 +00:00
|
|
|
from allmydata.blacklist import Blacklist
|
2018-02-28 18:13:14 +00:00
|
|
|
from allmydata import node
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
|
2007-11-09 09:54:51 +00:00
|
|
|
|
2008-01-16 10:03:35 +00:00
|
|
|
KiB=1024
|
|
|
|
MiB=1024*KiB
|
|
|
|
GiB=1024*MiB
|
|
|
|
TiB=1024*GiB
|
|
|
|
PiB=1024*TiB
|
|
|
|
|
2019-06-19 14:47:23 +00:00
|
|
|
def _is_valid_section(section_name):
|
|
|
|
"""
|
|
|
|
Check for valid dynamic configuration section names.
|
|
|
|
|
|
|
|
Currently considers all possible storage server plugin sections valid.
|
|
|
|
"""
|
2019-07-03 16:08:58 +00:00
|
|
|
return (
|
feat(py3): Fix section name unicode type clash
Before this change, there was an error in the tests in python 3. I couldn't find any
clues from the history as to why explicit byte-string literals were used here. This
change addresses the error under Python 3 and doesn't cause any regressions under Python
2 in the test suite. This changes two tests from failures to passing under Python 3 and
increases coverage a bit:
```diff
--- ../../.tox/make-test-py3-all-old.log 2020-10-04 21:42:22.931028265 -0700
+++ ../../.tox/make-test-py3-all-new.log 2020-10-04 21:49:19.164127097 -0700
@@ -313,7 +313,7 @@
####-##-##T##:##:##-###0 [twisted.scripts._twistd_unix.UnixAppLogger#info] twistd 20.3.0 (/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/bin/python 3.6.12) starting up.
####-##-##T##:##:##-###0 [twisted.scripts._twistd_unix.UnixAppLogger#info] reactor class: mock.mock.MagicMock.
####-##-##T##:##:##-###0 [twisted.scripts._twistd_unix.UnixAppLogger#info] Server Shut Down.
- [FAIL]
+ [OK]
allmydata.test
cli
test_status ... [ERROR]
@@ -1191,7 +1191,7 @@
test_disabled_but_helper ... [FAIL]
test_disabled_but_storage ... [FAIL]
Configuration
- test_create_client_invalid_config ... [FAIL]
+ test_create_client_invalid_config ... [OK]
test_read_invalid_config ... [OK]
IntroducerNotListening
test_port_none_introducer ... [FAIL]
@@ -2024,18 +2024,6 @@
===============================================================================
[FAIL]
Traceback (most recent call last):
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/mock/mock.py", line 1369, in patched
- return func(*newargs, **newkeywargs)
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/test/cli/test_start.py", line 265, in test_run_invalid_config
- output,
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/trial/_synctest.py", line 494, in assertIn
- % (containee, container))
-twisted.trial.unittest.FailTest: 'invalid section' not in '\nUnknown error\nTraceback (most recent call last):\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/test/cli/test_start.py", line 232, in cwr\n fn()\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/scripts/run_common.py", line 155, in start\n d = service_factory()\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/scripts/run_common.py", line 136, in <lambda>\n u"client": lambda: maybeDeferred(namedAny("allmydata.client.create_client"), self.basedir),\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/internet/defer.py", line 151, in maybeDeferred\n result = f(*args, **kw)\n--- <exception caught here> ---\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/client.py", line 243, in create_client\n config = read_config(basedir, u"client.port")\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/client.py", line 219, in read_config\n _valid_config=_valid_config(),\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/node.py", line 192, in read_config\n configutil.validate_config(config_fname, parser, _valid_config)\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/util/configutil.py", line 72, in validate_config\n if not valid_config.is_valid_section(section):\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/util/configutil.py", line 113, in is_valid_section\n self._is_valid_section(section_name)\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/util/configutil.py", line 141, in <lambda>\n return lambda *a, **kw: f(*a, **kw) or g(*a, **kw)\n File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/client.py", line 72, in _is_valid_section\n section_name.startswith(b"storageserver.plugins.") or\nbuiltins.TypeError: startswith first arg must be str or a tuple of str, not bytes\n'
-
-allmydata.test.cli.test_start.RunTests.test_run_invalid_config
-===============================================================================
-[FAIL]
-Traceback (most recent call last):
File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/trial/_asynctest.py", line 75, in _eb
raise self.failureException(output)
twisted.trial.unittest.FailTest:
@@ -2222,34 +2210,6 @@
result = result.throwExceptionIntoGenerator(g)
File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/test/test_node.py", line 741, in test_create_client_invalid_config
- yield client.create_client(self.basedir)
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/trial/_synctest.py", line 355, in __exit__
- self._expectedName, reason.getTraceback()),
-twisted.trial.unittest.FailTest: builtins.TypeError raised instead of UnknownConfigError:
- Traceback (most recent call last):
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/internet/defer.py", line 1529, in _cancellableInlineCallbacks
- _inlineCallbacks(None, g, status)
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
- result = result.throwExceptionIntoGenerator(g)
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
- return g.throw(self.type, self.value, self.tb)
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/test/test_node.py", line 741, in test_create_client_invalid_config
- yield client.create_client(self.basedir)
---- <exception caught here> ---
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/test/test_node.py", line 741, in test_create_client_invalid_config
- yield client.create_client(self.basedir)
-builtins.TypeError: startswith first arg must be str or a tuple of str, not bytes
-
-
-allmydata.test.test_node.Configuration.test_create_client_invalid_config
-===============================================================================
-[FAIL]
-Traceback (most recent call last):
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/internet/defer.py", line 1416, in _inlineCallbacks
- result = result.throwExceptionIntoGenerator(g)
- File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/python/failure.py", line 512, in throwExceptionIntoGenerator
- return g.throw(self.type, self.value, self.tb)
File "/home/rpatterson/src/work/sfu/tahoe-lafs/src/allmydata/test/test_node.py", line 704, in test_port_none_introducer
yield create_introducer(basedir)
File "/home/rpatterson/src/work/sfu/tahoe-lafs/.tox/py36-coverage/lib/python3.6/site-packages/twisted/trial/_synctest.py", line 355, in __exit__
@@ -8717,7 +8677,7 @@
-------------------------------------------------------------------------------
Ran 1300 tests in ###.###s
-FAILED (skips=42, expectedFailures=1, failures=35, errors=531, successes=707)
+FAILED (skips=42, expectedFailures=1, failures=33, errors=531, successes=709)
Unknown error
Traceback (most recent call last):
@@ -8806,7 +8766,7 @@
src/allmydata/scripts/create_node.py 302 98 114 10 66% 224-229, 235, 257-260, 262-265, 268-269, 289-292, 295-298, 329, 339, 347-380, 391-445, 461-477, 223->224, 234->235, 256->257, 261->262, 266->277, 267->268, 288->289, 294->295, 328->329, 338->339
src/allmydata/scripts/debug.py 719 638 202 0 9% 14, 31-32, 35-49, 52-60, 63-142, 146-154, 157-164, 168-217, 220-304, 307-401, 407, 417, 437-465, 468-485, 488-602, 606, 609-611, 637-648, 653-656, 659, 683-689, 692-810, 813-842, 845-848, 851-865, 869, 888, 891-940, 946, 949-950, 957, 960-961, 967-972, 984-985, 999-1000, 1003-1004, 1020-1021, 1025-1031, 1046-1050
src/allmydata/scripts/default_nodedir.py 15 5 6 2 57% 10-14, 9->10, 16->exit
-src/allmydata/scripts/run_common.py 135 18 24 6 85% 37, 41-46, 59-60, 149, 158, 192-193, 216-220, 226-227, 55->62, 135->exit, 135->exit, 148->149, 191->192, 225->226
+src/allmydata/scripts/run_common.py 135 17 24 5 86% 37, 41-46, 59-60, 158, 192-193, 216-220, 226-227, 55->62, 135->exit, 135->exit, 191->192, 225->226
src/allmydata/scripts/runner.py 138 49 42 5 61% 84-85, 91, 97-99, 150, 153-160, 174-181, 188-192, 202-232, 237-252, 255, 31->36, 149->150, 151->153, 185->188, 254->255
src/allmydata/scripts/slow_operation.py 69 56 22 0 14% 15-44, 47-52, 55-61, 64-83
src/allmydata/scripts/stats_gatherer.py 44 16 12 3 59% 8, 30, 75-79, 84-93, 7->8, 29->30, 74->75
@@ -8893,7 +8853,7 @@
src/allmydata/windows/fixups.py 133 133 54 0 0% 1-237
src/allmydata/windows/registry.py 42 42 12 0 0% 1-77
------------------------------------------------------------------------------------------------
-TOTAL 27477 11782 8244 605 54%
+TOTAL 27477 11781 8244 604 54%
18 files skipped due to complete coverage.
+ '[' '!' -z 1 ']'
```
2020-10-01 16:41:31 +00:00
|
|
|
section_name.startswith("storageserver.plugins.") or
|
|
|
|
section_name.startswith("storageclient.plugins.")
|
2019-07-03 16:08:58 +00:00
|
|
|
)
|
2019-06-19 14:47:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
_client_config = configutil.ValidConfiguration(
|
|
|
|
static_valid_sections={
|
2016-09-05 22:34:17 +00:00
|
|
|
"client": (
|
|
|
|
"helper.furl",
|
|
|
|
"introducer.furl",
|
|
|
|
"key_generator.furl",
|
|
|
|
"mutable.format",
|
|
|
|
"peers.preferred",
|
|
|
|
"shares.happy",
|
|
|
|
"shares.needed",
|
|
|
|
"shares.total",
|
|
|
|
"stats_gatherer.furl",
|
2019-06-27 18:51:41 +00:00
|
|
|
"storage.plugins",
|
2016-09-05 22:34:17 +00:00
|
|
|
),
|
|
|
|
"ftpd": (
|
|
|
|
"accounts.file",
|
|
|
|
"accounts.url",
|
|
|
|
"enabled",
|
|
|
|
"port",
|
|
|
|
),
|
|
|
|
"storage": (
|
|
|
|
"debug_discard",
|
|
|
|
"enabled",
|
2019-07-03 18:30:36 +00:00
|
|
|
"anonymous",
|
2016-09-05 22:34:17 +00:00
|
|
|
"expire.cutoff_date",
|
|
|
|
"expire.enabled",
|
|
|
|
"expire.immutable",
|
|
|
|
"expire.mode",
|
|
|
|
"expire.mode",
|
|
|
|
"expire.mutable",
|
|
|
|
"expire.override_lease_duration",
|
|
|
|
"readonly",
|
|
|
|
"reserved_space",
|
2018-05-20 02:10:39 +00:00
|
|
|
"storage_dir",
|
2019-06-17 18:18:36 +00:00
|
|
|
"plugins",
|
2016-09-05 22:34:17 +00:00
|
|
|
),
|
|
|
|
"sftpd": (
|
|
|
|
"accounts.file",
|
|
|
|
"accounts.url",
|
|
|
|
"enabled",
|
|
|
|
"host_privkey_file",
|
|
|
|
"host_pubkey_file",
|
|
|
|
"port",
|
|
|
|
),
|
|
|
|
"helper": (
|
|
|
|
"enabled",
|
|
|
|
),
|
2019-06-19 14:47:23 +00:00
|
|
|
},
|
|
|
|
is_valid_section=_is_valid_section,
|
|
|
|
# Anything in a valid section is a valid item, for now.
|
|
|
|
is_valid_item=lambda section, ignored: _is_valid_section(section),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _valid_config():
|
|
|
|
cfg = node._common_valid_config()
|
|
|
|
return cfg.update(_client_config)
|
2016-09-05 22:34:17 +00:00
|
|
|
|
2018-01-29 05:48:18 +00:00
|
|
|
# this is put into README in new node-directories
|
|
|
|
CLIENT_README = """
|
|
|
|
This directory contains files which contain private data for the Tahoe node,
|
|
|
|
such as private keys. On Unix-like systems, the permissions on this directory
|
|
|
|
are set to disallow users other than its owner from reading the contents of
|
|
|
|
the files. See the 'configuration.rst' documentation file for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2016-09-05 22:34:17 +00:00
|
|
|
|
2008-03-24 16:46:06 +00:00
|
|
|
def _make_secret():
|
2018-08-29 22:44:12 +00:00
|
|
|
"""
|
|
|
|
Returns a base32-encoded random secret of hashutil.CRYPTO_VAL_SIZE
|
|
|
|
bytes.
|
|
|
|
"""
|
2020-09-16 15:13:23 +00:00
|
|
|
return base32.b2a(os.urandom(hashutil.CRYPTO_VAL_SIZE)) + b"\n"
|
2008-03-24 16:46:06 +00:00
|
|
|
|
2018-01-31 01:04:08 +00:00
|
|
|
|
2019-05-15 06:17:44 +00:00
|
|
|
class SecretHolder(object):
|
2009-11-18 01:54:44 +00:00
|
|
|
def __init__(self, lease_secret, convergence_secret):
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self._lease_secret = lease_secret
|
2009-11-18 01:54:44 +00:00
|
|
|
self._convergence_secret = convergence_secret
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
|
|
|
|
def get_renewal_secret(self):
|
|
|
|
return hashutil.my_renewal_secret_hash(self._lease_secret)
|
|
|
|
|
|
|
|
def get_cancel_secret(self):
|
|
|
|
return hashutil.my_cancel_secret_hash(self._lease_secret)
|
|
|
|
|
2009-11-18 01:54:44 +00:00
|
|
|
def get_convergence_secret(self):
|
|
|
|
return self._convergence_secret
|
|
|
|
|
2019-05-15 06:17:44 +00:00
|
|
|
class KeyGenerator(object):
|
2010-01-13 00:42:26 +00:00
|
|
|
"""I create RSA keys for mutable files. Each call to generate() returns a
|
|
|
|
single keypair. The keysize is specified first by the keysize= argument
|
|
|
|
to generate(), then with a default set by set_default_keysize(), then
|
|
|
|
with a built-in default of 2048 bits."""
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
def __init__(self):
|
|
|
|
self.default_keysize = 2048
|
|
|
|
|
|
|
|
def set_default_keysize(self, keysize):
|
|
|
|
"""Call this to override the size of the RSA keys created for new
|
2010-01-13 00:42:26 +00:00
|
|
|
mutable files which don't otherwise specify a size. This will affect
|
|
|
|
all subsequent calls to generate() without a keysize= argument. The
|
|
|
|
default size is 2048 bits. Test cases should call this method once
|
2011-08-10 20:22:43 +00:00
|
|
|
during setup, to cause me to create smaller keys, so the unit tests
|
|
|
|
run faster."""
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self.default_keysize = keysize
|
|
|
|
|
|
|
|
def generate(self, keysize=None):
|
2010-01-13 00:42:26 +00:00
|
|
|
"""I return a Deferred that fires with a (verifyingkey, signingkey)
|
2011-08-10 20:22:43 +00:00
|
|
|
pair. I accept a keysize in bits (2048 bit keys are standard, smaller
|
|
|
|
keys are used for testing). If you do not provide a keysize, I will
|
2010-01-13 00:42:26 +00:00
|
|
|
use my default, which is set by a call to set_default_keysize(). If
|
|
|
|
set_default_keysize() has never been called, I will create 2048 bit
|
|
|
|
keys."""
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
keysize = keysize or self.default_keysize
|
2016-04-28 07:05:30 +00:00
|
|
|
# RSA key generation for a 2048 bit key takes between 0.8 and 3.2
|
|
|
|
# secs
|
2019-06-12 21:44:35 +00:00
|
|
|
signer, verifier = rsa.create_signing_keypair(keysize)
|
2016-04-28 07:05:30 +00:00
|
|
|
return defer.succeed( (verifier, signer) )
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
|
2010-08-04 07:27:02 +00:00
|
|
|
class Terminator(service.Service):
|
|
|
|
def __init__(self):
|
|
|
|
self._clients = weakref.WeakKeyDictionary()
|
|
|
|
def register(self, c):
|
|
|
|
self._clients[c] = None
|
|
|
|
def stopService(self):
|
|
|
|
for c in self._clients:
|
|
|
|
c.stop()
|
|
|
|
return service.Service.stopService(self)
|
|
|
|
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
|
2018-02-28 18:13:14 +00:00
|
|
|
def read_config(basedir, portnumfile, generated_files=[]):
|
2018-08-24 21:41:31 +00:00
|
|
|
"""
|
|
|
|
Read and validate configuration for a client-style Node. See
|
|
|
|
:method:`allmydata.node.read_config` for parameter meanings (the
|
|
|
|
only difference here is we pass different validation data)
|
|
|
|
|
|
|
|
:returns: :class:`allmydata.node._Config` instance
|
|
|
|
"""
|
2018-02-28 18:13:14 +00:00
|
|
|
return node.read_config(
|
|
|
|
basedir, portnumfile,
|
|
|
|
generated_files=generated_files,
|
2019-06-17 20:44:17 +00:00
|
|
|
_valid_config=_valid_config(),
|
2018-02-28 18:13:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-19 14:47:23 +00:00
|
|
|
config_from_string = partial(
|
|
|
|
node.config_from_string,
|
|
|
|
_valid_config=_valid_config(),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-03-04 21:29:17 +00:00
|
|
|
def create_client(basedir=u".", _client_factory=None):
|
2018-02-22 22:42:44 +00:00
|
|
|
"""
|
|
|
|
Creates a new client instance (a subclass of Node).
|
|
|
|
|
2018-08-24 21:41:31 +00:00
|
|
|
:param unicode basedir: the node directory (which may not exist yet)
|
|
|
|
|
|
|
|
:param _client_factory: (for testing) a callable that returns an
|
|
|
|
instance of :class:`allmydata.node.Node` (or a subclass). By default
|
|
|
|
this is :class:`allmydata.client._Client`
|
2018-02-22 22:42:44 +00:00
|
|
|
|
2018-09-04 20:55:36 +00:00
|
|
|
:returns: Deferred yielding an instance of :class:`allmydata.client._Client`
|
2018-02-22 22:42:44 +00:00
|
|
|
"""
|
2018-09-04 20:55:36 +00:00
|
|
|
try:
|
|
|
|
node.create_node_dir(basedir, CLIENT_README)
|
|
|
|
config = read_config(basedir, u"client.port")
|
|
|
|
# following call is async
|
|
|
|
return create_client_from_config(
|
|
|
|
config,
|
|
|
|
_client_factory=_client_factory,
|
|
|
|
)
|
|
|
|
except Exception:
|
2019-06-12 20:47:25 +00:00
|
|
|
return defer.fail()
|
2018-01-28 04:40:43 +00:00
|
|
|
|
2018-01-28 08:27:25 +00:00
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
@defer.inlineCallbacks
|
2019-06-27 18:59:04 +00:00
|
|
|
def create_client_from_config(config, _client_factory=None, _introducer_factory=None):
|
2018-01-31 18:30:46 +00:00
|
|
|
"""
|
2018-03-05 01:55:32 +00:00
|
|
|
Creates a new client instance (a subclass of Node). Most code
|
|
|
|
should probably use `create_client` instead.
|
|
|
|
|
2018-03-05 04:55:41 +00:00
|
|
|
:returns: Deferred yielding a _Client instance
|
|
|
|
|
2018-03-05 01:55:32 +00:00
|
|
|
:param config: configuration instance (from read_config()) which
|
|
|
|
encapsulates everything in the "node directory".
|
2018-01-31 18:30:46 +00:00
|
|
|
|
2018-03-05 01:55:32 +00:00
|
|
|
:param _client_factory: for testing; the class to instantiate
|
2018-03-05 04:55:41 +00:00
|
|
|
instead of _Client
|
2019-06-14 15:56:02 +00:00
|
|
|
|
2019-06-27 18:59:04 +00:00
|
|
|
:param _introducer_factory: for testing; the class to instantiate instead
|
2019-06-14 15:56:02 +00:00
|
|
|
of IntroducerClient
|
2018-01-31 18:30:46 +00:00
|
|
|
"""
|
2019-06-28 15:55:13 +00:00
|
|
|
if _client_factory is None:
|
|
|
|
_client_factory = _Client
|
|
|
|
|
|
|
|
i2p_provider = create_i2p_provider(reactor, config)
|
|
|
|
tor_provider = create_tor_provider(reactor, config)
|
|
|
|
handlers = node.create_connection_handlers(reactor, config, i2p_provider, tor_provider)
|
|
|
|
default_connection_handlers, foolscap_connection_handlers = handlers
|
|
|
|
tub_options = node.create_tub_options(config)
|
|
|
|
|
|
|
|
main_tub = node.create_main_tub(
|
|
|
|
config, tub_options, default_connection_handlers,
|
|
|
|
foolscap_connection_handlers, i2p_provider, tor_provider,
|
|
|
|
)
|
|
|
|
control_tub = node.create_control_tub()
|
|
|
|
|
|
|
|
introducer_clients = create_introducer_clients(config, main_tub, _introducer_factory)
|
|
|
|
storage_broker = create_storage_farm_broker(
|
|
|
|
config, default_connection_handlers, foolscap_connection_handlers,
|
|
|
|
tub_options, introducer_clients
|
|
|
|
)
|
|
|
|
|
|
|
|
client = _client_factory(
|
|
|
|
config,
|
|
|
|
main_tub,
|
|
|
|
control_tub,
|
|
|
|
i2p_provider,
|
|
|
|
tor_provider,
|
|
|
|
introducer_clients,
|
|
|
|
storage_broker,
|
|
|
|
)
|
|
|
|
|
|
|
|
# Initialize storage separately after creating the client. This is
|
|
|
|
# necessary because we need to pass a reference to the client in to the
|
|
|
|
# storage plugins to allow them to initialize themselves (specifically,
|
|
|
|
# they may want the anonymous IStorageServer implementation so they don't
|
|
|
|
# have to duplicate all of its basic storage functionality). A better way
|
|
|
|
# to do this, eventually, may be to create that implementation first and
|
|
|
|
# then pass it in to both storage plugin creation and the client factory.
|
|
|
|
# This avoids making a partially initialized client object escape the
|
|
|
|
# client factory and removes the circular dependency between these
|
|
|
|
# objects.
|
|
|
|
storage_plugins = yield _StoragePlugins.from_config(
|
|
|
|
client.get_anonymous_storage_server,
|
|
|
|
config,
|
|
|
|
)
|
|
|
|
client.init_storage(storage_plugins.announceable_storage_servers)
|
|
|
|
|
|
|
|
i2p_provider.setServiceParent(client)
|
|
|
|
tor_provider.setServiceParent(client)
|
|
|
|
for ic in introducer_clients:
|
|
|
|
ic.setServiceParent(client)
|
|
|
|
storage_broker.setServiceParent(client)
|
|
|
|
defer.returnValue(client)
|
|
|
|
|
|
|
|
|
|
|
|
@attr.s
|
|
|
|
class _StoragePlugins(object):
|
2019-06-28 16:02:38 +00:00
|
|
|
"""
|
|
|
|
Functionality related to getting storage plugins set up and ready for use.
|
|
|
|
|
|
|
|
:ivar list[IAnnounceableStorageServer] announceable_storage_servers: The
|
|
|
|
announceable storage servers that should be used according to node
|
|
|
|
configuration.
|
|
|
|
"""
|
2019-06-28 15:55:13 +00:00
|
|
|
announceable_storage_servers = attr.ib()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@defer.inlineCallbacks
|
|
|
|
def from_config(cls, get_anonymous_storage_server, config):
|
|
|
|
"""
|
|
|
|
Load and configured storage plugins.
|
2019-06-28 16:02:38 +00:00
|
|
|
|
|
|
|
:param get_anonymous_storage_server: A no-argument callable which
|
|
|
|
returns the node's anonymous ``IStorageServer`` implementation.
|
|
|
|
|
|
|
|
:param _Config config: The node's configuration.
|
|
|
|
|
|
|
|
:return: A ``_StoragePlugins`` initialized from the given
|
|
|
|
configuration.
|
2019-06-28 15:55:13 +00:00
|
|
|
"""
|
|
|
|
storage_plugin_names = cls._get_enabled_storage_plugin_names(config)
|
|
|
|
plugins = list(cls._collect_storage_plugins(storage_plugin_names))
|
2019-10-16 23:56:29 +00:00
|
|
|
unknown_plugin_names = storage_plugin_names - {plugin.name for plugin in plugins}
|
|
|
|
if unknown_plugin_names:
|
|
|
|
raise configutil.UnknownConfigError(
|
|
|
|
"Storage plugins {} are enabled but not known on this system.".format(
|
|
|
|
unknown_plugin_names,
|
|
|
|
),
|
|
|
|
)
|
2019-06-28 15:55:13 +00:00
|
|
|
announceable_storage_servers = yield cls._create_plugin_storage_servers(
|
|
|
|
get_anonymous_storage_server,
|
|
|
|
config,
|
|
|
|
plugins,
|
2018-09-04 20:55:36 +00:00
|
|
|
)
|
2019-06-28 15:55:13 +00:00
|
|
|
defer.returnValue(cls(
|
|
|
|
announceable_storage_servers,
|
|
|
|
))
|
2018-09-04 20:55:36 +00:00
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
@classmethod
|
|
|
|
def _get_enabled_storage_plugin_names(cls, config):
|
|
|
|
"""
|
|
|
|
Get the names of storage plugins that are enabled in the configuration.
|
|
|
|
"""
|
|
|
|
return set(
|
|
|
|
config.get_config(
|
|
|
|
"storage", "plugins", b""
|
|
|
|
).decode("ascii").split(u",")
|
2019-10-16 23:56:29 +00:00
|
|
|
) - {u""}
|
2018-09-04 20:55:36 +00:00
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
@classmethod
|
|
|
|
def _collect_storage_plugins(cls, storage_plugin_names):
|
|
|
|
"""
|
|
|
|
Get the storage plugins with names matching those given.
|
|
|
|
"""
|
|
|
|
return list(
|
|
|
|
plugin
|
|
|
|
for plugin
|
|
|
|
in getPlugins(IFoolscapStoragePlugin)
|
|
|
|
if plugin.name in storage_plugin_names
|
2018-09-04 20:55:36 +00:00
|
|
|
)
|
2019-06-28 15:55:13 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def _create_plugin_storage_servers(cls, get_anonymous_storage_server, config, plugins):
|
|
|
|
"""
|
|
|
|
Cause each storage plugin to instantiate its storage server and return
|
|
|
|
them all.
|
|
|
|
|
|
|
|
:return: A ``Deferred`` that fires with storage servers instantiated
|
|
|
|
by all of the given storage server plugins.
|
|
|
|
"""
|
|
|
|
return defer.gatherResults(
|
|
|
|
list(
|
|
|
|
plugin.get_storage_server(
|
|
|
|
cls._get_storage_plugin_configuration(config, plugin.name),
|
|
|
|
get_anonymous_storage_server,
|
|
|
|
).addCallback(
|
|
|
|
partial(
|
|
|
|
_add_to_announcement,
|
|
|
|
{u"name": plugin.name},
|
|
|
|
),
|
|
|
|
)
|
|
|
|
for plugin
|
|
|
|
# The order is fairly arbitrary and it is not meant to convey
|
|
|
|
# anything but providing *some* stable ordering makes the data
|
|
|
|
# a little easier to deal with (mainly in tests and when
|
|
|
|
# manually inspecting it).
|
|
|
|
in sorted(plugins, key=lambda p: p.name)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def _get_storage_plugin_configuration(cls, config, storage_plugin_name):
|
|
|
|
"""
|
|
|
|
Load the configuration for a storage server plugin with the given name.
|
|
|
|
|
|
|
|
:return dict[bytes, bytes]: The matching configuration.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
config = config.items(
|
|
|
|
"storageserver.plugins." + storage_plugin_name,
|
|
|
|
)
|
|
|
|
except NoSectionError:
|
|
|
|
config = []
|
|
|
|
return dict(config)
|
|
|
|
|
2018-01-31 01:04:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _sequencer(config):
|
2018-08-29 22:44:12 +00:00
|
|
|
"""
|
|
|
|
:returns: a 2-tuple consisting of a new announcement
|
2018-09-04 20:56:50 +00:00
|
|
|
sequence-number and random nonce (int, unicode). Reads and
|
|
|
|
re-writes configuration file "announcement-seqnum" (starting at 1
|
|
|
|
if that file doesn't exist).
|
2018-08-29 22:44:12 +00:00
|
|
|
"""
|
2018-01-31 01:04:08 +00:00
|
|
|
seqnum_s = config.get_config_from_file("announcement-seqnum")
|
|
|
|
if not seqnum_s:
|
2018-09-04 20:56:50 +00:00
|
|
|
seqnum_s = u"0"
|
2018-01-31 01:04:08 +00:00
|
|
|
seqnum = int(seqnum_s.strip())
|
|
|
|
seqnum += 1 # increment
|
2018-01-31 18:30:46 +00:00
|
|
|
config.write_config_file("announcement-seqnum", "{}\n".format(seqnum))
|
2018-01-31 01:04:08 +00:00
|
|
|
nonce = _make_secret().strip()
|
|
|
|
return seqnum, nonce
|
|
|
|
|
|
|
|
|
2019-06-27 18:59:04 +00:00
|
|
|
def create_introducer_clients(config, main_tub, _introducer_factory=None):
|
2018-01-31 18:30:46 +00:00
|
|
|
"""
|
2018-08-29 22:44:12 +00:00
|
|
|
Read, validate and parse any 'introducers.yaml' configuration.
|
|
|
|
|
2019-06-27 18:59:04 +00:00
|
|
|
:param _introducer_factory: for testing; the class to instantiate instead
|
2019-06-14 15:56:02 +00:00
|
|
|
of IntroducerClient
|
|
|
|
|
2018-03-05 03:08:11 +00:00
|
|
|
:returns: a list of IntroducerClient instances
|
2018-01-31 18:30:46 +00:00
|
|
|
"""
|
2019-06-27 18:59:04 +00:00
|
|
|
if _introducer_factory is None:
|
|
|
|
_introducer_factory = IntroducerClient
|
2019-06-14 15:56:02 +00:00
|
|
|
|
2018-03-05 03:08:11 +00:00
|
|
|
# we return this list
|
2018-01-31 01:04:08 +00:00
|
|
|
introducer_clients = []
|
|
|
|
|
2018-01-31 18:30:46 +00:00
|
|
|
introducers_yaml_filename = config.get_private_path("introducers.yaml")
|
2018-01-31 01:04:08 +00:00
|
|
|
introducers_filepath = FilePath(introducers_yaml_filename)
|
|
|
|
|
|
|
|
try:
|
|
|
|
with introducers_filepath.open() as f:
|
|
|
|
introducers_yaml = yamlutil.safe_load(f)
|
2018-09-07 21:20:53 +00:00
|
|
|
if introducers_yaml is None:
|
2018-09-11 17:14:41 +00:00
|
|
|
raise EnvironmentError(
|
|
|
|
EPERM,
|
|
|
|
"Can't read '{}'".format(introducers_yaml_filename),
|
|
|
|
introducers_yaml_filename,
|
|
|
|
)
|
2018-01-31 01:04:08 +00:00
|
|
|
introducers = introducers_yaml.get("introducers", {})
|
2018-01-31 18:30:46 +00:00
|
|
|
log.msg(
|
|
|
|
"found {} introducers in private/introducers.yaml".format(
|
|
|
|
len(introducers),
|
|
|
|
)
|
|
|
|
)
|
2018-09-04 20:56:58 +00:00
|
|
|
except EnvironmentError as e:
|
|
|
|
if e.errno != ENOENT:
|
|
|
|
raise
|
2018-01-31 01:04:08 +00:00
|
|
|
introducers = {}
|
|
|
|
|
|
|
|
if "default" in introducers.keys():
|
2018-01-31 18:30:46 +00:00
|
|
|
raise ValueError(
|
|
|
|
"'default' introducer furl cannot be specified in introducers.yaml;"
|
|
|
|
" please fix impossible configuration."
|
|
|
|
)
|
2018-01-31 01:04:08 +00:00
|
|
|
|
|
|
|
# read furl from tahoe.cfg
|
|
|
|
tahoe_cfg_introducer_furl = config.get_config("client", "introducer.furl", None)
|
|
|
|
if tahoe_cfg_introducer_furl == "None":
|
2018-01-31 18:30:46 +00:00
|
|
|
raise ValueError(
|
|
|
|
"tahoe.cfg has invalid 'introducer.furl = None':"
|
|
|
|
" to disable it, use 'introducer.furl ='"
|
|
|
|
" or omit the key entirely"
|
|
|
|
)
|
2018-01-31 01:04:08 +00:00
|
|
|
if tahoe_cfg_introducer_furl:
|
|
|
|
introducers[u'default'] = {'furl':tahoe_cfg_introducer_furl}
|
|
|
|
|
|
|
|
for petname, introducer in introducers.items():
|
2018-01-31 18:30:46 +00:00
|
|
|
introducer_cache_filepath = FilePath(config.get_private_path("introducer_{}_cache.yaml".format(petname)))
|
2019-06-27 18:59:04 +00:00
|
|
|
ic = _introducer_factory(
|
2018-01-28 01:05:16 +00:00
|
|
|
main_tub,
|
2018-01-31 01:04:08 +00:00
|
|
|
introducer['furl'].encode("ascii"),
|
|
|
|
config.nickname,
|
|
|
|
str(allmydata.__full_version__),
|
|
|
|
str(_Client.OLDEST_SUPPORTED_VERSION),
|
2018-03-04 21:29:17 +00:00
|
|
|
node.get_app_versions(),
|
2018-01-31 01:04:08 +00:00
|
|
|
partial(_sequencer, config),
|
|
|
|
introducer_cache_filepath,
|
2017-09-06 01:08:35 +00:00
|
|
|
)
|
2018-01-31 01:04:08 +00:00
|
|
|
introducer_clients.append(ic)
|
2018-03-05 03:08:11 +00:00
|
|
|
return introducer_clients
|
2018-01-31 01:04:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_storage_farm_broker(config, default_connection_handlers, foolscap_connection_handlers, tub_options, introducer_clients):
|
|
|
|
"""
|
2018-08-29 22:44:12 +00:00
|
|
|
Create a StorageFarmBroker object, for use by Uploader/Downloader
|
2018-01-31 01:04:08 +00:00
|
|
|
(and everybody else who wants to use storage servers)
|
2018-08-29 22:44:12 +00:00
|
|
|
|
|
|
|
:param config: a _Config instance
|
|
|
|
|
|
|
|
:param default_connection_handlers: default Foolscap handlers
|
|
|
|
|
|
|
|
:param foolscap_connection_handlers: available/configured Foolscap
|
|
|
|
handlers
|
|
|
|
|
|
|
|
:param dict tub_options: how to configure our Tub
|
|
|
|
|
|
|
|
:param list introducer_clients: IntroducerClient instances if
|
|
|
|
we're connecting to any
|
2018-01-31 01:04:08 +00:00
|
|
|
"""
|
2019-06-28 18:24:58 +00:00
|
|
|
storage_client_config = storage_client.StorageClientConfig.from_node_config(
|
|
|
|
config,
|
|
|
|
)
|
2018-01-31 01:04:08 +00:00
|
|
|
|
2018-09-04 20:57:26 +00:00
|
|
|
def tub_creator(handler_overrides=None, **kwargs):
|
2018-03-04 21:29:17 +00:00
|
|
|
return node.create_tub(
|
2018-01-31 01:04:08 +00:00
|
|
|
tub_options,
|
|
|
|
default_connection_handlers,
|
|
|
|
foolscap_connection_handlers,
|
2018-09-06 17:39:09 +00:00
|
|
|
handler_overrides={} if handler_overrides is None else handler_overrides,
|
2018-01-31 01:04:08 +00:00
|
|
|
**kwargs
|
|
|
|
)
|
|
|
|
|
|
|
|
sb = storage_client.StorageFarmBroker(
|
|
|
|
permute_peers=True,
|
|
|
|
tub_maker=tub_creator,
|
2019-08-19 20:09:26 +00:00
|
|
|
node_config=config,
|
2019-06-28 18:24:58 +00:00
|
|
|
storage_client_config=storage_client_config,
|
2018-01-28 01:05:16 +00:00
|
|
|
)
|
2018-01-31 01:04:08 +00:00
|
|
|
for ic in introducer_clients:
|
|
|
|
sb.use_introducer(ic)
|
|
|
|
return sb
|
2017-09-06 01:08:35 +00:00
|
|
|
|
|
|
|
|
2019-06-27 19:29:37 +00:00
|
|
|
def _register_reference(key, config, tub, referenceable):
|
|
|
|
"""
|
|
|
|
Register a referenceable in a tub with a stable fURL.
|
|
|
|
|
|
|
|
Stability is achieved by storing the fURL in the configuration the first
|
|
|
|
time and then reading it back on for future calls.
|
|
|
|
|
|
|
|
:param bytes key: An identifier for this reference which can be used to
|
|
|
|
identify its fURL in the configuration.
|
|
|
|
|
|
|
|
:param _Config config: The configuration to use for fURL persistence.
|
|
|
|
|
|
|
|
:param Tub tub: The tub in which to register the reference.
|
|
|
|
|
|
|
|
:param Referenceable referenceable: The referenceable to register in the
|
|
|
|
Tub.
|
|
|
|
|
|
|
|
:return bytes: The fURL at which the object is registered.
|
|
|
|
"""
|
|
|
|
persisted_furl = config.get_private_config(
|
|
|
|
key,
|
|
|
|
default=None,
|
|
|
|
)
|
|
|
|
name = None
|
|
|
|
if persisted_furl is not None:
|
|
|
|
_, _, name = decode_furl(persisted_furl)
|
|
|
|
registered_furl = tub.registerReference(
|
|
|
|
referenceable,
|
|
|
|
name=name,
|
|
|
|
)
|
|
|
|
if persisted_furl is None:
|
|
|
|
config.write_private_config(key, registered_furl)
|
|
|
|
return registered_furl
|
|
|
|
|
2019-06-14 20:34:10 +00:00
|
|
|
|
|
|
|
@implementer(IAnnounceableStorageServer)
|
|
|
|
@attr.s
|
|
|
|
class AnnounceableStorageServer(object):
|
|
|
|
announcement = attr.ib()
|
|
|
|
storage_server = attr.ib()
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
def _add_to_announcement(information, announceable_storage_server):
|
|
|
|
"""
|
|
|
|
Create a new ``AnnounceableStorageServer`` based on
|
|
|
|
``announceable_storage_server`` with ``information`` added to its
|
|
|
|
``announcement``.
|
|
|
|
"""
|
|
|
|
updated_announcement = announceable_storage_server.announcement.copy()
|
|
|
|
updated_announcement.update(information)
|
|
|
|
return AnnounceableStorageServer(
|
|
|
|
updated_announcement,
|
|
|
|
announceable_storage_server.storage_server,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-07-03 18:30:36 +00:00
|
|
|
def storage_enabled(config):
|
|
|
|
"""
|
|
|
|
Is storage enabled according to the given configuration object?
|
|
|
|
|
|
|
|
:param _Config config: The configuration to inspect.
|
|
|
|
|
|
|
|
:return bool: ``True`` if storage is enabled, ``False`` otherwise.
|
|
|
|
"""
|
|
|
|
return config.get_config(b"storage", b"enabled", True, boolean=True)
|
|
|
|
|
|
|
|
|
|
|
|
def anonymous_storage_enabled(config):
|
|
|
|
"""
|
|
|
|
Is anonymous access to storage enabled according to the given
|
|
|
|
configuration object?
|
|
|
|
|
|
|
|
:param _Config config: The configuration to inspect.
|
|
|
|
|
|
|
|
:return bool: ``True`` if storage is enabled, ``False`` otherwise.
|
|
|
|
"""
|
|
|
|
return (
|
|
|
|
storage_enabled(config) and
|
|
|
|
config.get_config(b"storage", b"anonymous", True, boolean=True)
|
|
|
|
)
|
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
|
2017-02-27 17:56:49 +00:00
|
|
|
@implementer(IStatsProducer)
|
2017-09-06 01:08:35 +00:00
|
|
|
class _Client(node.Node, pollmixin.PollMixin):
|
2008-04-17 18:13:39 +00:00
|
|
|
|
2006-12-01 03:14:23 +00:00
|
|
|
STOREDIR = 'storage'
|
2006-12-03 01:27:18 +00:00
|
|
|
NODETYPE = "client"
|
2014-08-17 14:36:57 +00:00
|
|
|
EXIT_TRIGGER_FILE = "exit_trigger"
|
2006-11-30 22:27:06 +00:00
|
|
|
|
2008-07-30 22:51:07 +00:00
|
|
|
# This means that if a storage server treats me as though I were a
|
|
|
|
# 1.0.0 storage client, it will work as they expect.
|
|
|
|
OLDEST_SUPPORTED_VERSION = "1.0.0"
|
2007-04-26 19:01:25 +00:00
|
|
|
|
2014-04-14 22:34:39 +00:00
|
|
|
# This is a dictionary of (needed, desired, total, max_segment_size). 'needed'
|
2008-01-16 10:03:35 +00:00
|
|
|
# is the number of shares required to reconstruct a file. 'desired' means
|
|
|
|
# that we will abort an upload unless we can allocate space for at least
|
|
|
|
# this many. 'total' is the total number of shares created by encoding.
|
|
|
|
# If everybody has room then this is is how many we will upload.
|
2008-02-05 20:05:13 +00:00
|
|
|
DEFAULT_ENCODING_PARAMETERS = {"k": 3,
|
|
|
|
"happy": 7,
|
|
|
|
"n": 10,
|
2019-05-08 20:04:57 +00:00
|
|
|
"max_segment_size": DEFAULT_MAX_SEGMENT_SIZE,
|
2008-01-16 10:03:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-05 03:08:11 +00:00
|
|
|
def __init__(self, config, main_tub, control_tub, i2p_provider, tor_provider, introducer_clients,
|
2018-03-06 23:29:24 +00:00
|
|
|
storage_farm_broker):
|
2018-01-31 01:04:08 +00:00
|
|
|
"""
|
2018-08-24 21:41:31 +00:00
|
|
|
Use :func:`allmydata.client.create_client` to instantiate one of these.
|
2018-01-31 01:04:08 +00:00
|
|
|
"""
|
2018-03-06 23:29:24 +00:00
|
|
|
node.Node.__init__(self, config, main_tub, control_tub, i2p_provider, tor_provider)
|
2018-01-31 01:04:08 +00:00
|
|
|
|
2008-04-17 18:13:39 +00:00
|
|
|
self.started_timestamp = time.time()
|
2018-01-31 01:04:08 +00:00
|
|
|
self.logSource = "Client"
|
2014-04-21 21:40:28 +00:00
|
|
|
self.encoding_params = self.DEFAULT_ENCODING_PARAMETERS.copy()
|
2018-01-31 01:04:08 +00:00
|
|
|
|
|
|
|
self.introducer_clients = introducer_clients
|
|
|
|
self.storage_broker = storage_farm_broker
|
|
|
|
|
stats: add a simple stats gathering system
We have a desire to collect runtime statistics from multiple nodes primarily
for server monitoring purposes. This implements a simple implementation of
such a system, as a skeleton to build more sophistication upon.
Each client now looks for a 'stats_gatherer.furl' config file. If it has
been configured to use a stats gatherer, then it instantiates internally
a StatsProvider. This is a central place for code which wishes to offer
stats up for monitoring to report them to, either by calling
stats_provider.count('stat.name', value) to increment a counter, or by
registering a class as a stats producer with sp.register_producer(obj).
The StatsProvider connects to the StatsGatherer server and provides its
provider upon startup. The StatsGatherer is then responsible for polling
the attached providers periodically to retrieve the data provided.
The provider queries each registered producer when the gatherer queries
the provider. Both the internal 'counters' and the queried 'stats' are
then reported to the gatherer.
This provides a simple gatherer app, (c.f. make stats-gatherer-run)
which prints its furl and listens for incoming connections. Once a
minute, the gatherer polls all connected providers, and writes the
retrieved data into a pickle file.
Also included is a munin plugin which knows how to read the gatherer's
stats.pickle and output data munin can interpret. this plugin,
tahoe-stats.py can be symlinked as multiple different names within
munin's 'plugins' directory, and inspects argv to determine which
data to display, doing a lookup in a table within that file.
It looks in the environment for 'statsfile' to determine the path to
the gatherer's stats.pickle. An example plugins-conf.d file is
provided.
2008-01-31 03:11:07 +00:00
|
|
|
self.init_stats_provider()
|
2009-11-18 01:54:44 +00:00
|
|
|
self.init_secrets()
|
2013-04-18 07:06:55 +00:00
|
|
|
self.init_node_key()
|
2008-02-06 02:58:38 +00:00
|
|
|
self.init_control()
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self._key_generator = KeyGenerator()
|
2018-01-31 18:30:46 +00:00
|
|
|
key_gen_furl = config.get_config("client", "key_generator.furl", None)
|
2008-04-02 01:45:13 +00:00
|
|
|
if key_gen_furl:
|
2016-04-28 07:05:30 +00:00
|
|
|
log.msg("[client]key_generator.furl= is now ignored, see #2783")
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self.init_client()
|
2016-08-27 00:31:02 +00:00
|
|
|
self.load_static_servers()
|
2016-03-29 01:02:22 +00:00
|
|
|
self.helper = None
|
2018-01-31 18:30:46 +00:00
|
|
|
if config.get_config("helper", "enabled", False, boolean=True):
|
2018-03-06 23:29:24 +00:00
|
|
|
if not self._is_tub_listening():
|
2016-08-30 01:49:20 +00:00
|
|
|
raise ValueError("config error: helper is enabled, but tub "
|
|
|
|
"is not listening ('tub.port=' is empty)")
|
2016-03-29 01:02:22 +00:00
|
|
|
self.init_helper()
|
2008-10-06 19:52:36 +00:00
|
|
|
self.init_ftp_server()
|
2008-11-05 01:00:22 +00:00
|
|
|
self.init_sftp_server()
|
2007-08-28 01:58:39 +00:00
|
|
|
|
2014-08-17 14:36:57 +00:00
|
|
|
# If the node sees an exit_trigger file, it will poll every second to see
|
|
|
|
# whether the file still exists, and what its mtime is. If the file does not
|
|
|
|
# exist or has not been modified for a given timeout, the node will exit.
|
2018-08-24 21:41:44 +00:00
|
|
|
exit_trigger_file = config.get_config_path(self.EXIT_TRIGGER_FILE)
|
2014-08-17 14:36:57 +00:00
|
|
|
if os.path.exists(exit_trigger_file):
|
|
|
|
age = time.time() - os.stat(exit_trigger_file)[stat.ST_MTIME]
|
|
|
|
self.log("%s file noticed (%ds old), starting timer" % (self.EXIT_TRIGGER_FILE, age))
|
|
|
|
exit_trigger = TimerService(1.0, self._check_exit_trigger, exit_trigger_file)
|
|
|
|
exit_trigger.setServiceParent(self)
|
2007-05-25 00:34:42 +00:00
|
|
|
|
2009-02-20 19:15:54 +00:00
|
|
|
# this needs to happen last, so it can use getServiceNamed() to
|
|
|
|
# acquire references to StorageServer and other web-statusable things
|
2018-08-24 21:41:44 +00:00
|
|
|
webport = config.get_config("node", "web.port", None)
|
2007-12-03 21:52:42 +00:00
|
|
|
if webport:
|
|
|
|
self.init_web(webport) # strports string
|
|
|
|
|
stats: add a simple stats gathering system
We have a desire to collect runtime statistics from multiple nodes primarily
for server monitoring purposes. This implements a simple implementation of
such a system, as a skeleton to build more sophistication upon.
Each client now looks for a 'stats_gatherer.furl' config file. If it has
been configured to use a stats gatherer, then it instantiates internally
a StatsProvider. This is a central place for code which wishes to offer
stats up for monitoring to report them to, either by calling
stats_provider.count('stat.name', value) to increment a counter, or by
registering a class as a stats producer with sp.register_producer(obj).
The StatsProvider connects to the StatsGatherer server and provides its
provider upon startup. The StatsGatherer is then responsible for polling
the attached providers periodically to retrieve the data provided.
The provider queries each registered producer when the gatherer queries
the provider. Both the internal 'counters' and the queried 'stats' are
then reported to the gatherer.
This provides a simple gatherer app, (c.f. make stats-gatherer-run)
which prints its furl and listens for incoming connections. Once a
minute, the gatherer polls all connected providers, and writes the
retrieved data into a pickle file.
Also included is a munin plugin which knows how to read the gatherer's
stats.pickle and output data munin can interpret. this plugin,
tahoe-stats.py can be symlinked as multiple different names within
munin's 'plugins' directory, and inspects argv to determine which
data to display, doing a lookup in a table within that file.
It looks in the environment for 'statsfile' to determine the path to
the gatherer's stats.pickle. An example plugins-conf.d file is
provided.
2008-01-31 03:11:07 +00:00
|
|
|
def init_stats_provider(self):
|
2018-01-31 18:30:46 +00:00
|
|
|
gatherer_furl = self.config.get_config("client", "stats_gatherer.furl", None)
|
2008-05-08 18:37:30 +00:00
|
|
|
self.stats_provider = StatsProvider(self, gatherer_furl)
|
2018-01-31 20:03:05 +00:00
|
|
|
self.stats_provider.setServiceParent(self)
|
2008-05-08 18:37:30 +00:00
|
|
|
self.stats_provider.register_producer(self)
|
stats: add a simple stats gathering system
We have a desire to collect runtime statistics from multiple nodes primarily
for server monitoring purposes. This implements a simple implementation of
such a system, as a skeleton to build more sophistication upon.
Each client now looks for a 'stats_gatherer.furl' config file. If it has
been configured to use a stats gatherer, then it instantiates internally
a StatsProvider. This is a central place for code which wishes to offer
stats up for monitoring to report them to, either by calling
stats_provider.count('stat.name', value) to increment a counter, or by
registering a class as a stats producer with sp.register_producer(obj).
The StatsProvider connects to the StatsGatherer server and provides its
provider upon startup. The StatsGatherer is then responsible for polling
the attached providers periodically to retrieve the data provided.
The provider queries each registered producer when the gatherer queries
the provider. Both the internal 'counters' and the queried 'stats' are
then reported to the gatherer.
This provides a simple gatherer app, (c.f. make stats-gatherer-run)
which prints its furl and listens for incoming connections. Once a
minute, the gatherer polls all connected providers, and writes the
retrieved data into a pickle file.
Also included is a munin plugin which knows how to read the gatherer's
stats.pickle and output data munin can interpret. this plugin,
tahoe-stats.py can be symlinked as multiple different names within
munin's 'plugins' directory, and inspects argv to determine which
data to display, doing a lookup in a table within that file.
It looks in the environment for 'statsfile' to determine the path to
the gatherer's stats.pickle. An example plugins-conf.d file is
provided.
2008-01-31 03:11:07 +00:00
|
|
|
|
2008-04-17 18:13:39 +00:00
|
|
|
def get_stats(self):
|
|
|
|
return { 'node.uptime': time.time() - self.started_timestamp }
|
|
|
|
|
2009-11-18 01:54:44 +00:00
|
|
|
def init_secrets(self):
|
2018-01-31 18:30:46 +00:00
|
|
|
lease_s = self.config.get_or_create_private_config("secret", _make_secret)
|
2009-11-18 01:54:44 +00:00
|
|
|
lease_secret = base32.a2b(lease_s)
|
2018-01-31 18:30:46 +00:00
|
|
|
convergence_s = self.config.get_or_create_private_config('convergence',
|
|
|
|
_make_secret)
|
2009-11-18 01:54:44 +00:00
|
|
|
self.convergence = base32.a2b(convergence_s)
|
|
|
|
self._secret_holder = SecretHolder(lease_secret, self.convergence)
|
2007-08-28 02:30:26 +00:00
|
|
|
|
2013-04-18 07:06:55 +00:00
|
|
|
def init_node_key(self):
|
new introducer: signed extensible dictionary-based messages! refs #466
This introduces new client and server halves to the Introducer (renaming the
old one with a _V1 suffix). Both have fallbacks to accomodate talking to a
different version: the publishing client switches on whether the server's
.get_version() advertises V2 support, the server switches on which
subscription method was invoked by the subscribing client.
The V2 protocol sends a three-tuple of (serialized announcement dictionary,
signature, pubkey) for each announcement. The V2 server dispatches messages
to subscribers according to the service-name, and throws errors for invalid
signatures, but does not otherwise examine the messages. The V2 receiver's
subscription callback will receive a (serverid, ann_dict) pair. The
'serverid' will be equal to the pubkey if all of the following are true:
the originating client is V2, and was told a privkey to use
the announcement went through a V2 server
the signature is valid
If not, 'serverid' will be equal to the tubid portion of the announced FURL,
as was the case for V1 receivers.
Servers will create a keypair if one does not exist yet, stored in
private/server.privkey .
The signed announcement dictionary puts the server FURL in a key named
"anonymous-storage-FURL", which anticipates upcoming Accounting-related
changes in the server advertisements. It also provides a key named
"permutation-seed-base32" to tell clients what permutation seed to use. This
is computed at startup, using tubid if there are existing shares, otherwise
the pubkey, to retain share-order compatibility for existing servers.
2011-11-20 10:21:32 +00:00
|
|
|
# we only create the key once. On all subsequent runs, we re-use the
|
|
|
|
# existing key
|
|
|
|
def _make_key():
|
2019-06-14 04:17:58 +00:00
|
|
|
private_key, _ = ed25519.create_signing_keypair()
|
2020-09-16 15:13:23 +00:00
|
|
|
return ed25519.string_from_signing_key(private_key) + b"\n"
|
2019-05-17 17:27:30 +00:00
|
|
|
|
2019-06-14 04:17:58 +00:00
|
|
|
private_key_str = self.config.get_or_create_private_config("node.privkey", _make_key)
|
|
|
|
private_key, public_key = ed25519.signing_keypair_from_string(private_key_str)
|
|
|
|
public_key_str = ed25519.string_from_verifying_key(public_key)
|
2020-09-16 15:13:23 +00:00
|
|
|
self.config.write_config_file("node.pubkey", public_key_str + b"\n", "wb")
|
2019-06-14 04:17:58 +00:00
|
|
|
self._node_private_key = private_key
|
|
|
|
self._node_public_key = public_key
|
new introducer: signed extensible dictionary-based messages! refs #466
This introduces new client and server halves to the Introducer (renaming the
old one with a _V1 suffix). Both have fallbacks to accomodate talking to a
different version: the publishing client switches on whether the server's
.get_version() advertises V2 support, the server switches on which
subscription method was invoked by the subscribing client.
The V2 protocol sends a three-tuple of (serialized announcement dictionary,
signature, pubkey) for each announcement. The V2 server dispatches messages
to subscribers according to the service-name, and throws errors for invalid
signatures, but does not otherwise examine the messages. The V2 receiver's
subscription callback will receive a (serverid, ann_dict) pair. The
'serverid' will be equal to the pubkey if all of the following are true:
the originating client is V2, and was told a privkey to use
the announcement went through a V2 server
the signature is valid
If not, 'serverid' will be equal to the tubid portion of the announced FURL,
as was the case for V1 receivers.
Servers will create a keypair if one does not exist yet, stored in
private/server.privkey .
The signed announcement dictionary puts the server FURL in a key named
"anonymous-storage-FURL", which anticipates upcoming Accounting-related
changes in the server advertisements. It also provides a key named
"permutation-seed-base32" to tell clients what permutation seed to use. This
is computed at startup, using tubid if there are existing shares, otherwise
the pubkey, to retain share-order compatibility for existing servers.
2011-11-20 10:21:32 +00:00
|
|
|
|
2013-04-14 21:32:13 +00:00
|
|
|
def get_long_nodeid(self):
|
|
|
|
# this matches what IServer.get_longname() says about us elsewhere
|
2019-07-08 18:46:22 +00:00
|
|
|
vk_string = ed25519.string_from_verifying_key(self._node_public_key)
|
|
|
|
return remove_prefix(vk_string, "pub-")
|
2013-04-14 21:32:13 +00:00
|
|
|
|
|
|
|
def get_long_tubid(self):
|
|
|
|
return idlib.nodeid_b2a(self.nodeid)
|
|
|
|
|
2019-08-24 18:31:08 +00:00
|
|
|
def get_web_service(self):
|
|
|
|
"""
|
|
|
|
:return: a reference to our web server
|
|
|
|
"""
|
|
|
|
return self.getServiceNamed("webish")
|
|
|
|
|
new introducer: signed extensible dictionary-based messages! refs #466
This introduces new client and server halves to the Introducer (renaming the
old one with a _V1 suffix). Both have fallbacks to accomodate talking to a
different version: the publishing client switches on whether the server's
.get_version() advertises V2 support, the server switches on which
subscription method was invoked by the subscribing client.
The V2 protocol sends a three-tuple of (serialized announcement dictionary,
signature, pubkey) for each announcement. The V2 server dispatches messages
to subscribers according to the service-name, and throws errors for invalid
signatures, but does not otherwise examine the messages. The V2 receiver's
subscription callback will receive a (serverid, ann_dict) pair. The
'serverid' will be equal to the pubkey if all of the following are true:
the originating client is V2, and was told a privkey to use
the announcement went through a V2 server
the signature is valid
If not, 'serverid' will be equal to the tubid portion of the announced FURL,
as was the case for V1 receivers.
Servers will create a keypair if one does not exist yet, stored in
private/server.privkey .
The signed announcement dictionary puts the server FURL in a key named
"anonymous-storage-FURL", which anticipates upcoming Accounting-related
changes in the server advertisements. It also provides a key named
"permutation-seed-base32" to tell clients what permutation seed to use. This
is computed at startup, using tubid if there are existing shares, otherwise
the pubkey, to retain share-order compatibility for existing servers.
2011-11-20 10:21:32 +00:00
|
|
|
def _init_permutation_seed(self, ss):
|
2018-01-31 18:30:46 +00:00
|
|
|
seed = self.config.get_config_from_file("permutation-seed")
|
new introducer: signed extensible dictionary-based messages! refs #466
This introduces new client and server halves to the Introducer (renaming the
old one with a _V1 suffix). Both have fallbacks to accomodate talking to a
different version: the publishing client switches on whether the server's
.get_version() advertises V2 support, the server switches on which
subscription method was invoked by the subscribing client.
The V2 protocol sends a three-tuple of (serialized announcement dictionary,
signature, pubkey) for each announcement. The V2 server dispatches messages
to subscribers according to the service-name, and throws errors for invalid
signatures, but does not otherwise examine the messages. The V2 receiver's
subscription callback will receive a (serverid, ann_dict) pair. The
'serverid' will be equal to the pubkey if all of the following are true:
the originating client is V2, and was told a privkey to use
the announcement went through a V2 server
the signature is valid
If not, 'serverid' will be equal to the tubid portion of the announced FURL,
as was the case for V1 receivers.
Servers will create a keypair if one does not exist yet, stored in
private/server.privkey .
The signed announcement dictionary puts the server FURL in a key named
"anonymous-storage-FURL", which anticipates upcoming Accounting-related
changes in the server advertisements. It also provides a key named
"permutation-seed-base32" to tell clients what permutation seed to use. This
is computed at startup, using tubid if there are existing shares, otherwise
the pubkey, to retain share-order compatibility for existing servers.
2011-11-20 10:21:32 +00:00
|
|
|
if not seed:
|
|
|
|
have_shares = ss.have_shares()
|
|
|
|
if have_shares:
|
|
|
|
# if the server has shares but not a recorded
|
|
|
|
# permutation-seed, then it has been around since pre-#466
|
|
|
|
# days, and the clients who uploaded those shares used our
|
|
|
|
# TubID as a permutation-seed. We should keep using that same
|
|
|
|
# seed to keep the shares in the same place in the permuted
|
|
|
|
# ring, so those clients don't have to perform excessive
|
|
|
|
# searches.
|
|
|
|
seed = base32.b2a(self.nodeid)
|
|
|
|
else:
|
|
|
|
# otherwise, we're free to use the more natural seed of our
|
|
|
|
# pubkey-based serverid
|
2019-07-08 18:46:22 +00:00
|
|
|
vk_string = ed25519.string_from_verifying_key(self._node_public_key)
|
|
|
|
vk_bytes = remove_prefix(vk_string, ed25519.PUBLIC_KEY_PREFIX)
|
new introducer: signed extensible dictionary-based messages! refs #466
This introduces new client and server halves to the Introducer (renaming the
old one with a _V1 suffix). Both have fallbacks to accomodate talking to a
different version: the publishing client switches on whether the server's
.get_version() advertises V2 support, the server switches on which
subscription method was invoked by the subscribing client.
The V2 protocol sends a three-tuple of (serialized announcement dictionary,
signature, pubkey) for each announcement. The V2 server dispatches messages
to subscribers according to the service-name, and throws errors for invalid
signatures, but does not otherwise examine the messages. The V2 receiver's
subscription callback will receive a (serverid, ann_dict) pair. The
'serverid' will be equal to the pubkey if all of the following are true:
the originating client is V2, and was told a privkey to use
the announcement went through a V2 server
the signature is valid
If not, 'serverid' will be equal to the tubid portion of the announced FURL,
as was the case for V1 receivers.
Servers will create a keypair if one does not exist yet, stored in
private/server.privkey .
The signed announcement dictionary puts the server FURL in a key named
"anonymous-storage-FURL", which anticipates upcoming Accounting-related
changes in the server advertisements. It also provides a key named
"permutation-seed-base32" to tell clients what permutation seed to use. This
is computed at startup, using tubid if there are existing shares, otherwise
the pubkey, to retain share-order compatibility for existing servers.
2011-11-20 10:21:32 +00:00
|
|
|
seed = base32.b2a(vk_bytes)
|
2018-01-31 18:30:46 +00:00
|
|
|
self.config.write_config_file("permutation-seed", seed+"\n")
|
new introducer: signed extensible dictionary-based messages! refs #466
This introduces new client and server halves to the Introducer (renaming the
old one with a _V1 suffix). Both have fallbacks to accomodate talking to a
different version: the publishing client switches on whether the server's
.get_version() advertises V2 support, the server switches on which
subscription method was invoked by the subscribing client.
The V2 protocol sends a three-tuple of (serialized announcement dictionary,
signature, pubkey) for each announcement. The V2 server dispatches messages
to subscribers according to the service-name, and throws errors for invalid
signatures, but does not otherwise examine the messages. The V2 receiver's
subscription callback will receive a (serverid, ann_dict) pair. The
'serverid' will be equal to the pubkey if all of the following are true:
the originating client is V2, and was told a privkey to use
the announcement went through a V2 server
the signature is valid
If not, 'serverid' will be equal to the tubid portion of the announced FURL,
as was the case for V1 receivers.
Servers will create a keypair if one does not exist yet, stored in
private/server.privkey .
The signed announcement dictionary puts the server FURL in a key named
"anonymous-storage-FURL", which anticipates upcoming Accounting-related
changes in the server advertisements. It also provides a key named
"permutation-seed-base32" to tell clients what permutation seed to use. This
is computed at startup, using tubid if there are existing shares, otherwise
the pubkey, to retain share-order compatibility for existing servers.
2011-11-20 10:21:32 +00:00
|
|
|
return seed.strip()
|
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
def get_anonymous_storage_server(self):
|
|
|
|
"""
|
|
|
|
Get the anonymous ``IStorageServer`` implementation for this node.
|
|
|
|
|
|
|
|
Note this will return an object even if storage is disabled on this
|
|
|
|
node (but the object will not be exposed, peers will not be able to
|
|
|
|
access it, and storage will remain disabled).
|
|
|
|
|
|
|
|
The one and only instance for this node is always returned. It is
|
|
|
|
created first if necessary.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
ss = self.getServiceNamed(StorageServer.name)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
return ss
|
|
|
|
|
2018-01-31 18:30:46 +00:00
|
|
|
readonly = self.config.get_config("storage", "readonly", False, boolean=True)
|
2008-02-05 20:05:13 +00:00
|
|
|
|
2018-03-19 18:21:28 +00:00
|
|
|
config_storedir = self.get_config(
|
|
|
|
"storage", "storage_dir", self.STOREDIR,
|
|
|
|
).decode('utf-8')
|
2018-01-31 18:30:46 +00:00
|
|
|
storedir = self.config.get_config_path(config_storedir)
|
2007-08-22 17:29:57 +00:00
|
|
|
|
2018-01-31 18:30:46 +00:00
|
|
|
data = self.config.get_config("storage", "reserved_space", None)
|
2008-12-02 00:24:21 +00:00
|
|
|
try:
|
|
|
|
reserved = parse_abbreviated_size(data)
|
|
|
|
except ValueError:
|
|
|
|
log.msg("[storage]reserved_space= contains unparseable value %s"
|
|
|
|
% data)
|
2013-03-20 22:25:10 +00:00
|
|
|
raise
|
2008-12-02 00:24:21 +00:00
|
|
|
if reserved is None:
|
|
|
|
reserved = 0
|
2018-01-31 18:30:46 +00:00
|
|
|
discard = self.config.get_config("storage", "debug_discard", False,
|
|
|
|
boolean=True)
|
2009-03-19 01:00:09 +00:00
|
|
|
|
2018-01-31 18:30:46 +00:00
|
|
|
expire = self.config.get_config("storage", "expire.enabled", False, boolean=True)
|
2009-03-19 01:00:09 +00:00
|
|
|
if expire:
|
2018-01-31 18:30:46 +00:00
|
|
|
mode = self.config.get_config("storage", "expire.mode") # require a mode
|
2009-03-19 01:00:09 +00:00
|
|
|
else:
|
2018-01-31 18:30:46 +00:00
|
|
|
mode = self.config.get_config("storage", "expire.mode", "age")
|
2009-03-19 01:00:09 +00:00
|
|
|
|
2018-01-31 18:30:46 +00:00
|
|
|
o_l_d = self.config.get_config("storage", "expire.override_lease_duration", None)
|
2009-03-19 01:00:09 +00:00
|
|
|
if o_l_d is not None:
|
|
|
|
o_l_d = parse_duration(o_l_d)
|
|
|
|
|
|
|
|
cutoff_date = None
|
|
|
|
if mode == "cutoff-date":
|
2018-01-31 18:30:46 +00:00
|
|
|
cutoff_date = self.config.get_config("storage", "expire.cutoff_date")
|
2009-03-19 01:00:09 +00:00
|
|
|
cutoff_date = parse_date(cutoff_date)
|
|
|
|
|
|
|
|
sharetypes = []
|
2018-01-31 18:30:46 +00:00
|
|
|
if self.config.get_config("storage", "expire.immutable", True, boolean=True):
|
2009-03-19 01:00:09 +00:00
|
|
|
sharetypes.append("immutable")
|
2018-01-31 18:30:46 +00:00
|
|
|
if self.config.get_config("storage", "expire.mutable", True, boolean=True):
|
2009-03-19 01:00:09 +00:00
|
|
|
sharetypes.append("mutable")
|
|
|
|
expiration_sharetypes = tuple(sharetypes)
|
|
|
|
|
2009-02-18 23:23:01 +00:00
|
|
|
ss = StorageServer(storedir, self.nodeid,
|
2008-12-02 00:24:21 +00:00
|
|
|
reserved_space=reserved,
|
|
|
|
discard_storage=discard,
|
|
|
|
readonly_storage=readonly,
|
2009-03-19 01:00:09 +00:00
|
|
|
stats_provider=self.stats_provider,
|
|
|
|
expiration_enabled=expire,
|
|
|
|
expiration_mode=mode,
|
|
|
|
expiration_override_lease_duration=o_l_d,
|
|
|
|
expiration_cutoff_date=cutoff_date,
|
|
|
|
expiration_sharetypes=expiration_sharetypes)
|
2018-01-31 20:03:05 +00:00
|
|
|
ss.setServiceParent(self)
|
2019-06-28 15:55:13 +00:00
|
|
|
return ss
|
|
|
|
|
|
|
|
def init_storage(self, announceable_storage_servers):
|
|
|
|
# should we run a storage server (and publish it for others to use)?
|
2019-07-03 18:30:36 +00:00
|
|
|
if not storage_enabled(self.config):
|
2019-06-28 15:55:13 +00:00
|
|
|
return
|
|
|
|
if not self._is_tub_listening():
|
|
|
|
raise ValueError("config error: storage is enabled, but tub "
|
|
|
|
"is not listening ('tub.port=' is empty)")
|
2009-03-19 01:00:09 +00:00
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
ss = self.get_anonymous_storage_server()
|
2019-07-03 19:20:42 +00:00
|
|
|
announcement = {
|
2019-06-28 15:55:13 +00:00
|
|
|
"permutation-seed-base32": self._init_permutation_seed(ss),
|
|
|
|
}
|
2019-06-14 20:34:10 +00:00
|
|
|
|
2019-07-03 19:20:42 +00:00
|
|
|
if anonymous_storage_enabled(self.config):
|
|
|
|
furl_file = self.config.get_private_path("storage.furl").encode(get_filesystem_encoding())
|
|
|
|
furl = self.tub.registerReference(ss, furlFile=furl_file)
|
|
|
|
announcement["anonymous-storage-FURL"] = furl
|
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
enabled_storage_servers = self._enable_storage_servers(
|
|
|
|
announceable_storage_servers,
|
2019-06-14 21:54:35 +00:00
|
|
|
)
|
2019-06-28 15:55:13 +00:00
|
|
|
storage_options = list(
|
|
|
|
storage_server.announcement
|
|
|
|
for storage_server
|
|
|
|
in enabled_storage_servers
|
2019-06-14 20:34:10 +00:00
|
|
|
)
|
2019-07-03 19:20:42 +00:00
|
|
|
plugins_announcement = {}
|
2019-06-28 15:55:13 +00:00
|
|
|
if storage_options:
|
|
|
|
# Only add the new key if there are any plugins enabled.
|
|
|
|
plugins_announcement[u"storage-options"] = storage_options
|
2019-06-14 20:34:10 +00:00
|
|
|
|
2019-07-03 19:20:42 +00:00
|
|
|
announcement.update(plugins_announcement)
|
2019-06-14 20:34:10 +00:00
|
|
|
|
2019-06-28 15:55:13 +00:00
|
|
|
for ic in self.introducer_clients:
|
2019-07-03 19:20:42 +00:00
|
|
|
ic.publish("storage", announcement, self._node_private_key)
|
2019-06-14 20:34:10 +00:00
|
|
|
|
2019-07-24 19:37:24 +00:00
|
|
|
def get_client_storage_plugin_web_resources(self):
|
|
|
|
"""
|
|
|
|
Get all of the client-side ``IResource`` implementations provided by
|
|
|
|
enabled storage plugins.
|
|
|
|
|
|
|
|
:return dict[bytes, IResource provider]: The implementations.
|
|
|
|
"""
|
2019-08-19 15:21:03 +00:00
|
|
|
return self.storage_broker.get_client_storage_plugin_web_resources(
|
|
|
|
self.config,
|
|
|
|
)
|
2019-07-24 19:37:24 +00:00
|
|
|
|
2019-06-14 20:34:10 +00:00
|
|
|
def _enable_storage_servers(self, announceable_storage_servers):
|
|
|
|
"""
|
|
|
|
Register and announce the given storage servers.
|
|
|
|
"""
|
|
|
|
for announceable in announceable_storage_servers:
|
2019-06-28 15:55:13 +00:00
|
|
|
yield self._enable_storage_server(announceable)
|
2019-06-14 20:34:10 +00:00
|
|
|
|
|
|
|
def _enable_storage_server(self, announceable_storage_server):
|
|
|
|
"""
|
2019-06-28 15:55:13 +00:00
|
|
|
Register a storage server.
|
2019-06-14 20:34:10 +00:00
|
|
|
"""
|
2019-06-27 19:29:37 +00:00
|
|
|
config_key = b"storage-plugin.{}.furl".format(
|
|
|
|
# Oops, why don't I have a better handle on this value?
|
|
|
|
announceable_storage_server.announcement[u"name"],
|
2019-06-14 20:34:10 +00:00
|
|
|
)
|
2019-06-27 19:29:37 +00:00
|
|
|
furl = _register_reference(
|
|
|
|
config_key,
|
|
|
|
self.config,
|
|
|
|
self.tub,
|
2019-06-14 20:34:10 +00:00
|
|
|
announceable_storage_server.storage_server,
|
|
|
|
)
|
2019-06-28 15:55:13 +00:00
|
|
|
announceable_storage_server = _add_to_announcement(
|
2019-06-14 20:34:10 +00:00
|
|
|
{u"storage-server-FURL": furl},
|
|
|
|
announceable_storage_server,
|
|
|
|
)
|
2019-06-28 15:55:13 +00:00
|
|
|
return announceable_storage_server
|
2019-06-14 20:34:10 +00:00
|
|
|
|
2008-03-12 02:20:10 +00:00
|
|
|
def init_client(self):
|
2018-01-31 18:30:46 +00:00
|
|
|
helper_furl = self.config.get_config("client", "helper.furl", None)
|
2012-12-29 04:17:00 +00:00
|
|
|
if helper_furl in ("None", ""):
|
|
|
|
helper_furl = None
|
|
|
|
|
2014-04-21 21:40:28 +00:00
|
|
|
DEP = self.encoding_params
|
2018-01-31 18:30:46 +00:00
|
|
|
DEP["k"] = int(self.config.get_config("client", "shares.needed", DEP["k"]))
|
|
|
|
DEP["n"] = int(self.config.get_config("client", "shares.total", DEP["n"]))
|
|
|
|
DEP["happy"] = int(self.config.get_config("client", "shares.happy", DEP["happy"]))
|
2009-06-01 21:06:04 +00:00
|
|
|
|
2016-01-27 06:49:23 +00:00
|
|
|
# for the CLI to authenticate to local JSON endpoints
|
|
|
|
self._create_auth_token()
|
|
|
|
|
2009-08-15 11:44:15 +00:00
|
|
|
self.history = History(self.stats_provider)
|
2010-08-04 07:27:02 +00:00
|
|
|
self.terminator = Terminator()
|
|
|
|
self.terminator.setServiceParent(self)
|
2018-01-31 20:03:05 +00:00
|
|
|
uploader = Uploader(
|
|
|
|
helper_furl,
|
|
|
|
self.stats_provider,
|
|
|
|
self.history,
|
|
|
|
)
|
|
|
|
uploader.setServiceParent(self)
|
2011-08-24 15:59:28 +00:00
|
|
|
self.init_blacklist()
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self.init_nodemaker()
|
2009-02-16 21:58:44 +00:00
|
|
|
|
2016-01-27 06:49:23 +00:00
|
|
|
def get_auth_token(self):
|
|
|
|
"""
|
|
|
|
This returns a local authentication token, which is just some
|
|
|
|
random data in "api_auth_token" which must be echoed to API
|
|
|
|
calls.
|
|
|
|
"""
|
2018-01-31 18:30:46 +00:00
|
|
|
return self.config.get_private_config('api_auth_token')
|
2016-01-27 06:49:23 +00:00
|
|
|
|
|
|
|
def _create_auth_token(self):
|
|
|
|
"""
|
|
|
|
Creates new auth-token data written to 'private/api_auth_token'.
|
|
|
|
|
|
|
|
This is intentionally re-created every time the node starts.
|
|
|
|
"""
|
2018-01-31 18:30:46 +00:00
|
|
|
self.config.write_private_config(
|
2016-01-27 06:49:23 +00:00
|
|
|
'api_auth_token',
|
2020-09-16 15:13:23 +00:00
|
|
|
urlsafe_b64encode(os.urandom(32)) + b'\n',
|
2016-01-27 06:49:23 +00:00
|
|
|
)
|
|
|
|
|
2009-06-02 02:25:11 +00:00
|
|
|
def get_storage_broker(self):
|
|
|
|
return self.storage_broker
|
|
|
|
|
2016-08-27 00:31:02 +00:00
|
|
|
def load_static_servers(self):
|
|
|
|
"""
|
|
|
|
Load the servers.yaml file if it exists, and provide the static
|
|
|
|
server data to the StorageFarmBroker.
|
|
|
|
"""
|
2018-01-31 18:30:46 +00:00
|
|
|
fn = self.config.get_private_path("servers.yaml")
|
2016-08-27 00:31:02 +00:00
|
|
|
servers_filepath = FilePath(fn)
|
|
|
|
try:
|
|
|
|
with servers_filepath.open() as f:
|
|
|
|
servers_yaml = yamlutil.safe_load(f)
|
|
|
|
static_servers = servers_yaml.get("storage", {})
|
|
|
|
log.msg("found %d static servers in private/servers.yaml" %
|
|
|
|
len(static_servers))
|
|
|
|
self.storage_broker.set_static_servers(static_servers)
|
|
|
|
except EnvironmentError:
|
|
|
|
pass
|
|
|
|
|
2011-08-24 15:59:28 +00:00
|
|
|
def init_blacklist(self):
|
2018-01-31 18:30:46 +00:00
|
|
|
fn = self.config.get_config_path("access.blacklist")
|
2011-08-24 15:59:28 +00:00
|
|
|
self.blacklist = Blacklist(fn)
|
|
|
|
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
def init_nodemaker(self):
|
2018-01-31 18:30:46 +00:00
|
|
|
default = self.config.get_config("client", "mutable.format", default="SDMF")
|
2011-10-13 16:32:29 +00:00
|
|
|
if default.upper() == "MDMF":
|
|
|
|
self.mutable_file_default = MDMF_VERSION
|
|
|
|
else:
|
|
|
|
self.mutable_file_default = SDMF_VERSION
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self.nodemaker = NodeMaker(self.storage_broker,
|
|
|
|
self._secret_holder,
|
|
|
|
self.get_history(),
|
|
|
|
self.getServiceNamed("uploader"),
|
2010-08-04 07:27:02 +00:00
|
|
|
self.terminator,
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
self.get_encoding_parameters(),
|
2011-10-13 16:32:29 +00:00
|
|
|
self.mutable_file_default,
|
2011-08-24 15:59:28 +00:00
|
|
|
self._key_generator,
|
|
|
|
self.blacklist)
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
|
2009-01-14 23:14:24 +00:00
|
|
|
def get_history(self):
|
2009-08-15 11:44:15 +00:00
|
|
|
return self.history
|
2009-01-14 23:14:24 +00:00
|
|
|
|
2008-02-06 02:58:38 +00:00
|
|
|
def init_control(self):
|
2016-04-27 04:54:45 +00:00
|
|
|
c = ControlServer()
|
|
|
|
c.setServiceParent(self)
|
2016-06-30 13:04:23 +00:00
|
|
|
control_url = self.control_tub.registerReference(c)
|
2020-09-16 15:13:23 +00:00
|
|
|
self.config.write_private_config("control.furl", control_url + b"\n")
|
2007-07-04 00:27:07 +00:00
|
|
|
|
2008-02-06 02:58:38 +00:00
|
|
|
def init_helper(self):
|
2018-01-31 18:30:46 +00:00
|
|
|
self.helper = Helper(self.config.get_config_path("helper"),
|
2016-04-27 04:54:45 +00:00
|
|
|
self.storage_broker, self._secret_holder,
|
|
|
|
self.stats_provider, self.history)
|
|
|
|
# TODO: this is confusing. BASEDIR/private/helper.furl is created by
|
|
|
|
# the helper. BASEDIR/helper.furl is consumed by the client who wants
|
|
|
|
# to use the helper. I like having the filename be the same, since
|
|
|
|
# that makes 'cp' work smoothly, but the difference between config
|
|
|
|
# inputs and generated outputs is hard to see.
|
2018-01-31 18:30:46 +00:00
|
|
|
helper_furlfile = self.config.get_private_path("helper.furl").encode(get_filesystem_encoding())
|
2016-04-27 04:54:45 +00:00
|
|
|
self.tub.registerReference(self.helper, furlFile=helper_furlfile)
|
2007-08-10 01:30:24 +00:00
|
|
|
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
def set_default_mutable_keysize(self, keysize):
|
|
|
|
self._key_generator.set_default_keysize(keysize)
|
2008-04-02 01:45:13 +00:00
|
|
|
|
2007-08-22 21:54:34 +00:00
|
|
|
def init_web(self, webport):
|
2007-12-03 21:52:42 +00:00
|
|
|
self.log("init_web(webport=%s)", args=(webport,))
|
|
|
|
|
2007-09-04 23:33:06 +00:00
|
|
|
from allmydata.webish import WebishServer
|
2018-01-31 18:30:46 +00:00
|
|
|
nodeurl_path = self.config.get_config_path("node.url")
|
|
|
|
staticdir_config = self.config.get_config("node", "web.static", "public_html").decode("utf-8")
|
|
|
|
staticdir = self.config.get_config_path(staticdir_config)
|
2009-02-20 19:15:54 +00:00
|
|
|
ws = WebishServer(self, webport, nodeurl_path, staticdir)
|
2018-01-31 20:03:05 +00:00
|
|
|
ws.setServiceParent(self)
|
2007-08-22 21:54:34 +00:00
|
|
|
|
2008-10-06 19:52:36 +00:00
|
|
|
def init_ftp_server(self):
|
2018-01-31 18:30:46 +00:00
|
|
|
if self.config.get_config("ftpd", "enabled", False, boolean=True):
|
2015-03-24 17:10:00 +00:00
|
|
|
accountfile = from_utf8_or_none(
|
2018-01-31 18:30:46 +00:00
|
|
|
self.config.get_config("ftpd", "accounts.file", None))
|
2015-03-24 17:10:00 +00:00
|
|
|
if accountfile:
|
2018-01-31 18:30:46 +00:00
|
|
|
accountfile = self.config.get_config_path(accountfile)
|
|
|
|
accounturl = self.config.get_config("ftpd", "accounts.url", None)
|
|
|
|
ftp_portstr = self.config.get_config("ftpd", "port", "8021")
|
2008-10-07 01:06:05 +00:00
|
|
|
|
2008-11-05 21:07:33 +00:00
|
|
|
from allmydata.frontends import ftpd
|
2008-10-07 01:06:05 +00:00
|
|
|
s = ftpd.FTPServer(self, accountfile, accounturl, ftp_portstr)
|
|
|
|
s.setServiceParent(self)
|
2008-10-06 19:52:36 +00:00
|
|
|
|
2008-11-05 01:00:22 +00:00
|
|
|
def init_sftp_server(self):
|
2018-01-31 18:30:46 +00:00
|
|
|
if self.config.get_config("sftpd", "enabled", False, boolean=True):
|
2015-03-24 17:10:00 +00:00
|
|
|
accountfile = from_utf8_or_none(
|
2018-01-31 18:30:46 +00:00
|
|
|
self.config.get_config("sftpd", "accounts.file", None))
|
2015-03-24 17:10:00 +00:00
|
|
|
if accountfile:
|
2018-01-31 18:30:46 +00:00
|
|
|
accountfile = self.config.get_config_path(accountfile)
|
|
|
|
accounturl = self.config.get_config("sftpd", "accounts.url", None)
|
|
|
|
sftp_portstr = self.config.get_config("sftpd", "port", "8022")
|
|
|
|
pubkey_file = from_utf8_or_none(self.config.get_config("sftpd", "host_pubkey_file"))
|
|
|
|
privkey_file = from_utf8_or_none(self.config.get_config("sftpd", "host_privkey_file"))
|
2008-11-05 01:00:22 +00:00
|
|
|
|
2008-11-05 21:07:33 +00:00
|
|
|
from allmydata.frontends import sftpd
|
2008-11-05 01:00:22 +00:00
|
|
|
s = sftpd.SFTPServer(self, accountfile, accounturl,
|
|
|
|
sftp_portstr, pubkey_file, privkey_file)
|
|
|
|
s.setServiceParent(self)
|
|
|
|
|
2014-08-17 14:36:57 +00:00
|
|
|
def _check_exit_trigger(self, exit_trigger_file):
|
|
|
|
if os.path.exists(exit_trigger_file):
|
|
|
|
mtime = os.stat(exit_trigger_file)[stat.ST_MTIME]
|
2009-03-08 03:50:39 +00:00
|
|
|
if mtime > time.time() - 120.0:
|
2007-05-25 00:34:42 +00:00
|
|
|
return
|
2007-09-19 20:56:00 +00:00
|
|
|
else:
|
2014-08-17 14:36:57 +00:00
|
|
|
self.log("%s file too old, shutting down" % (self.EXIT_TRIGGER_FILE,))
|
2007-09-19 20:56:00 +00:00
|
|
|
else:
|
2014-08-17 14:36:57 +00:00
|
|
|
self.log("%s file missing, shutting down" % (self.EXIT_TRIGGER_FILE,))
|
2007-05-25 00:34:42 +00:00
|
|
|
reactor.stop()
|
|
|
|
|
2007-07-12 22:33:30 +00:00
|
|
|
def get_encoding_parameters(self):
|
2014-04-21 21:40:28 +00:00
|
|
|
return self.encoding_params
|
2007-07-12 22:33:30 +00:00
|
|
|
|
2016-09-12 23:01:23 +00:00
|
|
|
def introducer_connection_statuses(self):
|
2016-12-08 23:15:49 +00:00
|
|
|
return [ic.connection_status() for ic in self.introducer_clients]
|
2016-09-12 23:01:23 +00:00
|
|
|
|
2007-06-10 04:03:57 +00:00
|
|
|
def connected_to_introducer(self):
|
2016-09-12 23:01:23 +00:00
|
|
|
return any([ic.connected_to_introducer() for ic in self.introducer_clients])
|
2007-08-28 02:00:18 +00:00
|
|
|
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
def get_renewal_secret(self): # this will go away
|
|
|
|
return self._secret_holder.get_renewal_secret()
|
2007-08-28 02:30:26 +00:00
|
|
|
|
2007-08-28 02:00:18 +00:00
|
|
|
def get_cancel_secret(self):
|
Overhaul IFilesystemNode handling, to simplify tests and use POLA internally.
* stop using IURI as an adapter
* pass cap strings around instead of URI instances
* move filenode/dirnode creation duties from Client to new NodeMaker class
* move other Client duties to KeyGenerator, SecretHolder, History classes
* stop passing Client reference to dirnode/filenode constructors
- pass less-powerful references instead, like StorageBroker or Uploader
* always create DirectoryNodes by wrapping a filenode (mutable for now)
* remove some specialized mock classes from unit tests
Detailed list of changes (done one at a time, then merged together)
always pass a string to create_node_from_uri(), not an IURI instance
always pass a string to IFilesystemNode constructors, not an IURI instance
stop using IURI() as an adapter, switch on cap prefix in create_node_from_uri()
client.py: move SecretHolder code out to a separate class
test_web.py: hush pyflakes
client.py: move NodeMaker functionality out into a separate object
LiteralFileNode: stop storing a Client reference
immutable Checker: remove Client reference, it only needs a SecretHolder
immutable Upload: remove Client reference, leave SecretHolder and StorageBroker
immutable Repairer: replace Client reference with StorageBroker and SecretHolder
immutable FileNode: remove Client reference
mutable.Publish: stop passing Client
mutable.ServermapUpdater: get StorageBroker in constructor, not by peeking into Client reference
MutableChecker: reference StorageBroker and History directly, not through Client
mutable.FileNode: removed unused indirection to checker classes
mutable.FileNode: remove Client reference
client.py: move RSA key generation into a separate class, so it can be passed to the nodemaker
move create_mutable_file() into NodeMaker
test_dirnode.py: stop using FakeClient mockups, use NoNetworkGrid instead. This simplifies the code, but takes longer to run (17s instead of 6s). This should come down later when other cleanups make it possible to use simpler (non-RSA) fake mutable files for dirnode tests.
test_mutable.py: clean up basedir names
client.py: move create_empty_dirnode() into NodeMaker
dirnode.py: get rid of DirectoryNode.create
remove DirectoryNode.init_from_uri, refactor NodeMaker for customization, simplify test_web's mock Client to match
stop passing Client to DirectoryNode, make DirectoryNode.create_with_mutablefile the normal DirectoryNode constructor, start removing client from NodeMaker
remove Client from NodeMaker
move helper status into History, pass History to web.Status instead of Client
test_mutable.py: fix minor typo
2009-08-15 11:02:56 +00:00
|
|
|
return self._secret_holder.get_cancel_secret()
|
2007-09-20 22:33:58 +00:00
|
|
|
|
|
|
|
def debug_wait_for_client_connections(self, num_clients):
|
|
|
|
"""Return a Deferred that fires (with None) when we have connections
|
|
|
|
to the given number of peers. Useful for tests that set up a
|
|
|
|
temporary test network and need to know when it is safe to proceed
|
|
|
|
with an upload or download."""
|
|
|
|
def _check():
|
2011-02-21 01:58:04 +00:00
|
|
|
return len(self.storage_broker.get_connected_servers()) >= num_clients
|
2007-09-20 22:33:58 +00:00
|
|
|
d = self.poll(_check, 0.5)
|
|
|
|
d.addCallback(lambda res: None)
|
|
|
|
return d
|
|
|
|
|
2007-11-01 22:15:29 +00:00
|
|
|
|
2007-11-09 09:54:51 +00:00
|
|
|
# these four methods are the primitives for creating filenodes and
|
|
|
|
# dirnodes. The first takes a URI and produces a filenode or (new-style)
|
|
|
|
# dirnode. The other three create brand-new filenodes/dirnodes.
|
|
|
|
|
2010-01-27 06:44:30 +00:00
|
|
|
def create_node_from_uri(self, write_uri, read_uri=None, deep_immutable=False, name="<unknown name>"):
|
|
|
|
# This returns synchronously.
|
|
|
|
# Note that it does *not* validate the write_uri and read_uri; instead we
|
|
|
|
# may get an opaque node if there were any problems.
|
|
|
|
return self.nodemaker.create_from_cap(write_uri, read_uri, deep_immutable=deep_immutable, name=name)
|
2007-11-09 09:54:51 +00:00
|
|
|
|
2011-10-13 16:29:51 +00:00
|
|
|
def create_dirnode(self, initial_children={}, version=None):
|
2011-08-02 01:48:11 +00:00
|
|
|
d = self.nodemaker.create_new_mutable_directory(initial_children, version=version)
|
2009-10-12 22:45:06 +00:00
|
|
|
return d
|
2010-01-27 06:44:30 +00:00
|
|
|
|
2009-11-18 07:09:00 +00:00
|
|
|
def create_immutable_dirnode(self, children, convergence=None):
|
|
|
|
return self.nodemaker.create_immutable_directory(children, convergence)
|
2007-11-01 22:15:29 +00:00
|
|
|
|
2011-08-02 01:48:11 +00:00
|
|
|
def create_mutable_file(self, contents=None, keysize=None, version=None):
|
|
|
|
return self.nodemaker.create_mutable_file(contents, keysize,
|
|
|
|
version=version)
|
2008-04-02 01:45:13 +00:00
|
|
|
|
2017-02-14 23:36:57 +00:00
|
|
|
def upload(self, uploadable, reactor=None):
|
2007-11-09 09:54:51 +00:00
|
|
|
uploader = self.getServiceNamed("uploader")
|
2017-02-14 23:36:57 +00:00
|
|
|
return uploader.upload(uploadable, reactor=reactor)
|