Unverified Commit 3b22e767 authored by Matthew Finkel's avatar Matthew Finkel
Browse files

Bug 40004: Cleanup unused/unneeded code

parent 580e2c01
......@@ -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);
......
......@@ -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.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment