]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
reinstate creation of node.url files upon startup
authorrobk-tahoe <robk-tahoe@allmydata.com>
Tue, 8 Jan 2008 01:04:56 +0000 (18:04 -0700)
committerrobk-tahoe <robk-tahoe@allmydata.com>
Tue, 8 Jan 2008 01:04:56 +0000 (18:04 -0700)
a recent purge of the start.html code also took away the logic that wrote
'node.url' into the node root.  this is required for the tahoe cli tool to
find the node.  this puts back a limited fraction of that code, so that the
node writes out a node.url file upon startup.

src/allmydata/client.py
src/allmydata/webish.py

index 8c3b028e15afe23dc8584f75331abce290a176f1..f6670d0e79a6c1c98d7af01e0b6236b0c747eaed 100644 (file)
@@ -97,7 +97,8 @@ class Client(node.Node, Referenceable, testutil.PollMixin):
         self.log("init_web(webport=%s)", args=(webport,))
 
         from allmydata.webish import WebishServer
-        ws = WebishServer(webport)
+        nodeurl_path = os.path.join(self.basedir, "node.url")
+        ws = WebishServer(webport, nodeurl_path)
         if self.get_config("webport_allow_localfile") is not None:
             ws.allow_local_access(True)
         self.add_service(ws)
index 13fc476cc50ddbcc3c973365be8ee97e7cfa17cd..aa3d0625923b55b4baa2f178551da1c3e4996018 100644 (file)
@@ -1,7 +1,7 @@
 
 from base64 import b32encode
 import os.path
-from twisted.application import service, strports
+from twisted.application import service, strports, internet
 from twisted.web import static, resource, server, html, http
 from twisted.python import util, log
 from twisted.internet import defer
@@ -1372,7 +1372,7 @@ class LocalAccess:
 class WebishServer(service.MultiService):
     name = "webish"
 
-    def __init__(self, webport):
+    def __init__(self, webport, nodeurl_path):
         service.MultiService.__init__(self)
         self.webport = webport
         self.root = Root()
@@ -1384,6 +1384,8 @@ class WebishServer(service.MultiService):
         s.setServiceParent(self)
         self.listener = s # stash it so the tests can query for the portnum
         self._started = defer.Deferred()
+        if nodeurl_path:
+            self._started.addCallback(self._write_nodeurl_file, nodeurl_path)
 
     def allow_local_access(self, enable=True):
         self.allow_local.local_access = enable
@@ -1399,3 +1401,19 @@ class WebishServer(service.MultiService):
         # apparently 'ISite' does not exist
         #self.site._client = self.parent
         self._started.callback(None)
+
+    def _write_nodeurl_file(self, junk, nodeurl_path):
+        # what is our webport?
+        s = self.listener
+        if isinstance(s, internet.TCPServer):
+            base_url = "http://localhost:%d" % s._port.getHost().port
+        elif isinstance(s, internet.SSLServer):
+            base_url = "https://localhost:%d" % s._port.getHost().port
+        else:
+            base_url = None
+        if base_url:
+            f = open(nodeurl_path, 'wb')
+            # this file is world-readable
+            f.write(base_url + "\n")
+            f.close()
+