commit c076038e82fcd5f5188ec7f889c9c9dc5d5eafd3 Author: Damian Johnson atagar@torproject.org Date: Sat Aug 24 10:45:14 2013 -0700
Handling bridge-ip-versions as a general extrainfo field
In commit 0d01ad6 I added support for the 'bridge-ip-versions' lines. These are only relevant to bridge descriptors, and ineed don't presently appear in the extrainfo consensus. However, that once could be said about the 'bridge-ips' field too.
It's wrong for bridge attributes to appear on public relays, but there's nothing in the spec prohibiting it. Hence moving this attribute's handler to the common ExtraInfoDescriptor parent class. --- stem/descriptor/extrainfo_descriptor.py | 36 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index 8c2b19e..a314e86 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -309,6 +309,7 @@ class ExtraInfoDescriptor(Descriptor): :var dict bridge_ips: mapping of locales to rounded count of unique user ips :var datetime geoip_start_time: replaced by bridge_stats_end (deprecated) :var dict geoip_client_origins: replaced by bridge_ips (deprecated) + :var dict ip_versions: mapping of ip protocols to a rounded count for the number of users
***** attribute is either required when we're parsed with validation or has a default value, others are left as **None** if undefined @@ -404,6 +405,8 @@ class ExtraInfoDescriptor(Descriptor): self.geoip_start_time = None self.geoip_client_origins = None
+ self.ip_versions = None + self._unrecognized_lines = []
entries = _get_descriptor_components(raw_contents, validate) @@ -786,6 +789,20 @@ class ExtraInfoDescriptor(Descriptor): self.entry_ips = locale_usage elif keyword == "bridge-ips": self.bridge_ips = locale_usage + elif keyword == "bridge-ip-versions": + self.ip_versions = {} + + if value: + for entry in value.split(','): + if not '=' in entry: + raise stem.ProtocolError("The bridge-ip-versions should be a comma separated listing of '<protocol>=<count>' mappings: %s" % line) + + protocol, count = entry.split('=', 1) + + if not count.isdigit(): + raise stem.ProtocolError("IP protocol count was non-numeric (%s): %s" % (count, line)) + + self.ip_versions[protocol] = int(count) else: self._unrecognized_lines.append(line)
@@ -862,12 +879,9 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor): """ Bridge extra-info descriptor (`bridge descriptor specification https://metrics.torproject.org/formats.html#bridgedesc`_) - - :var dict ip_versions: mapping of ip protocols to a rounded count for the number of users """
def __init__(self, raw_contents, validate = True): - self.ip_versions = None self._digest = None
super(BridgeExtraInfoDescriptor, self).__init__(raw_contents, validate) @@ -889,22 +903,6 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
self._digest = value del entries["router-digest"] - elif keyword == "bridge-ip-versions": - self.ip_versions = {} - - if value: - for entry in value.split(','): - if not '=' in entry: - raise stem.ProtocolError("The bridge-ip-versions should be a comma separated listing of '<protocol>=<count>' mappings: %s" % line) - - protocol, count = entry.split('=', 1) - - if not count.isdigit(): - raise stem.ProtocolError("IP protocol count was non-numeric (%s): %s" % (count, line)) - - self.ip_versions[protocol] = int(count) - - del entries["bridge-ip-versions"]
ExtraInfoDescriptor._parse(self, entries, validate)