From: Brian Warner Date: Wed, 4 Apr 2007 22:59:36 +0000 (-0700) Subject: allmydata.interfaces: remove some of the placeholders now that we require foolscap... X-Git-Url: https://git.rkrishnan.org/zeppelin?a=commitdiff_plain;h=92ba8dc8d25524cdb2caa362599a8afc5ca6a563;p=tahoe-lafs%2Ftahoe-lafs.git allmydata.interfaces: remove some of the placeholders now that we require foolscap-0.1.2 --- diff --git a/README b/README index 48624ab3..c81fd788 100644 --- a/README +++ b/README @@ -21,7 +21,7 @@ DEPENDENCIES: * web, trial, conch Note that Twisted requires zope.interface, and that the standard batteries-included Twisted distribution includes a copy. - Foolscap (probably 0.0.7 or newer) + Foolscap (0.1.2 or newer) - note: since the Foolscap wire protocol is not yet compatible from one release to the next, make sure all of your nodes are using the same version of Foolscap diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index 4cb69ba5..099a79e7 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -1,26 +1,19 @@ from zope.interface import Interface -from foolscap.schema import StringConstraint, ListOf, TupleOf, Any -from foolscap import RemoteInterface +from foolscap.schema import StringConstraint, ListOf, TupleOf, SetOf, DictOf +from foolscap import RemoteInterface, Referenceable HASH_SIZE=32 -Hash = StringConstraint(HASH_SIZE) # binary format 32-byte SHA256 hash -Nodeid = StringConstraint(20) # binary format 20-byte SHA1 hash +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 PBURL = StringConstraint(150) Verifierid = StringConstraint(20) URI = StringConstraint(200) # kind of arbitrary +MAX_BUCKETS = 200 # per peer ShareData = StringConstraint(100000) -# these six are here because Foolscap does not yet support the kind of -# restriction I really want to apply to these. -RIClient_ = Any() -Referenceable_ = Any() -RIBucketWriter_ = Any() -RIBucketReader_ = Any() -RIMutableDirectoryNode_ = Any() -RIMutableFileNode_ = Any() -def SetOf(*args, **kwargs): return Any() -def DictOf(*args, **kwargs): return Any() class RIIntroducerClient(RemoteInterface): def new_peers(pburls=SetOf(PBURL)): @@ -32,7 +25,7 @@ class RIIntroducer(RemoteInterface): class RIClient(RemoteInterface): def get_service(name=str): - return Referenceable_ + return Referenceable def get_nodeid(): return Nodeid @@ -57,18 +50,6 @@ class RIBucketWriter(RemoteInterface): """ return None -class RIStorageServer(RemoteInterface): - def allocate_buckets(verifierid=Verifierid, sharenums=SetOf(int), - sharesize=int, blocksize=int, canary=Referenceable_): - """ - @param canary: If the canary is lost before close(), the bucket is deleted. - @return: tuple of (alreadygot, allocated), where alreadygot is what we - already have and is what we hereby agree to accept - """ - return TupleOf(SetOf(int), DictOf(int, RIBucketWriter)) - def get_buckets(verifierid=Verifierid): - return DictOf(int, RIBucketReader_) - class RIBucketReader(RemoteInterface): def get_block(blocknum=int): """Most blocks will be the same size. The last block might be shorter @@ -80,6 +61,23 @@ class RIBucketReader(RemoteInterface): def get_share_hashes(): return ListOf(TupleOf(int, Hash)) +class RIStorageServer(RemoteInterface): + def allocate_buckets(verifierid=Verifierid, + sharenums=SetOf(int, maxLength=MAX_BUCKETS), + sharesize=int, blocksize=int, canary=Referenceable): + """ + @param canary: If the canary is lost before close(), the bucket is deleted. + @return: tuple of (alreadygot, allocated), where alreadygot is what we + already have and is what we hereby agree to accept + """ + return TupleOf(SetOf(int, maxLength=MAX_BUCKETS), + DictOf(int, RIBucketWriter, maxKeys=MAX_BUCKETS)) + def get_buckets(verifierid=Verifierid): + return DictOf(int, RIBucketReader, maxKeys=MAX_BUCKETS) + +# hm, we need a solution for forward references in schemas +from foolscap.schema import Any +RIMutableDirectoryNode_ = Any() # TODO: how can we avoid this? class RIMutableDirectoryNode(RemoteInterface): def list(): return ListOf( TupleOf(str, # name, relative to directory diff --git a/src/allmydata/storageserver.py b/src/allmydata/storageserver.py index 0579c88d..df9b1a61 100644 --- a/src/allmydata/storageserver.py +++ b/src/allmydata/storageserver.py @@ -4,7 +4,8 @@ from foolscap import Referenceable from twisted.application import service from zope.interface import implements -from allmydata.interfaces import RIStorageServer, RIBucketWriter +from allmydata.interfaces import RIStorageServer, RIBucketWriter, \ + RIBucketReader from allmydata import interfaces from allmydata.util import bencode, fileutil, idlib from allmydata.util.assertutil import _assert, precondition @@ -70,6 +71,8 @@ def str2l(s): return [ s[i:i+interfaces.HASH_SIZE] for i in range(0, len(s), interfaces.HASH_SIZE) ] class BucketReader(Referenceable): + implements(RIBucketReader) + def __init__(self, home): self.home = home self.blocksize = int(self._read_file('blocksize'))