--- home/omar/pc2/gs/tahoe-lafs/src/allmydata/client.py 2010-05-22 20:32:00.000000000 +0100 +++ media/disk3/gs/tahoe-lafs/src/allmydata/client.py 2010-06-16 20:12:13.000000000 +0100 @@ -31,6 +31,8 @@ GiB=1024*MiB TiB=1024*GiB PiB=1024*TiB +MULTI_INTRODUCERS_CFG = "introducers" + class StubClient(Referenceable): implements(RIStubClient) @@ -123,7 +125,7 @@ class Client(node.Node, pollmixin.PollMi self.started_timestamp = time.time() self.logSource="Client" self.DEFAULT_ENCODING_PARAMETERS = self.DEFAULT_ENCODING_PARAMETERS.copy() - self.init_introducer_client() + self.init_introducer_clients() self.init_stats_provider() self.init_secrets() self.init_storage() @@ -170,13 +172,37 @@ class Client(node.Node, pollmixin.PollMi if os.path.exists(os.path.join(self.basedir, "run_helper")): self.set_config("helper", "enabled", "true") - def init_introducer_client(self): + def init_introducer_clients(self): + # We do not like to break any reference to self.introducer_furl self.introducer_furl = self.get_config("client", "introducer.furl") - ic = IntroducerClient(self.tub, self.introducer_furl, + # build a list of introducers from MULTI_INTRODUCERS_CFG + # "BASEDIR/introducers" + self.introducer_furls = [] + self.introducer_furls.append(self.introducer_furl) + cfg = os.path.join(self.basedir, MULTI_INTRODUCERS_CFG) + if os.path.exists(cfg): + f = open(cfg, 'r') + for introducer_furl in f.read().split('\n'): + if not introducer_furl.strip(): + continue + self.introducer_furls.append(introducer_furl) + f.close() + #print "@Init_ICs: furls =", len(self.introducer_furls) + # create a list a introducers client + self.introducer_clients = [] + for introducer_furl in self.introducer_furls: + ic = IntroducerClient(self.tub, introducer_furl, self.nickname, str(allmydata.__full_version__), str(self.OLDEST_SUPPORTED_VERSION)) - self.introducer_client = ic + self.introducer_clients.append(ic) + # retain a link to self.introducer_client + self.introducer_client = self.introducer_clients[0] + for ic in self.introducer_clients: + self.init_introducer_client(ic) + + def init_introducer_client(self, ic): + #print "entering init_introducer_client:", ic # hold off on starting the IntroducerClient until our tub has been # started, so we'll have a useful address on our RemoteReference, so # that the introducer's status page will show us. @@ -185,7 +211,8 @@ class Client(node.Node, pollmixin.PollMi ic.setServiceParent(self) d.addCallback(_start_introducer_client) d.addErrback(log.err, facility="tahoe.init", - level=log.BAD, umid="URyI5w") + level=log.BAD, umid="URyI5x") + #print "exiting init_introducer_clinet()" def init_stats_provider(self): gatherer_furl = self.get_config("client", "stats_gatherer.furl", None) @@ -264,6 +291,11 @@ class Client(node.Node, pollmixin.PollMi furl_file = os.path.join(self.basedir, "private", "storage.furl") furl = self.tub.registerReference(ss, furlFile=furl_file) ri_name = RIStorageServer.__remote_name__ + # in case, we have multi-introducers configured + if self.introducer_clients: + for ic in self.introducer_clients: + ic.publish(furl, "storage", ri_name) + else: self.introducer_client.publish(furl, "storage", ri_name) d.addCallback(_publish) d.addErrback(log.err, facility="tahoe.init", @@ -318,6 +350,11 @@ class Client(node.Node, pollmixin.PollMi # check to see if we're supposed to use the introducer too if self.get_config("client-server-selection", "use_introducer", default=True, boolean=True): + # in case, we have multi-introducers configured + if self.introducer_clients: + for ic in self.introducer_clients: + sb.use_introducer(ic) + else: sb.use_introducer(self.introducer_client) def get_storage_broker(self): @@ -331,6 +368,11 @@ class Client(node.Node, pollmixin.PollMi sc = StubClient() furl = self.tub.registerReference(sc) ri_name = RIStubClient.__remote_name__ + # in case, we have multi-introducers configured + if self.introducer_clients: + for ic in self.introducer_clients: + ic.publish(furl, "stub_client", ri_name) + else: self.introducer_client.publish(furl, "stub_client", ri_name) d = self.when_tub_ready() d.addCallback(_publish) @@ -449,6 +491,18 @@ class Client(node.Node, pollmixin.PollMi return self.introducer_client.connected_to_introducer() return False + # In case we configure multiple introducers + def connected_to_introducers(self): + status = [] + if self.introducer_clients: + s = False + for ic in self.introducer_clients: + s = ic.connected_to_introducer() + status.append(s) + elif self.introducer_client: + return self.introducer_client.connected_to_introducer() + return status + def get_renewal_secret(self): # this will go away return self._secret_holder.get_renewal_secret()