commit 86bce1e8db0799efbca86af72a4ef3c0a27f9674 Author: Damian Johnson atagar@torproject.org Date: Sun May 13 13:46:49 2012 -0700
Parsing entry-stats-end and entry-ips lines
Handling a couple more extrainfo attributes. These were trivial thanks to earlier refactoring to make common value types easy to parse. --- stem/descriptor/extrainfo_descriptor.py | 20 +++++++++++++++++--- test/unit/descriptor/extrainfo_descriptor.py | 4 ++-- 2 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py index 9493f2b..7008272 100644 --- a/stem/descriptor/extrainfo_descriptor.py +++ b/stem/descriptor/extrainfo_descriptor.py @@ -223,6 +223,11 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): dir_write_history_interval (int) - seconds per interval dir_write_history_values (list) - bytes read during each interval
+ Guard Attributes: + entry_stats_end (datetime) - end of the period when stats were gathered + entry_stats_interval (int) - length in seconds of the interval + entry_ips (dict) - mapping of locales to rounded count of unique user ips + Bridge Attributes: bridge_stats_end (datetime) - end of the period when stats were gathered bridge_stats_interval (int) - length in seconds of the interval @@ -298,6 +303,10 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): self.dir_write_history_interval = None self.dir_write_history_values = None
+ self.entry_stats_end = None + self.entry_stats_interval = None + self.entry_ips = None + self.bridge_stats_end = None self.bridge_stats_interval = None self.bridge_ips = None @@ -446,13 +455,16 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): except ValueError: if validate: raise ValueError("Timestamp on %s line wasn't parseable: %s" % (keyword, line)) - elif keyword in ("bridge-stats-end", "dirreq-stats-end"): + elif keyword in ("entry-stats-end", "bridge-stats-end", "dirreq-stats-end"): # "<keyword>" YYYY-MM-DD HH:MM:SS (NSEC s)
try: timestamp, interval, _ = _parse_timestamp_and_interval(keyword, value)
- if keyword == "bridge-stats-end": + if keyword == "entry-stats-end": + self.entry_stats_end = timestamp + self.entry_stats_interval = interval + elif keyword == "bridge-stats-end": self.bridge_stats_end = timestamp self.bridge_stats_interval = interval elif keyword == "dirreq-stats-end": @@ -490,7 +502,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): self.dir_write_history_values = history_values except ValueError, exc: if validate: raise exc - elif keyword in ("dirreq-v2-ips", "dirreq-v3-ips", "dirreq-v2-reqs", "dirreq-v3-reqs", "geoip-client-origins", "bridge-ips"): + elif keyword in ("dirreq-v2-ips", "dirreq-v3-ips", "dirreq-v2-reqs", "dirreq-v3-reqs", "geoip-client-origins", "entry-ips", "bridge-ips"): # "<keyword>" CC=N,CC=N,... # # The maxmind geoip (https://www.maxmind.com/app/iso3166) has numeric @@ -524,6 +536,8 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor): self.dir_v3_requests = locale_usage elif keyword == "geoip-client-origins": self.geoip_client_origins = locale_usage + elif keyword == "entry-ips": + self.entry_ips = locale_usage elif keyword == "bridge-ips": self.bridge_ips = locale_usage elif keyword == "router-signature": diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py index e855a1d..1ea19da 100644 --- a/test/unit/descriptor/extrainfo_descriptor.py +++ b/test/unit/descriptor/extrainfo_descriptor.py @@ -268,7 +268,7 @@ class TestExtraInfoDescriptor(unittest.TestCase): "<keyword>" YYYY-MM-DD HH:MM:SS (NSEC s) """
- for keyword in ('bridge-stats-end', 'dirreq-stats-end'): + for keyword in ('entry-stats-end', 'bridge-stats-end', 'dirreq-stats-end'): end_attr = keyword.replace('-', '_').replace('dirreq', 'dir') interval_attr = end_attr[:-4] + "_interval"
@@ -342,7 +342,7 @@ class TestExtraInfoDescriptor(unittest.TestCase): "<keyword>" CC=N,CC=N,... """
- for keyword in ('dirreq-v2-ips', 'dirreq-v3-ips', 'dirreq-v2-reqs', 'dirreq-v3-reqs', 'geoip-client-origins', 'bridge-ips'): + for keyword in ('dirreq-v2-ips', 'dirreq-v3-ips', 'dirreq-v2-reqs', 'dirreq-v3-reqs', 'geoip-client-origins', 'entry-ips', 'bridge-ips'): attr = keyword.replace('-', '_').replace('dirreq', 'dir').replace('reqs', 'requests')
test_entries = (
tor-commits@lists.torproject.org