[tor-commits] [stem/master] Rejecting all footer fields in outdated consensus-method

atagar at torproject.org atagar at torproject.org
Sat Oct 13 18:35:45 UTC 2012


commit b3444ace427dca9a66a1afed1d24a09971612810
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Sep 16 17:43:46 2012 -0700

    Rejecting all footer fields in outdated consensus-method
    
    We were only checking that we lacked the mandatory footer fields when our
    consensus-method indicated that we shouldn't have a footer. Instead checking
    that we have no footer at all. This also makes the code a little nicer...
---
 stem/descriptor/networkstatus.py |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index e262264..0a4aaeb 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -521,14 +521,18 @@ class NetworkStatusDocument(stem.descriptor.Descriptor):
     
     missing_fields, disallowed_fields = [], []
     
+    if not self.meets_consensus_method(9):
+      # footers only appear in consensus-method 9 or later
+      if footer_entries:
+        raise ValueError("Network status document's footer should only apepar in consensus-method 9 or later")
+      else:
+        # pretend to have mandatory fields to prevent validation from whining
+        footer_entries = {"directory-footer": "", "directory-signature": ""}
+    
     for entries, fields in ((header_entries, HEADER_STATUS_DOCUMENT_FIELDS),\
                             (footer_entries, FOOTER_STATUS_DOCUMENT_FIELDS)):
       for field, in_votes, in_consensus, mandatory in fields:
-        if field in ('directory-footer', 'directory-signature') and not self.meets_consensus_method(9):
-          # footers only appear in consensus-method 9 or later
-          if field in entries.keys():
-            disallowed_fields.append(field)
-        elif mandatory and ((self.is_consensus and in_consensus) or (self.is_vote and in_votes)):
+        if mandatory and ((self.is_consensus and in_consensus) or (self.is_vote and in_votes)):
           # mandatory field, check that we have it
           if not field in entries.keys():
             missing_fields.append(field)





More information about the tor-commits mailing list