Ticket #13666: 0002-get-node-data-when-a-circuit-s-first-stream-is-built.patch

File 0002-get-node-data-when-a-circuit-s-first-stream-is-built.patch, 4.3 KB (added by arthuredelstein, 5 years ago)
  • src/chrome/content/tor-circuit-display.js

    From 94f9248c2ae83188edeb68132fca4c4a6f5b8239 Mon Sep 17 00:00:00 2001
    From: Arthur Edelstein <arthuredelstein@gmail.com>
    Date: Tue, 4 Nov 2014 15:07:18 -0800
    Subject: [PATCH 2/2] 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 b let localizedCountryNameFromCode = function (countryCode) { 
    5353// A mutable map that stores the current nodes for each domain.
    5454let domainToNodeDataMap = {};
    5555
     56let knownCircuitIDs = {};
     57
    5658// __trimQuotes(s)__.
    5759// Removes quotation marks around a quoted string.
    5860let trimQuotes = s => s ? s.match(/^\"(.*)\"$/)[1] : undefined;
    let updateCircuitDisplay = function () { 
    133135  }
    134136};
    135137
    136 // __collectBuiltCircuitData(aController)__.
    137 // Watches for CIRC BUILT events and records their data in the domainToNodeDataMap.
    138 let collectBuiltCircuitData = function (aController) {
     138// __getCircuitStatusByID(aController, circuitID, onCircuitStatus)__
     139// Returns the circuit status for the circuit with the given ID
     140// via onCircuitStatus(status).
     141let getCircuitStatusByID = function(aController, circuitID, onCircuitStatus) {
     142  aController.getInfo("circuit-status", function (circuitStatuses) {
     143    for (let circuitStatus of circuitStatuses) {
     144      if (circuitStatus.id === circuitID) {
     145        onCircuitStatus(circuitStatus);
     146      }
     147    }
     148  });
     149};
     150
     151// __collectIsolationData(aController)__.
     152// Watches for STREAM SENTCONNECT events. When a SENTCONNECT event occurs, then
     153// the isolation settings (SOCKS username+password) become fixed for the
     154// corresponding circuit. Whenever the first stream on a new circuit is seen,
     155// looks up u+p and records the node data in the domainToNodeDataMap.
     156let collectIsolationData = function (aController) {
    139157  aController.watchEvent(
    140     "CIRC",
    141     circuitEvent => circuitEvent.status === "EXTENDED" ||
    142                     circuitEvent.status === "BUILT",
    143     function (circuitEvent) {
    144       let domain = trimQuotes(circuitEvent.SOCKS_USERNAME);
    145       if (domain) {
    146         nodeDataForCircuit(aController, circuitEvent, function (nodeData) {
    147           domainToNodeDataMap[domain] = nodeData;
    148           updateCircuitDisplay();
     158    "STREAM",
     159    streamEvent => streamEvent.StreamStatus === "SENTCONNECT",
     160    function (streamEvent) {
     161      if (!knownCircuitIDs[streamEvent.CircuitID]) {
     162        logger.eclog(4, "streamEvent.CircuitID: " + streamEvent.CircuitID);
     163        knownCircuitIDs[streamEvent.CircuitID] = true;
     164        getCircuitStatusByID(aController, streamEvent.CircuitID, function (circuitStatus) {
     165          let domain = trimQuotes(circuitStatus.SOCKS_USERNAME);
     166          if (domain) {
     167            nodeDataForCircuit(aController, circuitStatus, function (nodeData) {
     168              domainToNodeDataMap[domain] = nodeData;
     169              updateCircuitDisplay();
     170            });
     171          } else {
     172            updateCircuitDisplay();
     173          }
    149174        });
    150       } else {
    151         updateCircuitDisplay();
    152175      }
    153176    });
    154177};
    let syncDisplayWithSelectedTab = function () { 
    181204let display = function (host, port, password) {
    182205  let myController = controller(host, port || 9151, password, function (x) { logger.eclog(5, x); });
    183206  syncDisplayWithSelectedTab();
    184   collectBuiltCircuitData(myController);
     207  collectIsolationData(myController);
    185208};
    186209
    187210return display;
  • src/modules/tor-control-port.js

    diff --git a/src/modules/tor-control-port.js b/src/modules/tor-control-port.js
    index c461aa6..ada80b5 100644
    a b io.controlSocket = function (host, port, password, onError) { 
    259259  // Log in to control port.
    260260  sendCommand("authenticate " + (password || ""));
    261261  // Activate needed events.
    262   sendCommand("setevents circ");
     262  sendCommand("setevents stream");
    263263  return { close : socket.close, sendCommand : sendCommand,
    264264           addNotificationCallback : notificationDispatcher.addCallback,
    265265           removeNotificationCallback : notificationDispatcher.removeCallback };