fix handling of local_ip file and rename it to advertised_ip_addresses and document it in README

This commit is contained in:
Zooko O'Whielacronx 2007-05-22 14:01:40 -07:00
parent 10df6fac02
commit a2970cf7c1
2 changed files with 34 additions and 17 deletions

8
README
View File

@ -229,6 +229,14 @@ RUNNING:
To stop it again, use 'make stop-client'. Similar makefile targets exist To stop it again, use 'make stop-client'. Similar makefile targets exist
for making and running an introducer node. 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 There is a public grid available for testing. Look at the wiki page
(http://allmydata.org) for the necessary .furl data. (http://allmydata.org) for the necessary .furl data.

View File

@ -1,5 +1,6 @@
import os.path import os.path, re
from twisted.python import log from twisted.python import log
from twisted.application import service from twisted.application import service
from twisted.internet import defer from twisted.internet import defer
@ -12,13 +13,16 @@ import allmydata
import zfec import zfec
import foolscap 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): class Node(service.MultiService):
# this implements common functionality of both Client nodes, Introducer # this implements common functionality of both Client nodes, Introducer
# nodes, and Vdrive nodes # nodes, and Vdrive nodes
NODETYPE = "unknown NODETYPE" NODETYPE = "unknown NODETYPE"
PORTNUMFILE = None PORTNUMFILE = None
CERTFILE = None CERTFILE = None
LOCAL_IP_FILE = "local_ip" LOCAL_IP_FILE = "advertised_ip_addresses"
NODEIDFILE = "my_nodeid" NODEIDFILE = "my_nodeid"
def __init__(self, basedir="."): def __init__(self, basedir="."):
@ -105,21 +109,26 @@ class Node(service.MultiService):
# running, which means after startService. # running, which means after startService.
l = self.tub.getListeners()[0] l = self.tub.getListeners()[0]
portnum = l.getPortnum() portnum = l.getPortnum()
local_ip_filename = os.path.join(self.basedir, self.LOCAL_IP_FILE) # record which port we're listening on, so we can grab the same one next time
if os.path.exists(local_ip_filename): open(self._portnumfile, "w").write("%d\n" % portnum)
f = open(local_ip_filename, "r")
local_ip = f.read() local_addresses = [ "%s:%d" % (addr, portnum,) for addr in local_addresses ]
f.close()
if local_ip not in local_addresses: addresses = []
local_addresses.append(local_ip) try:
if not os.path.exists(self._portnumfile): for addrline in open(os.path.join(self.basedir, self.LOCAL_IP_FILE), "rU"):
# record which port we're listening on, so we can grab the same mo = ADDR_RE.search(addrline)
# one next time if mo:
f = open(self._portnumfile, "w") (addr, dummy, aportnum,) = mo.groups()
f.write("%d\n" % portnum) if aportnum is None:
f.close() aportnum = portnum
location = ",".join(["%s:%d" % (ip, portnum) addresses.append("%s:%d" % (addr, aportnum,))
for ip in local_addresses]) except EnvironmentError:
pass
addresses.extend(local_addresses)
location = ",".join(addresses)
self.log("Tub location set to %s" % location) self.log("Tub location set to %s" % location)
self.tub.setLocation(location) self.tub.setLocation(location)
return self.tub return self.tub