henry pushed to branch tor-browser-128.8.0esr-14.5-1 at The Tor Project / Applications / Tor Browser

Commits:

3 changed files:

Changes:

  • browser/components/torpreferences/content/torLogDialog.js
    ... ... @@ -66,28 +66,22 @@ const gTorLogDialog = {
    66 66
           );
    
    67 67
         });
    
    68 68
     
    
    69
    -    // A waiting state should not be needed at this point.
    
    70
    -    // Also, we probably cannot even arrive here if the provider failed to
    
    71
    -    // initialize, otherwise we could use a try/catch, and write the exception
    
    72
    -    // text in the logs, instead.
    
    73
    -    TorProviderBuilder.build().then(provider => {
    
    74
    -      Services.obs.addObserver(this, TorProviderTopics.TorLog);
    
    75
    -      window.addEventListener(
    
    76
    -        "unload",
    
    77
    -        () => {
    
    78
    -          Services.obs.removeObserver(this, TorProviderTopics.TorLog);
    
    79
    -        },
    
    80
    -        { once: true }
    
    81
    -      );
    
    82
    -
    
    83
    -      for (const logEntry of provider.getLog()) {
    
    84
    -        this.addLogEntry(logEntry, true);
    
    85
    -      }
    
    86
    -      // Set the initial scroll to the bottom.
    
    87
    -      this._logTable.scrollTo({
    
    88
    -        top: this._logTable.scrollTopMax,
    
    89
    -        behaviour: "instant",
    
    90
    -      });
    
    69
    +    Services.obs.addObserver(this, TorProviderTopics.TorLog);
    
    70
    +    window.addEventListener(
    
    71
    +      "unload",
    
    72
    +      () => {
    
    73
    +        Services.obs.removeObserver(this, TorProviderTopics.TorLog);
    
    74
    +      },
    
    75
    +      { once: true }
    
    76
    +    );
    
    77
    +
    
    78
    +    for (const logEntry of TorProviderBuilder.getLog()) {
    
    79
    +      this.addLogEntry(logEntry, true);
    
    80
    +    }
    
    81
    +    // Set the initial scroll to the bottom.
    
    82
    +    this._logTable.scrollTo({
    
    83
    +      top: this._logTable.scrollTopMax,
    
    84
    +      behaviour: "instant",
    
    91 85
         });
    
    92 86
       },
    
    93 87
     
    

  • toolkit/components/tor-launcher/TorProvider.sys.mjs
    ... ... @@ -45,12 +45,6 @@ const logger = console.createInstance({
    45 45
      * @property {string} [host] The host to connect for a TCP proxy
    
    46 46
      * @property {number} [port] The port number to use for a TCP proxy
    
    47 47
      */
    
    48
    -/**
    
    49
    - * @typedef {object} LogEntry An object with a log message
    
    50
    - * @property {string} timestamp The local date-time stamp at which we received the message
    
    51
    - * @property {string} type The message level
    
    52
    - * @property {string} msg The message
    
    53
    - */
    
    54 48
     /**
    
    55 49
      * Stores the data associated with a circuit node.
    
    56 50
      *
    
    ... ... @@ -69,7 +63,6 @@ const Preferences = Object.freeze({
    69 63
       ControlUseIpc: "extensions.torlauncher.control_port_use_ipc",
    
    70 64
       ControlHost: "extensions.torlauncher.control_host",
    
    71 65
       ControlPort: "extensions.torlauncher.control_port",
    
    72
    -  MaxLogEntries: "extensions.torlauncher.max_tor_log_entries",
    
    73 66
     });
    
    74 67
     
    
    75 68
     /* Config Keys used to configure tor daemon */
    
    ... ... @@ -141,15 +134,6 @@ export class TorProvider {
    141 134
        */
    
    142 135
       #socksSettings = null;
    
    143 136
     
    
    144
    -  /**
    
    145
    -   * The logs we received over the control port.
    
    146
    -   * We store a finite number of log entries which can be configured with
    
    147
    -   * extensions.torlauncher.max_tor_log_entries.
    
    148
    -   *
    
    149
    -   * @type {LogEntry[]}
    
    150
    -   */
    
    151
    -  #logs = [];
    
    152
    -
    
    153 137
       #isBootstrapDone = false;
    
    154 138
       /**
    
    155 139
        * Keep the last warning to avoid broadcasting an async warning if it is the
    
    ... ... @@ -511,15 +495,6 @@ export class TorProvider {
    511 495
         return this.#controller.onionAuthViewKeys();
    
    512 496
       }
    
    513 497
     
    
    514
    -  /**
    
    515
    -   * Returns captured log messages.
    
    516
    -   *
    
    517
    -   * @returns {LogEntry[]} The logs we collected from the tor daemon so far.
    
    518
    -   */
    
    519
    -  getLog() {
    
    520
    -    return structuredClone(this.#logs);
    
    521
    -  }
    
    522
    -
    
    523 498
       /**
    
    524 499
        * @returns {boolean} true if we launched and control tor, false if we are
    
    525 500
        * using system tor.
    
    ... ... @@ -1033,15 +1008,6 @@ export class TorProvider {
    1033 1008
           TorProviderTopics.TorLog
    
    1034 1009
         );
    
    1035 1010
     
    
    1036
    -    const maxEntries = Services.prefs.getIntPref(
    
    1037
    -      Preferences.MaxLogEntries,
    
    1038
    -      1000
    
    1039
    -    );
    
    1040
    -    if (maxEntries > 0 && this.#logs.length >= maxEntries) {
    
    1041
    -      this.#logs.splice(0, 1);
    
    1042
    -    }
    
    1043
    -
    
    1044
    -    this.#logs.push({ type, msg, timestamp });
    
    1045 1011
         switch (type) {
    
    1046 1012
           case "ERR":
    
    1047 1013
             logger.error(`[Tor error] ${msg}`);
    

  • toolkit/components/tor-launcher/TorProviderBuilder.sys.mjs
    ... ... @@ -23,6 +23,13 @@ export const TorProviders = Object.freeze({
    23 23
       tor: 1,
    
    24 24
     });
    
    25 25
     
    
    26
    +/**
    
    27
    + * @typedef {object} LogEntry An object with a log message
    
    28
    + * @property {string} timestamp The local date-time stamp at which we received the message
    
    29
    + * @property {string} type The message level
    
    30
    + * @property {string} msg The message
    
    31
    + */
    
    32
    +
    
    26 33
     /**
    
    27 34
      * The factory to get a Tor provider.
    
    28 35
      * Currently we support only TorProvider, i.e., the one that interacts with
    
    ... ... @@ -36,6 +43,48 @@ export class TorProviderBuilder {
    36 43
        */
    
    37 44
       static #provider = null;
    
    38 45
     
    
    46
    +  /**
    
    47
    +   * A record of the log messages from all TorProvider instances.
    
    48
    +   *
    
    49
    +   * @type {LogEntry[]}
    
    50
    +   */
    
    51
    +  static #log = [];
    
    52
    +
    
    53
    +  /**
    
    54
    +   * Get a record of historic log entries.
    
    55
    +   *
    
    56
    +   * @returns {LogEntry[]} - The record of entries.
    
    57
    +   */
    
    58
    +  static getLog() {
    
    59
    +    return structuredClone(this.#log);
    
    60
    +  }
    
    61
    +
    
    62
    +  /**
    
    63
    +   * The limit on the number of log entries we should store.
    
    64
    +   *
    
    65
    +   * @type {integer}
    
    66
    +   */
    
    67
    +  static #logLimit;
    
    68
    +
    
    69
    +  /**
    
    70
    +   * The observer that checks for new TorLog messages.
    
    71
    +   *
    
    72
    +   * @type {Function}
    
    73
    +   */
    
    74
    +  static #logObserver;
    
    75
    +
    
    76
    +  /**
    
    77
    +   * Add a new log message.
    
    78
    +   *
    
    79
    +   * @param {LogEntry} logEntry - The log entry to add.
    
    80
    +   */
    
    81
    +  static #addLogEntry(logEntry) {
    
    82
    +    if (this.#logLimit > 0 && this.#log.length >= this.#logLimit) {
    
    83
    +      this.#log.splice(0, 1);
    
    84
    +    }
    
    85
    +    this.#log.push(logEntry);
    
    86
    +  }
    
    87
    +
    
    39 88
       /**
    
    40 89
        * The observer that checks when the tor process exits, and reinitializes the
    
    41 90
        * provider.
    
    ... ... @@ -56,6 +105,15 @@ export class TorProviderBuilder {
    56 105
        * Initialize the provider of choice.
    
    57 106
        */
    
    58 107
       static init() {
    
    108
    +    this.#logLimit = Services.prefs.getIntPref(
    
    109
    +      "extensions.torlauncher.max_tor_log_entries",
    
    110
    +      1000
    
    111
    +    );
    
    112
    +    this.#logObserver = subject => {
    
    113
    +      this.#addLogEntry(subject.wrappedJSObject);
    
    114
    +    };
    
    115
    +    Services.obs.addObserver(this.#logObserver, TorProviderTopics.TorLog);
    
    116
    +
    
    59 117
         switch (this.providerType) {
    
    60 118
           case TorProviders.tor:
    
    61 119
             // Even though initialization of the initial TorProvider is
    
    ... ... @@ -136,6 +194,7 @@ export class TorProviderBuilder {
    136 194
           );
    
    137 195
           this.#exitObserver = null;
    
    138 196
         }
    
    197
    +    Services.obs.removeObserver(this.#logObserver, TorProviderTopics.TorLog);
    
    139 198
       }
    
    140 199
     
    
    141 200
       /**