[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/maint-1.1] fix: v3bwfile: network means without relay type



commit f93a11ca264e4c50f8cc17106084ae75c367a460
Author: juga0 <juga@xxxxxxxxxx>
Date:   Fri Mar 19 13:37:17 2021 +0000

    fix: v3bwfile: network means without relay type
    
    This reverts commit fc3d3b992ada601a6255f8a6889179abd4b7e55e and partialy
    reverts a82c26184097bea3ca405ae19773de7c4354a541.
    
    It was a mistake to think torflow was using the means by relay type,
    it actually sets the same networks means for all relay types.
    
    Closes #40080.
---
 sbws/globals.py      |  8 --------
 sbws/lib/scaling.py  | 23 -----------------------
 sbws/lib/v3bwfile.py | 25 +++++++++----------------
 sbws/util/stem.py    | 23 -----------------------
 4 files changed, 9 insertions(+), 70 deletions(-)

diff --git a/sbws/globals.py b/sbws/globals.py
index 16d8aa5..4136970 100644
--- a/sbws/globals.py
+++ b/sbws/globals.py
@@ -189,14 +189,6 @@ MAX_RECENT_PRIORITY_RELAY_COUNT = (
     MAX_RECENT_PRIORITY_LIST_COUNT * MAX_RELAYS_PER_PRIORITY_LIST
 )
 
-# Used by util/stem.py
-G = 0
-M = 1
-E = 2
-GE = 3
-# Used by lib/scaling.py to calculate network means by relay type
-RELAY_TYPES = [G, M, E, GE]
-
 
 def fail_hard(*a, **kw):
     """ Log something ... and then exit as fast as possible """
diff --git a/sbws/lib/scaling.py b/sbws/lib/scaling.py
index 52b2cd2..1bd5af3 100644
--- a/sbws/lib/scaling.py
+++ b/sbws/lib/scaling.py
@@ -1,8 +1,5 @@
 from statistics import mean
 
-from sbws.globals import RELAY_TYPES
-from sbws.util.stem import rs_relay_type
-
 
 def bw_measurements_from_results(results):
     return [
@@ -30,23 +27,3 @@ def bw_filt(bw_measurements):
     if bws_gte_mean:
         return round(mean(bws_gte_mean))
     return mu
-
-
-def network_means_by_relay_type(bw_lines, router_statuses_d):
-    # Temporarily assign the type of relay to calculate network stream and
-    # filtered bandwidth by type
-    for line in bw_lines:
-        rs = None
-        if router_statuses_d:
-            rs = router_statuses_d.get(line.node_id.replace("$", ""), None)
-        line.set_relay_type(rs_relay_type(rs))
-
-    mu_type = muf_type = {}
-    for rt in RELAY_TYPES:
-        bw_lines_type = [line for line in bw_lines if line.relay_type == rt]
-        if len(bw_lines_type) > 0:
-            # Torflow does not round these values.
-            # Ensure they won't be 0 to avoid division by 0 Exception
-            mu_type[rt] = mean([line.bw_mean for line in bw_lines_type]) or 1
-            muf_type[rt] = mean([line.bw_filt for line in bw_lines_type]) or 1
-    return mu_type, muf_type
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 6010099..2784620 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -1068,12 +1068,6 @@ class V3BWLine(object):
             )
         return bw_line_str
 
-    def set_relay_type(self, relay_type):
-        self.relay_type = relay_type
-
-    def del_relay_type(self):
-        delattr(self, "relay_type")
-
 
 class V3BWFile(object):
     """
@@ -1354,11 +1348,12 @@ class V3BWFile(object):
         """
         log.info("Calculating relays' bandwidth using Torflow method.")
         bw_lines_tf = copy.deepcopy(bw_lines)
-        mu_type, muf_type = scaling.network_means_by_relay_type(
-            bw_lines_tf, router_statuses_d
-        )
-        log.debug("mu %s", mu_type)
-        log.debug("muf %s", muf_type)
+        # mean (Torflow's strm_avg)
+        mu = mean([l.bw_mean for l in bw_lines])
+        # filtered mean (Torflow's filt_avg)
+        muf = mean([l.bw_filt for l in bw_lines])
+        log.debug("mu %s", mu)
+        log.debug("muf %s", muf)
 
         # Torflow's ``tot_net_bw``, sum of the scaled bandwidth for the relays
         # that are in the last consensus
@@ -1423,12 +1418,10 @@ class V3BWFile(object):
                 continue
 
             # Torflow's scaling
-            # relay_type is set in `network_means_by_relay_type` in the lines
-            # above
-            ratio_stream = l.bw_mean / mu_type[l.relay_type]
-            ratio_stream_filtered = l.bw_filt / muf_type[l.relay_type]
-            l.del_relay_type()
+            ratio_stream = l.bw_mean / mu
+            ratio_stream_filtered = l.bw_filt / muf
             ratio = max(ratio_stream, ratio_stream_filtered)
+
             # Assign it to an attribute, so it's not lost before capping and
             # rounding
             l.bw = ratio * min_bandwidth
diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index cecd5d7..191d1a8 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -7,7 +7,6 @@ import socks
 import stem.process
 from stem import (
     ControllerError,
-    Flag,
     InvalidArguments,
     InvalidRequest,
     OperationFailed,
@@ -21,13 +20,9 @@ from stem.control import Controller, Listener
 
 from sbws import settings
 from sbws.globals import (
-    GE,
     TORRC_OPTIONS_CAN_FAIL,
     TORRC_RUNTIME_OPTIONS,
     TORRC_STARTING_POINT,
-    E,
-    G,
-    M,
     fail_hard,
 )
 
@@ -368,21 +363,3 @@ def is_torrc_starting_point_set(tor_controller):
     if not bad_options:
         log.info("Tor is correctly configured to work with sbws.")
     return bad_options
-
-
-def rs_relay_type(rs):
-    # In torflow, the equivalent to the bw_lines is initialized to "", so when
-    # the relay is not in the previous consensus and it is not known which
-    # flags it has, it would return "Medium", as it's the fail case in
-    # Node.node_class().
-    # It is not known if it is a bug, or a desired side effect that they relays
-    # not in the consensus will end up in the Middle class
-    if not rs:
-        return M
-    if Flag.EXIT in rs.flags and Flag.GUARD in rs.flags:
-        return GE
-    if Flag.GUARD in rs.flags:
-        return G
-    if Flag.EXIT in rs.flags:
-        return E
-    return M



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits