Sfoglia il codice sorgente

Merge branch 'bug24953_squashed'

Nick Mathewson 5 anni fa
parent
commit
9a61d3f5ad
2 ha cambiato i file con 35 aggiunte e 12 eliminazioni
  1. 4 0
      changes/bug24953
  2. 31 12
      scripts/maint/updateFallbackDirs.py

+ 4 - 0
changes/bug24953

@@ -0,0 +1,4 @@
+  o Minor bugfixes (fallback scripts):
+    - In updateFallbackDirs.py, call the filter file a "fallback list"
+      instead of a "whitelist" in check_existing mode.
+      Fixes bug 24953; bugfix on 0.3.0.3-alpha.

+ 31 - 12
scripts/maint/updateFallbackDirs.py

@@ -1594,7 +1594,11 @@ class CandidateList(dict):
     """ Apply the fallback whitelist_obj to this fallback list,
     """ Apply the fallback whitelist_obj to this fallback list,
         passing exact to is_in_whitelist(). """
         passing exact to is_in_whitelist(). """
     excluded_count = 0
     excluded_count = 0
-    logging.debug('Applying whitelist')
+    list_type = 'whitelist'
+    if whitelist_obj['check_existing']:
+        list_type = 'fallback list'
+
+    logging.debug('Applying {}'.format(list_type))
     # parse the whitelist
     # parse the whitelist
     whitelist = self.load_relaylist(whitelist_obj)
     whitelist = self.load_relaylist(whitelist_obj)
     filtered_fallbacks = []
     filtered_fallbacks = []
@@ -1609,14 +1613,18 @@ class CandidateList(dict):
       else:
       else:
           # exclude
           # exclude
           excluded_count += 1
           excluded_count += 1
-          log_excluded('Excluding %s: not in whitelist.',
-                       f._fpr)
+          log_excluded('Excluding %s: not in %s.',
+                       f._fpr, list_type)
     self.fallbacks = filtered_fallbacks
     self.fallbacks = filtered_fallbacks
     return excluded_count
     return excluded_count
 
 
   @staticmethod
   @staticmethod
-  def summarise_filters(initial_count, excluded_count):
-    return '/* Whitelist excluded %d of %d candidates. */'%(
+  def summarise_filters(initial_count, excluded_count, check_existing):
+    list_type = 'Whitelist'
+    if check_existing:
+        list_type = 'Fallback list'
+
+    return '/* %s excluded %d of %d candidates. */'%(list_type,
                                                 excluded_count, initial_count)
                                                 excluded_count, initial_count)
 
 
   # calculate each fallback's measured bandwidth based on the median
   # calculate each fallback's measured bandwidth based on the median
@@ -2146,7 +2154,7 @@ class CandidateList(dict):
                                                       fallback_count)))
                                                       fallback_count)))
 
 
   def summarise_fallbacks(self, eligible_count, operator_count, failed_count,
   def summarise_fallbacks(self, eligible_count, operator_count, failed_count,
-                          guard_count, target_count):
+                          guard_count, target_count, check_existing):
     s = ''
     s = ''
     # Report:
     # Report:
     #  whether we checked consensus download times
     #  whether we checked consensus download times
@@ -2198,12 +2206,15 @@ class CandidateList(dict):
     s += '\n'
     s += '\n'
     s += '*/'
     s += '*/'
     if fallback_count < MIN_FALLBACK_COUNT:
     if fallback_count < MIN_FALLBACK_COUNT:
+      list_type = 'whitelist'
+      if check_existing:
+          list_type = 'fallback list'
       # We must have a minimum number of fallbacks so they are always
       # We must have a minimum number of fallbacks so they are always
       # reachable, and are in diverse locations
       # reachable, and are in diverse locations
       s += '\n'
       s += '\n'
       s += '#error Fallback Count %d is too low. '%(fallback_count)
       s += '#error Fallback Count %d is too low. '%(fallback_count)
       s += 'Must be at least %d for diversity. '%(MIN_FALLBACK_COUNT)
       s += 'Must be at least %d for diversity. '%(MIN_FALLBACK_COUNT)
