[tor-commits] [arm/master] Replacing the get_my_bandwidth_rate() and get_my_bandwidth_burst() helpers
atagar at torproject.org
atagar at torproject.org
Tue Sep 9 02:33:47 UTC 2014
commit 0b1e813815009797242ae2bad49fcbd043052503
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Sep 8 16:42:37 2014 -0700
Replacing the get_my_bandwidth_rate() and get_my_bandwidth_burst() helpers
Couple legacy methods from our old torTools module. Replacing them with a
simpler helper that does the trick.
---
arm/graphing/bandwidth_stats.py | 54 +++++++++++----------------------------
1 file changed, 15 insertions(+), 39 deletions(-)
diff --git a/arm/graphing/bandwidth_stats.py b/arm/graphing/bandwidth_stats.py
index 980583a..ce8b5b1 100644
--- a/arm/graphing/bandwidth_stats.py
+++ b/arm/graphing/bandwidth_stats.py
@@ -405,8 +405,8 @@ class BandwidthStats(graph_panel.GraphStats):
if not self._title_stats or not my_fingerprint or (event and my_fingerprint in event.idlist):
stats = []
- bw_rate = get_my_bandwidth_rate(controller)
- bw_burst = get_my_bandwidth_burst(controller)
+ bw_rate = _min_config(controller, 'BandwidthRate', 'RelayBandwidthRate', 'MaxAdvertisedBandwidth')
+ bw_burst = _min_config(controller, 'BandwidthBurst', 'RelayBandwidthBurst')
my_server_descriptor = controller.get_server_descriptor(default = None)
bw_observed = getattr(my_server_descriptor, 'observed_bandwidth', None)
@@ -507,47 +507,23 @@ class BandwidthStats(graph_panel.GraphStats):
self.accounting_last_updated = time.time()
-def get_my_bandwidth_rate(controller):
+def _min_config(controller, *attributes):
"""
- Provides the effective relaying bandwidth rate of this relay. Currently
- this doesn't account for SETCONF events.
+ Provides the minimum of the given numeric bandwidth rate or burst config
+ options.
"""
- # effective relayed bandwidth is the minimum of BandwidthRate,
- # MaxAdvertisedBandwidth, and RelayBandwidthRate (if set)
+ value = None
- effective_rate = controller.get_conf('BandwidthRate', None)
- relay_rate = controller.get_conf('RelayBandwidthRate', None)
-
- if effective_rate and relay_rate and relay_rate != '0':
- effective_rate = min(int(effective_rate), int(relay_rate))
-
- max_advertised = controller.get_conf('MaxAdvertisedBandwidth', None)
-
- if max_advertised:
- effective_rate = min(int(effective_rate), int(max_advertised))
-
- if effective_rate is not None:
- return int(effective_rate)
- else:
- return None
-
-
-def get_my_bandwidth_burst(controller):
- """
- Provides the effective bandwidth burst rate of this relay. Currently this
- doesn't account for SETCONF events.
- """
-
- # effective burst (same for BandwidthBurst and RelayBandwidthBurst)
+ for attr in attributes:
+ try:
+ attr_value = int(controller.get_conf(attr))
- effective_burst = controller.get_conf('BandwidthBurst', None)
- relay_burst = controller.get_conf('RelayBandwidthBurst', None)
+ if attr_value == 0 and attr.startswith('Relay'):
+ continue # RelayBandwidthRate and RelayBandwidthBurst default to zero
- if effective_burst and relay_burst and relay_burst != '0':
- effective_burst = min(int(effective_burst), int(relay_burst))
+ value = min(value, attr_value) if value else attr_value
+ except:
+ pass
- if effective_burst is not None:
- return int(effective_burst)
- else:
- return None
+ return value
More information about the tor-commits
mailing list