Changes between Version 1 and Version 2 of Ticket #24706, comment 5


Ignore:
Timestamp:
Dec 27, 2017, 1:45:13 AM (22 months ago)
Author:
atagar
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #24706, comment 5

    v1 v2  
    1414# generateFallbackDirLine.py fingerprint ...
    1515
    16 import sys
     16import sys 
    1717import urllib2
    1818
     
    2424  sys.exit(1)
    2525
    26 fingerprint = sys.argv[1]
     26for fingerprint in sys.argv[1:]:
     27  if not stem.util.tor_tools.is_valid_fingerprint(fingerprint):
     28    print("'%s' isn't a valid relay fingerprint" % fingerprint)
     29    sys.exit(1)
    2730
    28 if not stem.util.tor_tools.is_valid_fingerprint(fingerprint):
    29   print("'%s' isn't a valid relay fingerprint" % fingerprint)
    30   sys.exit(1)
     31  try:
     32    desc = stem.descriptor.remote.get_server_descriptors(fingerprint).run()[0]
     33  except urllib2.HTTPError as exc:
     34    if exc.code == 404:
     35      print('# %s not found in current consensus' % fingerprint)
     36      continue
     37    else:
     38      raise
    3139
    32 try:
    33   desc = stem.descriptor.remote.get_server_descriptors(fingerprint).run()[0]
    34 except urllib2.HTTPError as exc:
    35   if exc.code == 404:
    36     print('# %s not found in current consensus' % fingerprint)
    37     sys.exit(1)
     40  if not desc.dir_port:
     41    print("# %s needs a DirPort" % fingerprint)
    3842  else:
    39     raise
     43    ipv6_addresses = [(address, port) for address, port, is_ipv6 in desc.or_addresses if is_ipv6]
     44    ipv6_field = ' ipv6=[%s]:%s' % ipv6_addresses[0] if ipv6_addresses else ''
     45    print('%s:%s orport=%s id=%s%s # %s' % (desc.address, desc.dir_port, desc.or_port, fingerprint, ipv6_field, desc.nickname))
     46}}}
    4047
    41 if not desc.dir_port:
    42   print("# %s needs a DirPort" % fingerprint)
    43 else:
    44   ipv6_addresses = [(address, port) for address, port, is_ipv6 in desc.or_addresses if is_ipv6]
    45   ipv6_field = ' ipv6=[%s]:%s' % ipv6_addresses[0] if ipv6_addresses else ''
    46   print('%s:%s orport=%s id=%s%s # %s' % (desc.address, desc.dir_port, desc.or_port, fingerprint, ipv6_field, desc.nickname))
    47 }}}
     48PS. Edited since I didn't catch that you wanted to accept multiple fingerprints.