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

[tor-commits] [sbws/master] new: destination: Add configuration option



commit 1667e592c82e2e4823986f3542bceb6ab6a2feff
Author: juga0 <juga@xxxxxxxxxx>
Date:   Sat Mar 16 13:15:56 2019 +0000

    new: destination: Add configuration option
    
    for the maximum number of failures before the destination is
    not functional.
    
    Part of #29589.
---
 docs/source/examples/sbws.example.ini |  4 ++++
 sbws/lib/destination.py               | 10 +++++++++-
 sbws/util/config.py                   |  6 ++++--
 3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/docs/source/examples/sbws.example.ini b/docs/source/examples/sbws.example.ini
index 5b9b756..1a2d6a4 100644
--- a/docs/source/examples/sbws.example.ini
+++ b/docs/source/examples/sbws.example.ini
@@ -25,6 +25,10 @@ verify = False
 # Use ZZ if the location is unknown (for instance, a CDN).
 country = ZZ
 
+# Number of consecutive times that a destination could not be used to measure
+# before stopping to try to use it for a while that by default is 3h.
+max_num_failures = 3
+
 ## The following logging options are set by default.
 ## There is no need to change them unless other options are prefered.
 ; [logging]
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index 59474a6..d2ffa84 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -286,7 +286,15 @@ class Destination:
         assert 'url' in conf_section
         url = conf_section['url']
         verify = _parse_verify_option(conf_section)
-        return Destination(url, max_dl, verify)
+        try:
+            max_num_failures = conf_section.getint('max_num_failures')
+        except ValueError:
+            log.warning("Configuration max_num_failures is wrong, ignoring.")
+            max_num_failures = None
+        if max_num_failures:
+            return Destination(url, max_dl, verify, max_num_failures)
+        else:
+            return Destination(url, max_dl, verify)
 
 
 class DestinationList:
diff --git a/sbws/util/config.py b/sbws/util/config.py
index 6622ba3..e1bc429 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -406,14 +406,16 @@ def _validate_destinations(conf):
     urls = {
         'url': {},
     }
-    all_valid_keys = list(urls.keys()) + ['verify', 'country']
+    all_valid_keys = list(urls.keys()) \
+        + ['verify', 'country', 'max_num_failures']
     for sec in dest_sections:
         if sec not in conf:
             errors.append('{} is an enabled destination but is not a '
                           'section in the config'.format(sec))
             continue
         errors.extend(_validate_section_keys(
-            conf, sec, all_valid_keys, err_tmpl, allow_missing=['verify']))
+            conf, sec, all_valid_keys, err_tmpl,
+            allow_missing=['verify', 'max_num_failures']))
         errors.extend(_validate_section_urls(conf, sec, urls, err_tmpl))
         errors.extend(_validate_country(conf, sec, 'country', err_tmpl))
     return errors



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