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

[tor-commits] [stem/master] Reject duplicate bandwidth file entries



commit a26c7c4d871e184cc9988b7b86d41d7c15b4e3d9
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Wed Jan 23 11:40:17 2019 -0800

    Reject duplicate bandwidth file entries
    
    Teor adjusted the bandwidth file spec so it is now at the discretion of parsers
    for how we behave when bandwidth files list a relay multiple times. My other
    descriptor parsers bias toward strictness so doing so here too. Doing so will
    hopefully help uncover if we ever get sbws regressions, and we can always
    adjust this back to something looser later.
---
 stem/descriptor/bandwidth_file.py | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/stem/descriptor/bandwidth_file.py b/stem/descriptor/bandwidth_file.py
index dfe8377b..4601ad18 100644
--- a/stem/descriptor/bandwidth_file.py
+++ b/stem/descriptor/bandwidth_file.py
@@ -154,17 +154,13 @@ def _parse_body(descriptor, entries):
   for line in content.readlines():
     line = stem.util.str_tools._to_unicode(line.strip())
     attr = dict(_mappings_for('measurement', line))
+    fingerprint = attr.get('node_id', '').lstrip('$')  # bwauths prefix fingerprints with '$'
 
-    if 'node_id' not in attr:
+    if not fingerprint:
       raise ValueError("Every meaurement must include 'node_id': %s" % line)
-    elif attr['node_id'] in measurements:
-      # Relay is listed multiple times. This is a bug for the bandwidth
-      # authority that made this descriptor, but according to the spec
-      # should be ignored by parsers.
+    elif fingerprint in measurements:
+      raise ValueError('Relay %s is listed multiple times. It should only be present once.' % fingerprint)
 
-      continue
-
-    fingerprint = attr['node_id'].lstrip('$')  # bwauths prefix fingerprints with '$'
     measurements[fingerprint] = attr
 
   descriptor.measurements = measurements

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