Make Reconnect function work

master
Frank Ploss 9 years ago
parent 751e413cf7
commit e604cec961

@ -26,6 +26,9 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
const TorButton = Me.imports.ui.tor_button.TorButton; const TorButton = Me.imports.ui.tor_button.TorButton;
const TorControlClient = Me.imports.tor_control_client.TorControlClient; 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 torButton = null;
let torControlClient = null; let torControlClient = null;
@ -35,7 +38,7 @@ function init(extensionMeta) {
} }
function enable() { function enable() {
torControlClient = new TorControlClient('127.0.0.1', 9051); torControlClient = new TorControlClient(TOR_CONTROL_HOST, TOR_CONTROL_PORT);
torButton = new TorButton(torControlClient); torButton = new TorButton(torControlClient);
Main.panel.addToStatusArea(torButton.Name, torButton); Main.panel.addToStatusArea(torButton.Name, torButton);
torControlClient.openConnection(); torControlClient.openConnection();

@ -166,8 +166,11 @@ const TorControlClient = new Lang.Class({
do { do {
let line = this._readLine(); 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; statusCode = reply.statusCode;
replyLines.push(reply.replyLine); replyLines.push(reply.replyLine);
} while (reply.isMidReplyLine); } while (reply.isMidReplyLine);
@ -180,7 +183,8 @@ const TorControlClient = new Lang.Class({
_readLine: function() { _readLine: function() {
[line, length] = this._inputStream.read_line(null, null); [line, length] = this._inputStream.read_line(null, null);
return line.toString().trim();
return (line !== null) ? line.toString().trim() : null;
}, },
_parseLine: function(line) { _parseLine: function(line) {

@ -64,7 +64,7 @@ const TorButton = new Lang.Class({
this._torControlClient.connect('protocol-error', Lang.bind(this, this._onProtocolError)); this._torControlClient.connect('protocol-error', Lang.bind(this, this._onProtocolError));
}, },
_onChangedConnectionState: function(source, state, message, reason) { _onChangedConnectionState: function(source, state, reason) {
switch (state) { switch (state) {
case 'ready': case 'ready':
this._showConnectedMenu(); this._showConnectedMenu();

Loading…
Cancel
Save