return self.http_site
def joinComplete(self, result):
- self.my_addr = findMyIPAddr(result, config.getint(config.get('DEFAULT', 'DHT'), 'PORT'))
+ self.my_addr = findMyIPAddr(result,
+ config.getint(config.get('DEFAULT', 'DHT'), 'PORT'),
+ config.getboolean('DEFAULT', 'LOCAL_OK'))
if not self.my_addr:
raise RuntimeError, "IP address for this machine could not be found"
self.cache.scanDirectories()
# User name to try and run as
'USERNAME': '',
+
+ # Whether it's OK to use an IP addres from a known local/private range
+ 'LOCAL_OK': 'no',
# Which DHT implementation to use.
# It must be possile to do "from <DHT>.DHT import DHT" to get a class that
'(172\.0?([1][6-9])|([2][0-9])|([3][0-1])\.[0-9]{1,3}\.[0-9]{1,3})|'+
'(127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$')
-def findMyIPAddr(addrs, intended_port):
+def findMyIPAddr(addrs, intended_port, local_ok = False):
+ """Find the best IP address to use from a list of possibilities.
+
+ @param addrs: the list of possible IP addresses
+ @param intended_port: the port that was supposed to be used
+ @param local_ok: whether known local/private IP ranges are allowed
+ (defaults to False)
+ @return: the preferred IP address, or None if one couldn't be found
+ """
log.msg("got addrs: %r" % (addrs,))
my_addr = None
# Get counts for all the non-local addresses returned
addr_count = {}
for addr in ifconfig:
- if not isLocal.match(addr):
+ if local_ok or not isLocal.match(addr):
addr_count.setdefault(addr, 0)
addr_count[addr] += 1
addr_count = {}
port_count = {}
for addr in addrs:
- if not isLocal.match(addr[0]):
+ if local_ok or not isLocal.match(addr[0]):
addr_count.setdefault(addr[0], 0)
addr_count[addr[0]] += 1
port_count.setdefault(addr[1], 0)