From e604cec9615a1a11611ae957c06a36c8bc1890b6 Mon Sep 17 00:00:00 2001 From: Frank Ploss Date: Mon, 28 Dec 2015 14:40:08 +0100 Subject: [PATCH] Make Reconnect function work --- extension.js | 5 ++++- tor_control_client.js | 8 ++++++-- ui/tor_button.js | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/extension.js b/extension.js index edf3de6..64af7b6 100644 --- a/extension.js +++ b/extension.js @@ -26,6 +26,9 @@ const Me = imports.misc.extensionUtils.getCurrentExtension(); const TorButton = Me.imports.ui.tor_button.TorButton; const TorControlClient = Me.imports.tor_control_client.TorControlClient; +const TOR_CONTROL_HOST = '127.0.0.1'; +const TOR_CONTROL_PORT = 9051; + let torButton = null; let torControlClient = null; @@ -35,7 +38,7 @@ function init(extensionMeta) { } function enable() { - torControlClient = new TorControlClient('127.0.0.1', 9051); + torControlClient = new TorControlClient(TOR_CONTROL_HOST, TOR_CONTROL_PORT); torButton = new TorButton(torControlClient); Main.panel.addToStatusArea(torButton.Name, torButton); torControlClient.openConnection(); diff --git a/tor_control_client.js b/tor_control_client.js index 64f03da..760a214 100644 --- a/tor_control_client.js +++ b/tor_control_client.js @@ -166,8 +166,11 @@ const TorControlClient = new Lang.Class({ do { let line = this._readLine(); - var reply = this._parseLine(line); + if (line === null) + return {replyLines: ['Lost connection to Tor server']}; + + var reply = this._parseLine(line); statusCode = reply.statusCode; replyLines.push(reply.replyLine); } while (reply.isMidReplyLine); @@ -180,7 +183,8 @@ const TorControlClient = new Lang.Class({ _readLine: function() { [line, length] = this._inputStream.read_line(null, null); - return line.toString().trim(); + + return (line !== null) ? line.toString().trim() : null; }, _parseLine: function(line) { diff --git a/ui/tor_button.js b/ui/tor_button.js index 5b6ee92..4ddca96 100644 --- a/ui/tor_button.js +++ b/ui/tor_button.js @@ -64,7 +64,7 @@ const TorButton = new Lang.Class({ this._torControlClient.connect('protocol-error', Lang.bind(this, this._onProtocolError)); }, - _onChangedConnectionState: function(source, state, message, reason) { + _onChangedConnectionState: function(source, state, reason) { switch (state) { case 'ready': this._showConnectedMenu();