[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Add DescriptorWarning for matching timestamps for the same bridge.



commit dcca03203be4e14233c7734c1d63fe35ea86fbbe
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Fri Dec 5 09:40:26 2014 +0000

    Add DescriptorWarning for matching timestamps for the same bridge.
---
 lib/bridgedb/parse/descriptors.py |   51 ++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 32 deletions(-)

diff --git a/lib/bridgedb/parse/descriptors.py b/lib/bridgedb/parse/descriptors.py
index 6eac164..66a34b9 100644
--- a/lib/bridgedb/parse/descriptors.py
+++ b/lib/bridgedb/parse/descriptors.py
@@ -17,6 +17,7 @@ import logging
 import os
 import shutil
 
+from stem import ProtocolError
 from stem.descriptor import extrainfo_descriptor
 from stem.descriptor import server_descriptor
 from stem.descriptor import parse_file
@@ -26,6 +27,10 @@ from stem.descriptor.router_status_entry import RouterStatusEntryV3
 from bridgedb import safelog
 
 
+class DescriptorWarning(Warning):
+    """Raised when we parse a very odd descriptor."""
+
+
 def _copyUnparseableDescriptorFile(filename):
     """Save a copy of the bad descriptor file for later debugging.
 
@@ -181,9 +186,10 @@ def deduplicate(descriptors):
             # ``platform`` line in its server-descriptor and tell whoever
             # wrote that code that they're probably (D)DOSing the Tor network.
             else:
-                logging.warn(("Duplicate descriptor with identical timestamp "
-                              "(%s) for router with fingerprint '%s'!")
-                             % (descriptor.published, fingerprint))
+                raise DescriptorWarning(
+                    ("Duplicate descriptor with identical timestamp (%s) for "
+                     "router with fingerprint '%s'!")
+                    % (descriptor.published, fingerprint))
 
         # Hoorah! No duplicates! (yet...)
         else:
@@ -238,38 +244,19 @@ def parseBridgeExtraInfoFiles(*filenames, **kwargs):
         validate = False
 
     for filename in filenames:
-        document = None
-        documentWasUnparseable = False
-
-        logging.info("Parsing %s descriptors with Stem: %s"
+        logging.info("Parsing %s descriptors in %s..."
                      % (descriptorType, filename))
-        try:
-            document = parse_file(filename, descriptorType, validate=validate)
-        except ValueError as error:
-            documentWasUnparseable = True
-
-        if documentWasUnparseable:
-            logging.warn(("Stem ran into an exception while parsing extrainfo "
-                          "file '%s'!") % filename)
-            logging.debug("Error while parsing extrainfo file:\n%s"
-                          % str(error))
-
-        if documentWasUnparseable and (validate is True):
-            logging.info(("Retrying parsing of extrainfo file '%s' with "
-                          "validation disabled...") % filename)
-            try:
-                document = parse_file(filename, descriptorType, validate=False)
-            except ValueError as another:
-                logging.critical(("We were still unable to parse extrainfo "
-                                  "file on the second attempt! Bailing!"))
-            else:
-                documentWasUnparseable = False
 
-        if documentWasUnparseable:
-            _copyUnparseableDescriptorFile(filename)
+        document = parse_file(filename, descriptorType, validate=validate)
 
-        if document:
-            descriptors.extend([router for router in document])
+        try:
+            for router in document:
+                descriptors.append(router)
+        except (ValueError, ProtocolError) as error:
+            logging.error(
+                ("Stem exception while parsing extrainfo descriptor from "
+                 "file '%s':\n%s") % (filename, str(error)))
+            _copyUnparseableDescriptorFile(filename)
 
     routers = deduplicate(descriptors)
     return routers



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits