commit bd6e5cea6525f76b95966b023a1c1fa88065adc3 Author: Damian Johnson atagar@torproject.org Date: Fri Dec 7 08:48:12 2012 -0800
Support for geoip6-db-digest extrainfo desc lines
Adding parsing support for the newish 'geoip6-db-digest' lines in extra-info descriptors. Lacking this support has been breaking our integ tests for a while, so I was able to exercise this both with the unit test addition and an actual consensus.
Bug: https://trac.torproject.org/7354 Spec addition: https://gitweb.torproject.org/torspec.git/commitdiff/9a518d9 Metrics-lib addition: https://gitweb.torproject.org/metrics-lib.git/commitdiff/43b9390 --- stem/descriptor/extrainfo_descriptor.py | 12 +++++++++++- test/unit/descriptor/extrainfo_descriptor.py | 9 ++++++++- 2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index 1ad5d46..582c409 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -101,6 +101,7 @@ SINGLE_FIELDS = ( "read-history", "write-history", "geoip-db-digest", + "geoip6-db-digest", "bridge-stats-end", "bridge-ips", "dirreq-stats-end", @@ -197,7 +198,8 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): :var str nickname: ***** relay's nickname :var str fingerprint: ***** identity key fingerprint :var datetime published: ***** time in UTC when this descriptor was made - :var str geoip_db_digest: sha1 of geoIP database file + :var str geoip_db_digest: sha1 of the geoIP database file for IPv4 addresses + :var str geoip6_db_digest: sha1 of the geoIP database file for IPv6 addresses :var dict transport: ***** mapping of transport methods to their (address, port, args) tuple, these usually appear on bridges in which case all of those are **None** @@ -311,6 +313,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): self.fingerprint = None self.published = None self.geoip_db_digest = None + self.geoip6_db_digest = None self.transport = {}
self.conn_bi_direct_end = None @@ -445,6 +448,13 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): raise ValueError("Geoip digest line had an invalid sha1 digest: %s" % line)
self.geoip_db_digest = value + elif keyword == "geoip6-db-digest": + # "geoip6-db-digest" Digest + + if validate and not stem.util.tor_tools.is_hex_digits(value, 40): + raise ValueError("Geoip v6 digest line had an invalid sha1 digest: %s" % line) + + self.geoip6_db_digest = value elif keyword == "transport": # "transport" transportname address:port [arglist] # Everything after the transportname is scrubbed in published bridge diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py index 011a0e5..dc64032 100644 --- a/test/unit/descriptor/extrainfo_descriptor.py +++ b/test/unit/descriptor/extrainfo_descriptor.py @@ -66,13 +66,17 @@ class TestExtraInfoDescriptor(unittest.TestCase):
def test_geoip_db_digest(self): """ - Parses the geoip-db-digest line with valid and invalid data. + Parses the geoip-db-digest and geoip6-db-digest lines with valid and + invalid data. """
geoip_db_digest = "916A3CA8B7DF61473D5AE5B21711F35F301CE9E8" desc = get_relay_extrainfo_descriptor({"geoip-db-digest": geoip_db_digest}) self.assertEquals(geoip_db_digest, desc.geoip_db_digest)
+ desc = get_relay_extrainfo_descriptor({"geoip6-db-digest": geoip_db_digest}) + self.assertEquals(geoip_db_digest, desc.geoip6_db_digest) + test_entries = ( "", "916A3CA8B7DF61473D5AE5B21711F35F301CE9E", @@ -84,6 +88,9 @@ class TestExtraInfoDescriptor(unittest.TestCase): for entry in test_entries: desc_text = get_relay_extrainfo_descriptor({"geoip-db-digest": entry}, content = True) self._expect_invalid_attr(desc_text, "geoip_db_digest", entry) + + desc_text = get_relay_extrainfo_descriptor({"geoip6-db-digest": entry}, content = True) + self._expect_invalid_attr(desc_text, "geoip6_db_digest", entry)
def test_cell_circuits_per_decile(self): """
tor-commits@lists.torproject.org