Browse Source

Logging existing fallbacks at warning level

Suphanat Chunhapanya 7 years ago
parent
commit
d97792d596
1 changed files with 31 additions and 25 deletions
  1. 31 25
      scripts/maint/updateFallbackDirs.py

+ 31 - 25
scripts/maint/updateFallbackDirs.py

@@ -708,15 +708,15 @@ class Candidate(object):
     #
     #
     # if the relay doesn't have a recommended version field, exclude the relay
     # if the relay doesn't have a recommended version field, exclude the relay
     if not self._data.has_key('recommended_version'):
     if not self._data.has_key('recommended_version'):
-      logging.info('%s not a candidate: no recommended_version field',
+      log_excluded('%s not a candidate: no recommended_version field',
                    self._fpr)
                    self._fpr)
       return False
       return False
     if not self._data['recommended_version']:
     if not self._data['recommended_version']:
-      logging.info('%s not a candidate: version not recommended', self._fpr)
+      log_excluded('%s not a candidate: version not recommended', self._fpr)
       return False
       return False
     # if the relay doesn't have version field, exclude the relay
     # if the relay doesn't have version field, exclude the relay
     if not self._data.has_key('version'):
     if not self._data.has_key('version'):
-      logging.info('%s not a candidate: no version field', self._fpr)
+      log_excluded('%s not a candidate: no version field', self._fpr)
       return False
       return False
     if self._data['version'] in Candidate.STALE_CONSENSUS_VERSIONS:
     if self._data['version'] in Candidate.STALE_CONSENSUS_VERSIONS:
       logging.warning('%s not a candidate: version delivers stale consensuses',
       logging.warning('%s not a candidate: version delivers stale consensuses',
@@ -870,36 +870,36 @@ class Candidate(object):
   def is_candidate(self):
   def is_candidate(self):
     try:
     try:
       if (MUST_BE_RUNNING_NOW and not self.is_running()):
       if (MUST_BE_RUNNING_NOW and not self.is_running()):
-        logging.info('%s not a candidate: not running now, unable to check ' +
+        log_excluded('%s not a candidate: not running now, unable to check ' +
                      'DirPort consensus download', self._fpr)
                      'DirPort consensus download', self._fpr)
         return False
         return False
       if (self._data['last_changed_address_or_port'] >
       if (self._data['last_changed_address_or_port'] >
           self.CUTOFF_ADDRESS_AND_PORT_STABLE):
           self.CUTOFF_ADDRESS_AND_PORT_STABLE):
-        logging.info('%s not a candidate: changed address/port recently (%s)',
+        log_excluded('%s not a candidate: changed address/port recently (%s)',
                      self._fpr, self._data['last_changed_address_or_port'])
                      self._fpr, self._data['last_changed_address_or_port'])
         return False
         return False
       if self._running < CUTOFF_RUNNING:
       if self._running < CUTOFF_RUNNING:
-        logging.info('%s not a candidate: running avg too low (%lf)',
+        log_excluded('%s not a candidate: running avg too low (%lf)',
                      self._fpr, self._running)
                      self._fpr, self._running)
         return False
         return False
       if self._v2dir < CUTOFF_V2DIR:
       if self._v2dir < CUTOFF_V2DIR:
-        logging.info('%s not a candidate: v2dir avg too low (%lf)',
+        log_excluded('%s not a candidate: v2dir avg too low (%lf)',
                      self._fpr, self._v2dir)
                      self._fpr, self._v2dir)
         return False
         return False
       if self._badexit is not None and self._badexit > PERMITTED_BADEXIT:
       if self._badexit is not None and self._badexit > PERMITTED_BADEXIT:
-        logging.info('%s not a candidate: badexit avg too high (%lf)',
+        log_excluded('%s not a candidate: badexit avg too high (%lf)',
                      self._fpr, self._badexit)
                      self._fpr, self._badexit)
         return False
         return False
       # this function logs a message depending on which check fails
       # this function logs a message depending on which check fails
       if not self.is_valid_version():
       if not self.is_valid_version():
         return False
         return False
       if self._guard < CUTOFF_GUARD:
       if self._guard < CUTOFF_GUARD:
-        logging.info('%s not a candidate: guard avg too low (%lf)',
+        log_excluded('%s not a candidate: guard avg too low (%lf)',
                      self._fpr, self._guard)
                      self._fpr, self._guard)
         return False
         return False
       if (not self._data.has_key('consensus_weight')
       if (not self._data.has_key('consensus_weight')
           or self._data['consensus_weight'] < 1):
           or self._data['consensus_weight'] < 1):
-        logging.info('%s not a candidate: consensus weight invalid', self._fpr)
+        log_excluded('%s not a candidate: consensus weight invalid', self._fpr)
         return False
         return False
     except BaseException as e:
     except BaseException as e:
       logging.warning("Exception %s when checking if fallback is a candidate",
       logging.warning("Exception %s when checking if fallback is a candidate",
@@ -980,26 +980,26 @@ class Candidate(object):
       for key in entry:
       for key in entry:
         value = entry[key]
         value = entry[key]
         if key == 'id' and value == self._fpr:
         if key == 'id' and value == self._fpr:
-          logging.info('%s is in the blacklist: fingerprint matches',
+          log_excluded('%s is in the blacklist: fingerprint matches',
                        self._fpr)
                        self._fpr)
           return True
           return True
         if key == 'ipv4' and value == self.dirip:
         if key == 'ipv4' and value == self.dirip:
           # if the dirport is present, check it too
           # if the dirport is present, check it too
           if entry.has_key('dirport'):
           if entry.has_key('dirport'):
             if int(entry['dirport']) == self.dirport:
             if int(entry['dirport']) == self.dirport:
-              logging.info('%s is in the blacklist: IPv4 (%s) and ' +
+              log_excluded('%s is in the blacklist: IPv4 (%s) and ' +
                            'DirPort (%d) match', self._fpr, self.dirip,
                            'DirPort (%d) match', self._fpr, self.dirip,
                            self.dirport)
                            self.dirport)
               return True
               return True
           # if the orport is present, check it too
           # if the orport is present, check it too
           elif entry.has_key('orport'):
           elif entry.has_key('orport'):
             if int(entry['orport']) == self.orport:
             if int(entry['orport']) == self.orport:
-              logging.info('%s is in the blacklist: IPv4 (%s) and ' +
+              log_excluded('%s is in the blacklist: IPv4 (%s) and ' +
                            'ORPort (%d) match', self._fpr, self.dirip,
                            'ORPort (%d) match', self._fpr, self.dirip,
                            self.orport)
                            self.orport)
               return True
               return True
           else:
           else:
-            logging.info('%s is in the blacklist: IPv4 (%s) matches, and ' +
+            log_excluded('%s is in the blacklist: IPv4 (%s) matches, and ' +
                          'entry has no DirPort or ORPort', self._fpr,
                          'entry has no DirPort or ORPort', self._fpr,
                          self.dirip)
                          self.dirip)
             return True
             return True
@@ -1013,19 +1013,19 @@ class Candidate(object):
             # if the dirport is present, check it too
             # if the dirport is present, check it too
             if entry.has_key('dirport'):
             if entry.has_key('dirport'):
               if int(entry['dirport']) == self.dirport:
               if int(entry['dirport']) == self.dirport:
-                logging.info('%s is in the blacklist: IPv6 (%s) and ' +
+                log_excluded('%s is in the blacklist: IPv6 (%s) and ' +
                              'DirPort (%d) match', self._fpr, ipv6,
                              'DirPort (%d) match', self._fpr, ipv6,
                              self.dirport)
                              self.dirport)
                 return True
                 return True
             # we've already checked the ORPort, it's part of entry['ipv6']
             # we've already checked the ORPort, it's part of entry['ipv6']
             else:
             else:
-              logging.info('%s is in the blacklist: IPv6 (%s) matches, and' +
+              log_excluded('%s is in the blacklist: IPv6 (%s) matches, and' +
                            'entry has no DirPort', self._fpr, ipv6)
                            'entry has no DirPort', self._fpr, ipv6)
               return True
               return True
         elif (key == 'ipv6' or self.has_ipv6()):
         elif (key == 'ipv6' or self.has_ipv6()):
           # only log if the fingerprint matches but the IPv6 doesn't
           # only log if the fingerprint matches but the IPv6 doesn't
           if entry.has_key('id') and entry['id'] == self._fpr:
           if entry.has_key('id') and entry['id'] == self._fpr:
-            logging.info('%s skipping IPv6 blacklist comparison: relay ' +
+            log_excluded('%s skipping IPv6 blacklist comparison: relay ' +
                          'has%s IPv6%s, but entry has%s IPv6%s', self._fpr,
                          'has%s IPv6%s, but entry has%s IPv6%s', self._fpr,
                          '' if self.has_ipv6() else ' no',
                          '' if self.has_ipv6() else ' no',
                          (' (' + ipv6 + ')') if self.has_ipv6() else  '',
                          (' (' + ipv6 + ')') if self.has_ipv6() else  '',
@@ -1193,7 +1193,7 @@ class Candidate(object):
       time_since_expiry = (end - consensus.valid_until).total_seconds()
       time_since_expiry = (end - consensus.valid_until).total_seconds()
     except Exception, stem_error:
     except Exception, stem_error:
       end = datetime.datetime.utcnow()
       end = datetime.datetime.utcnow()
-      logging.info('Unable to retrieve a consensus from %s: %s', nickname,
+      log_excluded('Unable to retrieve a consensus from %s: %s', nickname,
                     stem_error)
                     stem_error)
       status = 'error: "%s"' % (stem_error)
       status = 'error: "%s"' % (stem_error)
       level = logging.WARNING
       level = logging.WARNING
@@ -1520,7 +1520,7 @@ class CandidateList(dict):
       elif in_blacklist:
       elif in_blacklist:
         # exclude
         # exclude
         excluded_count += 1
         excluded_count += 1
-        logging.info('Excluding %s: in blacklist.', f._fpr)
+        log_excluded('Excluding %s: in blacklist.', f._fpr)
       else:
       else:
         if INCLUDE_UNLISTED_ENTRIES:
         if INCLUDE_UNLISTED_ENTRIES:
           # include
           # include
@@ -1528,7 +1528,7 @@ class CandidateList(dict):
         else:
         else:
           # exclude
           # exclude
           excluded_count += 1
           excluded_count += 1
-          logging.info('Excluding %s: in neither blacklist nor whitelist.',
+          log_excluded('Excluding %s: in neither blacklist nor whitelist.',
                        f._fpr)
                        f._fpr)
     self.fallbacks = filtered_fallbacks
     self.fallbacks = filtered_fallbacks
     return excluded_count
     return excluded_count
@@ -1564,7 +1564,7 @@ class CandidateList(dict):
         # the bandwidth we log here is limited by the relay's consensus weight
         # the bandwidth we log here is limited by the relay's consensus weight
         # as well as its adverttised bandwidth. See set_measured_bandwidth
         # as well as its adverttised bandwidth. See set_measured_bandwidth
         # for details
         # for details
-        logging.info('%s not a candidate: bandwidth %.1fMByte/s too low, ' +
+        log_excluded('%s not a candidate: bandwidth %.1fMByte/s too low, ' +
                      'must be at least %.1fMByte/s', f._fpr,
                      'must be at least %.1fMByte/s', f._fpr,
                      f._data['measured_bandwidth']/(1024.0*1024.0),
                      f._data['measured_bandwidth']/(1024.0*1024.0),
                      MIN_BANDWIDTH/(1024.0*1024.0))
                      MIN_BANDWIDTH/(1024.0*1024.0))
@@ -1668,13 +1668,13 @@ class CandidateList(dict):
           CandidateList.attribute_add(f.ipv6addr, ip_list)
           CandidateList.attribute_add(f.ipv6addr, ip_list)
       elif not CandidateList.attribute_allow(f.dirip, ip_list,
       elif not CandidateList.attribute_allow(f.dirip, ip_list,
                                              MAX_FALLBACKS_PER_IPV4):
                                              MAX_FALLBACKS_PER_IPV4):
-        logging.info('Eliminated %s: already have %d fallback(s) on IPv4 %s'
+        log_excluded('Eliminated %s: already have %d fallback(s) on IPv4 %s'
                      %(f._fpr, CandidateList.attribute_count(f.dirip, ip_list),
                      %(f._fpr, CandidateList.attribute_count(f.dirip, ip_list),
                        f.dirip))
                        f.dirip))
       elif (f.has_ipv6() and
       elif (f.has_ipv6() and
             not CandidateList.attribute_allow(f.ipv6addr, ip_list,
             not CandidateList.attribute_allow(f.ipv6addr, ip_list,
                                               MAX_FALLBACKS_PER_IPV6)):
                                               MAX_FALLBACKS_PER_IPV6)):
-        logging.info('Eliminated %s: already have %d fallback(s) on IPv6 %s'
+        log_excluded('Eliminated %s: already have %d fallback(s) on IPv6 %s'
                      %(f._fpr, CandidateList.attribute_count(f.ipv6addr,
                      %(f._fpr, CandidateList.attribute_count(f.ipv6addr,
                                                              ip_list),
                                                              ip_list),
                        f.ipv6addr))
                        f.ipv6addr))
@@ -1698,7 +1698,7 @@ class CandidateList(dict):
         contact_limit_fallbacks.append(f)
         contact_limit_fallbacks.append(f)
         CandidateList.attribute_add(f._data['contact'], contact_list)
         CandidateList.attribute_add(f._data['contact'], contact_list)
       else:
       else:
-        logging.info(
+        log_excluded(
           'Eliminated %s: already have %d fallback(s) on ContactInfo %s'
           'Eliminated %s: already have %d fallback(s) on ContactInfo %s'
           %(f._fpr, CandidateList.attribute_count(f._data['contact'],
           %(f._fpr, CandidateList.attribute_count(f._data['contact'],
                                                   contact_list),
                                                   contact_list),
@@ -1727,7 +1727,7 @@ class CandidateList(dict):
       else:
       else:
         # we already have a fallback with this fallback in its effective
         # we already have a fallback with this fallback in its effective
         # family
         # family
-        logging.info(
+        log_excluded(
           'Eliminated %s: already have %d fallback(s) in effective family'
           'Eliminated %s: already have %d fallback(s) in effective family'
           %(f._fpr, CandidateList.attribute_count(f._fpr, fingerprint_list)))
           %(f._fpr, CandidateList.attribute_count(f._fpr, fingerprint_list)))
     original_count = len(self.fallbacks)
     original_count = len(self.fallbacks)
@@ -2102,6 +2102,12 @@ def get_command():
   else:
   else:
     return None
     return None
 
 
+def log_excluded(msg, *args):
+  if get_command() == 'check_existing':
+    logging.warning(msg, *args)
+  else:
+    logging.info(msg, *args)
+
 def list_fallbacks(whitelist, blacklist):
 def list_fallbacks(whitelist, blacklist):
   """ 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 """