Browse Source

Add a delimiter to the end of each fallback entry

This helps external parsers.

Also, add comments indicating where to add new fields in the fallback
format.

Part of 24725.
teor 6 years ago
parent
commit
b6033f5734
2 changed files with 23 additions and 0 deletions
  1. 1 0
      changes/ticket24725
  2. 22 0
      scripts/maint/updateFallbackDirs.py

+ 1 - 0
changes/ticket24725

@@ -1,4 +1,5 @@
   o Minor features (fallback directory mirrors):
   o Minor features (fallback directory mirrors):
     - Add a type and version header to the fallback directory mirror file.
     - Add a type and version header to the fallback directory mirror file.
+      Also add a delimiter to the end of each fallback entry.
       This helps external parsers like stem and Relay Search.
       This helps external parsers like stem and Relay Search.
       Implements ticket 24725.
       Implements ticket 24725.

+ 22 - 0
scripts/maint/updateFallbackDirs.py

@@ -76,6 +76,8 @@ except ImportError:
 # * patch changes include changing header comments or other unstructured
 # * patch changes include changing header comments or other unstructured
 #   content
 #   content
 FALLBACK_FORMAT_VERSION = '2.0.0'
 FALLBACK_FORMAT_VERSION = '2.0.0'
+SECTION_SEPARATOR_BASE = '====='
+SECTION_SEPARATOR_COMMENT = '/* ' + SECTION_SEPARATOR_BASE + ' */'
 
 
 # Output all candidate fallbacks, or only output selected fallbacks?
 # Output all candidate fallbacks, or only output selected fallbacks?
 OUTPUT_CANDIDATES = False
 OUTPUT_CANDIDATES = False
@@ -1339,9 +1341,13 @@ class Candidate(object):
   # comment-out the returned string
   # comment-out the returned string
   def fallbackdir_info(self, dl_speed_ok):
   def fallbackdir_info(self, dl_speed_ok):
     # "address:dirport orport=port id=fingerprint"
     # "address:dirport orport=port id=fingerprint"
+    # (insert additional madatory fields here)
     # "[ipv6=addr:orport]"
     # "[ipv6=addr:orport]"
+    # (insert additional optional fields here)
     # /* nickname=name */
     # /* nickname=name */
     # /* extrainfo={0,1} */
     # /* extrainfo={0,1} */
+    # (insert additional comment fields here)
+    # /* ===== */
     # ,
     # ,
     #
     #
     # Do we want a C string, or a commented-out string?
     # Do we want a C string, or a commented-out string?
@@ -1363,9 +1369,11 @@ class Candidate(object):
             self.orport,
             self.orport,
             cleanse_c_string(self._fpr))
             cleanse_c_string(self._fpr))
     s += '\n'
     s += '\n'
+    # (insert additional madatory fields here)
     if self.has_ipv6():
     if self.has_ipv6():
       s += '" ipv6=%s:%d"'%(cleanse_c_string(self.ipv6addr), self.ipv6orport)
       s += '" ipv6=%s:%d"'%(cleanse_c_string(self.ipv6addr), self.ipv6orport)
       s += '\n'
       s += '\n'
+    # (insert additional optional fields here)
     if not comment_string:
     if not comment_string:
       s += '/* '
       s += '/* '
     s += 'nickname=%s'%(cleanse_c_string(self._data['nickname']))
     s += 'nickname=%s'%(cleanse_c_string(self._data['nickname']))
@@ -1380,6 +1388,14 @@ class Candidate(object):
     if not comment_string:
     if not comment_string:
       s += ' */'
       s += ' */'
     s += '\n'
     s += '\n'
+    # (insert additional comment fields here)
+    # The terminator and comma must be the last line in each fallback entry
+    if not comment_string:
+      s += '/* '
+    s += SECTION_SEPARATOR_BASE
+    if not comment_string:
+      s += ' */'
+    s += '\n'
     s += ','
     s += ','
     if comment_string:
     if comment_string:
       s += '\n'
       s += '\n'
@@ -2205,6 +2221,9 @@ def list_fallbacks(whitelist, blacklist):
   print "/* type=fallback */"
   print "/* type=fallback */"
   print ("/* version={} */"
   print ("/* version={} */"
          .format(cleanse_c_multiline_comment(FALLBACK_FORMAT_VERSION)))
          .format(cleanse_c_multiline_comment(FALLBACK_FORMAT_VERSION)))
+  # end the header with a separator, to make it easier for parsers
+  print SECTION_SEPARATOR_COMMENT
+
   logging.warning('Downloading and parsing Onionoo data. ' +
   logging.warning('Downloading and parsing Onionoo data. ' +
                   'This may take some time.')
                   'This may take some time.')
   # find relays that could be fallbacks
   # find relays that could be fallbacks
@@ -2296,6 +2315,9 @@ def list_fallbacks(whitelist, blacklist):
   for s in fetch_source_list():
   for s in fetch_source_list():
     print describe_fetch_source(s)
     print describe_fetch_source(s)
 
 
+  # start the list with a separator, to make it easy for parsers
+  print SECTION_SEPARATOR_COMMENT
+
   # sort the list differently depending on why we've created it:
   # sort the list differently depending on why we've created it:
   # if we're outputting the final fallback list, sort by fingerprint
   # if we're outputting the final fallback list, sort by fingerprint
   # this makes diffs much more stable
   # this makes diffs much more stable