-      s += 'Try adding entries to the whitelist, '
+      s += 'Try adding entries to %s, '%(list_type)
       s += 'or setting INCLUDE_UNLISTED_ENTRIES = True.'
       s += 'or setting INCLUDE_UNLISTED_ENTRIES = True.'
     return s
     return s
 
 
@@ -2211,14 +2222,16 @@ def process_existing():
   logging.basicConfig(level=logging.INFO)
   logging.basicConfig(level=logging.INFO)
   logging.getLogger('stem').setLevel(logging.INFO)
   logging.getLogger('stem').setLevel(logging.INFO)
   whitelist = {'data': parse_fallback_file(FALLBACK_FILE_NAME),
   whitelist = {'data': parse_fallback_file(FALLBACK_FILE_NAME),
-               'name': FALLBACK_FILE_NAME}
+               'name': FALLBACK_FILE_NAME,
+               'check_existing' : True}
   list_fallbacks(whitelist, exact=True)
   list_fallbacks(whitelist, exact=True)
 
 
 def process_default():
 def process_default():
   logging.basicConfig(level=logging.WARNING)
   logging.basicConfig(level=logging.WARNING)
   logging.getLogger('stem').setLevel(logging.WARNING)
   logging.getLogger('stem').setLevel(logging.WARNING)
   whitelist = {'data': read_from_file(WHITELIST_FILE_NAME, MAX_LIST_FILE_SIZE),
   whitelist = {'data': read_from_file(WHITELIST_FILE_NAME, MAX_LIST_FILE_SIZE),
-               'name': WHITELIST_FILE_NAME}
+               'name': WHITELIST_FILE_NAME,
+               'check_existing': False}
   list_fallbacks(whitelist, exact=False)
   list_fallbacks(whitelist, exact=False)
 
 
 ## Main Function
 ## Main Function
@@ -2244,7 +2257,11 @@ def list_fallbacks(whitelist, exact=False):
   """ Fetches required onionoo documents and evaluates the
   """ Fetches required onionoo documents and evaluates the
       fallback directory criteria for each of the relays,
       fallback directory criteria for each of the relays,
       passing exact to apply_filter_lists(). """
       passing exact to apply_filter_lists(). """
-  print "/* type=fallback */"
+  if whitelist['check_existing']:
+      print "/* type=fallback */"
+  else:
+      print "/* type=whitelist */"
+
   print ("/* version={} */"
   print ("/* version={} */"
          .format(cleanse_c_multiline_comment(FALLBACK_FORMAT_VERSION)))
          .format(cleanse_c_multiline_comment(FALLBACK_FORMAT_VERSION)))
   now = datetime.datetime.utcnow()
   now = datetime.datetime.utcnow()
@@ -2284,7 +2301,8 @@ def list_fallbacks(whitelist, exact=False):
   # instead, there will be an info-level log during the eligibility check.
   # instead, there will be an info-level log during the eligibility check.
   initial_count = len(candidates.fallbacks)
   initial_count = len(candidates.fallbacks)
   excluded_count = candidates.apply_filter_lists(whitelist, exact=exact)
   excluded_count = candidates.apply_filter_lists(whitelist, exact=exact)
-  print candidates.summarise_filters(initial_count, excluded_count)
+  print candidates.summarise_filters(initial_count, excluded_count,
+          whitelist['check_existing'])
   eligible_count = len(candidates.fallbacks)
   eligible_count = len(candidates.fallbacks)
 
 
   # calculate the measured bandwidth of each relay,
   # calculate the measured bandwidth of each relay,
@@ -2337,7 +2355,8 @@ def list_fallbacks(whitelist, exact=False):
   if len(candidates.fallbacks) > 0:
   if len(candidates.fallbacks) > 0:
     print candidates.summarise_fallbacks(eligible_count, operator_count,
     print candidates.summarise_fallbacks(eligible_count, operator_count,
                                          failed_count, guard_count,
                                          failed_count, guard_count,
-                                         target_count)
+                                         target_count,
+                                         whitelist['check_existing'])
   else:
   else:
     print '/* No Fallbacks met criteria */'
     print '/* No Fallbacks met criteria */'