diff --git src/allmydata/node.py src/allmydata/node.py index 7f5bf61..04a1035 100644 --- src/allmydata/node.py +++ src/allmydata/node.py @@ -258,7 +258,11 @@ class Node(service.MultiService): service.MultiService.startService(self) d = defer.succeed(None) - d.addCallback(lambda res: iputil.get_local_addresses_async()) + location = self.get_config("node", "tub.location", None) + if location == "": + d.addCallback(lambda res: ['127.0.0.1']) + else: + d.addCallback(lambda res: iputil.get_local_addresses_async()) d.addCallback(self._setup_tub) def _ready(res): self.log("%s running" % self.NODETYPE) @@ -333,6 +337,8 @@ class Node(service.MultiService): base_location = ",".join([ "%s:%d" % (addr, portnum) for addr in local_addresses ]) location = self.get_config("node", "tub.location", base_location) + if location == "": + location = base_location self.log("Tub location set to %s" % location) self.tub.setLocation(location) diff --git src/allmydata/test/test_node.py src/allmydata/test/test_node.py index 24ec571..c1300c1 100644 --- src/allmydata/test/test_node.py +++ src/allmydata/test/test_node.py @@ -1,5 +1,8 @@ import os, stat, sys, time + +from mock import patch + from twisted.trial import unittest from twisted.internet import defer from twisted.python import log @@ -31,6 +34,36 @@ class TestCase(testutil.SignalMixin, unittest.TestCase): d.addCallback(flushEventualQueue) return d + # XXX should use mock decorator from #1301 + def test_anonymous_location(self): + patcher = patch('allmydata.util.iputil.get_local_addresses_async') + mock = patcher.__enter__() + mock.return_value = ["1.2.3.4"] + + basedir = "test_node/test_anonymous_location" + fileutil.make_dirs(basedir) + f = open(os.path.join(basedir, 'tahoe.cfg'), 'wt') + f.write("[node]\n") + f.write("tub.location = \n") + f.close() + + n = TestNode(basedir) + n.setServiceParent(self.parent) + d = n.when_tub_ready() + + def _check_addresses(ignored_result): + furl = n.tub.registerReference(n) + self.failIf("1.2.3.4" in furl, furl) + self.failUnless("127.0.0.1" in furl, furl) + + d.addCallback(_check_addresses) + + def cleanup(res): + patcher.__exit__() + return res + d.addBoth(cleanup) + return d + def test_location(self): basedir = "test_node/test_location" fileutil.make_dirs(basedir)