[tbb-commits] [torbutton/master] get node data when a circuit's first stream is built

mikeperry at torproject.org mikeperry at torproject.org
Wed Nov 5 02:37:40 UTC 2014


commit 60fde4eaa8c097f68143356736d08bc1c82cc4f4
Author: Arthur Edelstein <arthuredelstein at gmail.com>
Date:   Tue Nov 4 15:07:18 2014 -0800

    get node data when a circuit's first stream is built
---
 src/chrome/content/tor-circuit-display.js |   53 +++++++++++++++++++++--------
 src/modules/tor-control-port.js           |    2 +-
 2 files changed, 39 insertions(+), 16 deletions(-)

diff --git a/src/chrome/content/tor-circuit-display.js b/src/chrome/content/tor-circuit-display.js
index c8d255e..49cd832 100644
--- a/src/chrome/content/tor-circuit-display.js
+++ b/src/chrome/content/tor-circuit-display.js
@@ -53,6 +53,8 @@ let localizedCountryNameFromCode = function (countryCode) {
 // A mutable map that stores the current nodes for each domain.
 let domainToNodeDataMap = {};
 
+let knownCircuitIDs = {};
+
 // __trimQuotes(s)__.
 // Removes quotation marks around a quoted string.
 let trimQuotes = s => s ? s.match(/^\"(.*)\"$/)[1] : undefined;
@@ -133,22 +135,43 @@ let updateCircuitDisplay = function () {
   }
 };
 
-// __collectBuiltCircuitData(aController)__.
-// Watches for CIRC BUILT events and records their data in the domainToNodeDataMap.
-let collectBuiltCircuitData = function (aController) {
+// __getCircuitStatusByID(aController, circuitID, onCircuitStatus)__
+// Returns the circuit status for the circuit with the given ID
+// via onCircuitStatus(status).
+let getCircuitStatusByID = function(aController, circuitID, onCircuitStatus) {
+  aController.getInfo("circuit-status", function (circuitStatuses) {
+    for (let circuitStatus of circuitStatuses) {
+      if (circuitStatus.id === circuitID) {
+        onCircuitStatus(circuitStatus);
+      }
+    }
+  });
+};
+
+// __collectIsolationData(aController)__.
+// Watches for STREAM SENTCONNECT events. When a SENTCONNECT event occurs, then
+// the isolation settings (SOCKS username+password) become fixed for the
+// corresponding circuit. Whenever the first stream on a new circuit is seen,
+// looks up u+p and records the node data in the domainToNodeDataMap.
+let collectIsolationData = function (aController) {
   aController.watchEvent(
-    "CIRC",
-    circuitEvent => circuitEvent.status === "EXTENDED" ||
-                    circuitEvent.status === "BUILT",
-    function (circuitEvent) {
-      let domain = trimQuotes(circuitEvent.SOCKS_USERNAME);
-      if (domain) {
-        nodeDataForCircuit(aController, circuitEvent, function (nodeData) {
-          domainToNodeDataMap[domain] = nodeData;
-          updateCircuitDisplay();
+    "STREAM",
+    streamEvent => streamEvent.StreamStatus === "SENTCONNECT",
+    function (streamEvent) {
+      if (!knownCircuitIDs[streamEvent.CircuitID]) {
+        logger.eclog(4, "streamEvent.CircuitID: " + streamEvent.CircuitID);
+        knownCircuitIDs[streamEvent.CircuitID] = true;
+        getCircuitStatusByID(aController, streamEvent.CircuitID, function (circuitStatus) {
+          let domain = trimQuotes(circuitStatus.SOCKS_USERNAME);
+          if (domain) {
+            nodeDataForCircuit(aController, circuitStatus, function (nodeData) {
+              domainToNodeDataMap[domain] = nodeData;
+              updateCircuitDisplay();
+            });
+          } else {
+            updateCircuitDisplay();
+          }
         });
-      } else {
-        updateCircuitDisplay();
       }
     });
 };
@@ -181,7 +204,7 @@ let syncDisplayWithSelectedTab = function () {
 let display = function (host, port, password) {
   let myController = controller(host, port || 9151, password, function (x) { logger.eclog(5, x); });
   syncDisplayWithSelectedTab();
-  collectBuiltCircuitData(myController);
+  collectIsolationData(myController);
 };
 
 return display;
diff --git a/src/modules/tor-control-port.js b/src/modules/tor-control-port.js
index c461aa6..ada80b5 100644
--- a/src/modules/tor-control-port.js
+++ b/src/modules/tor-control-port.js
@@ -259,7 +259,7 @@ io.controlSocket = function (host, port, password, onError) {
   // Log in to control port.
   sendCommand("authenticate " + (password || ""));
   // Activate needed events.
-  sendCommand("setevents circ");
+  sendCommand("setevents stream");
   return { close : socket.close, sendCommand : sendCommand,
            addNotificationCallback : notificationDispatcher.addCallback,
            removeNotificationCallback : notificationDispatcher.removeCallback };





More information about the tbb-commits mailing list