Ticket #1010: 1010-anonymize-local-addresses.patch

File 1010-anonymize-local-addresses.patch, 2.6 KB (added by duck, at 2011-01-12T21:54:12Z)

Allow for local address anonymization

  • src/allmydata/node.py

    diff --git src/allmydata/node.py src/allmydata/node.py
    index 7f5bf61..04a1035 100644
    class Node(service.MultiService): 
    258258
    259259        service.MultiService.startService(self)
    260260        d = defer.succeed(None)
    261         d.addCallback(lambda res: iputil.get_local_addresses_async())
     261        location = self.get_config("node", "tub.location", None)
     262        if location == "":
     263            d.addCallback(lambda res: ['127.0.0.1'])
     264        else:
     265            d.addCallback(lambda res: iputil.get_local_addresses_async())
    262266        d.addCallback(self._setup_tub)
    263267        def _ready(res):
    264268            self.log("%s running" % self.NODETYPE)
    class Node(service.MultiService): 
    333337        base_location = ",".join([ "%s:%d" % (addr, portnum)
    334338                                   for addr in local_addresses ])
    335339        location = self.get_config("node", "tub.location", base_location)
     340        if location == "":
     341            location = base_location
    336342        self.log("Tub location set to %s" % location)
    337343        self.tub.setLocation(location)
    338344
  • src/allmydata/test/test_node.py

    diff --git src/allmydata/test/test_node.py src/allmydata/test/test_node.py
    index 24ec571..c1300c1 100644
     
    11
    22import os, stat, sys, time
     3
     4from mock import patch
     5
    36from twisted.trial import unittest
    47from twisted.internet import defer
    58from twisted.python import log
    class TestCase(testutil.SignalMixin, unittest.TestCase): 
    3134        d.addCallback(flushEventualQueue)
    3235        return d
    3336
     37    # XXX should use mock decorator from #1301
     38    def test_anonymous_location(self):
     39        patcher = patch('allmydata.util.iputil.get_local_addresses_async')
     40        mock = patcher.__enter__()
     41        mock.return_value = ["1.2.3.4"]
     42
     43        basedir = "test_node/test_anonymous_location"
     44        fileutil.make_dirs(basedir)
     45        f = open(os.path.join(basedir, 'tahoe.cfg'), 'wt')
     46        f.write("[node]\n")
     47        f.write("tub.location = \n")
     48        f.close()
     49
     50        n = TestNode(basedir)
     51        n.setServiceParent(self.parent)
     52        d = n.when_tub_ready()
     53
     54        def _check_addresses(ignored_result):
     55            furl = n.tub.registerReference(n)
     56            self.failIf("1.2.3.4" in furl, furl)
     57            self.failUnless("127.0.0.1" in furl, furl)
     58
     59        d.addCallback(_check_addresses)
     60
     61        def cleanup(res):
     62            patcher.__exit__()
     63            return res
     64        d.addBoth(cleanup)
     65        return d
     66
    3467    def test_location(self):
    3568        basedir = "test_node/test_location"
    3669        fileutil.make_dirs(basedir)