2010-08-04 07:27:02 +00:00
|
|
|
import os, stat, time, weakref
|
2007-06-28 00:11:06 +00:00
|
|
|
from allmydata import node
|
2016-01-27 06:49:23 +00:00
|
|
|
from base64 import urlsafe_b64encode
|
2006-11-30 23:23:39 +00:00
|
|
|
|
2008-03-12 02:20:10 +00:00
|
|
|
from zope.interface import implements
|
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
|
2008-04-02 01:45:13 +00:00
|
|
|
from pycryptopp.publickey import rsa
|
2006-11-30 22:14:47 +00:00
|
|
|
|
2007-04-26 19:01:25 +00:00
|
|
|
import allmydata
|
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
|
2013-04-14 21:32:13 +00:00
|
|
|
from allmydata.util import hashutil, base32, pollmixin, log, keyutil, idlib
|
2015-03-24 17:10:00 +00:00
|
|
|
from allmydata.util.encodingutil import get_filesystem_encoding, \
|
|
|
|
from_utf8_or_none
|
2015-01-30 00:50:18 +00:00
|
|
|
from allmydata.util.fileutil import abspath_expanduser_unicode
|
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
|
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
|
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
|
|
|
from allmydata.interfaces import IStatsProducer, SDMF_VERSION, MDMF_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
|
|
|
from allmydata.nodemaker import NodeMaker
|
2011-08-24 15:59:28 +00:00
|
|
|
from allmydata.blacklist import Blacklist
|
2011-11-20 23:24:26 +00:00
|
|
|
from allmydata.node import OldConfigOptionError
|
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
|
|
|
|
|
2008-03-24 16:46:06 +00:00
|
|
|
def _make_secret():
|
|
|
|
return base32.b2a(os.urandom(hashutil.CRYPTO_VAL_SIZE)) + "\n"
|
|
|
|
|
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
|
|
|
class SecretHolder:
|
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
|
|
|
|
|
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
|
|
|
class KeyGenerator:
|
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._remote = None
|
|
|
|
self.default_keysize = 2048
|
|
|
|
|
|
|
|
def set_remote_generator(self, keygen):
|
|
|
|
self._remote = keygen
|
|
|
|
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
|
|
|
|
if self._remote:
|
|
|
|
d = self._remote.callRemote('get_rsa_key_pair', keysize)
|
|
|
|
def make_key_objs((verifying_key, signing_key)):
|
|
|
|
v = rsa.create_verifying_key_from_string(verifying_key)
|
|
|
|
s = rsa.create_signing_key_from_string(signing_key)
|
|
|
|
return v, s
|
|
|
|
d.addCallback(make_key_objs)
|
|
|
|
return d
|
|
|
|
else:
|
|
|
|
# RSA key generation for a 2048 bit key takes between 0.8 and 3.2
|
|
|
|
# secs
|
|
|
|
signer = rsa.generate(keysize)
|
|
|
|
verifier = signer.get_verifying_key()
|
|
|
|
return defer.succeed( (verifier, signer) )
|
|
|
|
|
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
|
|
|
|
2008-10-29 04:15:48 +00:00
|
|
|
class Client(node.Node, pollmixin.PollMixin):
|
2008-04-17 18:13:39 +00:00
|
|
|
implements(IStatsProducer)
|
|
|
|
|
2006-12-03 01:27:18 +00:00
|
|
|
PORTNUMFILE = "client.port"
|
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,
|
2008-03-08 02:24:51 +00:00
|
|
|
"max_segment_size": 128*KiB,
|
2008-01-16 10:03:35 +00:00
|
|
|
}
|
|
|
|
|
2006-12-03 01:27:18 +00:00
|
|
|
def __init__(self, basedir="."):
|
|
|
|
node.Node.__init__(self, basedir)
|
2016-04-27 04:54:45 +00:00
|
|
|
# All tub.registerReference must happen *after* we upcall, since
|
|
|
|
# that's what does tub.setLocation()
|
2008-04-17 18:13:39 +00:00
|
|
|
self.started_timestamp = time.time()
|
2007-08-11 21:52:37 +00:00
|
|
|
self.logSource="Client"
|
2014-04-21 21:40:28 +00:00
|
|
|
self.encoding_params = self.DEFAULT_ENCODING_PARAMETERS.copy()
|
2008-02-05 20:05:13 +00:00
|
|
|
self.init_introducer_client()
|
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()
|
2007-07-04 00:27:07 +00:00
|
|
|
self.init_storage()
|
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()
|
2008-09-30 23:21:49 +00:00
|
|
|
key_gen_furl = self.get_config("client", "key_generator.furl", None)
|
2008-04-02 01:45:13 +00:00
|
|
|
if key_gen_furl:
|
|
|
|
self.init_key_gen(key_gen_furl)
|
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-03-29 01:02:22 +00:00
|
|
|
self.helper = None
|
|
|
|
if self.get_config("helper", "enabled", False, boolean=True):
|
|
|
|
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()
|
2011-08-08 23:40:49 +00:00
|
|
|
self.init_drop_uploader()
|
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.
|
|
|
|
exit_trigger_file = os.path.join(self.basedir,
|
|
|
|
self.EXIT_TRIGGER_FILE)
|
|
|
|
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
|
2008-09-30 23:21:49 +00:00
|
|
|
webport = self.get_config("node", "web.port", None)
|
2007-12-03 21:52:42 +00:00
|
|
|
if webport:
|
|
|
|
self.init_web(webport) # strports string
|
|
|
|
|
2013-03-19 00:40:56 +00:00
|
|
|
def _sequencer(self):
|
|
|
|
seqnum_s = self.get_config_from_file("announcement-seqnum")
|
|
|
|
if not seqnum_s:
|
|
|
|
seqnum_s = "0"
|
|
|
|
seqnum = int(seqnum_s.strip())
|
|
|
|
seqnum += 1 # increment
|
|
|
|
self.write_config("announcement-seqnum", "%d\n" % seqnum)
|
|
|
|
nonce = _make_secret().strip()
|
|
|
|
return seqnum, nonce
|
|
|
|
|
2008-02-05 20:05:13 +00:00
|
|
|
def init_introducer_client(self):
|
2008-09-30 23:21:49 +00:00
|
|
|
self.introducer_furl = self.get_config("client", "introducer.furl")
|
2008-02-05 20:05:13 +00:00
|
|
|
ic = IntroducerClient(self.tub, self.introducer_furl,
|
|
|
|
self.nickname,
|
versioning: include an "appname" in the application version string in the versioning protocol, and make that appname be controlled by setup.py
It is currently hardcoded in setup.py to be 'allmydata-tahoe'. Ticket #556 is to make it configurable by a runtime command-line argument to setup.py: "--appname=foo", but I suddenly wondered if we really wanted that and at the same time realized that we don't need that for tahoe-1.3.0 release, so this patch just hardcodes it in setup.py.
setup.py inspects a file named 'src/allmydata/_appname.py' and assert that it contains the string "__appname__ = 'allmydata-tahoe'", and creates it if it isn't already present. src/allmydata/__init__.py import _appname and reads __appname__ from it. The rest of the Python code imports allmydata and inspects "allmydata.__appname__", although actually every use it uses "allmydata.__full_version__" instead, where "allmydata.__full_version__" is created in src/allmydata/__init__.py to be:
__full_version__ = __appname + '-' + str(__version__).
All the code that emits an "application version string" when describing what version of a protocol it supports (introducer server, storage server, upload helper), or when describing itself in general (introducer client), usese allmydata.__full_version__.
This fixes ticket #556 at least well enough for tahoe-1.3.0 release.
2009-02-12 00:18:16 +00:00
|
|
|
str(allmydata.__full_version__),
|
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
|
|
|
str(self.OLDEST_SUPPORTED_VERSION),
|
2013-03-19 00:40:56 +00:00
|
|
|
self.get_app_versions(),
|
|
|
|
self._sequencer)
|
2008-02-05 20:05:13 +00:00
|
|
|
self.introducer_client = ic
|
2016-04-27 04:54:45 +00:00
|
|
|
ic.setServiceParent(self)
|
2008-02-05 20:05:13 +00:00
|
|
|
|
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):
|
2008-09-30 23:21:49 +00:00
|
|
|
gatherer_furl = self.get_config("client", "stats_gatherer.furl", None)
|
2008-05-08 18:37:30 +00:00
|
|
|
self.stats_provider = StatsProvider(self, gatherer_furl)
|
|
|
|
self.add_service(self.stats_provider)
|
|
|
|
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):
|
|
|
|
lease_s = self.get_or_create_private_config("secret", _make_secret)
|
|
|
|
lease_secret = base32.a2b(lease_s)
|
|
|
|
convergence_s = self.get_or_create_private_config('convergence',
|
|
|
|
_make_secret)
|
|
|
|
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():
|
|
|
|
sk_vs,vk_vs = keyutil.make_keypair()
|
|
|
|
return sk_vs+"\n"
|
2013-04-14 21:03:34 +00:00
|
|
|
sk_vs = self.get_or_create_private_config("node.privkey", _make_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
|
|
|
sk,vk_vs = keyutil.parse_privkey(sk_vs.strip())
|
client.py: rename "server key" to "node key", use old name if present
This prepares for invitation-based reciprocal-permission Accounting. In
the scheme I'm developing, nodes publish "I accept shares from Y"
messages, which are assembled into a graph, and server will accept
shares from any client node reachable in this graph. For this to work,
the serverX->clientY edge must be connectable to the serverY->clientZ
edge, which means "clientY" and "serverY" must be connected. If clientY
and serverY are two distinct keys, they must be cross-signed. Life is
easier if there's just one key "Y", rather than distinct client- and
server- keys. Calling this one key "server.privkey" would be confusing.
"node.privkey" and "node.pubkey" makes more sense.
One-server-per-node is a pretty easy restriction. Originally I was
thinking that the client.key should be provided in each webapi call,
just like a filecap is, making a single node useable by multiple users
(Accounting principals), and not providing any ambient storage
authority. But I've been unable to think of a comfortable WUI for
that (at least without requiring javascript), nor a friendly way to
transfer account authority (e.g. writecaps that include storage
authority). So I'm more willing to have one-client-per-node these days.
(and note that this rename doesn't seriously preclude
many-clients-per-node or zero-clients-per-node anyways, it just makes
one-client-per-node less awkward)
2012-06-11 01:14:55 +00:00
|
|
|
self.write_config("node.pubkey", vk_vs+"\n")
|
2013-04-14 20:22:10 +00:00
|
|
|
self._node_key = sk
|
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
|
|
|
|
vk_bytes = self._node_key.get_verifying_key_bytes()
|
|
|
|
return "v0-"+base32.b2a(vk_bytes)
|
|
|
|
|
|
|
|
def get_long_tubid(self):
|
|
|
|
return idlib.nodeid_b2a(self.nodeid)
|
|
|
|
|
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):
|
|
|
|
seed = self.get_config_from_file("permutation-seed")
|
|
|
|
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
|
2013-04-14 20:22:10 +00:00
|
|
|
vk_bytes = self._node_key.get_verifying_key_bytes()
|
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)
|
|
|
|
self.write_config("permutation-seed", seed+"\n")
|
|
|
|
return seed.strip()
|
|
|
|
|
2007-07-04 00:27:07 +00:00
|
|
|
def init_storage(self):
|
2008-02-05 20:05:13 +00:00
|
|
|
# should we run a storage server (and publish it for others to use)?
|
2008-09-30 23:21:49 +00:00
|
|
|
if not self.get_config("storage", "enabled", True, boolean=True):
|
2008-02-05 20:05:13 +00:00
|
|
|
return
|
2008-09-30 23:21:49 +00:00
|
|
|
readonly = self.get_config("storage", "readonly", False, boolean=True)
|
2008-02-05 20:05:13 +00:00
|
|
|
|
2007-07-04 00:27:07 +00:00
|
|
|
storedir = os.path.join(self.basedir, self.STOREDIR)
|
2007-08-22 17:29:57 +00:00
|
|
|
|
2008-12-02 00:24:21 +00:00
|
|
|
data = self.get_config("storage", "reserved_space", None)
|
|
|
|
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
|
2008-09-30 23:21:49 +00:00
|
|
|
discard = self.get_config("storage", "debug_discard", False,
|
|
|
|
boolean=True)
|
2009-03-19 01:00:09 +00:00
|
|
|
|
|
|
|
expire = self.get_config("storage", "expire.enabled", False, boolean=True)
|
|
|
|
if expire:
|
|
|
|
mode = self.get_config("storage", "expire.mode") # require a mode
|
|
|
|
else:
|
|
|
|
mode = self.get_config("storage", "expire.mode", "age")
|
|
|
|
|
|
|
|
o_l_d = self.get_config("storage", "expire.override_lease_duration", None)
|
|
|
|
if o_l_d is not None:
|
|
|
|
o_l_d = parse_duration(o_l_d)
|
|
|
|
|
|
|
|
cutoff_date = None
|
|
|
|
if mode == "cutoff-date":
|
|
|
|
cutoff_date = self.get_config("storage", "expire.cutoff_date")
|
|
|
|
cutoff_date = parse_date(cutoff_date)
|
|
|
|
|
|
|
|
sharetypes = []
|
|
|
|
if self.get_config("storage", "expire.immutable", True, boolean=True):
|
|
|
|
sharetypes.append("immutable")
|
|
|
|
if self.get_config("storage", "expire.mutable", True, boolean=True):
|
|
|
|
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)
|
2008-02-05 20:05:13 +00:00
|
|
|
self.add_service(ss)
|
2009-03-19 01:00:09 +00:00
|
|
|
|
2016-04-27 04:54:45 +00:00
|
|
|
furl_file = os.path.join(self.basedir, "private", "storage.furl").encode(get_filesystem_encoding())
|
|
|
|
furl = self.tub.registerReference(ss, furlFile=furl_file)
|
|
|
|
ann = {"anonymous-storage-FURL": furl,
|
|
|
|
"permutation-seed-base32": self._init_permutation_seed(ss),
|
|
|
|
}
|
|
|
|
self.introducer_client.publish("storage", ann, self._node_key)
|
2008-02-05 20:05:13 +00:00
|
|
|
|
2008-03-12 02:20:10 +00:00
|
|
|
def init_client(self):
|
2008-09-30 23:21:49 +00:00
|
|
|
helper_furl = self.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
|
2008-11-18 07:29:44 +00:00
|
|
|
DEP["k"] = int(self.get_config("client", "shares.needed", DEP["k"]))
|
|
|
|
DEP["n"] = int(self.get_config("client", "shares.total", DEP["n"]))
|
|
|
|
DEP["happy"] = int(self.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-06-01 21:06:04 +00:00
|
|
|
self.init_client_storage_broker()
|
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)
|
2011-08-29 06:32:46 +00:00
|
|
|
self.add_service(Uploader(helper_furl, self.stats_provider,
|
|
|
|
self.history))
|
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.
|
|
|
|
|
|
|
|
Currently only the URI '/magic' for magic-folder status; other
|
|
|
|
endpoints are invited to include this as well, as appropriate.
|
|
|
|
"""
|
|
|
|
return self.get_private_config('api_auth_token')
|
|
|
|
|
|
|
|
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.
|
|
|
|
"""
|
|
|
|
self.write_private_config(
|
|
|
|
'api_auth_token',
|
|
|
|
urlsafe_b64encode(os.urandom(32)) + '\n',
|
|
|
|
)
|
|
|
|
|
2009-06-01 21:06:04 +00:00
|
|
|
def init_client_storage_broker(self):
|
|
|
|
# create a StorageFarmBroker object, for use by Uploader/Downloader
|
|
|
|
# (and everybody else who wants to use storage servers)
|
2015-12-01 18:47:50 +00:00
|
|
|
ps = self.get_config("client", "peers.preferred", "").split(",")
|
|
|
|
preferred_peers = tuple([p.strip() for p in ps if p != ""])
|
2016-04-26 07:22:52 +00:00
|
|
|
sb = storage_client.StorageFarmBroker(self.tub, permute_peers=True, preferred_peers=preferred_peers)
|
2016-04-26 17:44:58 +00:00
|
|
|
self.storage_broker = sb
|
2015-04-28 20:03:45 +00:00
|
|
|
|
|
|
|
connection_threshold = min(self.encoding_params["k"],
|
|
|
|
self.encoding_params["happy"] + 1)
|
2016-04-26 17:44:58 +00:00
|
|
|
helper = storage_client.ConnectedEnough(sb, connection_threshold)
|
|
|
|
self.upload_ready_d = helper.when_connected_enough()
|
2009-06-01 21:06:04 +00:00
|
|
|
|
2009-06-23 02:10:47 +00:00
|
|
|
# load static server specifications from tahoe.cfg, if any.
|
|
|
|
# Not quite ready yet.
|
2009-06-01 21:06:04 +00:00
|
|
|
#if self.config.has_section("client-server-selection"):
|
|
|
|
# server_params = {} # maps serverid to dict of parameters
|
|
|
|
# for (name, value) in self.config.items("client-server-selection"):
|
|
|
|
# pieces = name.split(".")
|
|
|
|
# if pieces[0] == "server":
|
|
|
|
# serverid = pieces[1]
|
|
|
|
# if serverid not in server_params:
|
|
|
|
# server_params[serverid] = {}
|
|
|
|
# server_params[serverid][pieces[2]] = value
|
|
|
|
# for serverid, params in server_params.items():
|
|
|
|
# server_type = params.pop("type")
|
|
|
|
# if server_type == "tahoe-foolscap":
|
|
|
|
# s = storage_client.NativeStorageClient(*params)
|
|
|
|
# else:
|
|
|
|
# msg = ("unrecognized server type '%s' in "
|
|
|
|
# "tahoe.cfg [client-server-selection]server.%s.type"
|
|
|
|
# % (server_type, serverid))
|
|
|
|
# raise storage_client.UnknownServerTypeError(msg)
|
|
|
|
# sb.add_server(s.serverid, s)
|
|
|
|
|
|
|
|
# check to see if we're supposed to use the introducer too
|
|
|
|
if self.get_config("client-server-selection", "use_introducer",
|
|
|
|
default=True, boolean=True):
|
|
|
|
sb.use_introducer(self.introducer_client)
|
|
|
|
|
2009-06-02 02:25:11 +00:00
|
|
|
def get_storage_broker(self):
|
|
|
|
return self.storage_broker
|
|
|
|
|
2011-08-24 15:59:28 +00:00
|
|
|
def init_blacklist(self):
|
|
|
|
fn = os.path.join(self.basedir, "access.blacklist")
|
|
|
|
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):
|
2011-10-13 16:32:29 +00:00
|
|
|
default = self.get_config("client", "mutable.format", default="SDMF")
|
|
|
|
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)
|
|
|
|
control_url = self.tub.registerReference(c)
|
|
|
|
self.write_private_config("control.furl", control_url + "\n")
|
2007-07-04 00:27:07 +00:00
|
|
|
|
2008-02-06 02:58:38 +00:00
|
|
|
def init_helper(self):
|
2016-04-27 04:54:45 +00:00
|
|
|
self.helper = Helper(os.path.join(self.basedir, "helper"),
|
|
|
|
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.
|
|
|
|
helper_furlfile = os.path.join(self.basedir,
|
|
|
|
"private", "helper.furl").encode(get_filesystem_encoding())
|
|
|
|
self.tub.registerReference(self.helper, furlFile=helper_furlfile)
|
2007-08-10 01:30:24 +00:00
|
|
|
|
2008-04-02 01:45:13 +00:00
|
|
|
def init_key_gen(self, key_gen_furl):
|
2016-04-27 04:54:45 +00:00
|
|
|
self.tub.connectTo(key_gen_furl, self._got_key_generator)
|
2008-04-02 01:45:13 +00:00
|
|
|
|
|
|
|
def _got_key_generator(self, key_generator):
|
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.set_remote_generator(key_generator)
|
2008-04-02 01:45:13 +00:00
|
|
|
key_generator.notifyOnDisconnect(self._lost_key_generator)
|
|
|
|
|
|
|
|
def _lost_key_generator(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
|
|
|
self._key_generator.set_remote_generator(None)
|
|
|
|
|
|
|
|
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
|
2008-01-08 01:04:56 +00:00
|
|
|
nodeurl_path = os.path.join(self.basedir, "node.url")
|
2015-01-30 00:50:18 +00:00
|
|
|
staticdir_config = self.get_config("node", "web.static", "public_html").decode("utf-8")
|
|
|
|
staticdir = abspath_expanduser_unicode(staticdir_config, base=self.basedir)
|
2009-02-20 19:15:54 +00:00
|
|
|
ws = WebishServer(self, webport, nodeurl_path, staticdir)
|
2007-08-22 21:54:34 +00:00
|
|
|
self.add_service(ws)
|
|
|
|
|
2008-10-06 19:52:36 +00:00
|
|
|
def init_ftp_server(self):
|
2008-10-07 01:06:05 +00:00
|
|
|
if self.get_config("ftpd", "enabled", False, boolean=True):
|
2015-03-24 17:10:00 +00:00
|
|
|
accountfile = from_utf8_or_none(
|
|
|
|
self.get_config("ftpd", "accounts.file", None))
|
|
|
|
if accountfile:
|
|
|
|
accountfile = abspath_expanduser_unicode(accountfile, base=self.basedir)
|
2008-11-06 02:34:42 +00:00
|
|
|
accounturl = self.get_config("ftpd", "accounts.url", None)
|
|
|
|
ftp_portstr = self.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):
|
|
|
|
if self.get_config("sftpd", "enabled", False, boolean=True):
|
2015-03-24 17:10:00 +00:00
|
|
|
accountfile = from_utf8_or_none(
|
|
|
|
self.get_config("sftpd", "accounts.file", None))
|
|
|
|
if accountfile:
|
|
|
|
accountfile = abspath_expanduser_unicode(accountfile, base=self.basedir)
|
2008-11-06 02:34:42 +00:00
|
|
|
accounturl = self.get_config("sftpd", "accounts.url", None)
|
|
|
|
sftp_portstr = self.get_config("sftpd", "port", "8022")
|
2015-03-03 20:06:35 +00:00
|
|
|
pubkey_file = from_utf8_or_none(self.get_config("sftpd", "host_pubkey_file"))
|
|
|
|
privkey_file = from_utf8_or_none(self.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)
|
|
|
|
|
2011-08-08 23:40:49 +00:00
|
|
|
def init_drop_uploader(self):
|
|
|
|
if self.get_config("drop_upload", "enabled", False, boolean=True):
|
2011-11-20 23:24:26 +00:00
|
|
|
if self.get_config("drop_upload", "upload.dircap", None):
|
|
|
|
raise OldConfigOptionError("The [drop_upload]upload.dircap option is no longer supported; please "
|
|
|
|
"put the cap in a 'private/drop_upload_dircap' file, and delete this option.")
|
|
|
|
|
|
|
|
upload_dircap = self.get_or_create_private_config("drop_upload_dircap")
|
|
|
|
local_dir_utf8 = self.get_config("drop_upload", "local.directory")
|
|
|
|
|
|
|
|
try:
|
|
|
|
from allmydata.frontends import drop_upload
|
|
|
|
s = drop_upload.DropUploader(self, upload_dircap, local_dir_utf8)
|
|
|
|
s.setServiceParent(self)
|
|
|
|
s.startService()
|
2015-04-28 20:03:45 +00:00
|
|
|
|
|
|
|
# start processing the upload queue when we've connected to enough servers
|
|
|
|
self.upload_ready_d.addCallback(s.upload_ready)
|
2011-11-20 23:24:26 +00:00
|
|
|
except Exception, e:
|
|
|
|
self.log("couldn't start drop-uploader: %r", args=(e,))
|
2011-08-08 23:40:49 +00:00
|
|
|
|
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
|
|
|
|
2007-06-10 04:03:57 +00:00
|
|
|
def connected_to_introducer(self):
|
|
|
|
if self.introducer_client:
|
|
|
|
return self.introducer_client.connected_to_introducer()
|
|
|
|
return False
|
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
|
|
|
|
2008-01-16 10:03:35 +00:00
|
|
|
def upload(self, uploadable):
|
2007-11-09 09:54:51 +00:00
|
|
|
uploader = self.getServiceNamed("uploader")
|
2011-08-29 06:32:46 +00:00
|
|
|
return uploader.upload(uploadable)
|