[tor-commits] [stem/master] BandwidthFile tor_version attribute
atagar at torproject.org
atagar at torproject.org
Sun Aug 30 23:51:35 UTC 2020
commit 8b09cbd778ccd2c4a350f00f0a1836a55b75ef4c
Author: Damian Johnson <atagar at torproject.org>
Date: Sun Aug 30 15:59:45 2020 -0700
BandwidthFile tor_version attribute
Adding our bandwidth file's tor_version. The spec claims that it's a version
1.5.0 attribute...
https://gitweb.torproject.org/torspec.git/commit/?id=7d8b4bc
However, our most recent bandwidth files have this attribute yet claim to be
1.4.0. Maybe our scanners added the attribute without bumping their version?
Working under that assumption and reached out to juga.
---
docs/faq.rst | 2 +-
stem/descriptor/bandwidth_file.py | 10 ++++++++++
test/unit/descriptor/bandwidth_file.py | 4 ++++
test/unit/descriptor/data/bandwidth_file_v1.4 | 1 +
4 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/docs/faq.rst b/docs/faq.rst
index 3dd19252..e10a0c6f 100644
--- a/docs/faq.rst
+++ b/docs/faq.rst
@@ -551,7 +551,7 @@ know if you get stuck or would like to discuss anything!
* If you don't already have a publicly accessible Stem repository then set one up. `GitHub <https://github.com/>`_ in particular is great for this.
* `File a ticket <https://github.com/torproject/stem/issues/>`_ or pull request.
- * I'll review the change and give suggestions. When we're both happy with it I'll push your change to the official repository.
+ * I'll review the change and give suggestions. When we're both happy with it I'll push your change into the official repository.
.. _how_do_i_run_the_tests:
diff --git a/stem/descriptor/bandwidth_file.py b/stem/descriptor/bandwidth_file.py
index f4be6020..2b1ed5d3 100644
--- a/stem/descriptor/bandwidth_file.py
+++ b/stem/descriptor/bandwidth_file.py
@@ -20,6 +20,7 @@ import io
import time
import stem.util.str_tools
+import stem.version
from typing import Any, BinaryIO, Callable, Dict, Iterator, List, Mapping, Optional, Sequence, Tuple, Type
@@ -105,6 +106,13 @@ def _csv(val: str) -> Sequence[str]:
return list(map(lambda v: v.strip(), val.split(','))) if val is not None else None
+def _tor_version(val: str) -> stem.version.Version:
+ try:
+ return stem.version.Version(val) if val else None
+ except ValueError:
+ return None # invalid tor version
+
+
# mapping of attributes => (header, type)
HEADER_ATTR = {
@@ -146,6 +154,7 @@ HEADER_ATTR = {
'recent_stats.relay_failures.insuffient_period': ('recent_measurements_excluded_near_count', _int),
'recent_stats.relay_failures.insufficient_measurements': ('recent_measurements_excluded_few_count', _int),
'recent_stats.relay_failures.stale': ('recent_measurements_excluded_old_count', _int),
+ 'tor_version': ('tor_version', _tor_version),
}
HEADER_DEFAULT = {
@@ -285,6 +294,7 @@ class BandwidthFile(Descriptor):
:var str scanner_country: country code where this scan took place
:var list destinations_countries: all country codes that were scanned
+ :var stem.version.Version tor_version: scanner's tor version
:var int time_to_report_half_network: estimated number of seconds required to
measure half the network, given recent measurements
diff --git a/test/unit/descriptor/bandwidth_file.py b/test/unit/descriptor/bandwidth_file.py
index 00539251..d7c49f64 100644
--- a/test/unit/descriptor/bandwidth_file.py
+++ b/test/unit/descriptor/bandwidth_file.py
@@ -8,6 +8,7 @@ import unittest
import stem.descriptor
import stem.util.str_tools
+import stem.version
from unittest.mock import Mock, patch
@@ -124,6 +125,7 @@ class TestBandwidthFile(unittest.TestCase):
self.assertEqual(None, desc.scanner_country)
self.assertEqual(None, desc.destinations_countries)
self.assertEqual(None, desc.time_to_report_half_network)
+ self.assertEqual(None, desc.tor_version)
stats = desc.recent_stats
self.assertEqual(None, stats.consensus_count)
@@ -168,6 +170,7 @@ class TestBandwidthFile(unittest.TestCase):
self.assertEqual(None, desc.scanner_country)
self.assertEqual(None, desc.destinations_countries)
self.assertEqual(None, desc.time_to_report_half_network)
+ self.assertEqual(None, desc.tor_version)
stats = desc.recent_stats
self.assertEqual(None, stats.consensus_count)
@@ -212,6 +215,7 @@ class TestBandwidthFile(unittest.TestCase):
self.assertEqual('US', desc.scanner_country)
self.assertEqual(['ZZ'], desc.destinations_countries)
self.assertEqual(223519, desc.time_to_report_half_network)
+ self.assertEqual(stem.version.Version('0.3.5.10'), desc.tor_version)
stats = desc.recent_stats
self.assertEqual(34, stats.consensus_count)
diff --git a/test/unit/descriptor/data/bandwidth_file_v1.4 b/test/unit/descriptor/data/bandwidth_file_v1.4
index 233ec10b..d0a3d81c 100644
--- a/test/unit/descriptor/data/bandwidth_file_v1.4
+++ b/test/unit/descriptor/data/bandwidth_file_v1.4
@@ -23,6 +23,7 @@ scanner_country=US
software=sbws
software_version=1.1.0
time_to_report_half_network=223519
+tor_version=0.3.5.10
=====
bw=1 bw_mean=21403 bw_median=21405 consensus_bandwidth=1000 consensus_bandwidth_is_unmeasured=False desc_bw_avg=25600 desc_bw_bur=61440 desc_bw_obs_last=34105 desc_bw_obs_mean=36357 error_circ=2 error_destination=0 error_misc=0 error_second_relay=0 error_stream=0 nick=t7 node_id=$F63DF6AA4F395AD2F5F363333D104279F2171381 relay_in_recent_consensus_count=19 relay_recent_measurement_attempt_count=1 relay_recent_measurements_excluded_error_count=2 relay_recent_priority_list_count=1 success=2 time=2019-04-21T06:53:01
bw=1 bw_mean=380199 bw_median=397005 consensus_bandwidth=395000 consensus_bandwidth_is_unmeasured=False desc_bw_avg=512000 desc_bw_bur=512000 desc_bw_obs_last=0 desc_bw_obs_mean=1 error_circ=1 error_destination=0 error_misc=0 error_second_relay=0 error_stream=0 master_key_ed25519=MAB0U2NzMiVSMflW9lSV7DilOcfUg1nFZ4Zeb7g4Vl0 nick=Unnamed node_id=$3E957D869E0DD829FA249E22D8A741AA30B938C2 relay_in_recent_consensus_count=27 relay_recent_measurement_attempt_count=1 relay_recent_measurements_excluded_error_count=1 relay_recent_priority_list_count=1 success=3 time=2019-04-21T15:29:15
More information about the tor-commits
mailing list