[tor-commits] [arm/master] Don't try to parse our own descriptors

atagar at torproject.org atagar at torproject.org
Sat Jun 1 01:06:18 UTC 2013


commit bc7d95d1e35e331df61349e2210bbd3b853df81a
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri May 31 09:00:03 2013 -0700

    Don't try to parse our own descriptors
    
    Now that we're using stem there's little reason to manually parse our own
    descriptor data.
---
 src/util/torTools.py |   42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/util/torTools.py b/src/util/torTools.py
index 353ad25..b2f09e4 100644
--- a/src/util/torTools.py
+++ b/src/util/torTools.py
@@ -1189,9 +1189,10 @@ class Controller:
         myFingerprint = self.getInfo("fingerprint", None)
         
         if myFingerprint:
-          queryType = "ns" if key == "nsEntry" else "desc"
-          queryResult = self.getInfo("%s/id/%s" % (queryType, myFingerprint), None)
-          if queryResult: result = queryResult.split("\n")
+          if key == "nsEntry":
+            result = self.controller.get_network_status(myFingerprint)
+          else:
+            result = self.controller.get_server_descriptor(myFingerprint)
       elif key == "bwRate":
         # effective relayed bandwidth is the minimum of BandwidthRate,
         # MaxAdvertisedBandwidth, and RelayBandwidthRate (if set)
@@ -1215,29 +1216,28 @@ class Controller:
         
         result = effectiveBurst
       elif key == "bwObserved":
-        for line in self.getMyDescriptor([]):
-          if line.startswith("bandwidth"):
-            # line should look something like:
-            # bandwidth 40960 102400 47284
-            comp = line.split()
-            
-            if len(comp) == 4 and comp[-1].isdigit():
-              result = int(comp[-1])
-              break
+        myDescriptor = self.getMyDescriptor()
+
+        if myDescriptor:
+          result = myDescriptor.observed_bandwidth
       elif key == "bwMeasured":
         # TODO: Currently there's no client side indication of what type of
         # measurement was used. Include this in results if it's ever available.
         
-        for line in self.getMyNetworkStatus([]):
-          if line.startswith("w Bandwidth="):
-            bwValue = line[12:]
-            if bwValue.isdigit(): result = int(bwValue)
-            break
+        # TODO: I don't believe the following ever worked. The
+        # getMyNetworkStatus() method provides a v2 router status entry but 'w'
+        # lines are part of v3 responses. Oh well, double check this while
+        # rewriting this module.
+
+        myStatusEntry = self.getMyNetworkStatus()
+
+        if myStatusEntry and hasattr(myStatusEntry, 'bandwidth'):
+          result = myStatusEntry.bandwidth
       elif key == "flags":
-        for line in self.getMyNetworkStatus([]):
-          if line.startswith("s "):
-            result = line[2:].split()
-            break
+        myStatusEntry = self.getMyNetworkStatus()
+
+        if myStatusEntry:
+          result = myStatusEntry.flags
       elif key == "user":
         result = self.controller.get_user(None)
       elif key == "fdLimit":





More information about the tor-commits mailing list