]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - allmydata/interfaces.py
14d081e398542d1d314a9466f69cc71a862b39cf
[tahoe-lafs/tahoe-lafs.git] / allmydata / interfaces.py
1
2 from foolscap.schema import StringConstraint, ListOf, TupleOf, Any, Nothing
3 from foolscap import RemoteInterface
4
5 Nodeid = StringConstraint(20) # binary format 20-byte SHA1 hash
6 PBURL = StringConstraint(150)
7 Verifierid = StringConstraint(20)
8 ShareData = StringConstraint(100000)
9 # these four are here because Foolscap does not yet support the kind of
10 # restriction I really want to apply to these.
11 RIClient_ = Any()
12 Referenceable_ = Any()
13 RIBucketWriter_ = Any()
14 RIBucketReader_ = Any()
15 RIMutableDirectoryNode_ = Any()
16 RIMutableFileNode_ = Any()
17
18 class RIQueenRoster(RemoteInterface):
19     def hello(nodeid=Nodeid, node=RIClient_, pburl=PBURL):
20         return RIMutableDirectoryNode_ # the virtual drive root
21
22 class RIClient(RemoteInterface):
23     def get_service(name=str):
24         return Referenceable_
25     def add_peers(new_peers=ListOf(TupleOf(Nodeid, PBURL), maxLength=100)):
26         return Nothing()
27     def lost_peers(lost_peers=ListOf(Nodeid)):
28         return Nothing()
29
30 class RIStorageServer(RemoteInterface):
31     def allocate_bucket(verifierid=Verifierid, bucket_num=int, size=int,
32                         leaser=Nodeid, canary=Referenceable_):
33         # if the canary is lost before close(), the bucket is deleted
34         return RIBucketWriter_
35     def get_buckets(verifierid=Verifierid):
36         return ListOf(TupleOf(int, RIBucketReader_))
37
38 class RIBucketWriter(RemoteInterface):
39     def write(data=ShareData):
40         return Nothing()
41
42     def close():
43         return Nothing()
44
45
46 class RIBucketReader(RemoteInterface):
47     def read():
48         return ShareData
49
50
51 class RIMutableDirectoryNode(RemoteInterface):
52     def list():
53         return ListOf( TupleOf(str, # name, relative to directory
54                                (RIMutableDirectoryNode_, Verifierid)),
55                        maxLength=100,
56                        )
57
58     def get(name=str):
59         return (RIMutableDirectoryNode_, Verifierid)
60
61     def add_directory(name=str):
62         return RIMutableDirectoryNode_
63
64     def add_file(name=str, data=Verifierid):
65         return Nothing()
66
67     def remove(name=str):
68         return Nothing()
69
70     # need more to move directories
71
72 # TODO: figleaf gets confused when the last line of a file is a comment. I
73 # suspect an off-by-one error in the code that decides which lines are code
74 # and which are not.
75 pass