]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
fix handling of local_ip file and rename it to advertised_ip_addresses and document...
authorZooko O'Whielacronx <zooko@zooko.com>
Tue, 22 May 2007 21:01:40 +0000 (14:01 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Tue, 22 May 2007 21:01:40 +0000 (14:01 -0700)
README
src/allmydata/node.py

diff --git a/README b/README
index 7fe024cb45191bc510ae30f70ca0419de4830e9f..75a268e156695a50ac92de6636fcf2c80cd9eaec 100644 (file)
--- a/README
+++ b/README
@@ -229,6 +229,14 @@ RUNNING:
  To stop it again, use 'make stop-client'.  Similar makefile targets exist
  for making and running an introducer node.
 
+ If you are behind a firewall and you can configure your firewall to forward
+ TCP connections on a port to the computer running your Tahoe node, then you
+ can configure the Tahoe node to announce itself as being available on that
+ IP address and port.  The way to do this is to create a file named
+ $HERE/advertised_ip_addresses, in which you can put IP addresses and port numbers in
+ "dotted-quad:port" form, e.g. "209.97.232.113:1345".  You can put multiple
+ IP-address-and-port-number entries into this file, on separate lines.
+
  There is a public grid available for testing.  Look at the wiki page
  (http://allmydata.org) for the necessary .furl data.
 
index b70a4a19a9ec17846371429fcdb9a4fabf31d6ab..c0c89159128438fc01a130e827b506a6435b80e7 100644 (file)
@@ -1,5 +1,6 @@
 
-import os.path
+import os.path, re
+
 from twisted.python import log
 from twisted.application import service
 from twisted.internet import defer
@@ -12,13 +13,16 @@ import allmydata
 import zfec
 import foolscap
 
+# group 1 will be addr (dotted quad string), group 3 if any will be portnum (string)
+ADDR_RE=re.compile("^([1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*)(:([1-9][0-9]*))?$")
+
 class Node(service.MultiService):
     # this implements common functionality of both Client nodes, Introducer 
     # nodes, and Vdrive nodes
     NODETYPE = "unknown NODETYPE"
     PORTNUMFILE = None
     CERTFILE = None
-    LOCAL_IP_FILE = "local_ip"
+    LOCAL_IP_FILE = "advertised_ip_addresses"
     NODEIDFILE = "my_nodeid"
 
     def __init__(self, basedir="."):
@@ -105,21 +109,26 @@ class Node(service.MultiService):
         # running, which means after startService.
         l = self.tub.getListeners()[0]
         portnum = l.getPortnum()
-        local_ip_filename = os.path.join(self.basedir, self.LOCAL_IP_FILE)
-        if os.path.exists(local_ip_filename):
-            f = open(local_ip_filename, "r")
-            local_ip = f.read()
-            f.close()
-            if local_ip not in local_addresses:
-                local_addresses.append(local_ip)
-        if not os.path.exists(self._portnumfile):
-            # record which port we're listening on, so we can grab the same
-            # one next time
-            f = open(self._portnumfile, "w")
-            f.write("%d\n" % portnum)
-            f.close()
-        location = ",".join(["%s:%d" % (ip, portnum)
-                             for ip in local_addresses])
+        # record which port we're listening on, so we can grab the same one next time
+        open(self._portnumfile, "w").write("%d\n" % portnum)
+
+        local_addresses = [ "%s:%d" % (addr, portnum,) for addr in local_addresses ]
+
+        addresses = []
+        try:
+            for addrline in open(os.path.join(self.basedir, self.LOCAL_IP_FILE), "rU"):
+                mo = ADDR_RE.search(addrline)
+                if mo:
+                    (addr, dummy, aportnum,) = mo.groups()
+                    if aportnum is None:
+                        aportnum = portnum
+                    addresses.append("%s:%d" % (addr, aportnum,))
+        except EnvironmentError:
+            pass
+
+        addresses.extend(local_addresses)
+
+        location = ",".join(addresses)
         self.log("Tub location set to %s" % location)
         self.tub.setLocation(location)
         return self.tub