Ticket #1402: relay.py

File relay.py, 1.6 KB (added by socrates, at 2011-05-12T00:07:15Z)

relay.py - proof of concept for introducer relay

Line 
1from allmydata.node import Node
2from allmydata.introducer.client import IntroducerClient
3from allmydata.util import log
4import allmydata
5
6class relay(Node):
7    def __init__(self,basedir=u'.'):
8        self.PORTNUMFILE = "derp"##not setting this causes Node.__init__ to raise
9        Node.__init__(self,basedir)
10        self.ICs = []
11        for Ifurl in self.get_config('node','Ifurls','').split('---'):
12            #not sure of the perfered way to get a list from tahoe.cfg
13            self.ICs.append(self.init_intro(Ifurl))
14        self.bridge = bridge(self.ICs)
15    def init_intro(self,furl):
16        IC = IntroducerClient(self.tub,furl,self.nickname,
17                              str(allmydata.__full_version__),"1.0.0")
18        d = self.when_tub_ready()
19        def _start_introducer_client(res):
20            IC.setServiceParent(self)
21        d.addCallback(_start_introducer_client)
22        d.addErrback(log.err,facility="tahoe.init",
23                     level=log.BAD, umid="URyI5w")
24        return IC
25class bridge():
26    def __init__(self,ICs):
27        self.ICs = ICs
28        for Ic in self.ICs:
29            Ic.subscribe_to('storage',self.resend_ann)
30    def resend_ann(self,serverid,ann_d):
31        for Ic in self.ICs:##resends to the ic recved from, could be less redundent
32            self.resend_to(Ic,ann_d)
33    def resend_to(self,IC,ann_d):
34        ann = self.ann_d_to_ann(ann_d)
35        IC._published_announcements.add(ann)
36        IC._maybe_publish()
37    def ann_d_to_ann(self,ann_d):
38        return (ann_d["FURL"],ann_d["service-name"],"RIStorageServer.tahoe.allmydata.com",
39                ann_d["nickname"].encode(),ann_d["my-version"],ann_d["oldest-supported"])