[tor-commits] [tor/master] Add fallback directory mirror helper scripts

nickm at torproject.org nickm at torproject.org
Fri Jan 5 21:47:34 UTC 2018


commit e244738bbd7d0fb58bb17bcec071a0b7b71fd532
Author: teor <teor2345 at gmail.com>
Date:   Fri Dec 22 21:38:12 2017 +1100

    Add fallback directory mirror helper scripts
    
    Add the generateFallbackDirLine.py script for automatically generating
    fallback directory mirror lines from relay fingerprints. No more typos!
    
    Add the lookupFallbackDirContact.py script for automatically looking up
    operator contact info from relay fingerprints.
    
    Implements ticket 24706.
---
 changes/ticket24706                       |  6 +++++
 scripts/maint/fallback.blacklist          |  2 ++
 scripts/maint/fallback.whitelist          |  2 ++
 scripts/maint/generateFallbackDirLine.py  | 41 +++++++++++++++++++++++++++++++
 scripts/maint/lookupFallbackDirContact.py | 28 +++++++++++++++++++++
 5 files changed, 79 insertions(+)

diff --git a/changes/ticket24706 b/changes/ticket24706
new file mode 100644
index 000000000..716f88c89
--- /dev/null
+++ b/changes/ticket24706
@@ -0,0 +1,6 @@
+  o Minor features (fallback directory mirrors):
+    - Add the generateFallbackDirLine.py script for automatically generating
+      fallback directory mirror lines from relay fingerprints. No more typos!
+      Add the lookupFallbackDirContact.py script for automatically looking up
+      operator contact info from relay fingerprints.
+      Implements ticket 24706.
diff --git a/scripts/maint/fallback.blacklist b/scripts/maint/fallback.blacklist
index 1d0edfd0b..a118cb591 100644
--- a/scripts/maint/fallback.blacklist
+++ b/scripts/maint/fallback.blacklist
@@ -3,6 +3,8 @@
 # Format:
 # [ IPv4[:DirPort] ] [ orport=<ORPort> ] [ id=<ID> ] ...
 #   [ ipv6=<IPv6>[:<IPv6 ORPort>] ]
+# or use:
+# scripts/maint/generateFallbackDirLine.py fingerprint ...
 #
 # If a sufficiently specific group of attributes matches, the directory mirror
 # will be excluded: (each group is listed on its own line)
diff --git a/scripts/maint/fallback.whitelist b/scripts/maint/fallback.whitelist
index b8bb82fd0..e9158e128 100644
--- a/scripts/maint/fallback.whitelist
+++ b/scripts/maint/fallback.whitelist
@@ -2,6 +2,8 @@
 #
 # Format:
 # IPv4:DirPort orport=<ORPort> id=<ID> [ ipv6=<IPv6>:<IPv6 ORPort> ]
+# or use:
+# scripts/maint/generateFallbackDirLine.py fingerprint ...
 #
 # All attributes must match for the directory mirror to be included.
 # If the fallback has an ipv6 key, the whitelist line must also have
diff --git a/scripts/maint/generateFallbackDirLine.py b/scripts/maint/generateFallbackDirLine.py
new file mode 100755
index 000000000..b59edc33f
--- /dev/null
+++ b/scripts/maint/generateFallbackDirLine.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+# Generate a fallback directory whitelist/blacklist line for every fingerprint
+# passed as an argument.
+#
+# Usage:
+# generateFallbackDirLine.py fingerprint ...
+
+import sys
+
+import stem.descriptor.remote as remote
+
+if len(sys.argv) <= 1:
+  print "Usage: {} fingerprint ...".format(sys.argv[0])
+  sys.exit(-1)
+
+# we need the full consensus, because it has IPv6 ORPorts
+# and we want a fingerprint to router mapping in routers
+#
+# stem returns document_handler='DOCUMENT' as a list of consensuses
+# with one entry
+consensus = remote.get_consensus(document_handler='DOCUMENT').run()[0]
+
+for fingerprint in sys.argv[1:]:
+  if fingerprint in consensus.routers:
+    r = consensus.routers[fingerprint]
+    # Tor clients don't use DirPorts, but old code requires one for fallbacks
+    if r.dir_port is not None:
+      # IPv4:DirPort orport=ORPort id=Fingerprint ipv6=[IPv6]:IPv6ORPort # nick
+      ipv6_or_ap_list = [ apv for apv in r.or_addresses if apv[2] ]
+      ipv6_str = ""
+      if len(ipv6_or_ap_list) > 0:
+        ipv6_or_ap = ipv6_or_ap_list[0]
+        ipv6_str = " ipv6=[{}]:{}".format(ipv6_or_ap[0], ipv6_or_ap[1])
+      print ("{}:{} orport={} id={}{} # {}"
+             .format(r.address, r.dir_port, r.or_port, r.fingerprint,
+                     ipv6_str, r.nickname))
+    else:
+      print "# {} needs a DirPort".format(fingerprint)    
+  else:
+    print "# {} not found in current consensus".format(fingerprint)
diff --git a/scripts/maint/lookupFallbackDirContact.py b/scripts/maint/lookupFallbackDirContact.py
new file mode 100755
index 000000000..14c53d128
--- /dev/null
+++ b/scripts/maint/lookupFallbackDirContact.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+# Lookup fallback directory contact lines for every fingerprint passed as an
+# argument.
+#
+# Usage:
+# lookupFallbackDirContact.py fingerprint ...
+
+import sys
+
+import stem.descriptor.remote as remote
+
+if len(sys.argv) <= 1:
+  print "Usage: {} fingerprint ...".format(sys.argv[0])
+  sys.exit(-1)
+
+# we need descriptors, because the consensus does not have contact infos
+descriptor_list = remote.get_server_descriptors(fingerprints=sys.argv[1:]).run()
+
+descriptor_list_fingerprints = []
+for d in descriptor_list:
+  assert d.fingerprint in sys.argv[1:]
+  descriptor_list_fingerprints.append(d.fingerprint)
+  print "{} {}".format(d.fingerprint, d.contact)
+
+for fingerprint in sys.argv[1:]:
+  if fingerprint not in descriptor_list_fingerprints:
+    print "{} not found in current descriptors".format(fingerprint)





More information about the tor-commits mailing list