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

[tor-commits] [stem/master] Supporting 'Unmeasured' in router status entries



commit a124b62f26c8ae1cee01f780a0383389275ee873
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Mar 16 10:12:57 2013 -0700

    Supporting 'Unmeasured' in router status entries
    
    Spec commit c3860e3 added a new 'Unmeasured' key/value entry to the 'w' lines
    of v3 router status entries.
---
 stem/descriptor/router_status_entry.py      |   18 +++++++++++++++---
 test/unit/descriptor/router_status_entry.py |   18 +++++++++++++-----
 2 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 68c1b38..69b8fa2 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -307,6 +307,8 @@ class RouterStatusEntryV3(RouterStatusEntry):
 
   :var int bandwidth: bandwidth claimed by the relay (in kb/s)
   :var int measured: bandwidth measured to be available by the relay
+  :var bool is_unmeasured: bandwidth measurement isn't based on three or more
+    measurements
   :var list unrecognized_bandwidth_entries: **\*** bandwidth weighting
     information that isn't yet recognized
 
@@ -326,6 +328,7 @@ class RouterStatusEntryV3(RouterStatusEntry):
 
     self.bandwidth = None
     self.measured = None
+    self.is_unmeasured = False
     self.unrecognized_bandwidth_entries = []
 
     self.exit_policy = None
@@ -394,6 +397,8 @@ class RouterStatusEntryMicroV3(RouterStatusEntry):
 
   :var int bandwidth: bandwidth claimed by the relay (in kb/s)
   :var int measured: bandwidth measured to be available by the relay
+  :var bool is_unmeasured: bandwidth measurement isn't based on three or more
+    measurements
   :var list unrecognized_bandwidth_entries: **\*** bandwidth weighting
     information that isn't yet recognized
 
@@ -404,8 +409,10 @@ class RouterStatusEntryMicroV3(RouterStatusEntry):
   """
 
   def __init__(self, content, validate = True, document = None):
-    self.version_line = None
-    self.version = None
+    self.bandwidth = None
+    self.measured = None
+    self.is_unmeasured = False
+    self.unrecognized_bandwidth_entries = []
 
     self.digest = None
 
@@ -581,7 +588,7 @@ def _parse_v_line(desc, value, validate):
 
 
 def _parse_w_line(desc, value, validate):
-  # "w" "Bandwidth=" INT ["Measured=" INT]
+  # "w" "Bandwidth=" INT ["Measured=" INT] ["Unmeasured=1"]
   # example: w Bandwidth=7980
 
   w_comp = value.split(" ")
@@ -619,6 +626,11 @@ def _parse_w_line(desc, value, validate):
         raise ValueError("%s 'Measured=' entry needs to have a numeric value: w %s" % (desc._name(), value))
 
       desc.measured = int(w_value)
+    elif w_key == "Unmeasured":
+      if validate and w_value != "1":
+        raise ValueError("%s 'Unmeasured=' should only have the value of '1': w %s" % (desc._name(), value))
+
+      desc.is_unmeasured = True
     else:
       desc.unrecognized_bandwidth_entries.append(w_entry)
 
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index 23baaeb..b61f5e8 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -81,6 +81,7 @@ class TestRouterStatusEntry(unittest.TestCase):
     self.assertEqual(None, entry.version)
     self.assertEqual(None, entry.bandwidth)
     self.assertEqual(None, entry.measured)
+    self.assertEqual(False, entry.is_unmeasured)
     self.assertEqual([], entry.unrecognized_bandwidth_entries)
     self.assertEqual(None, entry.exit_policy)
     self.assertEqual([], entry.microdescriptor_hashes)
@@ -403,17 +404,19 @@ class TestRouterStatusEntry(unittest.TestCase):
     """
 
     test_values = {
-      "Bandwidth=0": (0, None, []),
-      "Bandwidth=63138": (63138, None, []),
-      "Bandwidth=11111 Measured=482": (11111, 482, []),
-      "Bandwidth=11111 Measured=482 Blarg!": (11111, 482, ["Blarg!"]),
+      "Bandwidth=0": (0, None, False, []),
+      "Bandwidth=63138": (63138, None, False, []),
+      "Bandwidth=11111 Measured=482": (11111, 482, False, []),
+      "Bandwidth=11111 Measured=482 Blarg!": (11111, 482, False, ["Blarg!"]),
+      "Bandwidth=11111 Measured=482 Unmeasured=1 Blarg!": (11111, 482, True, ["Blarg!"]),
     }
 
     for w_line, expected in test_values.items():
       entry = get_router_status_entry_v3({'w': w_line})
       self.assertEquals(expected[0], entry.bandwidth)
       self.assertEquals(expected[1], entry.measured)
-      self.assertEquals(expected[2], entry.unrecognized_bandwidth_entries)
+      self.assertEquals(expected[2], entry.is_unmeasured)
+      self.assertEquals(expected[3], entry.unrecognized_bandwidth_entries)
 
     # tries some invalid inputs
     test_values = (
@@ -427,6 +430,11 @@ class TestRouterStatusEntry(unittest.TestCase):
       "Bandwidth=10 Measured",
       "Bandwidth=10 Measured=",
       "Bandwidth=10 Measured=-50",
+      "Bandwidth=10 Measured=482 Unmeasured",
+      "Bandwidth=10 Measured=482 Unmeasured=",
+      "Bandwidth=10 Measured=482 Unmeasured=0",
+      "Bandwidth=10 Measured=482 Unmeasured=842",
+      "Bandwidth=10 Measured=482 Unmeasured=-5",
     )
 
     for w_line in test_values:



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