diff --git a/extension.js b/extension.js index 73bd2fa..819458e 100644 --- a/extension.js +++ b/extension.js @@ -23,6 +23,7 @@ const Gtk = imports.gi.Gtk; const Main = imports.ui.main; const Me = imports.misc.extensionUtils.getCurrentExtension(); +const Log = Me.imports.log.Log; const TorButton = Me.imports.ui.tor_button.TorButton; const TorControlClient = Me.imports.tor_control_client.TorControlClient; @@ -42,6 +43,7 @@ function enable() { torButton = new TorButton(torControlClient); Main.panel.addToStatusArea(torButton.Name, torButton); torControlClient.openConnection(); + Log.debug('Enabled Tor extension'); } function disable() { @@ -50,4 +52,6 @@ function disable() { if (torButton !== null) torButton.destroy(); + + Log.debug('Disabled Tor extension'); } diff --git a/log.js b/log.js new file mode 100644 index 0000000..b368000 --- /dev/null +++ b/log.js @@ -0,0 +1,9 @@ +const Log = { + warn: function(message) { + log('[tor control] ' + message); + }, + + debug: function(message) { + //log('[tor control] DEBUG: ' + message); + } +} diff --git a/tor_control_client.js b/tor_control_client.js index 8749732..eb478c9 100644 --- a/tor_control_client.js +++ b/tor_control_client.js @@ -24,6 +24,9 @@ const GLib = imports.gi.GLib; const Lang = imports.lang; const Signals = imports.signals; +const Me = imports.misc.extensionUtils.getCurrentExtension(); +const Log = Me.imports.log.Log; + const TorConnectionError = new Lang.Class({ Name: 'TorConnectionError', @@ -58,6 +61,7 @@ const TorControlClient = new Lang.Class({ }, openConnection: function() { + Log.debug('Trying to reconnect ...'); try { this._connect(this._host, this._port); this._updateProtocolInfo(); @@ -65,10 +69,13 @@ const TorControlClient = new Lang.Class({ this._authenticate(); this.emit('changed-connection-state', 'ready'); this.stopAutoRetry(); + Log.debug('Connected to Tor control port'); } catch (e if e instanceof TorConnectionError) { + Log.debug('Could not connect to Tor control port'); this.closeConnection(e.message); this.startAutoRetry(); } catch (e if e instanceof TorProtocolError) { + Log.debug('Tor control protocol error: ' + e.message); this.closeConnection(e.message); this.startAutoRetry(); } @@ -92,16 +99,19 @@ const TorControlClient = new Lang.Class({ return; this._autoRetryTimerId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 1000, Lang.bind(this, function() { - //log('Retrying to open connection ...'); this.openConnection(); return this._connection === null || !this._connection.is_connected(); })); + + Log.debug('Started auto retry (timer id=' + this._autoRetryTimerId + ')'); }, stopAutoRetry: function() { if (this._autoRetryTimerId === null) return; + Log.debug('Stopping auto retry (timer id=' + this._autoRetryTimerId + ')'); + GLib.source_remove(this._autoRetryTimerId); this._autoRetryTimerId = null; },