commit ae7acb11669b380de4f7873857ca30167cd493b9 Author: Isis Lovecruft isis@torproject.org Date: Thu Apr 16 05:44:32 2015 +0000
Rename IPBasedDistributor → HTTPSDistributor. --- lib/bridgedb/Bridges.py | 2 +- lib/bridgedb/Dist.py | 25 +++++++++++++------------ lib/bridgedb/Main.py | 6 +++--- lib/bridgedb/bridges.py | 2 +- lib/bridgedb/https/request.py | 2 +- lib/bridgedb/https/server.py | 4 ++-- lib/bridgedb/test/https_helpers.py | 4 ++-- lib/bridgedb/test/legacy_Tests.py | 20 ++++++++++---------- lib/bridgedb/test/test_Main.py | 10 +++++----- lib/bridgedb/test/test_https_server.py | 6 +++--- 10 files changed, 41 insertions(+), 40 deletions(-)
diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py index a13a73e..b8fdd2e 100644 --- a/lib/bridgedb/Bridges.py +++ b/lib/bridgedb/Bridges.py @@ -523,7 +523,7 @@ class FilteredBridgeSplitter(BridgeHolder): :ivar bridges: DOCDOC :type distributorName: str :ivar distributorName: The name of this splitter's distributor. See - :meth:`bridgedb.Dist.IPBasedDistributor.setDistributorName`. + :meth:`bridgedb.Dist.HTTPSDistributor.setDistributorName`. """ self.key = key self.filterRings = {} diff --git a/lib/bridgedb/Dist.py b/lib/bridgedb/Dist.py index ff9a85d..e66c1e6 100644 --- a/lib/bridgedb/Dist.py +++ b/lib/bridgedb/Dist.py @@ -67,6 +67,7 @@ class Distributor(object):
def __init__(self): super(Distributor, self).__init__() + self.name = None
def setDistributorName(self, name): """Set a **name** for identifying this distributor. @@ -78,12 +79,10 @@ class Distributor(object): hashrings will also carry that name.
>>> from bridgedb import Dist - >>> ipDist = Dist.IPBasedDistributor(5, 'fake-hmac-key') - >>> ipDist.setDistributorName('HTTPS Distributor') - >>> ipDist.prepopulateRings() - >>> hashrings = ipDist.hashring.filterRings - >>> firstSubring = hashrings.items()[0][1][1] - >>> assert firstSubring.name + >>> dist = Dist.HTTPSDistributor(2, 'masterkey') + >>> dist.setDistributorName('Excellent Distributor') + >>> dist.name + 'Excellent Distributor'
:param str name: A name for this distributor. """ @@ -91,7 +90,7 @@ class Distributor(object): self.hashring.distributorName = name
-class IPBasedDistributor(Distributor): +class HTTPSDistributor(Distributor): """A Distributor that hands out bridges based on the IP address of an incoming request and the current time period.
@@ -128,6 +127,8 @@ class IPBasedDistributor(Distributor): parameters, i.e. that an answer has "at least two obfsproxy bridges" or "at least one bridge on port 443", etc. """ + super(HTTPSDistributor, self).__init__() + self.key = key self.totalSubrings = totalSubrings self.answerParameters = answerParameters @@ -171,14 +172,14 @@ class IPBasedDistributor(Distributor): ``1.2.178.234``) are placed within the same cluster, but Carol (with address ``1.3.11.33``) *might* end up in a different cluster.
- >>> from bridgedb.Dist import IPBasedDistributor - >>> IPBasedDistributor.getSubnet('1.2.3.4') + >>> from bridgedb.Dist import HTTPSDistributor + >>> HTTPSDistributor.getSubnet('1.2.3.4') '1.2.0.0/16' - >>> IPBasedDistributor.getSubnet('1.2.211.154') + >>> HTTPSDistributor.getSubnet('1.2.211.154') '1.2.0.0/16' - >>> IPBasedDistributor.getSubnet('2001:f::bc1:b13:2808') + >>> HTTPSDistributor.getSubnet('2001:f::bc1:b13:2808') '2001:f::/32' - >>> IPBasedDistributor.getSubnet('2a00:c98:2030:a020:2::42') + >>> HTTPSDistributor.getSubnet('2a00:c98:2030:a020:2::42') '2a00:c98::/32'
:param str ip: A string representing an IPv4 or IPv6 address. diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py index 1262122..0bb319d 100644 --- a/lib/bridgedb/Main.py +++ b/lib/bridgedb/Main.py @@ -194,7 +194,7 @@ def createBridgeRings(cfg, proxyList, key): known open proxies. :param bytes key: Hashring master key :rtype: tuple - :returns: A BridgeSplitter hashring, an IPBasedDistributor or None, + :returns: A BridgeSplitter hashring, an HTTPSDistributor or None, and an EmailBasedDistributor or None. """ # Create a BridgeSplitter to assign the bridges to the different @@ -210,7 +210,7 @@ def createBridgeRings(cfg, proxyList, key): # As appropriate, create an IP-based distributor. if cfg.HTTPS_DIST and cfg.HTTPS_SHARE: logging.debug("Setting up HTTPS Distributor...") - ipDistributor = Dist.IPBasedDistributor( + ipDistributor = Dist.HTTPSDistributor( cfg.N_IP_CLUSTERS, crypto.getHMAC(key, "HTTPS-IP-Dist-Key"), proxyList, @@ -329,7 +329,7 @@ def run(options, reactor=reactor): :type proxyList: :class:`~bridgedb.proxy.ProxySet` :ivar proxyList: The container for the IP addresses of any currently known open proxies. - :ivar ipDistributor: A :class:`Dist.IPBasedDistributor`. + :ivar ipDistributor: A :class:`Dist.HTTPSDistributor`. :ivar emailDistributor: A :class:`Dist.EmailBasedDistributor`. :ivar dict tasks: A dictionary of ``{name: task}``, where name is a string to associate with the ``task``, and ``task`` is some diff --git a/lib/bridgedb/bridges.py b/lib/bridgedb/bridges.py index 91b62fa..541e735 100644 --- a/lib/bridgedb/bridges.py +++ b/lib/bridgedb/bridges.py @@ -727,7 +727,7 @@ class BridgeBackwardsCompatibility(BridgeBase): :class:`ipaddr.IPv6Address`. :param addressClass: Type of address to choose. :param str request: A string (somewhat) unique to this request, - e.g. email-address or ``IPBasedDistributor.getSubnet(ip)``. In + e.g. email-address or ``HTTPSDistributor.getSubnet(ip)``. In this case, this is not a :class:`~bridgerequest.BridgeRequestBase` (as might be expected) but the equivalent of :data:`bridgerequest.BridgeRequestBase.client`. diff --git a/lib/bridgedb/https/request.py b/lib/bridgedb/https/request.py index a8f6920..37b3ed6 100644 --- a/lib/bridgedb/https/request.py +++ b/lib/bridgedb/https/request.py @@ -55,7 +55,7 @@ class HTTPSBridgeRequest(bridgerequest.BridgeRequestBase):
def __init__(self, addClientCountryCode=True): """Process a new bridge request received through the - :class:`~bridgedb.Dist.IPBasedDistributor`. + :class:`~bridgedb.Dist.HTTPSDistributor`.
:param bool addClientCountryCode: If ``True``, then calling :meth:`withoutBlockInCountry` will attempt to add the client's own diff --git a/lib/bridgedb/https/server.py b/lib/bridgedb/https/server.py index 6010218..e8cdd62 100644 --- a/lib/bridgedb/https/server.py +++ b/lib/bridgedb/https/server.py @@ -632,7 +632,7 @@ class BridgesResource(resource.Resource): includeFingerprints=True): """Create a new resource for displaying bridges to a client.
- :type distributor: :class:`IPBasedDistributor` + :type distributor: :class:`HTTPSDistributor` :param distributor: The mechanism to retrieve bridges for this distributor. :type schedule: :class:`~bridgedb.schedule.ScheduledInterval` @@ -819,7 +819,7 @@ def addWebServer(config, distributor): GIMP_CAPTCHA_DIR GIMP_CAPTCHA_HMAC_KEYFILE GIMP_CAPTCHA_RSA_KEYFILE - :type distributor: :class:`bridgedb.Dist.IPBasedDistributor` + :type distributor: :class:`bridgedb.Dist.HTTPSDistributor` :param distributor: A bridge distributor. :raises SystemExit: if the servers cannot be started. :rtype: :api:`twisted.web.server.Site` diff --git a/lib/bridgedb/test/https_helpers.py b/lib/bridgedb/test/https_helpers.py index f9232bc..00ccbd6 100644 --- a/lib/bridgedb/test/https_helpers.py +++ b/lib/bridgedb/test/https_helpers.py @@ -98,8 +98,8 @@ def _createConfig(configFile=TEST_CONFIG_FILE): return config
-class DummyIPBasedDistributor(object): - """A mocked :class:`bridgedb.Dist.IPBasedDistributor` which is used to test +class DummyHTTPSDistributor(object): + """A mocked :class:`bridgedb.Dist.HTTPSDistributor` which is used to test :class:`bridgedb.https.server.BridgesResource`. """ _bridge_class = util.DummyBridge diff --git a/lib/bridgedb/test/legacy_Tests.py b/lib/bridgedb/test/legacy_Tests.py index dc91c9b..cc1ba6d 100644 --- a/lib/bridgedb/test/legacy_Tests.py +++ b/lib/bridgedb/test/legacy_Tests.py @@ -187,7 +187,7 @@ class IPBridgeDistTests(unittest.TestCase): def dumbAreaMapper(self, ip): return ip def testBasicDist(self): - d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo") + d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Foo") for _ in xrange(256): d.insert(fakeBridge()) n = d.getBridges("1.2.3.4", "x", 2) @@ -195,7 +195,7 @@ class IPBridgeDistTests(unittest.TestCase): self.assertEquals(n, n2)
def testDistWithProxies(self): - d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo", + d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Foo", [RhymesWith255ProxySet()]) for _ in xrange(256): d.insert(fakeBridge()) @@ -219,8 +219,8 @@ class IPBridgeDistTests(unittest.TestCase): #XXX: #6175 breaks this test! #def testDistWithPortRestrictions(self): # param = bridgedb.Bridges.BridgeRingParameters(needPorts=[(443, 1)]) - # d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Baz", - # answerParameters=param) + # d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Baz", + # answerParameters=param) # for _ in xrange(32): # d.insert(fakeBridge(443)) # for _ in range(256): @@ -239,7 +239,7 @@ class IPBridgeDistTests(unittest.TestCase): # self.assertTrue(count >= 1)
def testDistWithFilterIP6(self): - d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo") + d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Foo") for _ in xrange(250): d.insert(fakeBridge6(or_addresses=True)) d.insert(fakeBridge(or_addresses=True)) @@ -255,7 +255,7 @@ class IPBridgeDistTests(unittest.TestCase): assert filterBridgesByIP6(random.choice(bridges))
def testDistWithFilterIP4(self): - d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo") + d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Foo") for _ in xrange(250): d.insert(fakeBridge6(or_addresses=True)) d.insert(fakeBridge(or_addresses=True)) @@ -271,7 +271,7 @@ class IPBridgeDistTests(unittest.TestCase): assert filterBridgesByIP4(random.choice(bridges))
def testDistWithFilterBoth(self): - d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo") + d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Foo") for _ in xrange(250): d.insert(fakeBridge6(or_addresses=True)) d.insert(fakeBridge(or_addresses=True)) @@ -295,7 +295,7 @@ class IPBridgeDistTests(unittest.TestCase):
def testDistWithFilterAll(self): - d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo") + d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Foo") for _ in xrange(250): d.insert(fakeBridge6(or_addresses=True)) d.insert(fakeBridge(or_addresses=True)) @@ -306,7 +306,7 @@ class IPBridgeDistTests(unittest.TestCase): assert len(b) == 0
def testDistWithFilterBlockedCountries(self): - d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo") + d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Foo") for _ in xrange(250): d.insert(fakeBridge6(or_addresses=True)) d.insert(fakeBridge(or_addresses=True)) @@ -332,7 +332,7 @@ class IPBridgeDistTests(unittest.TestCase): assert len(b) > 0
def testDistWithFilterBlockedCountriesAdvanced(self): - d = bridgedb.Dist.IPBasedDistributor(self.dumbAreaMapper, 3, "Foo") + d = bridgedb.Dist.HTTPSDistributor(self.dumbAreaMapper, 3, "Foo") for _ in xrange(250): d.insert(fakeBridge6(or_addresses=True, transports=True)) d.insert(fakeBridge(or_addresses=True, transports=True)) diff --git a/lib/bridgedb/test/test_Main.py b/lib/bridgedb/test/test_Main.py index ec3fdd2..26012f7 100644 --- a/lib/bridgedb/test/test_Main.py +++ b/lib/bridgedb/test/test_Main.py @@ -261,7 +261,7 @@ class MainTests(unittest.TestCase): (hashring, emailDist, httpsDist) = Main.createBridgeRings(self.config, proxyList, self.key) - # Should have an IPBasedDistributor ring, an EmailDistributor ring, + # Should have an HTTPSDistributor ring, an EmailDistributor ring, # and an UnallocatedHolder ring: self.assertEqual(len(hashring.ringsByName.keys()), 3)
@@ -275,7 +275,7 @@ class MainTests(unittest.TestCase): (hashring, emailDist, httpsDist) = Main.createBridgeRings(self.config, proxyList, self.key) - # Should have an IPBasedDistributor ring, an EmailDistributor ring, + # Should have an HTTPSDistributor ring, an EmailDistributor ring, # and an UnallocatedHolder ring: self.assertEqual(len(hashring.ringsByName.keys()), 3) self.assertGreater(len(httpsDist.proxies), 0) @@ -306,7 +306,7 @@ class MainTests(unittest.TestCase): (hashring, emailDist, httpsDist) = Main.createBridgeRings(config, proxyList, self.key) - # Should have an IPBasedDistributor ring, and an UnallocatedHolder ring: + # Should have an HTTPSDistributor ring, and an UnallocatedHolder ring: self.assertEqual(len(hashring.ringsByName.keys()), 2) self.assertNotIn('email', hashring.rings) self.assertNotIn(emailDist, hashring.ringsByName.values()) @@ -321,7 +321,7 @@ class MainTests(unittest.TestCase): (hashring, emailDist, httpsDist) = Main.createBridgeRings(config, proxyList, self.key) - # Should have an IPBasedDistributor ring, and an EmailDistributor ring: + # Should have an HTTPSDistributor ring, and an EmailDistributor ring: self.assertEqual(len(hashring.ringsByName.keys()), 2) self.assertNotIn('unallocated', hashring.rings)
@@ -339,7 +339,7 @@ class MainTests(unittest.TestCase): (hashring, emailDist, httpsDist) = Main.createBridgeRings(config, proxyList, self.key) - # Should have an IPBasedDistributor ring, an EmailDistributor, and an + # Should have an HTTPSDistributor ring, an EmailDistributor, and an # UnallocatedHolder ring: self.assertEqual(len(hashring.ringsByName.keys()), 3)
diff --git a/lib/bridgedb/test/test_https_server.py b/lib/bridgedb/test/test_https_server.py index 68a975e..e4f56f0 100644 --- a/lib/bridgedb/test/test_https_server.py +++ b/lib/bridgedb/test/test_https_server.py @@ -31,7 +31,7 @@ from bridgedb.https import server from bridgedb.schedule import ScheduledInterval from bridgedb.test.https_helpers import _createConfig from bridgedb.test.https_helpers import DummyRequest -from bridgedb.test.https_helpers import DummyIPBasedDistributor +from bridgedb.test.https_helpers import DummyHTTPSDistributor from bridgedb.test.util import DummyBridge from bridgedb.test.util import DummyMaliciousBridge
@@ -521,7 +521,7 @@ class BridgesResourceTests(unittest.TestCase): self.pagename = b'bridges.html' self.root = Resource()
- self.dist = DummyIPBasedDistributor() + self.dist = DummyHTTPSDistributor() self.sched = ScheduledInterval(1, 'hour') self.nBridgesPerRequest = 2
@@ -796,7 +796,7 @@ class HTTPSServerServiceTests(unittest.TestCase): def setUp(self): """Create a server.MailServerContext and EmailBasedDistributor.""" self.config = _createConfig() - self.distributor = DummyIPBasedDistributor() + self.distributor = DummyHTTPSDistributor()
def tearDown(self): """Cleanup method after each ``test_*`` method runs; removes timed out
tor-commits@lists.torproject.org