[tor-commits] [sbws/master] v3bwfile, tests: add desc_bw_bur attribute

juga at torproject.org juga at torproject.org
Sat Dec 1 09:57:01 UTC 2018


commit fb82eac83d6246cc3a5fc4f116da5b0cd8223317
Author: juga0 <juga at riseup.net>
Date:   Fri Nov 23 10:16:01 2018 +0000

    v3bwfile, tests: add desc_bw_bur attribute
    
    And method to obtain it from results.
---
 sbws/lib/v3bwfile.py            | 12 +++++++++++-
 tests/unit/lib/test_v3bwfile.py |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 657e1e3..0835839 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -50,7 +50,7 @@ BW_KEYVALUES_BASIC = ['node_id', 'bw']
 BW_KEYVALUES_FILE = BW_KEYVALUES_BASIC + \
                     ['master_key_ed25519', 'nick', 'rtt', 'time',
                      'success', 'error_stream', 'error_circ', 'error_misc']
-BW_KEYVALUES_EXTRA_BWS = ['bw_median', 'bw_mean', 'desc_bw_avg',
+BW_KEYVALUES_EXTRA_BWS = ['bw_median', 'bw_mean', 'desc_bw_avg', 'desc_bw_bur',
                           'desc_bw_obs_last', 'desc_bw_obs_mean']
 BW_KEYVALUES_EXTRA = BW_KEYVALUES_FILE + BW_KEYVALUES_EXTRA_BWS
 BW_KEYVALUES_INT = ['bw', 'rtt', 'success', 'error_stream',
@@ -336,6 +336,8 @@ class V3BWLine(object):
                 results_recent)
             kwargs['desc_bw_avg'] = \
                 cls.desc_bw_avg_from_results(results_recent)
+            kwargs['desc_bw_bur'] = \
+                cls.desc_bw_bur_from_results(results_recent)
             kwargs['desc_bw_obs_last'] = \
                 cls.desc_bw_obs_last_from_results(results_recent)
             kwargs['desc_bw_obs_mean'] = \
@@ -428,6 +430,14 @@ class V3BWLine(object):
         return None
 
     @staticmethod
+    def desc_bw_bur_from_results(results):
+        """Obtain the last descriptor bandwidth burst from the results."""
+        for r in reversed(results):
+            if r.relay_burst_bandwidth is not None:
+                return r.relay_burst_bandwidth
+        return None
+
+    @staticmethod
     def desc_bw_obs_mean_from_results(results):
         desc_bw_obs_ls = []
         for r in results:
diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py
index f9c50d5..3f3bded 100644
--- a/tests/unit/lib/test_v3bwfile.py
+++ b/tests/unit/lib/test_v3bwfile.py
@@ -40,7 +40,7 @@ header_extra_str = LINE_SEP.join(header_extra_ls) + LINE_SEP
 
 # Line produced without any scaling.
 raw_bwl_str = "bw=56 bw_mean=61423 bw_median=55656 "\
-    "desc_bw_avg=1000000000 desc_bw_obs_last=524288 "\
+    "desc_bw_avg=1000000000 desc_bw_bur=1000000000 desc_bw_obs_last=524288 "\
     "desc_bw_obs_mean=524288 error_circ=0 error_misc=0 error_stream=1 " \
     "master_key_ed25519=g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s " \
     "nick=A " \





More information about the tor-commits mailing list