|
|
@ -24,6 +24,9 @@ const GLib = imports.gi.GLib;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Lang = imports.lang;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
const Signals = imports.signals;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Me = imports.misc.extensionUtils.getCurrentExtension();
|
|
|
|
|
|
|
|
const Log = Me.imports.log.Log;
|
|
|
|
|
|
|
|
|
|
|
|
const TorConnectionError = new Lang.Class({
|
|
|
|
const TorConnectionError = new Lang.Class({
|
|
|
|
Name: 'TorConnectionError',
|
|
|
|
Name: 'TorConnectionError',
|
|
|
|
|
|
|
|
|
|
|
@ -58,6 +61,7 @@ const TorControlClient = new Lang.Class({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
openConnection: function() {
|
|
|
|
openConnection: function() {
|
|
|
|
|
|
|
|
Log.debug('Trying to reconnect ...');
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this._connect(this._host, this._port);
|
|
|
|
this._connect(this._host, this._port);
|
|
|
|
this._updateProtocolInfo();
|
|
|
|
this._updateProtocolInfo();
|
|
|
@ -65,10 +69,13 @@ const TorControlClient = new Lang.Class({
|
|
|
|
this._authenticate();
|
|
|
|
this._authenticate();
|
|
|
|
this.emit('changed-connection-state', 'ready');
|
|
|
|
this.emit('changed-connection-state', 'ready');
|
|
|
|
this.stopAutoRetry();
|
|
|
|
this.stopAutoRetry();
|
|
|
|
|
|
|
|
Log.debug('Connected to Tor control port');
|
|
|
|
} catch (e if e instanceof TorConnectionError) {
|
|
|
|
} catch (e if e instanceof TorConnectionError) {
|
|
|
|
|
|
|
|
Log.debug('Could not connect to Tor control port');
|
|
|
|
this.closeConnection(e.message);
|
|
|
|
this.closeConnection(e.message);
|
|
|
|
this.startAutoRetry();
|
|
|
|
this.startAutoRetry();
|
|
|
|
} catch (e if e instanceof TorProtocolError) {
|
|
|
|
} catch (e if e instanceof TorProtocolError) {
|
|
|
|
|
|
|
|
Log.debug('Tor control protocol error: ' + e.message);
|
|
|
|
this.closeConnection(e.message);
|
|
|
|
this.closeConnection(e.message);
|
|
|
|
this.startAutoRetry();
|
|
|
|
this.startAutoRetry();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -92,16 +99,19 @@ const TorControlClient = new Lang.Class({
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
this._autoRetryTimerId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, Lang.bind(this, function() {
|
|
|
|
this._autoRetryTimerId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, Lang.bind(this, function() {
|
|
|
|
//log('Retrying to open connection ...');
|
|
|
|
|
|
|
|
this.openConnection();
|
|
|
|
this.openConnection();
|
|
|
|
return this._connection === null || !this._connection.is_connected();
|
|
|
|
return this._connection === null || !this._connection.is_connected();
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.debug('Started auto retry (timer id=' + this._autoRetryTimerId + ')');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
stopAutoRetry: function() {
|
|
|
|
stopAutoRetry: function() {
|
|
|
|
if (this._autoRetryTimerId === null)
|
|
|
|
if (this._autoRetryTimerId === null)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Log.debug('Stopping auto retry (timer id=' + this._autoRetryTimerId + ')');
|
|
|
|
|
|
|
|
|
|
|
|
GLib.source_remove(this._autoRetryTimerId);
|
|
|
|
GLib.source_remove(this._autoRetryTimerId);
|
|
|
|
this._autoRetryTimerId = null;
|
|
|
|
this._autoRetryTimerId = null;
|
|
|
|
},
|
|
|
|
},
|
|
|
|