[tor-commits] [sbws/master] Add function to obtain percentage measured relays

juga at torproject.org juga at torproject.org
Wed Oct 24 09:40:23 UTC 2018


commit ed520c485a7bcd4ad9f1b1c3e4288b35303fae2e
Author: juga0 <juga at riseup.net>
Date:   Tue Oct 16 12:52:55 2018 +0000

    Add function to obtain percentage measured relays
---
 sbws/globals.py      |  1 +
 sbws/lib/v3bwfile.py | 23 ++++++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/sbws/globals.py b/sbws/globals.py
index 52c31bf..9ac30d1 100644
--- a/sbws/globals.py
+++ b/sbws/globals.py
@@ -40,6 +40,7 @@ TORFLOW_OBS_DECAYING = 3
 TORFLOW_ROUND_DIG = 3
 DAY_SECS = 86400
 NUM_MIN_RESULTS = 2
+MIN_REPORT = 60
 
 BW_LINE_SIZE = 510
 
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 4eecda6..58056b1 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -6,12 +6,13 @@ import copy
 import logging
 import os
 from statistics import median, mean
+from stem.descriptor import parse_file
 
 from sbws import __version__
 from sbws.globals import (SPEC_VERSION, BW_LINE_SIZE, SBWS_SCALE_CONSTANT,
                           TORFLOW_SCALING, SBWS_SCALING, TORFLOW_BW_MARGIN,
                           TORFLOW_OBS_LAST, TORFLOW_OBS_MEAN,
-                          TORFLOW_ROUND_DIG)
+                          TORFLOW_ROUND_DIG, MIN_REPORT)
 from sbws.lib.resultdump import ResultSuccess, _ResultType
 from sbws.util.filelock import DirectoryLock
 from sbws.util.timestamp import (now_isodt_str, unixts_to_isodt_str,
@@ -65,6 +66,22 @@ def result_type_to_key(type_str):
     return type_str.replace('-', '_')
 
 
+def is_min_percent_measured(consensus_path):
+    """"""
+    # cached-consensus should be updated every time that scanner get the
+    # network status or descriptors?
+    # It will not be updated to the last consensus, but the list of measured
+    # relays is not either.
+    descs = parse_file(consensus_path)
+    num_relays_net = len(list(descs))
+    if num_relays_net * MIN_REPORT / 100:
+        log.warning('The percentage of the measured relays is less than the %s'
+                    '%% of the relays in the network (%s).',
+                    MIN_REPORT, num_relays_net)
+        return False
+    return True
+
+
 class V3BWHeader(object):
     """
     Create a bandwidth measurements (V3bw) header
@@ -700,7 +717,7 @@ class V3BWFile(object):
         All of that can be expressed as:
 
         .. math::
-        
+
             bwn_i &=
                 max\\left(
                     \\frac{bw_i}{\\mu},
@@ -724,7 +741,7 @@ class V3BWFile(object):
                             \\right)}
                     \\right)
                 \\times bwobs_i \\
-        
+
              &=
                 max\\left(
                     \\frac{bw_i}{\\frac{\\sum_{i=1}^{n}bw_i}{n}},





More information about the tor-commits mailing list