commit d866aa9ecc4b0cdf1c6a1665a359d0e11586fea9 Author: Philipp Winter phw@nymity.ch Date: Thu Mar 26 16:49:19 2020 -0700
Remove unused class FixedBridgeSplitter. --- bridgedb/Bridges.py | 40 ---------------------------------------- bridgedb/test/test_Bridges.py | 42 ------------------------------------------ 2 files changed, 82 deletions(-)
diff --git a/bridgedb/Bridges.py b/bridgedb/Bridges.py index 84a6064..2126a7d 100644 --- a/bridgedb/Bridges.py +++ b/bridgedb/Bridges.py @@ -372,46 +372,6 @@ class BridgeRing(object): f.write("%s %s\n" % (b.fingerprint, " ".join(desc).strip()))
-class FixedBridgeSplitter(object): - """Splits bridges up based on an HMAC and assigns them to one of several - subhashrings with equal probability. - """ - def __init__(self, key, rings): - self.hmac = getHMACFunc(key, hex=True) - self.rings = rings[:] - - def insert(self, bridge): - # Grab the first 4 bytes - digest = self.hmac(bridge.identity) - pos = int( digest[:8], 16 ) - which = pos % len(self.rings) - self.rings[which].insert(bridge) - - def clear(self): - """Clear all bridges from every ring in ``rings``.""" - for r in self.rings: - r.clear() - - def __len__(self): - """Returns the total number of bridges in all ``rings``.""" - total = 0 - for ring in self.rings: - total += len(ring) - return total - - def dumpAssignments(self, filename, description=""): - """Write all bridges assigned to this hashring to ``filename``. - - :param string description: If given, include a description next to the - index number of the ring from :attr:`FilteredBridgeSplitter.rings` - the following bridges were assigned to. For example, if the - description is ``"IPv6 obfs2 bridges"`` the line would read: - ``"IPv6 obfs2 bridges ring=3"``. - """ - for index, ring in zip(range(len(self.rings)), self.rings): - ring.dumpAssignments(filename, "%s ring=%s" % (description, index)) - - class UnallocatedHolder(object): """A pseudo-bridgeholder that ignores its bridges and leaves them unassigned. diff --git a/bridgedb/test/test_Bridges.py b/bridgedb/test/test_Bridges.py index 2deeec7..96e6a72 100644 --- a/bridgedb/test/test_Bridges.py +++ b/bridgedb/test/test_Bridges.py @@ -120,48 +120,6 @@ class BridgeRingTests(unittest.TestCase): self.assertIn(first, data)
-class FixedBridgeSplitterTests(unittest.TestCase): - """Unittests for :class:`bridgedb.Bridges.FixedBridgeSplitter`.""" - - def setUp(self): - self.rings = [Bridges.BridgeRing('fake-hmac-key-1'), - Bridges.BridgeRing('fake-hmac-key-2')] - self.splitter = Bridges.FixedBridgeSplitter('fake-hmac-key', self.rings) - - def addRandomBridges(self): - bridges = copy.deepcopy(util.generateFakeBridges()) - - [self.splitter.insert(bridge) for bridge in bridges] - - def test_insert(self): - self.addRandomBridges() - self.assertGreater(len(self.splitter), 0) - - def test_clear(self): - """Clear should get rid of all the inserted bridges.""" - self.addRandomBridges() - self.assertGreater(len(self.splitter), 0) - self.splitter.clear() - self.assertEqual(len(self.splitter), 0) - - def test_dumpAssignments(self): - """This should dump the bridges to the file.""" - self.addRandomBridges() - - f = io.StringIO() - - self.splitter.dumpAssignments(f) - - f.flush() - f.seek(0) - - data = f.read() - first = list(self.splitter.rings[0].bridges.values())[0].fingerprint - - # The first bridge's fingerprint should be within the data somewhere - self.assertIn(first, data) - - class BridgeSplitterTests(unittest.TestCase): """Unittests for :class:`bridgedb.Bridges.BridgeSplitter`."""