mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 15:43:32 +01:00
Exclude relays that deliver an expired consensus from the fallback list
Part of #20539, based on #20501.
This commit is contained in:
parent
243d6fa0c7
commit
8381d928cf
@ -38,7 +38,8 @@ import dateutil.parser
|
|||||||
#from bson import json_util
|
#from bson import json_util
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from stem.descriptor.remote import DescriptorDownloader
|
from stem.descriptor import DocumentHandler
|
||||||
|
from stem.descriptor.remote import get_consensus
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
# INFO tells you why each relay was included or excluded
|
# INFO tells you why each relay was included or excluded
|
||||||
@ -80,6 +81,9 @@ PERFORM_IPV4_DIRPORT_CHECKS = False if OUTPUT_CANDIDATES else True
|
|||||||
# Don't check ~1000 candidates when OUTPUT_CANDIDATES is True
|
# Don't check ~1000 candidates when OUTPUT_CANDIDATES is True
|
||||||
PERFORM_IPV6_DIRPORT_CHECKS = False if OUTPUT_CANDIDATES else False
|
PERFORM_IPV6_DIRPORT_CHECKS = False if OUTPUT_CANDIDATES else False
|
||||||
|
|
||||||
|
# Clients have been using microdesc consensuses by default for a while now
|
||||||
|
DOWNLOAD_MICRODESC_CONSENSUS = True
|
||||||
|
|
||||||
# Output fallback name, flags, bandwidth, and ContactInfo in a C comment?
|
# Output fallback name, flags, bandwidth, and ContactInfo in a C comment?
|
||||||
OUTPUT_COMMENTS = True if OUTPUT_CANDIDATES else False
|
OUTPUT_COMMENTS = True if OUTPUT_CANDIDATES else False
|
||||||
|
|
||||||
@ -1120,25 +1124,30 @@ class Candidate(object):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# report how long it takes to download a consensus from dirip:dirport
|
# log how long it takes to download a consensus from dirip:dirport
|
||||||
|
# returns True if the download failed, False if it succeeded within max_time
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fallback_consensus_download_speed(dirip, dirport, nickname, max_time):
|
def fallback_consensus_download_speed(dirip, dirport, nickname, max_time):
|
||||||
download_failed = False
|
download_failed = False
|
||||||
downloader = DescriptorDownloader()
|
|
||||||
start = datetime.datetime.utcnow()
|
start = datetime.datetime.utcnow()
|
||||||
# some directory mirrors respond to requests in ways that hang python
|
# some directory mirrors respond to requests in ways that hang python
|
||||||
# sockets, which is why we log this line here
|
# sockets, which is why we log this line here
|
||||||
logging.info('Initiating consensus download from %s (%s:%d).', nickname,
|
logging.info('Initiating %sconsensus download from %s (%s:%d).',
|
||||||
dirip, dirport)
|
'microdesc ' if DOWNLOAD_MICRODESC_CONSENSUS else '',
|
||||||
|
nickname, dirip, dirport)
|
||||||
# there appears to be about 1 second of overhead when comparing stem's
|
# there appears to be about 1 second of overhead when comparing stem's
|
||||||
# internal trace time and the elapsed time calculated here
|
# internal trace time and the elapsed time calculated here
|
||||||
TIMEOUT_SLOP = 1.0
|
TIMEOUT_SLOP = 1.0
|
||||||
try:
|
try:
|
||||||
downloader.get_consensus(endpoints = [(dirip, dirport)],
|
consensus = get_consensus(
|
||||||
timeout = (max_time + TIMEOUT_SLOP),
|
endpoints = [(dirip, dirport)],
|
||||||
validate = True,
|
timeout = (max_time + TIMEOUT_SLOP),
|
||||||
retries = 0,
|
validate = True,
|
||||||
fall_back_to_authority = False).run()
|
retries = 0,
|
||||||
|
fall_back_to_authority = False,
|
||||||
|
document_handler = DocumentHandler.BARE_DOCUMENT,
|
||||||
|
microdescriptor = DOWNLOAD_MICRODESC_CONSENSUS
|
||||||
|
).run()[0]
|
||||||
except Exception, stem_error:
|
except Exception, stem_error:
|
||||||
logging.info('Unable to retrieve a consensus from %s: %s', nickname,
|
logging.info('Unable to retrieve a consensus from %s: %s', nickname,
|
||||||
stem_error)
|
stem_error)
|
||||||
@ -1146,10 +1155,19 @@ class Candidate(object):
|
|||||||
level = logging.WARNING
|
level = logging.WARNING
|
||||||
download_failed = True
|
download_failed = True
|
||||||
elapsed = (datetime.datetime.utcnow() - start).total_seconds()
|
elapsed = (datetime.datetime.utcnow() - start).total_seconds()
|
||||||
if elapsed > max_time:
|
if download_failed:
|
||||||
|
# keep the error failure status
|
||||||
|
pass
|
||||||
|
elif elapsed > max_time:
|
||||||
status = 'too slow'
|
status = 'too slow'
|
||||||
level = logging.WARNING
|
level = logging.WARNING
|
||||||
download_failed = True
|
download_failed = True
|
||||||
|
elif datetime.datetime.utcnow() > consensus.valid_until:
|
||||||
|
time_since_expiry = (datetime.datetime.utcnow() -
|
||||||
|
consensus.valid_until).total_seconds()
|
||||||
|
status = 'outdated consensus, expired %ds ago'%(int(time_since_expiry))
|
||||||
|
level = logging.WARNING
|
||||||
|
download_failed = True
|
||||||
else:
|
else:
|
||||||
status = 'ok'
|
status = 'ok'
|
||||||
level = logging.DEBUG
|
level = logging.DEBUG
|
||||||
|
Loading…
Reference in New Issue
Block a user