Ticket #13666: 0001-Various-minor-fixes-for-tor-control-port.js-and-tor-.patch

File 0001-Various-minor-fixes-for-tor-control-port.js-and-tor-.patch, 4.5 KB (added by arthuredelstein, 5 years ago)
  • src/chrome/content/tor-circuit-display.js

    From f8e508c3204b14f535af37a5837e266e4a621e34 Mon Sep 17 00:00:00 2001
    From: Arthur Edelstein <arthuredelstein@gmail.com>
    Date: Tue, 4 Nov 2014 11:17:45 -0800
    Subject: [PATCH 1/2] Various minor fixes for tor-control-port.js and
     tor-circuit-display.js
    
    ---
     src/chrome/content/tor-circuit-display.js | 51 +++++++++++++++++--------------
     src/modules/tor-control-port.js           |  4 +--
     2 files changed, 30 insertions(+), 25 deletions(-)
    
    diff --git a/src/chrome/content/tor-circuit-display.js b/src/chrome/content/tor-circuit-display.js
    index 3a1fed8..c8d255e 100644
    a b let domainToNodeDataMap = {}; 
    5555
    5656// __trimQuotes(s)__.
    5757// Removes quotation marks around a quoted string.
    58 let trimQuotes = s => s.match(/^\"(.*)\"$/)[1];
     58let trimQuotes = s => s ? s.match(/^\"(.*)\"$/)[1] : undefined;
    5959
    6060// nodeDataForID(controller, id, onResult)__.
    6161// Requests the IP, country code, and name of a node with given ID.
    let nodeLines = function (nodeData) { 
    9494  for (let {ip, country} of nodeData) {
    9595    result.push(localizedCountryNameFromCode(country) + " (" + ip + ")");
    9696  }
    97   result.push("Internet");
     97  result[4] = ("Internet");
    9898  return result;
    9999};
    100100
    let nodeLines = function (nodeData) { 
    102102// Updates the Tor circuit display SVG, showing the current domain
    103103// and the relay nodes for that domain.
    104104let updateCircuitDisplay = function () {
    105   let URI = gBrowser.selectedBrowser.currentURI,
    106       domain = null,
    107       nodeData = null;
    108   // Try to get a domain for this URI. Otherwise it remains null.
    109   try {
    110     domain = URI.host;
    111   } catch (e) { }
    112   if (domain) {
    113   // Check if we have anything to show for this domain.
    114     nodeData = domainToNodeDataMap[domain];
    115     if (nodeData) {
    116       // Update the displayed domain.
    117       document.querySelector("svg#tor-circuit text#domain").innerHTML = "(" + domain + "):";
    118       // Update the displayed information for the relay nodes.
    119       let diagramNodes = document.querySelectorAll("svg#tor-circuit text.node-text"),
    120       lines = nodeLines(nodeData);
    121       for (let i = 0; i < diagramNodes.length; ++i) {
    122         diagramNodes[i].innerHTML = lines[i];
     105  let selectedBrowser = gBrowser.selectedBrowser;
     106  if (selectedBrowser) {
     107    let URI = selectedBrowser.currentURI,
     108        domain = null,
     109        nodeData = null;
     110    // Try to get a domain for this URI. Otherwise it remains null.
     111    try {
     112      domain = URI.host;
     113    } catch (e) { }
     114    if (domain) {
     115    // Check if we have anything to show for this domain.
     116      nodeData = domainToNodeDataMap[domain];
     117      if (nodeData) {
     118        // Update the displayed domain.
     119        document.querySelector("svg#tor-circuit text#domain").innerHTML = "(" + domain + "):";
     120        // Update the displayed information for the relay nodes.
     121        let diagramNodes = document.querySelectorAll("svg#tor-circuit text.node-text"),
     122            //diagramCircles = document.querySelectorAll("svg#tor-circuit .node-circule"),
     123            lines = nodeLines(nodeData);
     124        for (let i = 0; i < diagramNodes.length; ++i) {
     125          let line = lines[i];
     126          diagramNodes[i].innerHTML = line ? line : "";
     127        }
    123128      }
    124129    }
     130    // Only show the Tor circuit if we have a domain and node data.
     131    document.querySelector("svg#tor-circuit").style.display = (domain && nodeData) ?
     132                                                              'block' : 'none';
    125133  }
    126   // Only show the Tor circuit if we have a domain and node data.
    127   document.querySelector("svg#tor-circuit").style.display = (domain && nodeData) ?
    128                                                             'block' : 'none';
    129134};
    130135
    131136// __collectBuiltCircuitData(aController)__.
  • src/modules/tor-control-port.js

    diff --git a/src/modules/tor-control-port.js b/src/modules/tor-control-port.js
    index 855b34b..c461aa6 100644
    a b io.asyncSocket = function (host, port, onInputData, onError) { 
    107107                 let totalString = pendingWrites.join("");
    108108                   try {
    109109                     outputStream.write(totalString, totalString.length);
    110                      log("wrote: " + aString + "\n");
     110                     log("controlPort << " + aString + "\n");
    111111                   } catch (err) {
    112112                     onError(err);
    113113                   }
    io.onLineFromOnMessage = function (onMessage) { 
    164164      pendingLines = [];
    165165      // Pass multiline message to onMessage.
    166166      onMessage(message);
    167       //log(message);
     167      log("controlPort >> " + message);
    168168    }
    169169  };
    170170};