henry pushed to branch tor-browser-128.8.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits: 480957e5 by Henry Wilkes at 2025-03-18T15:21:16+00:00 fixup! TB 40933: Add tor-launcher functionality
TB 42300: Store TorProvider log messages in TorProviderBuilder to be used between instances and to be available whilst a provider is not available.
- - - - - 0f529e6f by Henry Wilkes at 2025-03-18T15:21:16+00:00 fixup! TB 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection
TB 42300: Fetch tor logs from TorProviderBuilder.
- - - - -
3 changed files:
- browser/components/torpreferences/content/torLogDialog.js - toolkit/components/tor-launcher/TorProvider.sys.mjs - toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs
Changes:
===================================== browser/components/torpreferences/content/torLogDialog.js ===================================== @@ -66,28 +66,22 @@ const gTorLogDialog = { ); });
- // A waiting state should not be needed at this point. - // Also, we probably cannot even arrive here if the provider failed to - // initialize, otherwise we could use a try/catch, and write the exception - // text in the logs, instead. - TorProviderBuilder.build().then(provider => { - Services.obs.addObserver(this, TorProviderTopics.TorLog); - window.addEventListener( - "unload", - () => { - Services.obs.removeObserver(this, TorProviderTopics.TorLog); - }, - { once: true } - ); - - for (const logEntry of provider.getLog()) { - this.addLogEntry(logEntry, true); - } - // Set the initial scroll to the bottom. - this._logTable.scrollTo({ - top: this._logTable.scrollTopMax, - behaviour: "instant", - }); + Services.obs.addObserver(this, TorProviderTopics.TorLog); + window.addEventListener( + "unload", + () => { + Services.obs.removeObserver(this, TorProviderTopics.TorLog); + }, + { once: true } + ); + + for (const logEntry of TorProviderBuilder.getLog()) { + this.addLogEntry(logEntry, true); + } + // Set the initial scroll to the bottom. + this._logTable.scrollTo({ + top: this._logTable.scrollTopMax, + behaviour: "instant", }); },
===================================== toolkit/components/tor-launcher/TorProvider.sys.mjs ===================================== @@ -45,12 +45,6 @@ const logger = console.createInstance({ * @property {string} [host] The host to connect for a TCP proxy * @property {number} [port] The port number to use for a TCP proxy */ -/** - * @typedef {object} LogEntry An object with a log message - * @property {string} timestamp The local date-time stamp at which we received the message - * @property {string} type The message level - * @property {string} msg The message - */ /** * Stores the data associated with a circuit node. * @@ -69,7 +63,6 @@ const Preferences = Object.freeze({ ControlUseIpc: "extensions.torlauncher.control_port_use_ipc", ControlHost: "extensions.torlauncher.control_host", ControlPort: "extensions.torlauncher.control_port", - MaxLogEntries: "extensions.torlauncher.max_tor_log_entries", });
/* Config Keys used to configure tor daemon */ @@ -141,15 +134,6 @@ export class TorProvider { */ #socksSettings = null;
- /** - * The logs we received over the control port. - * We store a finite number of log entries which can be configured with - * extensions.torlauncher.max_tor_log_entries. - * - * @type {LogEntry[]} - */ - #logs = []; - #isBootstrapDone = false; /** * Keep the last warning to avoid broadcasting an async warning if it is the @@ -511,15 +495,6 @@ export class TorProvider { return this.#controller.onionAuthViewKeys(); }
- /** - * Returns captured log messages. - * - * @returns {LogEntry[]} The logs we collected from the tor daemon so far. - */ - getLog() { - return structuredClone(this.#logs); - } - /** * @returns {boolean} true if we launched and control tor, false if we are * using system tor. @@ -1033,15 +1008,6 @@ export class TorProvider { TorProviderTopics.TorLog );
- const maxEntries = Services.prefs.getIntPref( - Preferences.MaxLogEntries, - 1000 - ); - if (maxEntries > 0 && this.#logs.length >= maxEntries) { - this.#logs.splice(0, 1); - } - - this.#logs.push({ type, msg, timestamp }); switch (type) { case "ERR": logger.error(`[Tor error] ${msg}`);
===================================== toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs ===================================== @@ -23,6 +23,13 @@ export const TorProviders = Object.freeze({ tor: 1, });
+/** + * @typedef {object} LogEntry An object with a log message + * @property {string} timestamp The local date-time stamp at which we received the message + * @property {string} type The message level + * @property {string} msg The message + */ + /** * The factory to get a Tor provider. * Currently we support only TorProvider, i.e., the one that interacts with @@ -36,6 +43,48 @@ export class TorProviderBuilder { */ static #provider = null;
+ /** + * A record of the log messages from all TorProvider instances. + * + * @type {LogEntry[]} + */ + static #log = []; + + /** + * Get a record of historic log entries. + * + * @returns {LogEntry[]} - The record of entries. + */ + static getLog() { + return structuredClone(this.#log); + } + + /** + * The limit on the number of log entries we should store. + * + * @type {integer} + */ + static #logLimit; + + /** + * The observer that checks for new TorLog messages. + * + * @type {Function} + */ + static #logObserver; + + /** + * Add a new log message. + * + * @param {LogEntry} logEntry - The log entry to add. + */ + static #addLogEntry(logEntry) { + if (this.#logLimit > 0 && this.#log.length >= this.#logLimit) { + this.#log.splice(0, 1); + } + this.#log.push(logEntry); + } + /** * The observer that checks when the tor process exits, and reinitializes the * provider. @@ -56,6 +105,15 @@ export class TorProviderBuilder { * Initialize the provider of choice. */ static init() { + this.#logLimit = Services.prefs.getIntPref( + "extensions.torlauncher.max_tor_log_entries", + 1000 + ); + this.#logObserver = subject => { + this.#addLogEntry(subject.wrappedJSObject); + }; + Services.obs.addObserver(this.#logObserver, TorProviderTopics.TorLog); + switch (this.providerType) { case TorProviders.tor: // Even though initialization of the initial TorProvider is @@ -136,6 +194,7 @@ export class TorProviderBuilder { ); this.#exitObserver = null; } + Services.obs.removeObserver(this.#logObserver, TorProviderTopics.TorLog); }
/**
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/ad21bdd...
tor-commits@lists.torproject.org