From ca3c7abe3afc38633ca1e20daff68c7cdcc7094d Mon Sep 17 00:00:00 2001
From: Daira Hopwood <daira@jacaranda.org>
Date: Mon, 9 Feb 2015 19:20:42 +0000
Subject: [PATCH] Only get the local addresses if they are actually used. refs
 #754

Signed-off-by: Daira Hopwood <daira@jacaranda.org>
---
 src/allmydata/node.py | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/allmydata/node.py b/src/allmydata/node.py
index ab8722af..c20fef3e 100644
--- a/src/allmydata/node.py
+++ b/src/allmydata/node.py
@@ -326,7 +326,6 @@ class Node(service.MultiService):
 
         service.MultiService.startService(self)
         d = defer.succeed(None)
-        d.addCallback(lambda res: iputil.get_local_addresses_async())
         d.addCallback(self._setup_tub)
         def _ready(res):
             self.log("%s running" % self.NODETYPE)
@@ -389,7 +388,7 @@ class Node(service.MultiService):
     def log(self, *args, **kwargs):
         return log.msg(*args, **kwargs)
 
-    def _setup_tub(self, local_addresses):
+    def _setup_tub(self, ign):
         # we can't get a dynamically-assigned portnum until our Tub is
         # running, which means after startService.
         l = self.tub.getListeners()[0]
@@ -400,18 +399,25 @@ class Node(service.MultiService):
 
         location = self.get_config("node", "tub.location", "AUTO")
 
-        # Replace the location "AUTO" with the detected local addresses.
+        # Replace the location "AUTO", if present, with the detected local addresses.
         split_location = location.split(",")
         if "AUTO" in split_location:
-            split_location.remove("AUTO")
-            split_location.extend([ "%s:%d" % (addr, portnum)
-                                    for addr in local_addresses ])
-            location = ",".join(split_location)
-
-        self.log("Tub location set to %s" % location)
-        self.tub.setLocation(location)
-
-        return self.tub
+            d = iputil.get_local_addresses_async()
+            def _add_local(local_addresses):
+                split_location.remove("AUTO")
+                split_location.extend([ "%s:%d" % (addr, portnum)
+                                        for addr in local_addresses ])
+                return ",".join(split_location)
+            d.addCallback(_add_local)
+        else:
+            d = defer.succeed(location)
+
+        def _got_location(location):
+            self.log("Tub location set to %s" % (location,))
+            self.tub.setLocation(location)
+            return self.tub
+        d.addCallback(_got_location)
+        return d
 
     def when_tub_ready(self):
         return self._tub_ready_observerlist.when_fired()
-- 
2.45.2