]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - src/allmydata/introducer/interfaces.py
switch all foolscap imports to use foolscap.api or foolscap.logging
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / introducer / interfaces.py
1
2 from zope.interface import Interface
3 from foolscap.api import StringConstraint, TupleOf, SetOf, DictOf, Any, \
4     RemoteInterface
5 FURL = StringConstraint(1000)
6
7 # Announcements are (FURL, service_name, remoteinterface_name,
8 #                    nickname, my_version, oldest_supported)
9 #  the (FURL, service_name, remoteinterface_name) refer to the service being
10 #  announced. The (nickname, my_version, oldest_supported) refer to the
11 #  client as a whole. The my_version/oldest_supported strings can be parsed
12 #  by an allmydata.util.version.Version instance, and then compared. The
13 #  first goal is to make sure that nodes are not confused by speaking to an
14 #  incompatible peer. The second goal is to enable the development of
15 #  backwards-compatibility code.
16
17 Announcement = TupleOf(FURL, str, str,
18                        str, str, str)
19
20 class RIIntroducerSubscriberClient(RemoteInterface):
21     __remote_name__ = "RIIntroducerSubscriberClient.tahoe.allmydata.com"
22
23     def announce(announcements=SetOf(Announcement)):
24         """I accept announcements from the publisher."""
25         return None
26
27     def set_encoding_parameters(parameters=(int, int, int)):
28         """Advise the client of the recommended k-of-n encoding parameters
29         for this grid. 'parameters' is a tuple of (k, desired, n), where 'n'
30         is the total number of shares that will be created for any given
31         file, while 'k' is the number of shares that must be retrieved to
32         recover that file, and 'desired' is the minimum number of shares that
33         must be placed before the uploader will consider its job a success.
34         n/k is the expansion ratio, while k determines the robustness.
35
36         Introducers should specify 'n' according to the expected size of the
37         grid (there is no point to producing more shares than there are
38         peers), and k according to the desired reliability-vs-overhead goals.
39
40         Note that setting k=1 is equivalent to simple replication.
41         """
42         return None
43
44 # When Foolscap can handle multiple interfaces (Foolscap#17), the
45 # full-powered introducer will implement both RIIntroducerPublisher and
46 # RIIntroducerSubscriberService. Until then, we define
47 # RIIntroducerPublisherAndSubscriberService as a combination of the two, and
48 # make everybody use that.
49
50 class RIIntroducerPublisher(RemoteInterface):
51     """To publish a service to the world, connect to me and give me your
52     announcement message. I will deliver a copy to all connected subscribers."""
53     __remote_name__ = "RIIntroducerPublisher.tahoe.allmydata.com"
54
55     def publish(announcement=Announcement):
56         # canary?
57         return None
58
59 class RIIntroducerSubscriberService(RemoteInterface):
60     __remote_name__ = "RIIntroducerSubscriberService.tahoe.allmydata.com"
61
62     def subscribe(subscriber=RIIntroducerSubscriberClient, service_name=str):
63         """Give me a subscriber reference, and I will call its new_peers()
64         method will any announcements that match the desired service name. I
65         will ignore duplicate subscriptions.
66         """
67         return None
68
69 class RIIntroducerPublisherAndSubscriberService(RemoteInterface):
70     __remote_name__ = "RIIntroducerPublisherAndSubscriberService.tahoe.allmydata.com"
71     def get_version():
72         return DictOf(str, Any())
73     def publish(announcement=Announcement):
74         return None
75     def subscribe(subscriber=RIIntroducerSubscriberClient, service_name=str):
76         return None
77
78 class IIntroducerClient(Interface):
79     """I provide service introduction facilities for a node. I help nodes
80     publish their services to the rest of the world, and I help them learn
81     about services available on other nodes."""
82
83     def publish(furl, service_name, remoteinterface_name):
84         """Once you call this, I will tell the world that the Referenceable
85         available at FURL is available to provide a service named
86         SERVICE_NAME. The precise definition of the service being provided is
87         identified by the Foolscap 'remote interface name' in the last
88         parameter: this is supposed to be a globally-unique string that
89         identifies the RemoteInterface that is implemented."""
90
91     def subscribe_to(service_name):
92         """Call this if you will eventually want to use services with the
93         given SERVICE_NAME. This will prompt me to subscribe to announcements
94         of those services. You can pick up the announcements later by calling
95         get_all_connections_for() or get_permuted_peers().
96         """
97
98     def get_all_connections():
99         """Return a frozenset of (nodeid, service_name, rref) tuples, one for
100         each active connection we've established to a remote service. This is
101         mostly useful for unit tests that need to wait until a certain number
102         of connections have been made."""
103
104     def get_all_connectors():
105         """Return a dict that maps from (nodeid, service_name) to a
106         RemoteServiceConnector instance for all services that we are actively
107         trying to connect to. Each RemoteServiceConnector has the following
108         public attributes::
109
110           service_name: the type of service provided, like 'storage'
111           announcement_time: when we first heard about this service
112           last_connect_time: when we last established a connection
113           last_loss_time: when we last lost a connection
114
115           version: the peer's version, from the most recent connection
116           oldest_supported: the peer's oldest supported version, same
117
118           rref: the RemoteReference, if connected, otherwise None
119           remote_host: the IAddress, if connected, otherwise None
120
121         This method is intended for monitoring interfaces, such as a web page
122         which describes connecting and connected peers.
123         """
124
125     def get_all_peerids():
126         """Return a frozenset of all peerids to whom we have a connection (to
127         one or more services) established. Mostly useful for unit tests."""
128
129     def get_all_connections_for(service_name):
130         """Return a frozenset of (nodeid, service_name, rref) tuples, one
131         for each active connection that provides the given SERVICE_NAME."""
132
133     def get_permuted_peers(service_name, key):
134         """Returns an ordered list of (peerid, rref) tuples, selecting from
135         the connections that provide SERVICE_NAME, using a hash-based
136         permutation keyed by KEY. This randomizes the service list in a
137         repeatable way, to distribute load over many peers.
138         """
139
140     def connected_to_introducer():
141         """Returns a boolean, True if we are currently connected to the
142         introducer, False if not."""
143