From ca2a3574346b569da5bd1c2dc49f39367f8f32b3 Mon Sep 17 00:00:00 2001
From: KillYourTV <killyourtv@i2pmail.org>
Date: Wed, 7 Aug 2013 15:16:10 +0000
Subject: [PATCH] use only 127.0.0.1 as local address
---
docs/configuration.rst | 24 ++++++++++++++----------
src/allmydata/node.py | 22 +++++++++++++++++-----
src/allmydata/test/test_node.py | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+), 15 deletions(-)
diff --git a/docs/configuration.rst b/docs/configuration.rst
index f3db298..384b7cc 100644
a
|
b
|
set the ``tub.location`` option described below. |
152 | 152 | You might want to override this value if your node lives behind a |
153 | 153 | firewall that is doing inbound port forwarding, or if you are using other |
154 | 154 | proxies such that the local IP address or port number is not the same one |
155 | | that remote clients should use to connect. You might also want to control |
156 | | this when using a Tor proxy to avoid revealing your actual IP address |
157 | | through the Introducer announcement. |
| 155 | that remote clients should use to connect. |
158 | 156 | |
159 | | The value is a comma-separated string of host:port location hints, like |
160 | | this:: |
| 157 | You might also want to control this when using a Tor or I2P proxy to avoid |
| 158 | revealing your actual IP addresses through the Introducer announcement. |
| 159 | To hide the node's local IP addresses, use a blank value:: |
| 160 | |
| 161 | ``tub.location =`` |
| 162 | |
| 163 | Note that this is not the same as omitting ``tub.location``. |
| 164 | |
| 165 | When it is not blank, the value is a comma-separated string of |
| 166 | ``host:port`` location hints, like this:: |
161 | 167 | |
162 | 168 | 123.45.67.89:8098,tahoe.example.com:8098,127.0.0.1:8098 |
163 | 169 | |
… |
… |
set the ``tub.location`` option described below. |
183 | 189 | |
184 | 190 | * Run a node behind a Tor proxy (perhaps via ``torsocks``), in |
185 | 191 | client-only mode (i.e. we can make outbound connections, but other |
186 | | nodes will not be able to connect to us). The literal |
187 | | '``unreachable.example.org``' will not resolve, but will serve as a |
188 | | reminder to human observers that this node cannot be reached. "Don't |
189 | | call us.. we'll call you":: |
| 192 | nodes will not be able to connect to us). "Don't call us.. |
| 193 | we'll call you":: |
190 | 194 | |
191 | 195 | tub.port = 8098 |
192 | | tub.location = unreachable.example.org:0 |
| 196 | tub.location = |
193 | 197 | |
194 | 198 | * Run a node behind a Tor proxy, and make the server available as a Tor |
195 | 199 | "hidden service". (This assumes that other clients are running their |
diff --git a/src/allmydata/node.py b/src/allmydata/node.py
index 8873e5c..af0cb55 100644
a
|
b
|
class Node(service.MultiService): |
305 | 305 | |
306 | 306 | service.MultiService.startService(self) |
307 | 307 | d = defer.succeed(None) |
308 | | d.addCallback(lambda res: iputil.get_local_addresses_async()) |
| 308 | location = self.get_config("node", "tub.location", None) |
| 309 | if location is None: |
| 310 | d = iputil.get_local_addresses_async() |
| 311 | else: |
| 312 | # 'tub.location=' or 'tub.location=addr:port'. either way, we |
| 313 | # don't need to determine our local addresses |
| 314 | d = defer.succeed([]) |
309 | 315 | d.addCallback(self._setup_tub) |
310 | 316 | def _ready(res): |
311 | 317 | self.log("%s running" % self.NODETYPE) |
… |
… |
class Node(service.MultiService): |
378 | 384 | # next time |
379 | 385 | fileutil.write_atomically(self._portnumfile, "%d\n" % portnum, mode="") |
380 | 386 | |
381 | | base_location = ",".join([ "%s:%d" % (addr, portnum) |
382 | | for addr in local_addresses ]) |
383 | | location = self.get_config("node", "tub.location", base_location) |
384 | | self.log("Tub location set to %s" % location) |
| 387 | location = self.get_config("node", "tub.location", None) |
| 388 | if location is None: |
| 389 | location = ",".join([ "%s:%d" % (addr, portnum) |
| 390 | for addr in local_addresses ]) |
| 391 | elif location == "": |
| 392 | # we'd prefer to have no connection-hints, but foolscap can't |
| 393 | # handle that, so use 127.0.0.1 |
| 394 | location = "127.0.0.1:%d" % portnum |
| 395 | # otherwise we use location as-is from tahoe.cfg |
| 396 | self.log("Tub location set to '%s'" % location) |
385 | 397 | self.tub.setLocation(location) |
386 | 398 | |
387 | 399 | return self.tub |
diff --git a/src/allmydata/test/test_node.py b/src/allmydata/test/test_node.py
index 72d6ef8..2e0e04e 100644
a
|
b
|
class TestCase(testutil.SignalMixin, unittest.TestCase): |
33 | 33 | d.addCallback(flushEventualQueue) |
34 | 34 | return d |
35 | 35 | |
| 36 | # TODO: should use mock decorator from #1301 |
| 37 | def test_anonymous_location(self): |
| 38 | patcher = patch('allmydata.util.iputil.get_local_addresses_async') |
| 39 | mock = patcher.__enter__() |
| 40 | try: |
| 41 | mock.return_value = ["1.2.3.4"] |
| 42 | |
| 43 | basedir = "test_node/test_anonymous_location" |
| 44 | fileutil.make_dirs(basedir) |
| 45 | fileutil.write(os.path.join(basedir, 'tahoe.cfg'), |
| 46 | "[node]\n" |
| 47 | "tub.location = \n") |
| 48 | # "tub.location=" (i.e. empty string) means create FURL with no |
| 49 | # connection-hints. Foolscap can't handle that now, so instead we |
| 50 | # make one with only 127.0.0.1 |
| 51 | |
| 52 | n = TestNode(basedir) |
| 53 | n.setServiceParent(self.parent) |
| 54 | d = n.when_tub_ready() |
| 55 | |
| 56 | def _check_addresses(ignored_result): |
| 57 | furl = n.tub.registerReference(n) |
| 58 | self.failIf("1.2.3.4" in furl, furl) |
| 59 | self.failUnless("127.0.0.1" in furl, furl) |
| 60 | |
| 61 | d.addCallback(_check_addresses) |
| 62 | def cleanup(res): |
| 63 | patcher.__exit__() |
| 64 | return res |
| 65 | d.addBoth(cleanup) |
| 66 | return d |
| 67 | except: |
| 68 | patcher.__exit__() |
| 69 | raise |
| 70 | |
36 | 71 | def test_location(self): |
37 | 72 | basedir = "test_node/test_location" |
38 | 73 | fileutil.make_dirs(basedir) |