summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2018-04-14 13:00:22 -0700
committerDamian Johnson <atagar@torproject.org>2018-04-14 13:00:22 -0700
commit0e5010b01a0da7616ceeb8ba52080bd91b4a6cc6 (patch)
tree87a66eea5a5f57fe790ac05bbb75917c808c8108
parent82435ed83fb91ae838757c32b6a6a4d49c3bc901 (diff)
Prevent duplicate 'fingerprint changed' notices
Strange. It doesn't commonly happen but as reported in... https://trac.torproject.org/projects/tor/ticket/25789 ... sometimes we list a relay twice. My only guess is that this arises if a particular address/port is a relay in the consensus twice. Adjusting the code in a way that should deduplicate these.
-rwxr-xr-xfingerprint_change_checker.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/fingerprint_change_checker.py b/fingerprint_change_checker.py
index 96bdb2a..6bc0a94 100755
--- a/fingerprint_change_checker.py
+++ b/fingerprint_change_checker.py
@@ -42,7 +42,7 @@ def main():
fingerprint_changes = load_fingerprint_changes()
downloader = DescriptorDownloader(timeout = 15)
- alarm_for = set()
+ alarm_for = {}
for relay in downloader.get_consensus():
prior_fingerprints = fingerprint_changes.setdefault((relay.address, relay.or_port), {})
@@ -62,13 +62,13 @@ def main():
# if we've changed more than ten times in the last ten days then alarm
if len(prior_fingerprints) >= 10:
- alarm_for.add((relay.address, relay.or_port, relay.fingerprint))
+ alarm_for['%s:%s' % (relay.address, relay.or_port)] = (relay.address, relay.or_port, relay.fingerprint)
- if alarm_for and not is_notification_suppressed(alarm_for):
+ if alarm_for and not is_notification_suppressed(alarm_for.values()):
log.debug("Sending a notification for %i relays..." % len(alarm_for))
body = EMAIL_BODY
- for address, or_port, fingerprint in alarm_for:
+ for address, or_port, fingerprint in alarm_for.values():
try:
desc = downloader.get_server_descriptors(fingerprint).run()[0]
except:
@@ -102,7 +102,7 @@ def main():
subject = EMAIL_SUBJECT
if len(alarm_for) == 1:
- subject += ' (%s:%s)' % list(alarm_for)[0][:2]
+ subject += ' (%s:%s)' % alarm_for.values()[0][:2]
util.send(subject, body = body, to = ['bad-relays@lists.torproject.org', 'atagar@torproject.org'])
@@ -110,7 +110,7 @@ def main():
current_time = str(int(time.time()))
- for address, or_port, _ in alarm_for:
+ for address, or_port, _ in alarm_for.values():
last_notified_config.set('%s:%s' % (address, or_port), current_time)
last_notified_config.save()