|
@@ -53,6 +53,9 @@ PERFORM_IPV4_DIRPORT_CHECKS = False if OUTPUT_CANDIDATES else True
|
|
|
|
|
|
PERFORM_IPV6_DIRPORT_CHECKS = False if OUTPUT_CANDIDATES else False
|
|
|
|
|
|
+
|
|
|
+OUTPUT_COMMENTS = True if OUTPUT_CANDIDATES else False
|
|
|
+
|
|
|
|
|
|
|
|
|
CONTACT_COUNT = True if OUTPUT_CANDIDATES else False
|
|
@@ -933,8 +936,9 @@ class Candidate(object):
|
|
|
def is_running(self):
|
|
|
return 'Running' in self._data['flags']
|
|
|
|
|
|
+
|
|
|
@staticmethod
|
|
|
- def fallback_consensus_dl_speed(dirip, dirport, nickname, max_time):
|
|
|
+ def fallback_consensus_download_speed(dirip, dirport, nickname, max_time):
|
|
|
download_failed = False
|
|
|
downloader = DescriptorDownloader()
|
|
|
start = datetime.datetime.utcnow()
|
|
@@ -970,47 +974,60 @@ class Candidate(object):
|
|
|
dirip, dirport, max_time)
|
|
|
return download_failed
|
|
|
|
|
|
- def fallback_consensus_dl_check(self):
|
|
|
+
|
|
|
+ def check_fallback_download_consensus(self):
|
|
|
|
|
|
ipv4_failed = False
|
|
|
ipv6_failed = False
|
|
|
if PERFORM_IPV4_DIRPORT_CHECKS:
|
|
|
- ipv4_failed = Candidate.fallback_consensus_dl_speed(self.dirip,
|
|
|
+ ipv4_failed = Candidate.fallback_consensus_download_speed(self.dirip,
|
|
|
self.dirport,
|
|
|
self._data['nickname'],
|
|
|
CONSENSUS_DOWNLOAD_SPEED_MAX)
|
|
|
if self.ipv6addr is not None and PERFORM_IPV6_DIRPORT_CHECKS:
|
|
|
|
|
|
- ipv6_failed = Candidate.fallback_consensus_dl_speed(self.ipv6addr,
|
|
|
- self.dirport,
|
|
|
- self._data['nickname'],
|
|
|
- CONSENSUS_DOWNLOAD_SPEED_MAX)
|
|
|
-
|
|
|
- if (PERFORM_IPV4_DIRPORT_CHECKS and ipv4_failed
|
|
|
- and CONSENSUS_DOWNLOAD_RETRY):
|
|
|
- ipv4_failed = Candidate.fallback_consensus_dl_speed(self.dirip,
|
|
|
- self.dirport,
|
|
|
- self._data['nickname'],
|
|
|
- CONSENSUS_DOWNLOAD_SPEED_MAX)
|
|
|
- if (self.ipv6addr is not None and PERFORM_IPV6_DIRPORT_CHECKS
|
|
|
- and ipv6_failed and CONSENSUS_DOWNLOAD_RETRY):
|
|
|
- ipv6_failed = Candidate.fallback_consensus_dl_speed(self.ipv6addr,
|
|
|
+ ipv6_failed = Candidate.fallback_consensus_download_speed(self.ipv6addr,
|
|
|
self.dirport,
|
|
|
self._data['nickname'],
|
|
|
CONSENSUS_DOWNLOAD_SPEED_MAX)
|
|
|
return ((not ipv4_failed) and (not ipv6_failed))
|
|
|
|
|
|
- def fallbackdir_line(self, dl_speed_ok, fallbacks, prefilter_fallbacks):
|
|
|
+
|
|
|
+
|
|
|
+ def try_fallback_download_consensus(self):
|
|
|
+ if not self.get_fallback_download_consensus():
|
|
|
+ self._data['download_check'] = self.check_fallback_download_consensus()
|
|
|
+
|
|
|
+
|
|
|
+ def get_fallback_download_consensus(self):
|
|
|
+
|
|
|
+ if not PERFORM_IPV4_DIRPORT_CHECKS and not PERFORM_IPV6_DIRPORT_CHECKS:
|
|
|
+ return True
|
|
|
+
|
|
|
+ if not self._data.has_key('download_check'):
|
|
|
+ return False
|
|
|
+ return self._data['download_check']
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def fallbackdir_line(self, fallbacks, prefilter_fallbacks):
|
|
|
+ s = ''
|
|
|
+ if OUTPUT_COMMENTS:
|
|
|
+ s += self.fallbackdir_comment(fallbacks, prefilter_fallbacks)
|
|
|
+
|
|
|
+
|
|
|
+ if self.get_fallback_download_consensus() or OUTPUT_COMMENTS:
|
|
|
+ s += self.fallbackdir_info(self.get_fallback_download_consensus())
|
|
|
+ return s
|
|
|
+
|
|
|
+
|
|
|
+ def fallbackdir_comment(self, fallbacks, prefilter_fallbacks):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
s = '/*'
|
|
|
s += '\n'
|
|
@@ -1040,9 +1057,26 @@ class Candidate(object):
|
|
|
s += '\n'
|
|
|
s += '*/'
|
|
|
s += '\n'
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def fallbackdir_info(self, dl_speed_ok):
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ c_string = dl_speed_ok
|
|
|
+ comment_string = not dl_speed_ok and OUTPUT_COMMENTS
|
|
|
+
|
|
|
+ if not c_string and not comment_string:
|
|
|
+ return ''
|
|
|
+ s = ''
|
|
|
|
|
|
|
|
|
- if not dl_speed_ok:
|
|
|
+ if comment_string:
|
|
|
s += '/* Consensus download failed or was too slow:\n'
|
|
|
|
|
|
|
|
@@ -1057,7 +1091,7 @@ class Candidate(object):
|
|
|
cleanse_c_string(self.ipv6addr), cleanse_c_string(self.ipv6orport))
|
|
|
s += '\n'
|
|
|
s += '" weight=%d",'%(FALLBACK_OUTPUT_WEIGHT)
|
|
|
- if not dl_speed_ok:
|
|
|
+ if comment_string:
|
|
|
s += '\n'
|
|
|
s += '*/'
|
|
|
return s
|
|
@@ -1129,13 +1163,19 @@ class CandidateList(dict):
|
|
|
|
|
|
|
|
|
def sort_fallbacks_by_cw_to_bw_factor(self):
|
|
|
- self.fallbacks.sort(key=lambda x: self[x].cw_to_bw_factor())
|
|
|
+ self.fallbacks.sort(key=lambda f: f.cw_to_bw_factor(), self.fallbacks)
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
def sort_fallbacks_by_measured_bandwidth(self):
|
|
|
- self.fallbacks.sort(key=lambda x: self[x].self._data['measured_bandwidth'],
|
|
|
- reverse=True)
|
|
|
+ self.fallbacks.sort(key=lambda f: f._data['measured_bandwidth'],
|
|
|
+ self.fallbacks, reverse=True)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def sort_fallbacks_by_fingerprint(self):
|
|
|
+ self.fallbacks.sort(key=lambda f: self[f]._fpr, self.fallbacks)
|
|
|
|
|
|
@staticmethod
|
|
|
def load_relaylist(file_name):
|
|
@@ -1301,6 +1341,39 @@ class CandidateList(dict):
|
|
|
else:
|
|
|
return None
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def try_download_consensus_checks(self, max_count):
|
|
|
+ dl_ok_count = 0
|
|
|
+ for f in self.fallbacks:
|
|
|
+ f.try_fallback_download_consensus()
|
|
|
+ if f.get_fallback_download_consensus():
|
|
|
+
|
|
|
+ dl_ok_count += 1
|
|
|
+ if dl_ok_count >= max_count:
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ def perform_download_consensus_checks(self, max_count):
|
|
|
+ self.sort_fallbacks_by_measured_bandwidth()
|
|
|
+ self.try_download_consensus_checks(max_count)
|
|
|
+ if CONSENSUS_DOWNLOAD_RETRY:
|
|
|
+
|
|
|
+
|
|
|
+ self.try_download_consensus_checks(max_count)
|
|
|
+
|
|
|
+
|
|
|
+ self.fallbacks = filter(lambda x: x.get_fallback_download_consensus(),
|
|
|
+ self.fallbacks)
|
|
|
+ self.fallbacks = self.fallbacks[:max_count]
|
|
|
+
|
|
|
def summarise_fallbacks(self, eligible_count, guard_count, target_count,
|
|
|
max_count):
|
|
|
|
|
@@ -1393,9 +1466,6 @@ def list_fallbacks():
|
|
|
|
|
|
candidates.calculate_measured_bandwidth()
|
|
|
candidates.remove_low_bandwidth_relays()
|
|
|
-
|
|
|
-
|
|
|
- candidates.sort_fallbacks_by_measured_bandwidth()
|
|
|
|
|
|
|
|
|
|
|
@@ -1412,17 +1482,18 @@ def list_fallbacks():
|
|
|
for s in fetch_source_list():
|
|
|
print describe_fetch_source(s)
|
|
|
|
|
|
- active_count = 0
|
|
|
+
|
|
|
+ candidates.perform_download_consensus_checks(max_count)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if not OUTPUT_CANDIDATES:
|
|
|
+ candidates.sort_fallbacks_by_fingerprint()
|
|
|
+
|
|
|
for x in candidates.fallbacks:
|
|
|
- dl_speed_ok = x.fallback_consensus_dl_check()
|
|
|
- print x.fallbackdir_line(dl_speed_ok, candidates.fallbacks,
|
|
|
- prefilter_fallbacks)
|
|
|
- if dl_speed_ok:
|
|
|
-
|
|
|
- active_count += 1
|
|
|
- if active_count >= max_count:
|
|
|
-
|
|
|
- break
|
|
|
+ print x.fallbackdir_line(candidates.fallbacks, prefilter_fallbacks)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
list_fallbacks()
|