[tor-commits] [tor-launcher/master] Bug 40004: Cleanup unused/unneeded code

sysrqb at torproject.org sysrqb at torproject.org
Fri Aug 27 20:40:09 UTC 2021


commit 3b22e7671322c6f1d200c8b5f08ac3965f57bd1e
Author: Matthew Finkel <sysrqb at torproject.org>
Date:   Wed Aug 25 15:05:10 2021 +0000

    Bug 40004: Cleanup unused/unneeded code
---
 src/components/tl-process.js  | 16 ---------
 src/components/tl-protocol.js | 79 -------------------------------------------
 2 files changed, 95 deletions(-)

diff --git a/src/components/tl-process.js b/src/components/tl-process.js
index bafc295..f45c17c 100644
--- a/src/components/tl-process.js
+++ b/src/components/tl-process.js
@@ -100,22 +100,6 @@ TorProcessService.prototype =
 
     if ("profile-after-change" == aTopic)
     {
-      // Initialize the DNS service here (as early as possible). This
-      // avoids a deadlock that can occur inside TorProtocolService's
-      // _openAuthenticatedConnection() function. What happens in the
-      // deadlock case is that a Necko socket thread tries to dispatch
-      // initialization of the DNS service to the main thread while the
-      // main thread is blocked in a writeBytes() call inside the
-      // _sendCommand() function. The ultimate solution is to change
-      // our control port socket to use asynchronous I/O.
-      // References:
-      //   netwerk/dns/nsDNSService2.cpp nsDNSService::GetSingleton()
-      //   https://bugzilla.mozilla.org/show_bug.cgi?id=1625151 (the
-      //     fix for this bug introduced the deadlock because it changed
-      //     DNS service initialization to occur on the main thread).
-      const dns = Cc["@mozilla.org/network/dns-service;1"]
-                    .getService(Ci.nsIDNSService);
-
       this.mObsSvc.addObserver(this, "quit-application-granted", false);
       this.mObsSvc.addObserver(this, kOpenNetworkSettingsTopic, false);
       this.mObsSvc.addObserver(this, kUserQuitTopic, false);
diff --git a/src/components/tl-protocol.js b/src/components/tl-protocol.js
index 93b22bb..ceb5a0c 100644
--- a/src/components/tl-protocol.js
+++ b/src/components/tl-protocol.js
@@ -827,85 +827,6 @@ TorProtocolService.prototype =
       this.mControlConnection = null;
   },
 
-  _setSocketTimeout: function(aConn)
-  {
-    if (aConn && aConn.socket)
-      aConn.socket.setTimeout(Ci.nsISocketTransport.TIMEOUT_READ_WRITE, 15);
-  },
-
-  _clearSocketTimeout: function(aConn)
-  {
-    if (aConn && aConn.socket)
-    {
-      var secs = Math.pow(2,32) - 1; // UINT32_MAX
-      aConn.socket.setTimeout(Ci.nsISocketTransport.TIMEOUT_READ_WRITE, secs);
-    }
-  },
-
-  _sendCommand: function(aConn, aCmd, aArgs)
-  {
-    var reply;
-    if (aConn)
-    {
-      var cmd = aCmd;
-      if (aArgs)
-        cmd += ' ' + aArgs;
-      TorLauncherLogger.safelog(2, "Sending Tor command: ", cmd);
-      cmd += "\r\n";
-
-      ++aConn.useCount;
-      this._setSocketTimeout(aConn);
-      // TODO: should handle NS_BASE_STREAM_WOULD_BLOCK here.
-      aConn.binOutStream.writeBytes(cmd, cmd.length);
-      reply = this._torReadReply(aConn.binInStream);
-      this._clearSocketTimeout(aConn);
-    }
-
-    return reply;
-  },
-
-  // Returns a reply object.  Blocks until entire reply has been received.
-  _torReadReply: function(aInput)
-  {
-    var replyObj = {};
-    do
-    {
-      var line = this._torReadLine(aInput);
-      TorLauncherLogger.safelog(2, "Command response: ", line);
-    } while (!this._parseOneReplyLine(line, replyObj));
-
-    return (replyObj._parseError) ? null : replyObj;
-  },
-
-  // Returns a string.  Blocks until a line has been received.
-  _torReadLine: function(aInput)
-  {
-    var str = "";
-    while(true)
-    {
-      try
-      {
-// TODO: readBytes() will sometimes hang if the control connection is opened
-// immediately after tor opens its listener socket.  Why?
-        let bytes = aInput.readBytes(1);
-        if ('\n' == bytes)
-          break;
-
-        str += bytes;
-      }
-      catch (e)
-      {
-        if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK)
-          throw e;
-      }
-    }
-
-    var len = str.length;
-    if ((len > 0) && ('\r' == str.substr(len - 1)))
-      str = str.substr(0, len - 1);
-    return str;
-  },
-
   // Returns false if more lines are needed.  The first time, callers
   // should pass an empty aReplyObj.
   // Parsing errors are indicated by aReplyObj._parseError = true.



More information about the tor-commits mailing list