2006-12-02 02:17:50 +00:00
|
|
|
|
2007-01-05 04:52:51 +00:00
|
|
|
from zope.interface import Interface
|
2007-04-14 02:04:38 +00:00
|
|
|
from foolscap.schema import StringConstraint, ListOf, TupleOf, SetOf, DictOf, \
|
2008-03-11 17:50:31 +00:00
|
|
|
ChoiceOf, IntegerConstraint
|
2007-06-15 07:37:32 +00:00
|
|
|
from foolscap import RemoteInterface, Referenceable
|
2006-12-02 02:17:50 +00:00
|
|
|
|
2007-03-30 03:19:52 +00:00
|
|
|
HASH_SIZE=32
|
|
|
|
|
2007-04-04 22:59:36 +00:00
|
|
|
Hash = StringConstraint(maxLength=HASH_SIZE,
|
|
|
|
minLength=HASH_SIZE)# binary format 32-byte SHA256 hash
|
|
|
|
Nodeid = StringConstraint(maxLength=20,
|
|
|
|
minLength=20) # binary format 20-byte SHA1 hash
|
2007-05-22 21:08:30 +00:00
|
|
|
FURL = StringConstraint(1000)
|
2007-07-23 02:48:44 +00:00
|
|
|
StorageIndex = StringConstraint(16)
|
2007-04-27 01:08:29 +00:00
|
|
|
URI = StringConstraint(300) # kind of arbitrary
|
2007-12-18 20:15:08 +00:00
|
|
|
|
2007-04-04 22:59:36 +00:00
|
|
|
MAX_BUCKETS = 200 # per peer
|
2007-09-11 18:29:18 +00:00
|
|
|
|
2008-04-12 05:51:54 +00:00
|
|
|
ShareData = StringConstraint(None)
|
2007-06-08 22:59:16 +00:00
|
|
|
URIExtensionData = StringConstraint(1000)
|
2008-03-11 17:50:31 +00:00
|
|
|
Number = IntegerConstraint(8) # 2**(8*8) == 16EiB ~= 18e18 ~= 18 exabytes
|
|
|
|
Offset = Number
|
2008-05-07 15:39:03 +00:00
|
|
|
ReadSize = int # the 'int' constraint is 2**31 == 2Gib -- large files are processed in not-so-large increments
|
2008-07-10 01:06:55 +00:00
|
|
|
WriteEnablerSecret = Hash # used to protect mutable bucket modifications
|
2007-08-28 00:28:51 +00:00
|
|
|
LeaseRenewSecret = Hash # used to protect bucket lease renewal requests
|
|
|
|
LeaseCancelSecret = Hash # used to protect bucket lease cancellation requests
|
|
|
|
|
2008-03-12 02:20:10 +00:00
|
|
|
class RIStubClient(RemoteInterface):
|
|
|
|
"""Each client publishes a service announcement for a dummy object called
|
|
|
|
the StubClient. This object doesn't actually offer any services, but the
|
|
|
|
announcement helps the Introducer keep track of which clients are
|
|
|
|
subscribed (so the grid admin can keep track of things like the size of
|
|
|
|
the grid and the client versions in use. This is the (empty)
|
|
|
|
RemoteInterface for the StubClient."""
|
2006-12-02 02:17:50 +00:00
|
|
|
|
|
|
|
class RIBucketWriter(RemoteInterface):
|
2008-03-11 17:50:31 +00:00
|
|
|
def write(offset=Offset, data=ShareData):
|
2007-07-13 21:04:49 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def close():
|
|
|
|
"""
|
|
|
|
If the data that has been written is incomplete or inconsistent then
|
|
|
|
the server will throw the data away, else it will store it for future
|
|
|
|
retrieval.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2008-01-15 04:22:55 +00:00
|
|
|
def abort():
|
|
|
|
"""Abandon all the data that has been written.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2007-07-13 21:04:49 +00:00
|
|
|
class RIBucketReader(RemoteInterface):
|
2008-03-11 17:50:31 +00:00
|
|
|
def read(offset=Offset, length=ReadSize):
|
2007-07-13 21:04:49 +00:00
|
|
|
return ShareData
|
|
|
|
|
2008-03-11 17:50:31 +00:00
|
|
|
TestVector = ListOf(TupleOf(Offset, ReadSize, str, str))
|
2007-10-31 02:47:36 +00:00
|
|
|
# elements are (offset, length, operator, specimen)
|
2007-11-06 03:17:14 +00:00
|
|
|
# operator is one of "lt, le, eq, ne, ge, gt"
|
2007-10-31 02:47:36 +00:00
|
|
|
# nop always passes and is used to fetch data while writing.
|
|
|
|
# you should use length==len(specimen) for everything except nop
|
2008-03-11 17:50:31 +00:00
|
|
|
DataVector = ListOf(TupleOf(Offset, ShareData))
|
2007-10-31 02:47:36 +00:00
|
|
|
# (offset, data). This limits us to 30 writes of 1MiB each per call
|
2007-11-06 03:17:14 +00:00
|
|
|
TestAndWriteVectorsForShares = DictOf(int,
|
|
|
|
TupleOf(TestVector,
|
|
|
|
DataVector,
|
2008-03-11 17:50:31 +00:00
|
|
|
ChoiceOf(None, Offset), # new_length
|
|
|
|
))
|
|
|
|
ReadVector = ListOf(TupleOf(Offset, ReadSize))
|
2007-11-06 03:17:14 +00:00
|
|
|
ReadData = ListOf(ShareData)
|
2007-10-31 02:47:36 +00:00
|
|
|
# returns data[offset:offset+length] for each element of TestVector
|
|
|
|
|
2007-07-13 21:04:49 +00:00
|
|
|
class RIStorageServer(RemoteInterface):
|
2008-02-05 20:05:13 +00:00
|
|
|
__remote_name__ = "RIStorageServer.tahoe.allmydata.com"
|
|
|
|
|
|
|
|
def get_versions():
|
|
|
|
"""Return a tuple of (my_version, oldest_supported) strings.
|
|
|
|
Each string can be parsed by an allmydata.util.version.Version
|
|
|
|
instance, and then compared. The first goal is to make sure that
|
|
|
|
nodes are not confused by speaking to an incompatible peer. The
|
|
|
|
second goal is to enable the development of backwards-compatibility
|
|
|
|
code.
|
|
|
|
|
|
|
|
This method is likely to change in incompatible ways until we get the
|
|
|
|
whole compatibility scheme nailed down.
|
|
|
|
"""
|
|
|
|
return TupleOf(str, str)
|
|
|
|
|
2007-07-13 21:04:49 +00:00
|
|
|
def allocate_buckets(storage_index=StorageIndex,
|
2007-08-28 00:28:51 +00:00
|
|
|
renew_secret=LeaseRenewSecret,
|
|
|
|
cancel_secret=LeaseCancelSecret,
|
2007-07-13 21:04:49 +00:00
|
|
|
sharenums=SetOf(int, maxLength=MAX_BUCKETS),
|
2008-03-11 17:50:31 +00:00
|
|
|
allocated_size=Offset, canary=Referenceable):
|
2007-07-13 21:04:49 +00:00
|
|
|
"""
|
2007-08-28 00:28:51 +00:00
|
|
|
@param storage_index: the index of the bucket to be created or
|
|
|
|
increfed.
|
|
|
|
@param sharenums: these are the share numbers (probably between 0 and
|
|
|
|
99) that the sender is proposing to store on this
|
|
|
|
server.
|
|
|
|
@param renew_secret: This is the secret used to protect bucket refresh
|
|
|
|
This secret is generated by the client and
|
|
|
|
stored for later comparison by the server. Each
|
|
|
|
server is given a different secret.
|
|
|
|
@param cancel_secret: Like renew_secret, but protects bucket decref.
|
|
|
|
@param canary: If the canary is lost before close(), the bucket is
|
|
|
|
deleted.
|
2007-07-13 21:04:49 +00:00
|
|
|
@return: tuple of (alreadygot, allocated), where alreadygot is what we
|
2007-08-28 00:28:51 +00:00
|
|
|
already have and is what we hereby agree to accept. New
|
|
|
|
leases are added for shares in both lists.
|
2007-07-13 21:04:49 +00:00
|
|
|
"""
|
|
|
|
return TupleOf(SetOf(int, maxLength=MAX_BUCKETS),
|
|
|
|
DictOf(int, RIBucketWriter, maxKeys=MAX_BUCKETS))
|
2007-08-28 06:41:40 +00:00
|
|
|
|
2008-07-10 01:06:55 +00:00
|
|
|
def add_lease(storage_index=StorageIndex,
|
|
|
|
renew_secret=LeaseRenewSecret,
|
|
|
|
cancel_secret=LeaseCancelSecret):
|
|
|
|
"""
|
|
|
|
Add a new lease on the given bucket. If the renew_secret matches an
|
|
|
|
existing lease, that lease will be renewed instead.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2007-08-28 06:41:40 +00:00
|
|
|
def renew_lease(storage_index=StorageIndex, renew_secret=LeaseRenewSecret):
|
|
|
|
"""
|
|
|
|
Renew the lease on a given bucket. Some networks will use this, some
|
|
|
|
will not.
|
|
|
|
"""
|
2008-07-10 01:06:55 +00:00
|
|
|
return None
|
2007-08-28 06:41:40 +00:00
|
|
|
|
|
|
|
def cancel_lease(storage_index=StorageIndex,
|
|
|
|
cancel_secret=LeaseCancelSecret):
|
|
|
|
"""
|
|
|
|
Cancel the lease on a given bucket. If this was the last lease on the
|
|
|
|
bucket, the bucket will be deleted.
|
|
|
|
"""
|
2008-07-10 01:06:55 +00:00
|
|
|
return None
|
2007-08-28 06:41:40 +00:00
|
|
|
|
2007-07-13 21:04:49 +00:00
|
|
|
def get_buckets(storage_index=StorageIndex):
|
|
|
|
return DictOf(int, RIBucketReader, maxKeys=MAX_BUCKETS)
|
|
|
|
|
|
|
|
|
2007-11-06 03:17:14 +00:00
|
|
|
|
|
|
|
def slot_readv(storage_index=StorageIndex,
|
|
|
|
shares=ListOf(int), readv=ReadVector):
|
|
|
|
"""Read a vector from the numbered shares associated with the given
|
|
|
|
storage index. An empty shares list means to return data from all
|
|
|
|
known shares. Returns a dictionary with one key per share."""
|
2007-11-07 21:19:01 +00:00
|
|
|
return DictOf(int, ReadData) # shnum -> results
|
2007-11-06 03:17:14 +00:00
|
|
|
|
|
|
|
def slot_testv_and_readv_and_writev(storage_index=StorageIndex,
|
2008-07-10 01:06:55 +00:00
|
|
|
secrets=TupleOf(WriteEnablerSecret,
|
|
|
|
LeaseRenewSecret,
|
|
|
|
LeaseCancelSecret),
|
2007-11-06 03:17:14 +00:00
|
|
|
tw_vectors=TestAndWriteVectorsForShares,
|
|
|
|
r_vector=ReadVector,
|
|
|
|
):
|
|
|
|
"""General-purpose test-and-set operation for mutable slots. Perform
|
|
|
|
a bunch of comparisons against the existing shares. If they all pass,
|
|
|
|
then apply a bunch of write vectors to those shares. Then use the
|
|
|
|
read vectors to extract data from all the shares and return the data.
|
|
|
|
|
|
|
|
This method is, um, large. The goal is to allow clients to update all
|
|
|
|
the shares associated with a mutable file in a single round trip.
|
|
|
|
|
2007-10-31 02:47:36 +00:00
|
|
|
@param storage_index: the index of the bucket to be created or
|
|
|
|
increfed.
|
|
|
|
@param write_enabler: a secret that is stored along with the slot.
|
|
|
|
Writes are accepted from any caller who can
|
|
|
|
present the matching secret. A different secret
|
|
|
|
should be used for each slot*server pair.
|
|
|
|
@param renew_secret: This is the secret used to protect bucket refresh
|
|
|
|
This secret is generated by the client and
|
|
|
|
stored for later comparison by the server. Each
|
|
|
|
server is given a different secret.
|
|
|
|
@param cancel_secret: Like renew_secret, but protects bucket decref.
|
|
|
|
|
2007-11-06 03:17:14 +00:00
|
|
|
The 'secrets' argument is a tuple of (write_enabler, renew_secret,
|
|
|
|
cancel_secret). The first is required to perform any write. The
|
|
|
|
latter two are used when allocating new shares. To simply acquire a
|
|
|
|
new lease on existing shares, use an empty testv and an empty writev.
|
|
|
|
|
|
|
|
Each share can have a separate test vector (i.e. a list of
|
|
|
|
comparisons to perform). If all vectors for all shares pass, then all
|
|
|
|
writes for all shares are recorded. Each comparison is a 4-tuple of
|
2007-11-07 01:53:34 +00:00
|
|
|
(offset, length, operator, specimen), which effectively does a bool(
|
|
|
|
(read(offset, length)) OPERATOR specimen ) and only performs the
|
|
|
|
write if all these evaluate to True. Basic test-and-set uses 'eq'.
|
|
|
|
Write-if-newer uses a seqnum and (offset, length, 'lt', specimen).
|
|
|
|
Write-if-same-or-newer uses 'le'.
|
|
|
|
|
|
|
|
Reads from the end of the container are truncated, and missing shares
|
|
|
|
behave like empty ones, so to assert that a share doesn't exist (for
|
|
|
|
use when creating a new share), use (0, 1, 'eq', '').
|
2007-11-06 03:17:14 +00:00
|
|
|
|
|
|
|
The write vector will be applied to the given share, expanding it if
|
|
|
|
necessary. A write vector applied to a share number that did not
|
|
|
|
exist previously will cause that share to be created.
|
|
|
|
|
|
|
|
Each write vector is accompanied by a 'new_length' argument. If
|
|
|
|
new_length is not None, use it to set the size of the container. This
|
|
|
|
can be used to pre-allocate space for a series of upcoming writes, or
|
|
|
|
truncate existing data. If the container is growing, new_length will
|
|
|
|
be applied before datav. If the container is shrinking, it will be
|
|
|
|
applied afterwards.
|
|
|
|
|
|
|
|
The read vector is used to extract data from all known shares,
|
|
|
|
*before* any writes have been applied. The same vector is used for
|
|
|
|
all shares. This captures the state that was tested by the test
|
|
|
|
vector.
|
|
|
|
|
|
|
|
This method returns two values: a boolean and a dict. The boolean is
|
|
|
|
True if the write vectors were applied, False if not. The dict is
|
|
|
|
keyed by share number, and each value contains a list of strings, one
|
|
|
|
for each element of the read vector.
|
2007-10-31 02:47:36 +00:00
|
|
|
|
2007-11-06 03:17:14 +00:00
|
|
|
If the write_enabler is wrong, this will raise BadWriteEnablerError.
|
2008-07-10 01:06:55 +00:00
|
|
|
To enable share migration (using update_write_enabler), the exception
|
|
|
|
will have the nodeid used for the old write enabler embedded in it,
|
|
|
|
in the following string::
|
2007-10-31 02:47:36 +00:00
|
|
|
|
2007-11-06 03:17:14 +00:00
|
|
|
The write enabler was recorded by nodeid '%s'.
|
2007-10-31 02:47:36 +00:00
|
|
|
|
2007-11-07 01:49:59 +00:00
|
|
|
Note that the nodeid here is encoded using the same base32 encoding
|
|
|
|
used by Foolscap and allmydata.util.idlib.nodeid_b2a().
|
|
|
|
|
2007-11-06 03:17:14 +00:00
|
|
|
"""
|
|
|
|
return TupleOf(bool, DictOf(int, ReadData))
|
2007-10-31 02:47:36 +00:00
|
|
|
|
2008-07-10 01:06:55 +00:00
|
|
|
def update_write_enabler(storage_index=StorageIndex,
|
|
|
|
old_write_enabler=WriteEnablerSecret,
|
|
|
|
new_write_enabler=WriteEnablerSecret):
|
|
|
|
"""
|
|
|
|
Replace the write-enabler on a given bucket. This is used when a
|
|
|
|
share has been moved from one server to another, causing the secret
|
|
|
|
(which is scoped to a given server's nodeid) to become invalid. The
|
|
|
|
client discovers this when it gets a BadWriteEnablerError, and the
|
|
|
|
string body of the exception will contain a message that includes the
|
|
|
|
nodeid that was used for the old secret.
|
|
|
|
|
|
|
|
The client should compute the old write-enabler secret, and send it
|
|
|
|
in conjunction with the new one. The server will then update the
|
|
|
|
share to record the new write-enabler instead of the old one. The
|
|
|
|
client can then retry its writev call.
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
2007-07-13 21:04:49 +00:00
|
|
|
class IStorageBucketWriter(Interface):
|
2007-03-30 03:19:52 +00:00
|
|
|
def put_block(segmentnum=int, data=ShareData):
|
2007-03-30 23:50:50 +00:00
|
|
|
"""@param data: For most segments, this data will be 'blocksize'
|
|
|
|
bytes in length. The last segment might be shorter.
|
2007-07-25 02:43:21 +00:00
|
|
|
@return: a Deferred that fires (with None) when the operation completes
|
2007-03-30 23:50:50 +00:00
|
|
|
"""
|
2007-06-07 02:40:20 +00:00
|
|
|
|
|
|
|
def put_plaintext_hashes(hashes=ListOf(Hash, maxLength=2**20)):
|
2007-07-25 02:43:21 +00:00
|
|
|
"""
|
|
|
|
@return: a Deferred that fires (with None) when the operation completes
|
|
|
|
"""
|
|
|
|
|
2007-06-07 02:40:20 +00:00
|
|
|
def put_crypttext_hashes(hashes=ListOf(Hash, maxLength=2**20)):
|
2007-07-25 02:43:21 +00:00
|
|
|
"""
|
|
|
|
@return: a Deferred that fires (with None) when the operation completes
|
|
|
|
"""
|
2007-06-07 02:40:20 +00:00
|
|
|
|
2007-04-30 06:51:15 +00:00
|
|
|
def put_block_hashes(blockhashes=ListOf(Hash, maxLength=2**20)):
|
2007-07-25 02:43:21 +00:00
|
|
|
"""
|
|
|
|
@return: a Deferred that fires (with None) when the operation completes
|
|
|
|
"""
|
2007-11-01 22:22:57 +00:00
|
|
|
|
2007-07-25 02:43:21 +00:00
|
|
|
def put_share_hashes(sharehashes=ListOf(TupleOf(int, Hash),
|
|
|
|
maxLength=2**20)):
|
|
|
|
"""
|
|
|
|
@return: a Deferred that fires (with None) when the operation completes
|
|
|
|
"""
|
2007-03-30 03:19:52 +00:00
|
|
|
|
2007-06-08 22:59:16 +00:00
|
|
|
def put_uri_extension(data=URIExtensionData):
|
|
|
|
"""This block of data contains integrity-checking information (hashes
|
|
|
|
of plaintext, crypttext, and shares), as well as encoding parameters
|
|
|
|
that are necessary to recover the data. This is a serialized dict
|
|
|
|
mapping strings to other strings. The hash of this data is kept in
|
|
|
|
the URI and verified before any of the data is used. All buckets for
|
|
|
|
a given file contain identical copies of this data.
|
2007-06-08 23:17:54 +00:00
|
|
|
|
|
|
|
The serialization format is specified with the following pseudocode:
|
|
|
|
for k in sorted(dict.keys()):
|
|
|
|
assert re.match(r'^[a-zA-Z_\-]+$', k)
|
|
|
|
write(k + ':' + netstring(dict[k]))
|
2007-07-25 02:43:21 +00:00
|
|
|
|
|
|
|
@return: a Deferred that fires (with None) when the operation completes
|
2007-06-02 01:48:01 +00:00
|
|
|
"""
|
2007-07-25 02:43:21 +00:00
|
|
|
|
2006-12-02 02:17:50 +00:00
|
|
|
def close():
|
2007-07-25 02:43:21 +00:00
|
|
|
"""Finish writing and close the bucket. The share is not finalized
|
|
|
|
until this method is called: if the uploading client disconnects
|
|
|
|
before calling close(), the partially-written share will be
|
|
|
|
discarded.
|
|
|
|
|
|
|
|
@return: a Deferred that fires (with None) when the operation completes
|
|
|
|
"""
|
2007-07-13 21:04:49 +00:00
|
|
|
|
|
|
|
class IStorageBucketReader(Interface):
|
2006-12-02 02:17:50 +00:00
|
|
|
|
2007-03-30 03:19:52 +00:00
|
|
|
def get_block(blocknum=int):
|
2007-03-30 23:50:50 +00:00
|
|
|
"""Most blocks will be the same size. The last block might be shorter
|
|
|
|
than the others.
|
2007-07-25 02:43:21 +00:00
|
|
|
|
|
|
|
@return: ShareData
|
2007-03-30 23:50:50 +00:00
|
|
|
"""
|
2007-06-07 07:15:41 +00:00
|
|
|
|
|
|
|
def get_plaintext_hashes():
|
2007-07-25 02:43:21 +00:00
|
|
|
"""
|
|
|
|
@return: ListOf(Hash, maxLength=2**20)
|
|
|
|
"""
|
|
|
|
|
2007-06-07 07:15:41 +00:00
|
|
|
def get_crypttext_hashes():
|
2007-07-25 02:43:21 +00:00
|
|
|
"""
|
|
|
|
@return: ListOf(Hash, maxLength=2**20)
|
|
|
|
"""
|
2007-06-07 07:15:41 +00:00
|
|
|
|
2007-03-30 03:19:52 +00:00
|
|
|
def get_block_hashes():
|
2007-07-25 02:43:21 +00:00
|
|
|
"""
|
|
|
|
@return: ListOf(Hash, maxLength=2**20)
|
|
|
|
"""
|
|
|
|
|
2007-03-30 03:19:52 +00:00
|
|
|
def get_share_hashes():
|
2007-07-25 02:43:21 +00:00
|
|
|
"""
|
|
|
|
@return: ListOf(TupleOf(int, Hash), maxLength=2**20)
|
|
|
|
"""
|
|
|
|
|
2007-06-08 22:59:16 +00:00
|
|
|
def get_uri_extension():
|
2007-07-25 02:43:21 +00:00
|
|
|
"""
|
|
|
|
@return: URIExtensionData
|
|
|
|
"""
|
2007-06-02 01:48:01 +00:00
|
|
|
|
2006-12-03 00:25:57 +00:00
|
|
|
|
2007-07-09 06:27:46 +00:00
|
|
|
|
2007-04-04 22:59:36 +00:00
|
|
|
# hm, we need a solution for forward references in schemas
|
|
|
|
from foolscap.schema import Any
|
2007-06-15 03:14:34 +00:00
|
|
|
|
|
|
|
FileNode_ = Any() # TODO: foolscap needs constraints on copyables
|
|
|
|
DirectoryNode_ = Any() # TODO: same
|
|
|
|
AnyNode_ = ChoiceOf(FileNode_, DirectoryNode_)
|
2007-06-25 20:23:51 +00:00
|
|
|
EncryptedThing = str
|
2007-06-15 03:14:34 +00:00
|
|
|
|
2007-07-21 22:40:36 +00:00
|
|
|
class IURI(Interface):
|
|
|
|
def init_from_string(uri):
|
|
|
|
"""Accept a string (as created by my to_string() method) and populate
|
|
|
|
this instance with its data. I am not normally called directly,
|
|
|
|
please use the module-level uri.from_string() function to convert
|
|
|
|
arbitrary URI strings into IURI-providing instances."""
|
|
|
|
|
|
|
|
def is_readonly():
|
|
|
|
"""Return False if this URI be used to modify the data. Return True
|
|
|
|
if this URI cannot be used to modify the data."""
|
|
|
|
|
|
|
|
def is_mutable():
|
|
|
|
"""Return True if the data can be modified by *somebody* (perhaps
|
|
|
|
someone who has a more powerful URI than this one)."""
|
|
|
|
|
|
|
|
def get_readonly():
|
|
|
|
"""Return another IURI instance, which represents a read-only form of
|
|
|
|
this one. If is_readonly() is True, this returns self."""
|
|
|
|
|
2007-10-15 23:16:39 +00:00
|
|
|
def get_verifier():
|
|
|
|
"""Return an instance that provides IVerifierURI, which can be used
|
|
|
|
to check on the availability of the file or directory, without
|
|
|
|
providing enough capabilities to actually read or modify the
|
|
|
|
contents. This may return None if the file does not need checking or
|
|
|
|
verification (e.g. LIT URIs).
|
|
|
|
"""
|
|
|
|
|
|
|
|
def to_string():
|
|
|
|
"""Return a string of printable ASCII characters, suitable for
|
|
|
|
passing into init_from_string."""
|
|
|
|
|
|
|
|
class IVerifierURI(Interface):
|
|
|
|
def init_from_string(uri):
|
|
|
|
"""Accept a string (as created by my to_string() method) and populate
|
|
|
|
this instance with its data. I am not normally called directly,
|
|
|
|
please use the module-level uri.from_string() function to convert
|
|
|
|
arbitrary URI strings into IURI-providing instances."""
|
|
|
|
|
2007-07-21 22:40:36 +00:00
|
|
|
def to_string():
|
|
|
|
"""Return a string of printable ASCII characters, suitable for
|
|
|
|
passing into init_from_string."""
|
|
|
|
|
|
|
|
class IDirnodeURI(Interface):
|
|
|
|
"""I am a URI which represents a dirnode."""
|
|
|
|
|
2007-10-15 23:16:39 +00:00
|
|
|
|
2007-07-21 22:40:36 +00:00
|
|
|
class IFileURI(Interface):
|
|
|
|
"""I am a URI which represents a filenode."""
|
|
|
|
def get_size():
|
|
|
|
"""Return the length (in bytes) of the file that I represent."""
|
|
|
|
|
2007-11-01 22:15:29 +00:00
|
|
|
class IMutableFileURI(Interface):
|
|
|
|
"""I am a URI which represents a mutable filenode."""
|
|
|
|
class INewDirectoryURI(Interface):
|
|
|
|
pass
|
2007-12-03 21:52:42 +00:00
|
|
|
class IReadonlyNewDirectoryURI(Interface):
|
|
|
|
pass
|
2007-11-01 22:15:29 +00:00
|
|
|
|
2007-07-21 22:40:36 +00:00
|
|
|
|
2007-12-03 21:52:42 +00:00
|
|
|
class IFilesystemNode(Interface):
|
|
|
|
def get_uri():
|
|
|
|
"""
|
|
|
|
Return the URI that can be used by others to get access to this
|
|
|
|
node. If this node is read-only, the URI will only offer read-only
|
|
|
|
access. If this node is read-write, the URI will offer read-write
|
|
|
|
access.
|
|
|
|
|
|
|
|
If you have read-write access to a node and wish to share merely
|
|
|
|
read-only access with others, use get_readonly_uri().
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get_readonly_uri():
|
|
|
|
"""Return the directory URI that can be used by others to get
|
|
|
|
read-only access to this directory node. The result is a read-only
|
|
|
|
URI, regardless of whether this dirnode is read-only or read-write.
|
|
|
|
|
|
|
|
If you have merely read-only access to this dirnode,
|
|
|
|
get_readonly_uri() will return the same thing as get_uri().
|
|
|
|
"""
|
|
|
|
|
2007-12-05 06:01:37 +00:00
|
|
|
def get_verifier():
|
|
|
|
"""Return an IVerifierURI instance that represents the
|
|
|
|
'verifiy/refresh capability' for this node. The holder of this
|
|
|
|
capability will be able to renew the lease for this node, protecting
|
|
|
|
it from garbage-collection. They will also be able to ask a server if
|
|
|
|
it holds a share for the file or directory.
|
|
|
|
"""
|
|
|
|
|
2008-07-07 21:37:36 +00:00
|
|
|
def check(verify=False, repair=False):
|
|
|
|
"""Perform a file check. See IChecker.check for details.
|
|
|
|
|
|
|
|
The default mode is named 'check' and simply asks each server whether
|
|
|
|
or not it has a share, and believes the answers. If verify=True, this
|
|
|
|
switches into the 'verify' mode, in which every byte of every share
|
|
|
|
is retrieved, and all hashes are verified. This uses much more
|
|
|
|
network and disk bandwidth than simple checking, especially for large
|
|
|
|
files, but will catch disk errors.
|
|
|
|
|
|
|
|
The default repair=False argument means that files which are not
|
|
|
|
perfectly healthy will be reported, but not fixed. When repair=True,
|
|
|
|
the node will attempt to repair the file first. The results will
|
|
|
|
indicate the initial status of the file in either case. If repair was
|
|
|
|
attempted, the results will indicate that too.
|
|
|
|
"""
|
2007-12-05 06:01:37 +00:00
|
|
|
|
|
|
|
def is_readonly():
|
|
|
|
"""Return True if this reference provides mutable access to the given
|
|
|
|
file or directory (i.e. if you can modify it), or False if not. Note
|
|
|
|
that even if this reference is read-only, someone else may hold a
|
|
|
|
read-write reference to it."""
|
|
|
|
|
|
|
|
def is_mutable():
|
|
|
|
"""Return True if this file or directory is mutable (by *somebody*,
|
|
|
|
not necessarily you), False if it is is immutable. Note that a file
|
|
|
|
might be mutable overall, but your reference to it might be
|
|
|
|
read-only. On the other hand, all references to an immutable file
|
|
|
|
will be read-only; there are no read-write references to an immutable
|
|
|
|
file.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class IMutableFilesystemNode(IFilesystemNode):
|
|
|
|
pass
|
|
|
|
|
2007-12-03 21:52:42 +00:00
|
|
|
class IFileNode(IFilesystemNode):
|
|
|
|
def download(target):
|
|
|
|
"""Download the file's contents to a given IDownloadTarget"""
|
|
|
|
|
|
|
|
def download_to_data():
|
|
|
|
"""Download the file's contents. Return a Deferred that fires
|
|
|
|
with those contents."""
|
|
|
|
|
|
|
|
def get_size():
|
|
|
|
"""Return the length (in bytes) of the data this node represents."""
|
|
|
|
|
|
|
|
class IMutableFileNode(IFileNode, IMutableFilesystemNode):
|
2008-04-18 00:51:38 +00:00
|
|
|
"""I provide access to a 'mutable file', which retains its identity
|
|
|
|
regardless of what contents are put in it.
|
|
|
|
|
|
|
|
The consistency-vs-availability problem means that there might be
|
|
|
|
multiple versions of a file present in the grid, some of which might be
|
|
|
|
unrecoverable (i.e. have fewer than 'k' shares). These versions are
|
|
|
|
loosely ordered: each has a sequence number and a hash, and any version
|
|
|
|
with seqnum=N was uploaded by a node which has seen at least one version
|
|
|
|
with seqnum=N-1.
|
|
|
|
|
|
|
|
The 'servermap' (an instance of IMutableFileServerMap) is used to
|
|
|
|
describe the versions that are known to be present in the grid, and which
|
|
|
|
servers are hosting their shares. It is used to represent the 'state of
|
|
|
|
the world', and is used for this purpose by my test-and-set operations.
|
|
|
|
Downloading the contents of the mutable file will also return a
|
|
|
|
servermap. Uploading a new version into the mutable file requires a
|
|
|
|
servermap as input, and the semantics of the replace operation is
|
|
|
|
'replace the file with my new version if it looks like nobody else has
|
|
|
|
changed the file since my previous download'. Because the file is
|
|
|
|
distributed, this is not a perfect test-and-set operation, but it will do
|
|
|
|
its best. If the replace process sees evidence of a simultaneous write,
|
|
|
|
it will signal an UncoordinatedWriteError, so that the caller can take
|
|
|
|
corrective action.
|
|
|
|
|
|
|
|
|
|
|
|
Most readers will want to use the 'best' current version of the file, and
|
|
|
|
should use my 'download_best_version()' method.
|
|
|
|
|
|
|
|
To unconditionally replace the file, callers should use overwrite(). This
|
|
|
|
is the mode that user-visible mutable files will probably use.
|
|
|
|
|
|
|
|
To apply some delta to the file, call modify() with a callable modifier
|
|
|
|
function that can apply the modification that you want to make. This is
|
|
|
|
the mode that dirnodes will use, since most directory modification
|
|
|
|
operations can be expressed in terms of deltas to the directory state.
|
|
|
|
|
|
|
|
|
|
|
|
Three methods are available for users who need to perform more complex
|
|
|
|
operations. The first is get_servermap(), which returns an up-to-date
|
|
|
|
servermap using a specified mode. The second is download_version(), which
|
|
|
|
downloads a specific version (not necessarily the 'best' one). The third
|
|
|
|
is 'upload', which accepts new contents and a servermap (which must have
|
|
|
|
been updated with MODE_WRITE). The upload method will attempt to apply
|
|
|
|
the new contents as long as no other node has modified the file since the
|
|
|
|
servermap was updated. This might be useful to a caller who wants to
|
|
|
|
merge multiple versions into a single new one.
|
|
|
|
|
|
|
|
Note that each time the servermap is updated, a specific 'mode' is used,
|
|
|
|
which determines how many peers are queried. To use a servermap for my
|
|
|
|
replace() method, that servermap must have been updated in MODE_WRITE.
|
|
|
|
These modes are defined in allmydata.mutable.common, and consist of
|
|
|
|
MODE_READ, MODE_WRITE, MODE_ANYTHING, and MODE_CHECK. Please look in
|
|
|
|
allmydata/mutable/servermap.py for details about the differences.
|
|
|
|
|
|
|
|
Mutable files are currently limited in size (about 3.5MB max) and can
|
|
|
|
only be retrieved and updated all-at-once, as a single big string. Future
|
|
|
|
versions of our mutable files will remove this restriction.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def download_best_version():
|
|
|
|
"""Download the 'best' available version of the file, meaning one of
|
|
|
|
the recoverable versions with the highest sequence number. If no
|
|
|
|
uncoordinated writes have occurred, and if enough shares are
|
|
|
|
available, then this will be the most recent version that has been
|
|
|
|
uploaded.
|
|
|
|
|
|
|
|
I return a Deferred that fires with a (contents, servermap) pair. The
|
|
|
|
servermap is updated with MODE_READ. The contents will be the version
|
|
|
|
of the file indicated by servermap.best_recoverable_version(). If no
|
|
|
|
version is recoverable, the Deferred will errback with
|
|
|
|
UnrecoverableFileError.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def overwrite(new_contents):
|
|
|
|
"""Unconditionally replace the contents of the mutable file with new
|
|
|
|
ones. This simply chains get_servermap(MODE_WRITE) and upload(). This
|
|
|
|
is only appropriate to use when the new contents of the file are
|
|
|
|
completely unrelated to the old ones, and you do not care about other
|
|
|
|
clients' changes.
|
|
|
|
|
|
|
|
I return a Deferred that fires (with a PublishStatus object) when the
|
|
|
|
update has completed.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def modify(modifier_cb):
|
|
|
|
"""Modify the contents of the file, by downloading the current
|
|
|
|
version, applying the modifier function (or bound method), then
|
|
|
|
uploading the new version. I return a Deferred that fires (with a
|
|
|
|
PublishStatus object) when the update is complete.
|
|
|
|
|
|
|
|
The modifier callable will be given two arguments: a string (with the
|
|
|
|
old contents) and a servermap. As with download_best_version(), the
|
|
|
|
old contents will be from the best recoverable version, but the
|
|
|
|
modifier can use the servermap to make other decisions (such as
|
|
|
|
refusing to apply the delta if there are multiple parallel versions,
|
|
|
|
or if there is evidence of a newer unrecoverable version).
|
|
|
|
|
|
|
|
The callable should return a string with the new contents. The
|
|
|
|
callable must be prepared to be called multiple times, and must
|
|
|
|
examine the input string to see if the change that it wants to make
|
|
|
|
is already present in the old version. If it does not need to make
|
|
|
|
any changes, it can either return None, or return its input string.
|
|
|
|
|
|
|
|
If the modifier raises an exception, it will be returned in the
|
|
|
|
errback.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def get_servermap(mode):
|
|
|
|
"""Return a Deferred that fires with an IMutableFileServerMap
|
|
|
|
instance, updated using the given mode.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def download_version(servermap, version):
|
|
|
|
"""Download a specific version of the file, using the servermap
|
|
|
|
as a guide to where the shares are located.
|
|
|
|
|
|
|
|
I return a Deferred that fires with the requested contents, or
|
|
|
|
errbacks with UnrecoverableFileError. Note that a servermap which was
|
|
|
|
updated with MODE_ANYTHING or MODE_READ may not know about shares for
|
|
|
|
all versions (those modes stop querying servers as soon as they can
|
|
|
|
fulfil their goals), so you may want to use MODE_CHECK (which checks
|
|
|
|
everything) to get increased visibility.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def upload(new_contents, servermap):
|
|
|
|
"""Replace the contents of the file with new ones. This requires a
|
|
|
|
servermap that was previously updated with MODE_WRITE.
|
|
|
|
|
|
|
|
I attempt to provide test-and-set semantics, in that I will avoid
|
|
|
|
modifying any share that is different than the version I saw in the
|
|
|
|
servermap. However, if another node is writing to the file at the
|
|
|
|
same time as me, I may manage to update some shares while they update
|
|
|
|
others. If I see any evidence of this, I will signal
|
|
|
|
UncoordinatedWriteError, and the file will be left in an inconsistent
|
2008-03-13 01:00:43 +00:00
|
|
|
state (possibly the version you provided, possibly the old version,
|
|
|
|
possibly somebody else's version, and possibly a mix of shares from
|
2008-04-18 00:51:38 +00:00
|
|
|
all of these).
|
|
|
|
|
|
|
|
The recommended response to UncoordinatedWriteError is to either
|
|
|
|
return it to the caller (since they failed to coordinate their
|
|
|
|
writes), or to attempt some sort of recovery. It may be sufficient to
|
|
|
|
wait a random interval (with exponential backoff) and repeat your
|
|
|
|
operation. If I do not signal UncoordinatedWriteError, then I was
|
|
|
|
able to write the new version without incident.
|
|
|
|
|
|
|
|
I return a Deferred that fires (with a PublishStatus object) when the
|
|
|
|
publish has completed. I will update the servermap in-place with the
|
|
|
|
location of all new shares.
|
2007-11-01 22:15:29 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def get_writekey():
|
|
|
|
"""Return this filenode's writekey, or None if the node does not have
|
|
|
|
write-capability. This may be used to assist with data structures
|
|
|
|
that need to make certain data available only to writers, such as the
|
|
|
|
read-write child caps in dirnodes. The recommended process is to have
|
|
|
|
reader-visible data be submitted to the filenode in the clear (where
|
|
|
|
it will be encrypted by the filenode using the readkey), but encrypt
|
|
|
|
writer-visible data using this writekey.
|
|
|
|
"""
|
|
|
|
|
2008-05-16 23:09:47 +00:00
|
|
|
class ExistingChildError(Exception):
|
|
|
|
"""A directory node was asked to add or replace a child that already
|
|
|
|
exists, and overwrite= was set to False."""
|
|
|
|
|
2007-12-03 21:52:42 +00:00
|
|
|
class IDirectoryNode(IMutableFilesystemNode):
|
2008-02-14 22:45:56 +00:00
|
|
|
"""I represent a name-to-child mapping, holding the tahoe equivalent of a
|
|
|
|
directory. All child names are unicode strings, and all children are some
|
|
|
|
sort of IFilesystemNode (either files or subdirectories).
|
|
|
|
"""
|
|
|
|
|
2007-06-25 20:23:51 +00:00
|
|
|
def get_uri():
|
2007-12-03 21:52:42 +00:00
|
|
|
"""
|
2007-06-27 02:41:20 +00:00
|
|
|
The dirnode ('1') URI returned by this method can be used in
|
|
|
|
set_uri() on a different directory ('2') to 'mount' a reference to
|
|
|
|
this directory ('1') under the other ('2'). This URI is just a
|
|
|
|
string, so it can be passed around through email or other out-of-band
|
|
|
|
protocol.
|
2007-06-25 20:23:51 +00:00
|
|
|
"""
|
|
|
|
|
2007-12-03 21:52:42 +00:00
|
|
|
def get_readonly_uri():
|
2007-06-25 20:23:51 +00:00
|
|
|
"""
|
2007-12-03 21:52:42 +00:00
|
|
|
The dirnode ('1') URI returned by this method can be used in
|
|
|
|
set_uri() on a different directory ('2') to 'mount' a reference to
|
|
|
|
this directory ('1') under the other ('2'). This URI is just a
|
|
|
|
string, so it can be passed around through email or other out-of-band
|
|
|
|
protocol.
|
2007-06-27 02:41:20 +00:00
|
|
|
"""
|
|
|
|
|
2007-06-15 07:37:32 +00:00
|
|
|
def list():
|
2007-06-25 20:23:51 +00:00
|
|
|
"""I return a Deferred that fires with a dictionary mapping child
|
2008-02-14 22:45:56 +00:00
|
|
|
name (a unicode string) to (node, metadata_dict) tuples, in which
|
|
|
|
'node' is either an IFileNode or IDirectoryNode, and 'metadata_dict'
|
|
|
|
is a dictionary of metadata."""
|
2007-06-15 07:37:32 +00:00
|
|
|
|
2007-08-15 20:22:01 +00:00
|
|
|
def has_child(name):
|
|
|
|
"""I return a Deferred that fires with a boolean, True if there
|
2008-02-14 22:45:56 +00:00
|
|
|
exists a child of the given name, False if not. The child name must
|
|
|
|
be a unicode string."""
|
2007-08-15 20:22:01 +00:00
|
|
|
|
2007-06-15 07:37:32 +00:00
|
|
|
def get(name):
|
2007-06-25 20:23:51 +00:00
|
|
|
"""I return a Deferred that fires with a specific named child node,
|
2008-02-14 22:45:56 +00:00
|
|
|
either an IFileNode or an IDirectoryNode. The child name must be a
|
|
|
|
unicode string."""
|
2007-06-25 20:23:51 +00:00
|
|
|
|
2008-02-09 01:43:47 +00:00
|
|
|
def get_metadata_for(name):
|
|
|
|
"""I return a Deferred that fires with the metadata dictionary for a
|
|
|
|
specific named child node. This metadata is stored in the *edge*, not
|
|
|
|
in the child, so it is attached to the parent dirnode rather than the
|
2008-02-14 22:45:56 +00:00
|
|
|
child dir-or-file-node. The child name must be a unicode string."""
|
2008-02-09 01:43:47 +00:00
|
|
|
|
|
|
|
def set_metadata_for(name, metadata):
|
|
|
|
"""I replace any existing metadata for the named child with the new
|
2008-02-14 22:45:56 +00:00
|
|
|
metadata. The child name must be a unicode string. This metadata is
|
|
|
|
stored in the *edge*, not in the child, so it is attached to the
|
|
|
|
parent dirnode rather than the child dir-or-file-node. I return a
|
|
|
|
Deferred (that fires with this dirnode) when the operation is
|
|
|
|
complete."""
|
2008-02-09 01:43:47 +00:00
|
|
|
|
2007-07-07 02:38:37 +00:00
|
|
|
def get_child_at_path(path):
|
|
|
|
"""Transform a child path into an IDirectoryNode or IFileNode.
|
|
|
|
|
|
|
|
I perform a recursive series of 'get' operations to find the named
|
|
|
|
descendant node. I return a Deferred that fires with the node, or
|
|
|
|
errbacks with IndexError if the node could not be found.
|
|
|
|
|
|
|
|
The path can be either a single string (slash-separated) or a list of
|
2008-02-14 22:45:56 +00:00
|
|
|
path-name elements. All elements must be unicode strings.
|
2007-07-07 02:38:37 +00:00
|
|
|
"""
|
|
|
|
|
2008-05-16 23:09:47 +00:00
|
|
|
def set_uri(name, child_uri, metadata=None, overwrite=True):
|
2007-06-25 20:23:51 +00:00
|
|
|
"""I add a child (by URI) at the specific name. I return a Deferred
|
2008-05-16 23:09:47 +00:00
|
|
|
that fires when the operation finishes. If overwrite= is True, I will
|
|
|
|
replace any existing child of the same name, otherwise an existing
|
|
|
|
child will cause me to return ExistingChildError. The child name must
|
|
|
|
be a unicode string.
|
2007-06-25 20:23:51 +00:00
|
|
|
|
|
|
|
The child_uri could be for a file, or for a directory (either
|
|
|
|
read-write or read-only, using a URI that came from get_uri() ).
|
2007-06-15 07:37:32 +00:00
|
|
|
|
2008-02-09 01:43:47 +00:00
|
|
|
If metadata= is provided, I will use it as the metadata for the named
|
|
|
|
edge. This will replace any existing metadata. If metadata= is left
|
|
|
|
as the default value of None, I will set ['mtime'] to the current
|
|
|
|
time, and I will set ['ctime'] to the current time if there was not
|
|
|
|
already a child by this name present. This roughly matches the
|
|
|
|
ctime/mtime semantics of traditional filesystems.
|
|
|
|
|
2007-06-25 20:23:51 +00:00
|
|
|
If this directory node is read-only, the Deferred will errback with a
|
|
|
|
NotMutableError."""
|
|
|
|
|
2008-05-16 23:09:47 +00:00
|
|
|
def set_children(entries, overwrite=True):
|
2008-02-09 01:43:47 +00:00
|
|
|
"""Add multiple (name, child_uri) pairs (or (name, child_uri,
|
|
|
|
metadata) triples) to a directory node. Returns a Deferred that fires
|
|
|
|
(with None) when the operation finishes. This is equivalent to
|
2008-02-14 22:45:56 +00:00
|
|
|
calling set_uri() multiple times, but is much more efficient. All
|
|
|
|
child names must be unicode strings.
|
2007-12-19 06:30:02 +00:00
|
|
|
"""
|
|
|
|
|
2008-05-16 23:09:47 +00:00
|
|
|
def set_node(name, child, metadata=None, overwrite=True):
|
2007-06-15 07:37:32 +00:00
|
|
|
"""I add a child at the specific name. I return a Deferred that fires
|
2007-06-25 20:23:51 +00:00
|
|
|
when the operation finishes. This Deferred will fire with the child
|
2007-08-17 00:03:19 +00:00
|
|
|
node that was just added. I will replace any existing child of the
|
2008-02-14 22:45:56 +00:00
|
|
|
same name. The child name must be a unicode string.
|
2007-06-25 20:23:51 +00:00
|
|
|
|
2008-02-09 01:43:47 +00:00
|
|
|
If metadata= is provided, I will use it as the metadata for the named
|
|
|
|
edge. This will replace any existing metadata. If metadata= is left
|
|
|
|
as the default value of None, I will set ['mtime'] to the current
|
|
|
|
time, and I will set ['ctime'] to the current time if there was not
|
|
|
|
already a child by this name present. This roughly matches the
|
|
|
|
ctime/mtime semantics of traditional filesystems.
|
|
|
|
|
2007-06-25 20:23:51 +00:00
|
|
|
If this directory node is read-only, the Deferred will errback with a
|
|
|
|
NotMutableError."""
|
2007-06-15 07:37:32 +00:00
|
|
|
|
2008-05-16 23:09:47 +00:00
|
|
|
def set_nodes(entries, overwrite=True):
|
2008-02-09 01:43:47 +00:00
|
|
|
"""Add multiple (name, child_node) pairs (or (name, child_node,
|
|
|
|
metadata) triples) to a directory node. Returns a Deferred that fires
|
|
|
|
(with None) when the operation finishes. This is equivalent to
|
2008-02-14 22:45:56 +00:00
|
|
|
calling set_node() multiple times, but is much more efficient. All
|
|
|
|
child names must be unicode strings."""
|
2007-12-19 06:30:02 +00:00
|
|
|
|
|
|
|
|
2008-05-16 23:09:47 +00:00
|
|
|
def add_file(name, uploadable, metadata=None, overwrite=True):
|
2007-06-15 07:37:32 +00:00
|
|
|
"""I upload a file (using the given IUploadable), then attach the
|
2008-02-09 01:43:47 +00:00
|
|
|
resulting FileNode to the directory at the given name. I set metadata
|
2008-02-14 22:45:56 +00:00
|
|
|
the same way as set_uri and set_node. The child name must be a
|
|
|
|
unicode string.
|
2008-02-09 01:43:47 +00:00
|
|
|
|
|
|
|
I return a Deferred that fires (with the IFileNode of the uploaded
|
|
|
|
file) when the operation completes."""
|
2007-06-15 07:37:32 +00:00
|
|
|
|
2007-06-25 20:23:51 +00:00
|
|
|
def delete(name):
|
2007-06-15 07:37:32 +00:00
|
|
|
"""I remove the child at the specific name. I return a Deferred that
|
2008-02-14 22:45:56 +00:00
|
|
|
fires when the operation finishes. The child name must be a unicode
|
|
|
|
string."""
|
2007-06-15 07:37:32 +00:00
|
|
|
|
2008-05-16 23:09:47 +00:00
|
|
|
def create_empty_directory(name, overwrite=True):
|
2008-02-14 22:45:56 +00:00
|
|
|
"""I create and attach an empty directory at the given name. The
|
|
|
|
child name must be a unicode string. I return a Deferred that fires
|
|
|
|
when the operation finishes."""
|
2007-06-15 07:37:32 +00:00
|
|
|
|
2008-05-16 23:09:47 +00:00
|
|
|
def move_child_to(current_child_name, new_parent, new_child_name=None,
|
|
|
|
overwrite=True):
|
2007-06-15 07:37:32 +00:00
|
|
|
"""I take one of my children and move them to a new parent. The child
|
|
|
|
is referenced by name. On the new parent, the child will live under
|
2008-02-09 01:43:47 +00:00
|
|
|
'new_child_name', which defaults to 'current_child_name'. TODO: what
|
|
|
|
should we do about metadata? I return a Deferred that fires when the
|
2008-02-14 22:45:56 +00:00
|
|
|
operation finishes. The child name must be a unicode string."""
|
2006-12-07 21:58:23 +00:00
|
|
|
|
2007-06-27 02:41:20 +00:00
|
|
|
def build_manifest():
|
2008-05-08 20:21:14 +00:00
|
|
|
"""Return a Deferred that fires with a frozenset of
|
|
|
|
verifier-capability strings for all nodes (directories and files)
|
|
|
|
reachable from this one."""
|
|
|
|
|
|
|
|
def deep_stats():
|
|
|
|
"""Return a Deferred that fires with a dictionary of statistics
|
|
|
|
computed by examining all nodes (directories and files) reachable
|
|
|
|
from this one, with the following keys::
|
|
|
|
|
|
|
|
count-immutable-files: count of how many CHK files are in the set
|
|
|
|
count-mutable-files: same, for mutable files (does not include
|
|
|
|
directories)
|
|
|
|
count-literal-files: same, for LIT files
|
|
|
|
count-files: sum of the above three
|
|
|
|
|
|
|
|
count-directories: count of directories
|
|
|
|
|
|
|
|
size-immutable-files: total bytes for all CHK files in the set
|
|
|
|
size-mutable-files (TODO): same, for current version of all mutable
|
|
|
|
files, does not include directories
|
|
|
|
size-literal-files: same, for LIT files
|
|
|
|
size-directories: size of mutable files used by directories
|
|
|
|
|
|
|
|
largest-directory: number of bytes in the largest directory
|
|
|
|
largest-directory-children: number of children in the largest
|
|
|
|
directory
|
|
|
|
largest-immutable-file: number of bytes in the largest CHK file
|
|
|
|
|
|
|
|
size-mutable-files is not yet implemented, because it would involve
|
|
|
|
even more queries than deep_stats does.
|
|
|
|
|
|
|
|
This operation will visit every directory node underneath this one,
|
|
|
|
and can take a long time to run. On a typical workstation with good
|
|
|
|
bandwidth, this can examine roughly 15 directories per second (and
|
|
|
|
takes several minutes of 100% CPU for ~1700 directories).
|
|
|
|
"""
|
2007-01-05 04:52:51 +00:00
|
|
|
|
2007-01-12 03:57:14 +00:00
|
|
|
class ICodecEncoder(Interface):
|
2007-01-16 04:22:22 +00:00
|
|
|
def set_params(data_size, required_shares, max_shares):
|
2007-01-05 04:52:51 +00:00
|
|
|
"""Set up the parameters of this encoder.
|
|
|
|
|
2007-03-28 02:05:09 +00:00
|
|
|
This prepares the encoder to perform an operation that converts a
|
|
|
|
single block of data into a number of shares, such that a future
|
|
|
|
ICodecDecoder can use a subset of these shares to recover the
|
|
|
|
original data. This operation is invoked by calling encode(). Once
|
|
|
|
the encoding parameters are set up, the encode operation can be
|
|
|
|
invoked multiple times.
|
|
|
|
|
|
|
|
set_params() prepares the encoder to accept blocks of input data that
|
|
|
|
are exactly 'data_size' bytes in length. The encoder will be prepared
|
|
|
|
to produce 'max_shares' shares for each encode() operation (although
|
|
|
|
see the 'desired_share_ids' to use less CPU). The encoding math will
|
|
|
|
be chosen such that the decoder can get by with as few as
|
|
|
|
'required_shares' of these shares and still reproduce the original
|
|
|
|
data. For example, set_params(1000, 5, 5) offers no redundancy at
|
|
|
|
all, whereas set_params(1000, 1, 10) provides 10x redundancy.
|
|
|
|
|
2007-03-28 03:14:45 +00:00
|
|
|
Numerical Restrictions: 'data_size' is required to be an integral
|
|
|
|
multiple of 'required_shares'. In general, the caller should choose
|
|
|
|
required_shares and max_shares based upon their reliability
|
|
|
|
requirements and the number of peers available (the total storage
|
|
|
|
space used is roughly equal to max_shares*data_size/required_shares),
|
|
|
|
then choose data_size to achieve the memory footprint desired (larger
|
|
|
|
data_size means more efficient operation, smaller data_size means
|
|
|
|
smaller memory footprint).
|
|
|
|
|
|
|
|
In addition, 'max_shares' must be equal to or greater than
|
|
|
|
'required_shares'. Of course, setting them to be equal causes
|
|
|
|
encode() to degenerate into a particularly slow form of the 'split'
|
|
|
|
utility.
|
|
|
|
|
2007-03-28 02:05:09 +00:00
|
|
|
See encode() for more details about how these parameters are used.
|
2007-03-28 03:14:45 +00:00
|
|
|
|
2007-03-28 02:05:09 +00:00
|
|
|
set_params() must be called before any other ICodecEncoder methods
|
|
|
|
may be invoked.
|
2007-01-05 04:52:51 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def get_encoder_type():
|
2007-01-17 04:29:59 +00:00
|
|
|
"""Return a short string that describes the type of this encoder.
|
2007-01-05 04:52:51 +00:00
|
|
|
|
2007-01-24 22:34:02 +00:00
|
|
|
There is required to be a global table of encoder classes. This method
|
|
|
|
returns an index into this table; the value at this index is an
|
|
|
|
encoder class, and this encoder is an instance of that class.
|
2007-01-05 04:52:51 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def get_serialized_params(): # TODO: maybe, maybe not
|
|
|
|
"""Return a string that describes the parameters of this encoder.
|
|
|
|
|
|
|
|
This string can be passed to the decoder to prepare it for handling
|
|
|
|
the encoded shares we create. It might contain more information than
|
|
|
|
was presented to set_params(), if there is some flexibility of
|
|
|
|
parameter choice.
|
|
|
|
|
|
|
|
This string is intended to be embedded in the URI, so there are
|
|
|
|
several restrictions on its contents. At the moment I'm thinking that
|
2007-01-17 04:29:59 +00:00
|
|
|
this means it may contain hex digits and hyphens, and nothing else.
|
|
|
|
The idea is that the URI contains something like '%s:%s:%s' %
|
|
|
|
(encoder.get_encoder_name(), encoder.get_serialized_params(),
|
2007-06-10 03:46:04 +00:00
|
|
|
b2a(crypttext_hash)), and this is enough information to construct a
|
2007-01-17 04:29:59 +00:00
|
|
|
compatible decoder.
|
2007-01-05 04:52:51 +00:00
|
|
|
"""
|
|
|
|
|
2007-03-30 17:52:19 +00:00
|
|
|
def get_block_size():
|
|
|
|
"""Return the length of the shares that encode() will produce.
|
|
|
|
"""
|
|
|
|
|
2007-03-28 03:14:45 +00:00
|
|
|
def encode_proposal(data, desired_share_ids=None):
|
|
|
|
"""Encode some data.
|
|
|
|
|
|
|
|
'data' must be a string (or other buffer object), and len(data) must
|
|
|
|
be equal to the 'data_size' value passed earlier to set_params().
|
|
|
|
|
|
|
|
This will return a Deferred that will fire with two lists. The first
|
|
|
|
is a list of shares, each of which is a string (or other buffer
|
|
|
|
object) such that len(share) is the same as what get_share_size()
|
|
|
|
returned earlier. The second is a list of shareids, in which each is
|
|
|
|
an integer. The lengths of the two lists will always be equal to each
|
|
|
|
other. The user should take care to keep each share closely
|
|
|
|
associated with its shareid, as one is useless without the other.
|
|
|
|
|
|
|
|
The length of this output list will normally be the same as the value
|
|
|
|
provided to the 'max_shares' parameter of set_params(). This may be
|
|
|
|
different if 'desired_share_ids' is provided.
|
|
|
|
|
|
|
|
'desired_share_ids', if provided, is required to be a sequence of
|
|
|
|
ints, each of which is required to be >= 0 and < max_shares. If not
|
|
|
|
provided, encode() will produce 'max_shares' shares, as if
|
|
|
|
'desired_share_ids' were set to range(max_shares). You might use this
|
|
|
|
if you initially thought you were going to use 10 peers, started
|
|
|
|
encoding, and then two of the peers dropped out: you could use
|
|
|
|
desired_share_ids= to skip the work (both memory and CPU) of
|
|
|
|
producing shares for the peers which are no longer available.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2007-01-24 22:34:02 +00:00
|
|
|
def encode(inshares, desired_share_ids=None):
|
2007-11-01 22:33:47 +00:00
|
|
|
"""Encode some data. This may be called multiple times. Each call is
|
2007-02-01 23:07:00 +00:00
|
|
|
independent.
|
2007-01-05 04:52:51 +00:00
|
|
|
|
2007-03-06 03:57:38 +00:00
|
|
|
inshares is a sequence of length required_shares, containing buffers
|
|
|
|
(i.e. strings), where each buffer contains the next contiguous
|
|
|
|
non-overlapping segment of the input data. Each buffer is required to
|
|
|
|
be the same length, and the sum of the lengths of the buffers is
|
|
|
|
required to be exactly the data_size promised by set_params(). (This
|
|
|
|
implies that the data has to be padded before being passed to
|
|
|
|
encode(), unless of course it already happens to be an even multiple
|
|
|
|
of required_shares in length.)
|
|
|
|
|
|
|
|
ALSO: the requirement to break up your data into 'required_shares'
|
|
|
|
chunks before calling encode() feels a bit surprising, at least from
|
|
|
|
the point of view of a user who doesn't know how FEC works. It feels
|
|
|
|
like an implementation detail that has leaked outside the
|
|
|
|
abstraction barrier. Can you imagine a use case in which the data to
|
|
|
|
be encoded might already be available in pre-segmented chunks, such
|
|
|
|
that it is faster or less work to make encode() take a list rather
|
|
|
|
than splitting a single string?
|
|
|
|
|
|
|
|
ALSO ALSO: I think 'inshares' is a misleading term, since encode()
|
|
|
|
is supposed to *produce* shares, so what it *accepts* should be
|
|
|
|
something other than shares. Other places in this interface use the
|
|
|
|
word 'data' for that-which-is-not-shares.. maybe we should use that
|
|
|
|
term?
|
|
|
|
|
|
|
|
'desired_share_ids', if provided, is required to be a sequence of
|
|
|
|
ints, each of which is required to be >= 0 and < max_shares. If not
|
|
|
|
provided, encode() will produce 'max_shares' shares, as if
|
2007-03-28 02:05:09 +00:00
|
|
|
'desired_share_ids' were set to range(max_shares). You might use this
|
|
|
|
if you initially thought you were going to use 10 peers, started
|
|
|
|
encoding, and then two of the peers dropped out: you could use
|
|
|
|
desired_share_ids= to skip the work (both memory and CPU) of
|
|
|
|
producing shares for the peers which are no longer available.
|
2007-01-24 22:34:02 +00:00
|
|
|
|
|
|
|
For each call, encode() will return a Deferred that fires with two
|
2007-02-01 23:07:00 +00:00
|
|
|
lists, one containing shares and the other containing the shareids.
|
2007-03-28 19:52:44 +00:00
|
|
|
The get_share_size() method can be used to determine the length of
|
|
|
|
the share strings returned by encode(). Each shareid is a small
|
|
|
|
integer, exactly as passed into 'desired_share_ids' (or
|
|
|
|
range(max_shares), if desired_share_ids was not provided).
|
|
|
|
|
2007-11-01 22:33:47 +00:00
|
|
|
The shares and their corresponding shareids are required to be kept
|
|
|
|
together during storage and retrieval. Specifically, the share data is
|
|
|
|
useless by itself: the decoder needs to be told which share is which
|
2007-02-01 23:07:00 +00:00
|
|
|
by providing it with both the shareid and the actual share data.
|
2007-01-05 04:52:51 +00:00
|
|
|
|
2007-03-28 19:52:44 +00:00
|
|
|
This function will allocate an amount of memory roughly equal to::
|
|
|
|
|
|
|
|
(max_shares - required_shares) * get_share_size()
|
2007-02-01 23:07:00 +00:00
|
|
|
|
2007-03-28 19:52:44 +00:00
|
|
|
When combined with the memory that the caller must allocate to
|
|
|
|
provide the input data, this leads to a memory footprint roughly
|
|
|
|
equal to the size of the resulting encoded shares (i.e. the expansion
|
|
|
|
factor times the size of the input segment).
|
2007-01-05 04:52:51 +00:00
|
|
|
"""
|
|
|
|
|
2007-03-28 03:14:45 +00:00
|
|
|
# rejected ideas:
|
|
|
|
#
|
|
|
|
# returning a list of (shareidN,shareN) tuples instead of a pair of
|
|
|
|
# lists (shareids..,shares..). Brian thought the tuples would
|
|
|
|
# encourage users to keep the share and shareid together throughout
|
|
|
|
# later processing, Zooko pointed out that the code to iterate
|
|
|
|
# through two lists is not really more complicated than using a list
|
|
|
|
# of tuples and there's also a performance improvement
|
|
|
|
#
|
|
|
|
# having 'data_size' not required to be an integral multiple of
|
|
|
|
# 'required_shares'. Doing this would require encode() to perform
|
|
|
|
# padding internally, and we'd prefer to have any padding be done
|
|
|
|
# explicitly by the caller. Yes, it is an abstraction leak, but
|
|
|
|
# hopefully not an onerous one.
|
|
|
|
|
|
|
|
|
2007-01-12 03:57:14 +00:00
|
|
|
class ICodecDecoder(Interface):
|
2007-01-05 04:52:51 +00:00
|
|
|
def set_serialized_params(params):
|
|
|
|
"""Set up the parameters of this encoder, from a string returned by
|
|
|
|
encoder.get_serialized_params()."""
|
|
|
|
|
2007-03-30 17:52:19 +00:00
|
|
|
def get_needed_shares():
|
2007-01-16 04:22:22 +00:00
|
|
|
"""Return the number of shares needed to reconstruct the data.
|
2007-01-24 22:34:02 +00:00
|
|
|
set_serialized_params() is required to be called before this."""
|
2007-01-16 04:22:22 +00:00
|
|
|
|
2007-01-24 22:34:02 +00:00
|
|
|
def decode(some_shares, their_shareids):
|
2007-01-05 04:52:51 +00:00
|
|
|
"""Decode a partial list of shares into data.
|
|
|
|
|
2007-02-01 23:07:00 +00:00
|
|
|
'some_shares' is required to be a sequence of buffers of sharedata, a
|
2007-01-24 22:34:02 +00:00
|
|
|
subset of the shares returned by ICodecEncode.encode(). Each share is
|
|
|
|
required to be of the same length. The i'th element of their_shareids
|
2007-02-01 23:07:00 +00:00
|
|
|
is required to be the shareid of the i'th buffer in some_shares.
|
2007-01-24 22:34:02 +00:00
|
|
|
|
|
|
|
This returns a Deferred which fires with a sequence of buffers. This
|
|
|
|
sequence will contain all of the segments of the original data, in
|
2007-03-28 02:05:09 +00:00
|
|
|
order. The sum of the lengths of all of the buffers will be the
|
2007-01-24 22:34:02 +00:00
|
|
|
'data_size' value passed into the original ICodecEncode.set_params()
|
2007-03-28 02:05:09 +00:00
|
|
|
call. To get back the single original input block of data, use
|
|
|
|
''.join(output_buffers), or you may wish to simply write them in
|
|
|
|
order to an output file.
|
|
|
|
|
|
|
|
Note that some of the elements in the result sequence may be
|
|
|
|
references to the elements of the some_shares input sequence. In
|
|
|
|
particular, this means that if those share objects are mutable (e.g.
|
|
|
|
arrays) and if they are changed, then both the input (the
|
|
|
|
'some_shares' parameter) and the output (the value given when the
|
|
|
|
deferred is triggered) will change.
|
2007-01-24 22:34:02 +00:00
|
|
|
|
|
|
|
The length of 'some_shares' is required to be exactly the value of
|
|
|
|
'required_shares' passed into the original ICodecEncode.set_params()
|
|
|
|
call.
|
2007-01-05 04:52:51 +00:00
|
|
|
"""
|
2007-01-21 22:01:34 +00:00
|
|
|
|
2007-03-28 18:24:53 +00:00
|
|
|
class IEncoder(Interface):
|
2007-07-24 02:31:53 +00:00
|
|
|
"""I take an object that provides IEncryptedUploadable, which provides
|
|
|
|
encrypted data, and a list of shareholders. I then encode, hash, and
|
|
|
|
deliver shares to those shareholders. I will compute all the necessary
|
|
|
|
Merkle hash trees that are necessary to validate the crypttext that
|
|
|
|
eventually comes back from the shareholders. I provide the URI Extension
|
|
|
|
Block Hash, and the encoding parameters, both of which must be included
|
|
|
|
in the URI.
|
2007-03-28 18:24:53 +00:00
|
|
|
|
|
|
|
I do not choose shareholders, that is left to the IUploader. I must be
|
|
|
|
given a dict of RemoteReferences to storage buckets that are ready and
|
|
|
|
willing to receive data.
|
|
|
|
"""
|
|
|
|
|
2007-07-24 02:31:53 +00:00
|
|
|
def set_size(size):
|
|
|
|
"""Specify the number of bytes that will be encoded. This must be
|
|
|
|
peformed before get_serialized_params() can be called.
|
2007-03-28 18:24:53 +00:00
|
|
|
"""
|
2007-07-24 02:31:53 +00:00
|
|
|
def set_params(params):
|
|
|
|
"""Override the default encoding parameters. 'params' is a tuple of
|
|
|
|
(k,d,n), where 'k' is the number of required shares, 'd' is the
|
|
|
|
shares_of_happiness, and 'n' is the total number of shares that will
|
|
|
|
be created.
|
2007-03-28 18:24:53 +00:00
|
|
|
|
2007-07-24 02:31:53 +00:00
|
|
|
Encoding parameters can be set in three ways. 1: The Encoder class
|
2007-10-16 02:53:59 +00:00
|
|
|
provides defaults (3/7/10). 2: the Encoder can be constructed with
|
2007-07-24 02:31:53 +00:00
|
|
|
an 'options' dictionary, in which the
|
|
|
|
needed_and_happy_and_total_shares' key can be a (k,d,n) tuple. 3:
|
|
|
|
set_params((k,d,n)) can be called.
|
2007-03-30 18:53:03 +00:00
|
|
|
|
2007-07-24 02:31:53 +00:00
|
|
|
If you intend to use set_params(), you must call it before
|
|
|
|
get_share_size or get_param are called.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def set_encrypted_uploadable(u):
|
|
|
|
"""Provide a source of encrypted upload data. 'u' must implement
|
|
|
|
IEncryptedUploadable.
|
|
|
|
|
|
|
|
When this is called, the IEncryptedUploadable will be queried for its
|
|
|
|
length and the storage_index that should be used.
|
2007-03-30 18:53:03 +00:00
|
|
|
|
2007-07-24 02:31:53 +00:00
|
|
|
This returns a Deferred that fires with this Encoder instance.
|
|
|
|
|
|
|
|
This must be performed before start() can be called.
|
2007-03-30 18:53:03 +00:00
|
|
|
"""
|
|
|
|
|
2007-07-24 02:31:53 +00:00
|
|
|
def get_param(name):
|
|
|
|
"""Return an encoding parameter, by name.
|
|
|
|
|
|
|
|
'storage_index': return a string with the (16-byte truncated SHA-256
|
|
|
|
hash) storage index to which these shares should be
|
|
|
|
pushed.
|
|
|
|
|
|
|
|
'share_counts': return a tuple describing how many shares are used:
|
|
|
|
(needed_shares, shares_of_happiness, total_shares)
|
|
|
|
|
|
|
|
'num_segments': return an int with the number of segments that
|
|
|
|
will be encoded.
|
|
|
|
|
|
|
|
'segment_size': return an int with the size of each segment.
|
|
|
|
|
|
|
|
'block_size': return the size of the individual blocks that will
|
|
|
|
be delivered to a shareholder's put_block() method. By
|
|
|
|
knowing this, the shareholder will be able to keep all
|
|
|
|
blocks in a single file and still provide random access
|
|
|
|
when reading them. # TODO: can we avoid exposing this?
|
|
|
|
|
|
|
|
'share_size': an int with the size of the data that will be stored
|
|
|
|
on each shareholder. This is aggregate amount of data
|
|
|
|
that will be sent to the shareholder, summed over all
|
|
|
|
the put_block() calls I will ever make. It is useful to
|
|
|
|
determine this size before asking potential
|
|
|
|
shareholders whether they will grant a lease or not,
|
|
|
|
since their answers will depend upon how much space we
|
|
|
|
need. TODO: this might also include some amount of
|
|
|
|
overhead, like the size of all the hashes. We need to
|
|
|
|
decide whether this is useful or not.
|
|
|
|
|
|
|
|
'serialized_params': a string with a concise description of the
|
|
|
|
codec name and its parameters. This may be passed
|
|
|
|
into the IUploadable to let it make sure that
|
|
|
|
the same file encoded with different parameters
|
|
|
|
will result in different storage indexes.
|
|
|
|
|
|
|
|
Once this is called, set_size() and set_params() may not be called.
|
2007-03-28 18:24:53 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def set_shareholders(shareholders):
|
2007-07-24 02:31:53 +00:00
|
|
|
"""Tell the encoder where to put the encoded shares. 'shareholders'
|
|
|
|
must be a dictionary that maps share number (an integer ranging from
|
|
|
|
0 to n-1) to an instance that provides IStorageBucketWriter. This
|
|
|
|
must be performed before start() can be called."""
|
2007-03-28 18:24:53 +00:00
|
|
|
|
|
|
|
def start():
|
2007-07-24 02:31:53 +00:00
|
|
|
"""Begin the encode/upload process. This involves reading encrypted
|
|
|
|
data from the IEncryptedUploadable, encoding it, uploading the shares
|
2007-03-28 18:24:53 +00:00
|
|
|
to the shareholders, then sending the hash trees.
|
|
|
|
|
2007-07-24 02:31:53 +00:00
|
|
|
set_encrypted_uploadable() and set_shareholders() must be called
|
|
|
|
before this can be invoked.
|
|
|
|
|
|
|
|
This returns a Deferred that fires with a tuple of
|
|
|
|
(uri_extension_hash, needed_shares, total_shares, size) when the
|
|
|
|
upload process is complete. This information, plus the encryption
|
|
|
|
key, is sufficient to construct the URI.
|
2007-03-28 18:24:53 +00:00
|
|
|
"""
|
|
|
|
|
2007-03-28 18:31:31 +00:00
|
|
|
class IDecoder(Interface):
|
|
|
|
"""I take a list of shareholders and some setup information, then
|
|
|
|
download, validate, decode, and decrypt data from them, writing the
|
|
|
|
results to an output file.
|
|
|
|
|
|
|
|
I do not locate the shareholders, that is left to the IDownloader. I must
|
|
|
|
be given a dict of RemoteReferences to storage buckets that are ready to
|
|
|
|
send data.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setup(outfile):
|
|
|
|
"""I take a file-like object (providing write and close) to which all
|
|
|
|
the plaintext data will be written.
|
|
|
|
|
|
|
|
TODO: producer/consumer . Maybe write() should return a Deferred that
|
|
|
|
indicates when it will accept more data? But probably having the
|
|
|
|
IDecoder be a producer is easier to glue to IConsumer pieces.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def set_shareholders(shareholders):
|
|
|
|
"""I take a dictionary that maps share identifiers (small integers)
|
|
|
|
to RemoteReferences that provide RIBucketReader. This must be called
|
|
|
|
before start()."""
|
|
|
|
|
|
|
|
def start():
|
|
|
|
"""I start the download. This process involves retrieving data and
|
|
|
|
hash chains from the shareholders, using the hashes to validate the
|
|
|
|
data, decoding the shares into segments, decrypting the segments,
|
|
|
|
then writing the resulting plaintext to the output file.
|
|
|
|
|
|
|
|
I return a Deferred that will fire (with self) when the download is
|
|
|
|
complete.
|
|
|
|
"""
|
2007-03-28 18:24:53 +00:00
|
|
|
|
2007-01-21 22:01:34 +00:00
|
|
|
class IDownloadTarget(Interface):
|
2008-07-14 22:25:21 +00:00
|
|
|
# Note that if the IDownloadTarget is also an IConsumable, the downloader
|
|
|
|
# will register itself as a producer. This allows the target to invoke
|
|
|
|
# downloader.pauseProducing, resumeProducing, and stopProducing.
|
2007-07-03 22:09:00 +00:00
|
|
|
def open(size):
|
2007-07-03 20:47:37 +00:00
|
|
|
"""Called before any calls to write() or close(). If an error
|
|
|
|
occurs before any data is available, fail() may be called without
|
2007-07-03 22:09:00 +00:00
|
|
|
a previous call to open().
|
|
|
|
|
|
|
|
'size' is the length of the file being downloaded, in bytes."""
|
|
|
|
|
2007-01-21 22:01:34 +00:00
|
|
|
def write(data):
|
|
|
|
"""Output some data to the target."""
|
|
|
|
def close():
|
|
|
|
"""Inform the target that there is no more data to be written."""
|
2007-07-03 20:18:14 +00:00
|
|
|
def fail(why):
|
|
|
|
"""fail() is called to indicate that the download has failed. 'why'
|
|
|
|
is a Failure object indicating what went wrong. No further methods
|
|
|
|
will be invoked on the IDownloadTarget after fail()."""
|
2007-01-21 22:01:34 +00:00
|
|
|
def register_canceller(cb):
|
|
|
|
"""The FileDownloader uses this to register a no-argument function
|
|
|
|
that the target can call to cancel the download. Once this canceller
|
|
|
|
is invoked, no further calls to write() or close() will be made."""
|
2007-07-07 02:39:47 +00:00
|
|
|
def finish():
|
2007-01-21 22:01:34 +00:00
|
|
|
"""When the FileDownloader is done, this finish() function will be
|
|
|
|
called. Whatever it returns will be returned to the invoker of
|
|
|
|
Downloader.download.
|
|
|
|
"""
|
|
|
|
|
|
|
|
class IDownloader(Interface):
|
|
|
|
def download(uri, target):
|
|
|
|
"""Perform a CHK download, sending the data to the given target.
|
2007-07-03 20:18:14 +00:00
|
|
|
'target' must provide IDownloadTarget.
|
|
|
|
|
|
|
|
Returns a Deferred that fires (with the results of target.finish)
|
|
|
|
when the download is finished, or errbacks if something went wrong."""
|
2007-01-21 22:01:34 +00:00
|
|
|
|
2007-07-24 02:31:53 +00:00
|
|
|
class IEncryptedUploadable(Interface):
|
2008-02-12 22:36:05 +00:00
|
|
|
def set_upload_status(upload_status):
|
|
|
|
"""Provide an IUploadStatus object that should be filled with status
|
|
|
|
information. The IEncryptedUploadable is responsible for setting
|
|
|
|
key-determination progress ('chk'), size, storage_index, and
|
|
|
|
ciphertext-fetch progress. It may delegate some of this
|
|
|
|
responsibility to others, in particular to the IUploadable."""
|
|
|
|
|
2007-07-24 02:31:53 +00:00
|
|
|
def get_size():
|
|
|
|
"""This behaves just like IUploadable.get_size()."""
|
|
|
|
|
2008-01-16 10:03:35 +00:00
|
|
|
def get_all_encoding_parameters():
|
|
|
|
"""Return a Deferred that fires with a tuple of
|
|
|
|
(k,happy,n,segment_size). The segment_size will be used as-is, and
|
|
|
|
must match the following constraints: it must be a multiple of k, and
|
|
|
|
it shouldn't be unreasonably larger than the file size (if
|
|
|
|
segment_size is larger than filesize, the difference must be stored
|
|
|
|
as padding).
|
2007-07-24 02:31:53 +00:00
|
|
|
|
2008-02-07 01:39:03 +00:00
|
|
|
This usually passes through to the IUploadable method of the same
|
|
|
|
name.
|
|
|
|
|
2008-01-16 10:03:35 +00:00
|
|
|
The encoder strictly obeys the values returned by this method. To
|
|
|
|
make an upload use non-default encoding parameters, you must arrange
|
|
|
|
to control the values that this method returns.
|
2007-07-24 02:31:53 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def get_storage_index():
|
2008-01-16 10:03:35 +00:00
|
|
|
"""Return a Deferred that fires with a 16-byte storage index.
|
2007-07-24 02:31:53 +00:00
|
|
|
"""
|
|
|
|
|
2008-01-25 00:25:33 +00:00
|
|
|
def read_encrypted(length, hash_only):
|
2007-07-24 02:31:53 +00:00
|
|
|
"""This behaves just like IUploadable.read(), but returns crypttext
|
2008-01-25 00:25:33 +00:00
|
|
|
instead of plaintext. If hash_only is True, then this discards the
|
|
|
|
data (and returns an empty list); this improves efficiency when
|
|
|
|
resuming an interrupted upload (where we need to compute the
|
|
|
|
plaintext hashes, but don't need the redundant encrypted data)."""
|
2007-07-24 02:31:53 +00:00
|
|
|
|
2008-01-10 00:58:47 +00:00
|
|
|
def get_plaintext_hashtree_leaves(first, last, num_segments):
|
|
|
|
"""Get the leaf nodes of a merkle hash tree over the plaintext
|
2008-01-16 10:03:35 +00:00
|
|
|
segments, i.e. get the tagged hashes of the given segments. The
|
|
|
|
segment size is expected to be generated by the IEncryptedUploadable
|
|
|
|
before any plaintext is read or ciphertext produced, so that the
|
|
|
|
segment hashes can be generated with only a single pass.
|
2007-07-24 02:31:53 +00:00
|
|
|
|
2008-01-10 00:58:47 +00:00
|
|
|
This returns a Deferred which fires with a sequence of hashes, using:
|
2007-07-24 02:31:53 +00:00
|
|
|
|
2008-01-10 00:58:47 +00:00
|
|
|
tuple(segment_hashes[first:last])
|
2007-07-24 02:31:53 +00:00
|
|
|
|
|
|
|
'num_segments' is used to assert that the number of segments that the
|
|
|
|
IEncryptedUploadable handled matches the number of segments that the
|
|
|
|
encoder was expecting.
|
2008-01-10 00:58:47 +00:00
|
|
|
|
|
|
|
This method must not be called until the final byte has been read
|
|
|
|
from read_encrypted(). Once this method is called, read_encrypted()
|
|
|
|
can never be called again.
|
2007-07-24 02:31:53 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def get_plaintext_hash():
|
|
|
|
"""Get the hash of the whole plaintext.
|
|
|
|
|
|
|
|
This returns a Deferred which fires with a tagged SHA-256 hash of the
|
|
|
|
whole plaintext, obtained from hashutil.plaintext_hash(data).
|
|
|
|
"""
|
|
|
|
|
|
|
|
def close():
|
|
|
|
"""Just like IUploadable.close()."""
|
|
|
|
|
2007-01-21 22:01:34 +00:00
|
|
|
class IUploadable(Interface):
|
2008-02-12 22:36:05 +00:00
|
|
|
def set_upload_status(upload_status):
|
|
|
|
"""Provide an IUploadStatus object that should be filled with status
|
|
|
|
information. The IUploadable is responsible for setting
|
|
|
|
key-determination progress ('chk')."""
|
|
|
|
|
2008-02-07 01:39:03 +00:00
|
|
|
def set_default_encoding_parameters(params):
|
|
|
|
"""Set the default encoding parameters, which must be a dict mapping
|
|
|
|
strings to ints. The meaningful keys are 'k', 'happy', 'n', and
|
|
|
|
'max_segment_size'. These might have an influence on the final
|
|
|
|
encoding parameters returned by get_all_encoding_parameters(), if the
|
|
|
|
Uploadable doesn't have more specific preferences.
|
|
|
|
|
|
|
|
This call is optional: if it is not used, the Uploadable will use
|
|
|
|
some built-in defaults. If used, this method must be called before
|
|
|
|
any other IUploadable methods to have any effect.
|
|
|
|
"""
|
|
|
|
|
2007-07-20 01:21:44 +00:00
|
|
|
def get_size():
|
|
|
|
"""Return a Deferred that will fire with the length of the data to be
|
|
|
|
uploaded, in bytes. This will be called before the data is actually
|
|
|
|
used, to compute encoding parameters.
|
|
|
|
"""
|
|
|
|
|
2008-02-07 01:39:03 +00:00
|
|
|
def get_all_encoding_parameters():
|
|
|
|
"""Return a Deferred that fires with a tuple of
|
|
|
|
(k,happy,n,segment_size). The segment_size will be used as-is, and
|
|
|
|
must match the following constraints: it must be a multiple of k, and
|
|
|
|
it shouldn't be unreasonably larger than the file size (if
|
|
|
|
segment_size is larger than filesize, the difference must be stored
|
|
|
|
as padding).
|
2007-07-24 02:31:53 +00:00
|
|
|
|
2008-02-07 01:39:03 +00:00
|
|
|
The relative values of k and n allow some IUploadables to request
|
|
|
|
better redundancy than others (in exchange for consuming more space
|
|
|
|
in the grid).
|
2007-07-24 02:31:53 +00:00
|
|
|
|
2008-02-07 01:39:03 +00:00
|
|
|
Larger values of segment_size reduce hash overhead, while smaller
|
|
|
|
values reduce memory footprint and cause data to be delivered in
|
|
|
|
smaller pieces (which may provide a smoother and more predictable
|
|
|
|
download experience).
|
2007-07-24 02:31:53 +00:00
|
|
|
|
2008-02-07 01:39:03 +00:00
|
|
|
The encoder strictly obeys the values returned by this method. To
|
|
|
|
make an upload use non-default encoding parameters, you must arrange
|
|
|
|
to control the values that this method returns. One way to influence
|
|
|
|
them may be to call set_encoding_parameters() before calling
|
|
|
|
get_all_encoding_parameters().
|
2007-07-24 02:31:53 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def get_encryption_key():
|
2007-07-20 01:21:44 +00:00
|
|
|
"""Return a Deferred that fires with a 16-byte AES key. This key will
|
|
|
|
be used to encrypt the data. The key will also be hashed to derive
|
2007-07-24 02:31:53 +00:00
|
|
|
the StorageIndex.
|
2007-07-20 01:21:44 +00:00
|
|
|
|
|
|
|
Uploadables which want to achieve convergence should hash their file
|
2007-07-24 02:31:53 +00:00
|
|
|
contents and the serialized_encoding_parameters to form the key
|
|
|
|
(which of course requires a full pass over the data). Uploadables can
|
|
|
|
use the upload.ConvergentUploadMixin class to achieve this
|
|
|
|
automatically.
|
2007-07-20 01:21:44 +00:00
|
|
|
|
|
|
|
Uploadables which do not care about convergence (or do not wish to
|
|
|
|
make multiple passes over the data) can simply return a
|
|
|
|
strongly-random 16 byte string.
|
2007-07-24 02:31:53 +00:00
|
|
|
|
|
|
|
get_encryption_key() may be called multiple times: the IUploadable is
|
|
|
|
required to return the same value each time.
|
2007-07-20 01:21:44 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def read(length):
|
|
|
|
"""Return a Deferred that fires with a list of strings (perhaps with
|
|
|
|
only a single element) which, when concatenated together, contain the
|
|
|
|
next 'length' bytes of data. If EOF is near, this may provide fewer
|
|
|
|
than 'length' bytes. The total number of bytes provided by read()
|
|
|
|
before it signals EOF must equal the size provided by get_size().
|
|
|
|
|
|
|
|
If the data must be acquired through multiple internal read
|
|
|
|
operations, returning a list instead of a single string may help to
|
|
|
|
reduce string copies.
|
|
|
|
|
|
|
|
'length' will typically be equal to (min(get_size(),1MB)/req_shares),
|
|
|
|
so a 10kB file means length=3kB, 100kB file means length=30kB,
|
|
|
|
and >=1MB file means length=300kB.
|
|
|
|
|
|
|
|
This method provides for a single full pass through the data. Later
|
|
|
|
use cases may desire multiple passes or access to only parts of the
|
|
|
|
data (such as a mutable file making small edits-in-place). This API
|
|
|
|
will be expanded once those use cases are better understood.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def close():
|
|
|
|
"""The upload is finished, and whatever filehandle was in use may be
|
|
|
|
closed."""
|
2007-01-21 22:01:34 +00:00
|
|
|
|
2008-02-06 04:01:38 +00:00
|
|
|
class IUploadResults(Interface):
|
|
|
|
"""I am returned by upload() methods. I contain a number of public
|
2008-03-04 02:19:21 +00:00
|
|
|
attributes which can be read to determine the results of the upload. Some
|
|
|
|
of these are functional, some are timing information. All of these may be
|
|
|
|
None.::
|
2008-02-06 04:01:38 +00:00
|
|
|
|
2008-03-04 02:19:21 +00:00
|
|
|
.file_size : the size of the file, in bytes
|
2008-02-06 04:01:38 +00:00
|
|
|
.uri : the CHK read-cap for the file
|
2008-03-04 02:19:21 +00:00
|
|
|
.ciphertext_fetched : how many bytes were fetched by the helper
|
|
|
|
.sharemap : dict mapping share number to placement string
|
|
|
|
.servermap : dict mapping server peerid to a set of share numbers
|
|
|
|
.timings : dict of timing information, mapping name to seconds (float)
|
|
|
|
total : total upload time, start to finish
|
|
|
|
storage_index : time to compute the storage index
|
|
|
|
peer_selection : time to decide which peers will be used
|
|
|
|
contacting_helper : initial helper query to upload/no-upload decision
|
|
|
|
existence_check : helper pre-upload existence check
|
|
|
|
helper_total : initial helper query to helper finished pushing
|
|
|
|
cumulative_fetch : helper waiting for ciphertext requests
|
|
|
|
total_fetch : helper start to last ciphertext response
|
|
|
|
cumulative_encoding : just time spent in zfec
|
|
|
|
cumulative_sending : just time spent waiting for storage servers
|
|
|
|
hashes_and_close : last segment push to shareholder close
|
|
|
|
total_encode_and_push : first encode to shareholder close
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
class IDownloadResults(Interface):
|
|
|
|
"""I am created internally by download() methods. I contain a number of
|
|
|
|
public attributes which contain details about the download process.::
|
|
|
|
|
2008-03-04 03:09:32 +00:00
|
|
|
.file_size : the size of the file, in bytes
|
2008-03-04 03:53:45 +00:00
|
|
|
.servers_used : set of server peerids that were used during download
|
2008-03-04 03:30:35 +00:00
|
|
|
.server_problems : dict mapping server peerid to a problem string. Only
|
|
|
|
servers that had problems (bad hashes, disconnects) are
|
|
|
|
listed here.
|
2008-03-04 03:09:32 +00:00
|
|
|
.servermap : dict mapping server peerid to a set of share numbers. Only
|
|
|
|
servers that had any shares are listed here.
|
2008-03-04 02:19:21 +00:00
|
|
|
.timings : dict of timing information, mapping name to seconds (float)
|
|
|
|
peer_selection : time to ask servers about shares
|
|
|
|
servers_peer_selection : dict of peerid to DYHB-query time
|
|
|
|
uri_extension : time to fetch a copy of the URI extension block
|
|
|
|
hashtrees : time to fetch the hash trees
|
2008-03-04 03:09:32 +00:00
|
|
|
segments : time to fetch, decode, and deliver segments
|
|
|
|
cumulative_fetch : time spent waiting for storage servers
|
|
|
|
cumulative_decode : just time spent in zfec
|
|
|
|
cumulative_decrypt : just time spent in decryption
|
2008-03-04 02:19:21 +00:00
|
|
|
total : total download time, start to finish
|
2008-03-04 03:53:45 +00:00
|
|
|
fetch_per_server : dict of peerid to list of per-segment fetch times
|
2008-02-06 04:01:38 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
2007-01-21 22:01:34 +00:00
|
|
|
class IUploader(Interface):
|
2008-01-14 21:55:59 +00:00
|
|
|
def upload(uploadable):
|
2007-01-21 22:01:34 +00:00
|
|
|
"""Upload the file. 'uploadable' must impement IUploadable. This
|
2008-02-06 04:01:38 +00:00
|
|
|
returns a Deferred which fires with an UploadResults instance, from
|
|
|
|
which the URI of the file can be obtained as results.uri ."""
|
2007-01-21 22:01:34 +00:00
|
|
|
|
|
|
|
def upload_ssk(write_capability, new_version, uploadable):
|
2007-04-18 22:46:37 +00:00
|
|
|
"""TODO: how should this work?"""
|
2007-01-24 22:10:53 +00:00
|
|
|
|
2008-07-16 00:23:25 +00:00
|
|
|
class ICheckable(Interface):
|
|
|
|
def check(verify=False, repair=False):
|
|
|
|
"""Check upon my health, optionally repairing any problems.
|
|
|
|
|
|
|
|
This returns a Deferred that fires with an instance that provides
|
|
|
|
ICheckerResults.
|
|
|
|
|
|
|
|
Filenodes and dirnodes (which provide IFilesystemNode) are also
|
|
|
|
checkable. Instances that represent verifier-caps will be checkable
|
|
|
|
but not downloadable. Some objects (like LIT files) do not actually
|
|
|
|
live in the grid, and their checkers indicate a healthy result.
|
|
|
|
|
|
|
|
If verify=False, a relatively lightweight check will be performed: I
|
|
|
|
will ask all servers if they have a share for me, and I will believe
|
|
|
|
whatever they say. If there are at least N distinct shares on the
|
|
|
|
grid, my results will indicate r.is_healthy()==True. This requires a
|
|
|
|
roundtrip to each server, but does not transfer very much data, so
|
|
|
|
the network bandwidth is fairly low.
|
|
|
|
|
|
|
|
If verify=True, a more resource-intensive check will be performed:
|
|
|
|
every share will be downloaded, and the hashes will be validated on
|
|
|
|
every bit. I will ignore any shares that failed their hash checks. If
|
|
|
|
there are at least N distinct valid shares on the grid, my results
|
|
|
|
will indicate r.is_healthy()==True. This requires N/k times as much
|
|
|
|
download bandwidth (and server disk IO) as a regular download. If a
|
|
|
|
storage server is holding a corrupt share, or is experiencing memory
|
|
|
|
failures during retrieval, or is malicious or buggy, then
|
|
|
|
verification will detect the problem, but checking will not.
|
|
|
|
|
|
|
|
If repair=True, then a non-healthy result will cause an immediate
|
|
|
|
repair operation, to generate and upload new shares. After repair,
|
|
|
|
the file will be as healthy as we can make it. Details about what
|
|
|
|
sort of repair is done will be put in the checker results. My
|
|
|
|
Deferred will not fire until the repair is complete.
|
|
|
|
|
|
|
|
TODO: any problems seen during checking will be reported to the
|
|
|
|
health-manager.furl, a centralized object which is responsible for
|
|
|
|
figuring out why files are unhealthy so corrective action can be
|
|
|
|
taken.
|
|
|
|
"""
|
|
|
|
|
2008-07-17 01:20:57 +00:00
|
|
|
def deep_check(verify=False, repair=False):
|
|
|
|
"""Check upon the health of me and everything I can reach.
|
|
|
|
|
|
|
|
This is a recursive form of check(), useable on dirnodes. (it can be
|
|
|
|
called safely on filenodes too, but only checks the one object).
|
|
|
|
|
|
|
|
I return a Deferred that fires with an IDeepCheckResults object.
|
|
|
|
"""
|
|
|
|
|
2008-07-16 00:23:25 +00:00
|
|
|
class ICheckerResults(Interface):
|
|
|
|
"""I contain the detailed results of a check/verify/repair operation.
|
|
|
|
|
|
|
|
The IFilesystemNode.check()/verify()/repair() methods all return
|
|
|
|
instances that provide ICheckerResults.
|
|
|
|
"""
|
2007-10-23 00:46:24 +00:00
|
|
|
|
2008-07-16 00:23:25 +00:00
|
|
|
def is_healthy():
|
|
|
|
"""Return a bool, True if the file is fully healthy, False if it is
|
|
|
|
damaged in any way."""
|
|
|
|
|
2008-07-16 22:42:56 +00:00
|
|
|
def get_storage_index_string():
|
|
|
|
"""Return a string with the abbreviated storage index."""
|
|
|
|
def get_mutability_string():
|
|
|
|
"""Return a string with 'mutable' or 'immutable'."""
|
|
|
|
|
|
|
|
def to_string():
|
|
|
|
"""Return a string that describes the detailed results of the
|
|
|
|
check/verify operation. This string will be displayed on a page all
|
|
|
|
by itself."""
|
2008-07-16 00:23:25 +00:00
|
|
|
|
|
|
|
# The old checker results (for only immutable files) were described
|
|
|
|
# with this:
|
|
|
|
# For filenodes, this fires with a tuple of (needed_shares,
|
|
|
|
# total_shares, found_shares, sharemap). The first three are ints. The
|
|
|
|
# basic health of the file is found_shares / needed_shares: if less
|
|
|
|
# than 1.0, the file is unrecoverable.
|
|
|
|
#
|
|
|
|
# The sharemap has a key for each sharenum. The value is a list of
|
|
|
|
# (binary) nodeids who hold that share. If two shares are kept on the
|
|
|
|
# same nodeid, they will fail as a pair, and overall reliability is
|
|
|
|
# decreased.
|
2007-10-23 00:46:24 +00:00
|
|
|
|
2008-07-17 01:20:57 +00:00
|
|
|
class IDeepCheckResults(Interface):
|
|
|
|
"""I contain the results of a deep-check operation.
|
|
|
|
|
|
|
|
This is returned by a call to ICheckable.deep_check().
|
|
|
|
"""
|
|
|
|
|
2008-07-17 23:47:09 +00:00
|
|
|
def get_root_storage_index_string():
|
|
|
|
"""Return the storage index (abbreviated human-readable string) of
|
|
|
|
the first object checked."""
|
2008-07-17 01:20:57 +00:00
|
|
|
def count_objects_checked():
|
|
|
|
"""Return the number of objects that were checked."""
|
|
|
|
def count_objects_healthy():
|
|
|
|
"""Return the number of objects that were fully healthy."""
|
|
|
|
def count_repairs_attempted():
|
|
|
|
"""Return the number of repair operations that were attempted."""
|
|
|
|
def count_repairs_successful():
|
|
|
|
"""Return the number of repair operations that succeeded in bringing
|
|
|
|
the object back up to full health."""
|
|
|
|
def get_server_problems():
|
|
|
|
"""Return a dict, mapping server nodeid to a count of how many
|
|
|
|
problems involved that server."""
|
|
|
|
def get_problems():
|
|
|
|
"""Return a list of ICheckerResults, one for each object that
|
|
|
|
was not fully healthy."""
|
2007-10-23 00:46:24 +00:00
|
|
|
|
|
|
|
|
2007-12-04 21:32:04 +00:00
|
|
|
class IClient(Interface):
|
2008-01-14 21:55:59 +00:00
|
|
|
def upload(uploadable):
|
2008-02-06 04:01:38 +00:00
|
|
|
"""Upload some data into a CHK, get back the UploadResults for it.
|
2007-12-04 21:32:04 +00:00
|
|
|
@param uploadable: something that implements IUploadable
|
2008-02-06 04:01:38 +00:00
|
|
|
@return: a Deferred that fires with the UploadResults instance.
|
|
|
|
To get the URI for this file, use results.uri .
|
2007-12-04 21:32:04 +00:00
|
|
|
"""
|
2007-12-07 01:36:58 +00:00
|
|
|
|
2008-01-14 21:55:59 +00:00
|
|
|
def create_mutable_file(contents=""):
|
2007-12-07 01:36:58 +00:00
|
|
|
"""Create a new mutable file with contents, get back the URI string.
|
|
|
|
@param contents: the initial contents to place in the file.
|
|
|
|
@return: a Deferred that fires with tne (string) SSK URI for the new
|
|
|
|
file.
|
|
|
|
"""
|
|
|
|
|
2008-01-14 21:55:59 +00:00
|
|
|
def create_empty_dirnode():
|
2007-12-04 21:32:04 +00:00
|
|
|
"""Create a new dirnode, empty and unattached.
|
|
|
|
@return: a Deferred that fires with the new IDirectoryNode instance.
|
|
|
|
"""
|
2007-12-07 01:36:58 +00:00
|
|
|
|
2007-12-04 21:32:04 +00:00
|
|
|
def create_node_from_uri(uri):
|
|
|
|
"""Create a new IFilesystemNode instance from the uri, synchronously.
|
|
|
|
@param uri: a string or IURI-providing instance. This could be for a
|
|
|
|
LiteralFileNode, a CHK file node, a mutable file node, or
|
|
|
|
a directory node
|
|
|
|
@return: an instance that provides IFilesystemNode (or more usefully one
|
|
|
|
of its subclasses). File-specifying URIs will result in
|
|
|
|
IFileNode or IMutableFileNode -providing instances, like
|
|
|
|
FileNode, LiteralFileNode, or MutableFileNode.
|
|
|
|
Directory-specifying URIs will result in
|
|
|
|
IDirectoryNode-providing instances, like NewDirectoryNode.
|
|
|
|
"""
|
|
|
|
|
2008-02-12 22:39:45 +00:00
|
|
|
class IClientStatus(Interface):
|
2008-03-01 05:19:03 +00:00
|
|
|
def list_all_uploads():
|
2008-03-03 21:48:52 +00:00
|
|
|
"""Return a list of uploader objects, one for each upload which
|
|
|
|
currently has an object available (tracked with weakrefs). This is
|
|
|
|
intended for debugging purposes."""
|
|
|
|
def list_active_uploads():
|
|
|
|
"""Return a list of active IUploadStatus objects."""
|
2008-03-01 05:19:03 +00:00
|
|
|
def list_recent_uploads():
|
|
|
|
"""Return a list of IUploadStatus objects for the most recently
|
|
|
|
started uploads."""
|
|
|
|
|
|
|
|
def list_all_downloads():
|
2008-03-03 21:48:52 +00:00
|
|
|
"""Return a list of downloader objects, one for each download which
|
|
|
|
currently has an object available (tracked with weakrefs). This is
|
|
|
|
intended for debugging purposes."""
|
|
|
|
def list_active_downloads():
|
|
|
|
"""Return a list of active IDownloadStatus objects."""
|
2008-03-01 05:19:03 +00:00
|
|
|
def list_recent_downloads():
|
|
|
|
"""Return a list of IDownloadStatus objects for the most recently
|
|
|
|
started downloads."""
|
2008-02-12 22:39:45 +00:00
|
|
|
|
2008-02-12 22:36:05 +00:00
|
|
|
class IUploadStatus(Interface):
|
2008-03-05 01:50:44 +00:00
|
|
|
def get_started():
|
|
|
|
"""Return a timestamp (float with seconds since epoch) indicating
|
|
|
|
when the operation was started."""
|
2008-02-12 22:36:05 +00:00
|
|
|
def get_storage_index():
|
|
|
|
"""Return a string with the (binary) storage index in use on this
|
|
|
|
upload. Returns None if the storage index has not yet been
|
|
|
|
calculated."""
|
|
|
|
def get_size():
|
|
|
|
"""Return an integer with the number of bytes that will eventually
|
|
|
|
be uploaded for this file. Returns None if the size is not yet known.
|
|
|
|
"""
|
|
|
|
def using_helper():
|
|
|
|
"""Return True if this upload is using a Helper, False if not."""
|
|
|
|
def get_status():
|
|
|
|
"""Return a string describing the current state of the upload
|
|
|
|
process."""
|
|
|
|
def get_progress():
|
|
|
|
"""Returns a tuple of floats, (chk, ciphertext, encode_and_push),
|
|
|
|
each from 0.0 to 1.0 . 'chk' describes how much progress has been
|
|
|
|
made towards hashing the file to determine a CHK encryption key: if
|
|
|
|
non-convergent encryption is in use, this will be trivial, otherwise
|
|
|
|
the whole file must be hashed. 'ciphertext' describes how much of the
|
|
|
|
ciphertext has been pushed to the helper, and is '1.0' for non-helper
|
|
|
|
uploads. 'encode_and_push' describes how much of the encode-and-push
|
|
|
|
process has finished: for helper uploads this is dependent upon the
|
|
|
|
helper providing progress reports. It might be reasonable to add all
|
|
|
|
three numbers and report the sum to the user."""
|
2008-02-26 22:35:28 +00:00
|
|
|
def get_active():
|
|
|
|
"""Return True if the upload is currently active, False if not."""
|
2008-03-03 21:48:52 +00:00
|
|
|
def get_results():
|
|
|
|
"""Return an instance of UploadResults (which contains timing and
|
|
|
|
sharemap information). Might return None if the upload is not yet
|
|
|
|
finished."""
|
2008-03-01 05:19:03 +00:00
|
|
|
def get_counter():
|
|
|
|
"""Each upload status gets a unique number: this method returns that
|
|
|
|
number. This provides a handle to this particular upload, so a web
|
|
|
|
page can generate a suitable hyperlink."""
|
2008-02-12 22:36:05 +00:00
|
|
|
|
2008-02-12 22:38:39 +00:00
|
|
|
class IDownloadStatus(Interface):
|
2008-03-05 01:50:44 +00:00
|
|
|
def get_started():
|
|
|
|
"""Return a timestamp (float with seconds since epoch) indicating
|
|
|
|
when the operation was started."""
|
2008-02-12 22:38:39 +00:00
|
|
|
def get_storage_index():
|
|
|
|
"""Return a string with the (binary) storage index in use on this
|
|
|
|
download. This may be None if there is no storage index (i.e. LIT
|
|
|
|
files)."""
|
|
|
|
def get_size():
|
|
|
|
"""Return an integer with the number of bytes that will eventually be
|
|
|
|
retrieved for this file. Returns None if the size is not yet known.
|
|
|
|
"""
|
|
|
|
def using_helper():
|
|
|
|
"""Return True if this download is using a Helper, False if not."""
|
|
|
|
def get_status():
|
|
|
|
"""Return a string describing the current state of the download
|
|
|
|
process."""
|
|
|
|
def get_progress():
|
|
|
|
"""Returns a float (from 0.0 to 1.0) describing the amount of the
|
|
|
|
download that has completed. This value will remain at 0.0 until the
|
|
|
|
first byte of plaintext is pushed to the download target."""
|
2008-02-26 22:35:28 +00:00
|
|
|
def get_active():
|
|
|
|
"""Return True if the download is currently active, False if not."""
|
2008-03-01 05:19:03 +00:00
|
|
|
def get_counter():
|
|
|
|
"""Each download status gets a unique number: this method returns
|
|
|
|
that number. This provides a handle to this particular download, so a
|
|
|
|
web page can generate a suitable hyperlink."""
|
2008-02-12 22:38:39 +00:00
|
|
|
|
2008-04-17 02:05:41 +00:00
|
|
|
class IServermapUpdaterStatus(Interface):
|
|
|
|
pass
|
2008-03-04 08:07:44 +00:00
|
|
|
class IPublishStatus(Interface):
|
|
|
|
pass
|
|
|
|
class IRetrieveStatus(Interface):
|
|
|
|
pass
|
2007-10-23 00:46:24 +00:00
|
|
|
|
2007-01-21 22:15:31 +00:00
|
|
|
class NotCapableError(Exception):
|
|
|
|
"""You have tried to write to a read-only node."""
|
2007-03-08 02:16:06 +00:00
|
|
|
|
2007-10-31 02:47:36 +00:00
|
|
|
class BadWriteEnablerError(Exception):
|
|
|
|
pass
|
|
|
|
|
2007-03-08 02:16:06 +00:00
|
|
|
class RIControlClient(RemoteInterface):
|
2007-05-30 00:39:39 +00:00
|
|
|
|
|
|
|
def wait_for_client_connections(num_clients=int):
|
|
|
|
"""Do not return until we have connections to at least NUM_CLIENTS
|
|
|
|
storage servers.
|
|
|
|
"""
|
|
|
|
|
2008-03-24 16:46:06 +00:00
|
|
|
def upload_from_file_to_uri(filename=str, convergence=ChoiceOf(None, StringConstraint(2**20))):
|
2007-04-30 20:06:09 +00:00
|
|
|
"""Upload a file to the grid. This accepts a filename (which must be
|
2008-03-24 16:46:06 +00:00
|
|
|
absolute) that points to a file on the node's local disk. The node will
|
|
|
|
read the contents of this file, upload it to the grid, then return the
|
|
|
|
URI at which it was uploaded. If convergence is None then a random
|
|
|
|
encryption key will be used, else the plaintext will be hashed, then
|
|
|
|
that hash will be mixed together with the "convergence" string to form
|
|
|
|
the encryption key.
|
2007-03-08 02:16:06 +00:00
|
|
|
"""
|
|
|
|
return URI
|
|
|
|
|
|
|
|
def download_from_uri_to_file(uri=URI, filename=str):
|
2007-04-30 20:06:09 +00:00
|
|
|
"""Download a file from the grid, placing it on the node's local disk
|
2007-03-08 02:16:06 +00:00
|
|
|
at the given filename (which must be absolute[?]). Returns the
|
|
|
|
absolute filename where the file was written."""
|
|
|
|
return str
|
|
|
|
|
|
|
|
# debug stuff
|
|
|
|
|
|
|
|
def get_memory_usage():
|
|
|
|
"""Return a dict describes the amount of memory currently in use. The
|
|
|
|
keys are 'VmPeak', 'VmSize', and 'VmData'. The values are integers,
|
|
|
|
measuring memory consupmtion in bytes."""
|
|
|
|
return DictOf(str, int)
|
2007-09-20 01:40:18 +00:00
|
|
|
|
2008-01-30 03:44:32 +00:00
|
|
|
def speed_test(count=int, size=int, mutable=Any()):
|
2007-09-20 23:55:33 +00:00
|
|
|
"""Write 'count' tempfiles to disk, all of the given size. Measure
|
|
|
|
how long (in seconds) it takes to upload them all to the servers.
|
2007-12-14 09:05:31 +00:00
|
|
|
Then measure how long it takes to download all of them. If 'mutable'
|
2008-01-30 03:44:32 +00:00
|
|
|
is 'create', time creation of mutable files. If 'mutable' is
|
|
|
|
'upload', then time access to the same mutable file instead of
|
|
|
|
creating one.
|
2007-09-21 01:52:44 +00:00
|
|
|
|
|
|
|
Returns a tuple of (upload_time, download_time).
|
2007-09-20 01:40:18 +00:00
|
|
|
"""
|
2007-09-21 01:52:44 +00:00
|
|
|
return (float, float)
|
2007-09-26 19:21:15 +00:00
|
|
|
|
|
|
|
def measure_peer_response_time():
|
|
|
|
"""Send a short message to each connected peer, and measure the time
|
|
|
|
it takes for them to respond to it. This is a rough measure of the
|
|
|
|
application-level round trip time.
|
|
|
|
|
|
|
|
@return: a dictionary mapping peerid to a float (RTT time in seconds)
|
|
|
|
"""
|
|
|
|
|
|
|
|
return DictOf(Nodeid, float)
|
2008-01-10 04:25:47 +00:00
|
|
|
|
2008-02-06 08:52:25 +00:00
|
|
|
UploadResults = Any() #DictOf(str, str)
|
2008-01-10 04:25:47 +00:00
|
|
|
|
|
|
|
class RIEncryptedUploadable(RemoteInterface):
|
|
|
|
__remote_name__ = "RIEncryptedUploadable.tahoe.allmydata.com"
|
|
|
|
|
|
|
|
def get_size():
|
2008-03-11 17:50:31 +00:00
|
|
|
return Offset
|
2008-01-10 04:25:47 +00:00
|
|
|
|
2008-01-16 10:03:35 +00:00
|
|
|
def get_all_encoding_parameters():
|
|
|
|
return (int, int, int, long)
|
2008-01-10 04:25:47 +00:00
|
|
|
|
2008-03-11 17:50:31 +00:00
|
|
|
def read_encrypted(offset=Offset, length=ReadSize):
|
2008-01-11 12:42:55 +00:00
|
|
|
return ListOf(str)
|
2008-01-10 04:25:47 +00:00
|
|
|
|
2008-01-11 12:42:55 +00:00
|
|
|
def get_plaintext_hashtree_leaves(first=int, last=int, num_segments=int):
|
2008-01-10 04:25:47 +00:00
|
|
|
return ListOf(Hash)
|
|
|
|
|
|
|
|
def get_plaintext_hash():
|
|
|
|
return Hash
|
|
|
|
|
2008-01-17 08:52:33 +00:00
|
|
|
def close():
|
|
|
|
return None
|
|
|
|
|
2008-01-10 04:25:47 +00:00
|
|
|
|
2008-01-11 11:53:37 +00:00
|
|
|
class RICHKUploadHelper(RemoteInterface):
|
2008-01-10 04:25:47 +00:00
|
|
|
__remote_name__ = "RIUploadHelper.tahoe.allmydata.com"
|
|
|
|
|
|
|
|
def upload(reader=RIEncryptedUploadable):
|
|
|
|
return UploadResults
|
|
|
|
|
|
|
|
|
|
|
|
class RIHelper(RemoteInterface):
|
|
|
|
__remote_name__ = "RIHelper.tahoe.allmydata.com"
|
|
|
|
|
2008-01-11 11:53:37 +00:00
|
|
|
def upload_chk(si=StorageIndex):
|
2008-01-10 04:25:47 +00:00
|
|
|
"""See if a file with a given storage index needs uploading. The
|
|
|
|
helper will ask the appropriate storage servers to see if the file
|
|
|
|
has already been uploaded. If so, the helper will return a set of
|
|
|
|
'upload results' that includes whatever hashes are needed to build
|
|
|
|
the read-cap, and perhaps a truncated sharemap.
|
|
|
|
|
|
|
|
If the file has not yet been uploaded (or if it was only partially
|
|
|
|
uploaded), the helper will return an empty upload-results dictionary
|
2008-01-11 11:53:37 +00:00
|
|
|
and also an RICHKUploadHelper object that will take care of the
|
|
|
|
upload process. The client should call upload() on this object and
|
|
|
|
pass it a reference to an RIEncryptedUploadable object that will
|
|
|
|
provide ciphertext. When the upload is finished, the upload() method
|
|
|
|
will finish and return the upload results.
|
2008-01-10 04:25:47 +00:00
|
|
|
"""
|
2008-01-11 11:53:37 +00:00
|
|
|
return (UploadResults, ChoiceOf(RICHKUploadHelper, None))
|
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
|
|
|
|
|
|
|
|
|
|
|
class RIStatsProvider(RemoteInterface):
|
|
|
|
__remote_name__ = "RIStatsProvider.tahoe.allmydata.com"
|
|
|
|
"""
|
|
|
|
Provides access to statistics and monitoring information.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get_stats():
|
|
|
|
"""
|
|
|
|
returns a dictionary containing 'counters' and 'stats', each a dictionary
|
|
|
|
with string counter/stat name keys, and numeric values. counters are
|
|
|
|
monotonically increasing measures of work done, and stats are instantaneous
|
|
|
|
measures (potentially time averaged internally)
|
|
|
|
"""
|
|
|
|
return DictOf(str, DictOf(str, ChoiceOf(float, int, long)))
|
|
|
|
|
|
|
|
class RIStatsGatherer(RemoteInterface):
|
|
|
|
__remote_name__ = "RIStatsGatherer.tahoe.allmydata.com"
|
|
|
|
"""
|
|
|
|
Provides a monitoring service for centralised collection of stats
|
|
|
|
"""
|
|
|
|
|
|
|
|
def provide(provider=RIStatsProvider, nickname=str):
|
|
|
|
"""
|
|
|
|
@param provider: a stats collector instance which should be polled
|
|
|
|
periodically by the gatherer to collect stats.
|
|
|
|
@param nickname: a name useful to identify the provided client
|
|
|
|
"""
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2008-02-01 04:10:15 +00:00
|
|
|
class IStatsProducer(Interface):
|
|
|
|
def get_stats():
|
|
|
|
"""
|
|
|
|
returns a dictionary, with str keys representing the names of stats
|
|
|
|
to be monitored, and numeric values.
|
|
|
|
"""
|
|
|
|
|
2008-04-02 01:45:13 +00:00
|
|
|
class RIKeyGenerator(RemoteInterface):
|
|
|
|
__remote_name__ = "RIKeyGenerator.tahoe.allmydata.com"
|
|
|
|
"""
|
|
|
|
Provides a service offering to make RSA key pairs.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def get_rsa_key_pair(key_size=int):
|
|
|
|
"""
|
|
|
|
@param key_size: the size of the signature key.
|
|
|
|
@return: tuple(verifying_key, signing_key)
|
|
|
|
"""
|
|
|
|
return TupleOf(str, str)
|
2008-06-03 07:01:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FileTooLargeError(Exception):
|
|
|
|
pass
|
|
|
|
|