]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
refactor node startup, remove tub_ready()
authorBrian Warner <warner@allmydata.com>
Wed, 6 Feb 2008 02:58:38 +0000 (19:58 -0700)
committerBrian Warner <warner@allmydata.com>
Wed, 6 Feb 2008 02:58:38 +0000 (19:58 -0700)
src/allmydata/client.py
src/allmydata/introducer.py
src/allmydata/node.py

index 38fd4c75b0ce53c4b6b8e7e09e51c2b30ac87f96..f485a4d572633daf2e81b7f23cf0f5c5e6159113 100644 (file)
@@ -59,7 +59,10 @@ class Client(node.Node, testutil.PollMixin):
         self.init_stats_provider()
         self.init_lease_secret()
         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")
         self.add_service(Uploader(helper_furl))
         self.add_service(Downloader())
@@ -142,11 +145,33 @@ class Client(node.Node, testutil.PollMixin):
             ri_name = RIStorageServer.__remote_name__
             self.introducer_client.publish(furl, "storage", ri_name)
         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):
-        pass
+    def init_helper(self):
+        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):
         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")
         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):
         return self.introducer_client.get_all_peerids()
 
index 45168ad75524c0a0a29ff0f2c0b1c34b8638c672..621721579be88e05dcad857fda4c0e35f7d8cffd 100644 (file)
@@ -15,7 +15,11 @@ class IntroducerNode(node.Node):
     ENCODING_PARAMETERS_FILE = "encoding_parameters"
     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
         data = self.get_config("encoding_parameters")
         if data is not None:
@@ -23,9 +27,15 @@ class IntroducerNode(node.Node):
             k = int(k); desired = int(desired); n = int(n)
         introducerservice = IntroducerService(self.basedir, (k, desired, n))
         self.add_service(introducerservice)
-        self.introducer_url = self.tub.registerReference(introducerservice, "introducer")
-        self.log(" introducer is at %s" % self.introducer_url)
-        self.write_config("introducer.furl", self.introducer_url + "\n")
+
+        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.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):
     implements(RIIntroducerPublisherAndSubscriberService)
index 56b63ccebef54c708fd410fcd525f40b8ccc682c..ae1f9229c0486534ffa803cd248a9b7cde72449d 100644 (file)
@@ -161,7 +161,6 @@ class Node(service.MultiService):
         d = defer.succeed(None)
         d.addCallback(lambda res: iputil.get_local_addresses_async())
         d.addCallback(self._setup_tub)
-        d.addCallback(lambda res: self.tub_ready())
         def _ready(res):
             self.log("%s running" % self.NODETYPE)
             self._tub_ready_observerlist.fire(self)
@@ -257,10 +256,6 @@ class Node(service.MultiService):
         self.tub.setLocation(location)
         return self.tub
 
-    def tub_ready(self):
-        # called when the Tub is available for registerReference
-        pass
-
     def when_tub_ready(self):
         return self._tub_ready_observerlist.when_fired()