refactor node startup, remove tub_ready()

This commit is contained in:
Brian Warner 2008-02-05 19:58:38 -07:00
parent 09e2a3ec09
commit 315725926f
3 changed files with 43 additions and 44 deletions

View File

@ -59,7 +59,10 @@ class Client(node.Node, testutil.PollMixin):
self.init_stats_provider() self.init_stats_provider()
self.init_lease_secret() self.init_lease_secret()
self.init_storage() self.init_storage()
self.init_options() self.init_control()
run_helper = self.get_config("run_helper")
if run_helper:
self.init_helper()
helper_furl = self.get_config("helper.furl") helper_furl = self.get_config("helper.furl")
self.add_service(Uploader(helper_furl)) self.add_service(Uploader(helper_furl))
self.add_service(Downloader()) self.add_service(Downloader())
@ -142,11 +145,33 @@ class Client(node.Node, testutil.PollMixin):
ri_name = RIStorageServer.__remote_name__ ri_name = RIStorageServer.__remote_name__
self.introducer_client.publish(furl, "storage", ri_name) self.introducer_client.publish(furl, "storage", ri_name)
d.addCallback(_publish) d.addCallback(_publish)
d.addErrback(log.err, facility="tahoe.storage", level=log.BAD) d.addErrback(log.err, facility="tahoe.init", level=log.BAD)
def init_control(self):
d = self.when_tub_ready()
def _publish(res):
c = ControlServer()
c.setServiceParent(self)
control_url = self.tub.registerReference(c)
self.write_private_config("control.furl", control_url + "\n")
d.addCallback(_publish)
d.addErrback(log.err, facility="tahoe.init", level=log.BAD)
def init_options(self): def init_helper(self):
pass d = self.when_tub_ready()
def _publish(self):
h = Helper(os.path.join(self.basedir, "helper"))
h.setServiceParent(self)
# TODO: this is confusing. BASEDIR/private/helper.furl is created
# by the helper. BASEDIR/helper.furl is consumed by the client
# who wants to use the helper. I like having the filename be the
# same, since that makes 'cp' work smoothly, but the difference
# between config inputs and generated outputs is hard to see.
helper_furlfile = os.path.join(self.basedir,
"private", "helper.furl")
self.tub.registerReference(h, furlFile=helper_furlfile)
d.addCallback(_publish)
d.addErrback(log.err, facility="tahoe.init", level=log.BAD)
def init_web(self, webport): def init_web(self, webport):
self.log("init_web(webport=%s)", args=(webport,)) self.log("init_web(webport=%s)", args=(webport,))
@ -169,37 +194,6 @@ class Client(node.Node, testutil.PollMixin):
self.log("hotline file missing, shutting down") self.log("hotline file missing, shutting down")
reactor.stop() reactor.stop()
def tub_ready(self):
self.log("tub_ready")
node.Node.tub_ready(self)
# TODO: replace register_control() with an init_control() that
# internally uses self.when_tub_ready() to stall registerReference.
# Do the same for register_helper(). That will remove the need for
# this tub_ready() method.
self.register_control()
self.register_helper()
def register_control(self):
c = ControlServer()
c.setServiceParent(self)
control_url = self.tub.registerReference(c)
self.write_private_config("control.furl", control_url + "\n")
def register_helper(self):
run_helper = self.get_config("run_helper")
if not run_helper:
return
h = Helper(os.path.join(self.basedir, "helper"))
h.setServiceParent(self)
# TODO: this is confusing. BASEDIR/private/helper.furl is created by
# the helper. BASEDIR/helper.furl is consumed by the client who wants
# to use the helper. I like having the filename be the same, since
# that makes 'cp' work smoothly, but the difference between config
# inputs and generated outputs is hard to see.
helper_furlfile = os.path.join(self.basedir, "private", "helper.furl")
self.tub.registerReference(h, furlFile=helper_furlfile)
def get_all_peerids(self): def get_all_peerids(self):
return self.introducer_client.get_all_peerids() return self.introducer_client.get_all_peerids()

View File

@ -15,7 +15,11 @@ class IntroducerNode(node.Node):
ENCODING_PARAMETERS_FILE = "encoding_parameters" ENCODING_PARAMETERS_FILE = "encoding_parameters"
DEFAULT_K, DEFAULT_DESIRED, DEFAULT_N = 3, 7, 10 DEFAULT_K, DEFAULT_DESIRED, DEFAULT_N = 3, 7, 10
def tub_ready(self): def __init__(self, basedir="."):
node.Node.__init__(self, basedir)
self.init_introducer()
def init_introducer(self):
k, desired, n = self.DEFAULT_K, self.DEFAULT_DESIRED, self.DEFAULT_N k, desired, n = self.DEFAULT_K, self.DEFAULT_DESIRED, self.DEFAULT_N
data = self.get_config("encoding_parameters") data = self.get_config("encoding_parameters")
if data is not None: if data is not None:
@ -23,9 +27,15 @@ class IntroducerNode(node.Node):
k = int(k); desired = int(desired); n = int(n) k = int(k); desired = int(desired); n = int(n)
introducerservice = IntroducerService(self.basedir, (k, desired, n)) introducerservice = IntroducerService(self.basedir, (k, desired, n))
self.add_service(introducerservice) self.add_service(introducerservice)
self.introducer_url = self.tub.registerReference(introducerservice, "introducer")
d = self.when_tub_ready()
def _publish(res):
self.introducer_url = self.tub.registerReference(introducerservice,
"introducer")
self.log(" introducer is at %s" % self.introducer_url) self.log(" introducer is at %s" % self.introducer_url)
self.write_config("introducer.furl", self.introducer_url + "\n") self.write_config("introducer.furl", self.introducer_url + "\n")
d.addCallback(_publish)
d.addErrback(log.err, facility="tahoe.init", level=log.BAD)
class IntroducerService(service.MultiService, Referenceable): class IntroducerService(service.MultiService, Referenceable):
implements(RIIntroducerPublisherAndSubscriberService) implements(RIIntroducerPublisherAndSubscriberService)

View File

@ -161,7 +161,6 @@ class Node(service.MultiService):
d = defer.succeed(None) d = defer.succeed(None)
d.addCallback(lambda res: iputil.get_local_addresses_async()) d.addCallback(lambda res: iputil.get_local_addresses_async())
d.addCallback(self._setup_tub) d.addCallback(self._setup_tub)
d.addCallback(lambda res: self.tub_ready())
def _ready(res): def _ready(res):
self.log("%s running" % self.NODETYPE) self.log("%s running" % self.NODETYPE)
self._tub_ready_observerlist.fire(self) self._tub_ready_observerlist.fire(self)
@ -257,10 +256,6 @@ class Node(service.MultiService):
self.tub.setLocation(location) self.tub.setLocation(location)
return self.tub return self.tub
def tub_ready(self):
# called when the Tub is available for registerReference
pass
def when_tub_ready(self): def when_tub_ready(self):
return self._tub_ready_observerlist.when_fired() return self._tub_ready_observerlist.when_fired()