Verified Commit 0c5e98ab authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

fixup! Bug 40597: Implement TorSettings module

Bug 41114: Refactor TorConnect.

The purpose of this commit is just to make the review easier.
It lints the previous commit to make it closer to the next form it will
take.
To review this commit, you can lint TorConnect.sys.mjs and check you
obtain the same result.
parent 2b75d115
Loading
Loading
Loading
Loading
+17 −34
Changes for toolkit/modules/TorConnect.sys.mjs: 17 added lines, 34 removed lines.
Original line number Diff line number Diff line
@@ -292,20 +292,14 @@ const debug_sleep = async ms => {
  // wait until bootstrap completes or we get an error
  await new Promise(async (resolve, reject) => {
    // debug hook to simulate censorship preventing bootstrapping
              if (
                Services.prefs.getIntPref(TorConnectPrefs.censorship_level, 0) >
                0
              ) {
    if (Services.prefs.getIntPref(TorConnectPrefs.censorship_level, 0) > 0) {
      this.on_transition = nextState => {
        resolve();
      };
      await debug_sleep(1500);
      TorConnect._hasBootstrapEverFailed = true;
      if (
                  Services.prefs.getIntPref(
                    TorConnectPrefs.censorship_level,
                    0
                  ) === 2
        Services.prefs.getIntPref(TorConnectPrefs.censorship_level, 0) === 2
      ) {
        const codes = Object.keys(TorConnect._countryNames);
        TorConnect._detectedLocation =
@@ -388,9 +382,7 @@ const debug_sleep = async ms => {
        // get "Building circuits: Establishing a Tor circuit failed".
        // TODO: Maybe move this logic deeper in the process to know
        // when to filter out such errors triggered by cancelling.
                  lazy.logger.warn(
                    `Post-cancel error => ${message}; ${details}`
                  );
        lazy.logger.warn(`Post-cancel error => ${message}; ${details}`);
        return;
      }
      // We have to wait for the Internet test to finish before sending the bootstrap error
@@ -412,9 +404,7 @@ const debug_sleep = async ms => {
  });
}

          async function autoBootstrappingCallback(
            countryCode
          ) {
async function autoBootstrappingCallback(countryCode) {
  await new Promise(async (resolve, reject) => {
    this.on_transition = nextState => {
      resolve();
@@ -526,10 +516,7 @@ const debug_sleep = async ms => {

      // apply each of our settings and try to bootstrap with each
      try {
                  for (const [
                    index,
                    currentSetting,
                  ] of this.settings.entries()) {
        for (const [index, currentSetting] of this.settings.entries()) {
          // we want to break here so we can fall through and restore original settings
          if (this.transitioning) {
            break;
@@ -568,9 +555,7 @@ const debug_sleep = async ms => {
            TorConnect._updateBootstrapStatus(progress, status);
          };
          tbr.onbootstraperror = (message, details) => {
                      lazy.logger.error(
                        `Auto-Bootstrap error => ${message}; ${details}`
                      );
            lazy.logger.error(`Auto-Bootstrap error => ${message}; ${details}`);
          };

          // update transition callback for user cancel
@@ -614,8 +599,7 @@ const debug_sleep = async ms => {
    } catch (err) {
      if (this.mrpc?.inited) {
        // lookup countries which have settings available
                  TorConnect._countryCodes =
                    await this.mrpc.circumvention_countries();
        TorConnect._countryCodes = await this.mrpc.circumvention_countries();
      }
      if (!this.transitioning) {
        TorConnect._changeState(
@@ -645,18 +629,11 @@ const debug_sleep = async ms => {
      resolve();
    };
    // notify observers of bootstrap completion
              Services.obs.notifyObservers(
                null,
                TorConnectTopics.BootstrapComplete
              );
    Services.obs.notifyObservers(null, TorConnectTopics.BootstrapComplete);
  });
}

          async function errorCallback(
            errorMessage,
            errorDetails,
            bootstrappingFailure
          ) {
async function errorCallback(errorMessage, errorDetails, bootstrappingFailure) {
  await new Promise((resolve, reject) => {
    this.on_transition = async nextState => {
      resolve();
@@ -825,12 +802,18 @@ export const TorConnect = (() => {
        /* Bootstrapping */
        [
          TorConnectState.Bootstrapping,
          new StateCallback(TorConnectState.Bootstrapping, bootstrappingCallback),
          new StateCallback(
            TorConnectState.Bootstrapping,
            bootstrappingCallback
          ),
        ],
        /* AutoBootstrapping */
        [
          TorConnectState.AutoBootstrapping,
          new StateCallback(TorConnectState.AutoBootstrapping, autoBootstrappingCallback),
          new StateCallback(
            TorConnectState.AutoBootstrapping,
            autoBootstrappingCallback
          ),
        ],
        /* Bootstrapped */
        [