Verified Commit 9846297e authored by henry's avatar henry Committed by Pier Angelo Vendrame
Browse files

fixup! Bug 40597: Implement TorSettings module

Bug 41608 - Ignore tor connection errors when tor connection is
cancelled by the user. This can happen if the bootstrap process is
cancelled late in the process.

Also remove unused cancelAutoBootstrapping.
parent c0ea39b4
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ const TorConnectState = Object.freeze({
  └─┼─────▶ │                                                          │  │
    │       └──────────────────────────────────────────────────────────┘  │
    │         │                        ▲                                  │
    │         │ beginAutoBootstrap()   │ cancelAutoBootstrap()            │
    │         │ beginAutoBootstrap()   │ cancelBootstrap()                
    │         ▼                        │                                  │
    │       ┌───────────────────────┐  │                                  │
    └────── │   AutoBootstrapping   │ ─┘                                  │
@@ -461,6 +461,7 @@ const TorConnect = (() => {

              const tbr = new TorBootstrapRequest();
              const internetTest = new InternetTest();
              let cancelled = false;

              let bootstrapError = "";
              let bootstrapErrorDetails = "";
@@ -503,6 +504,7 @@ const TorConnect = (() => {
              this.on_transition = async nextState => {
                if (nextState === TorConnectState.Configuring) {
                  // stop bootstrap process if user cancelled
                  cancelled = true;
                  internetTest.cancel();
                  await tbr.cancel();
                }
@@ -517,6 +519,19 @@ const TorConnect = (() => {
                TorConnect._changeState(TorConnectState.Bootstrapped);
              };
              tbr.onbootstraperror = (message, details) => {
                if (cancelled) {
                  // We ignore this error since it occurred after cancelling (by
                  // the user). We assume the error is just a side effect of the
                  // cancelling.
                  // E.g. If the cancelling is triggered late in the process, we
                  // 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.
                  console.log(
                    `TorConnect: Post-cancel error => ${message}; ${details}`
                  );
                  return;
                }
                // We have to wait for the Internet test to finish before sending the bootstrap error
                bootstrapError = message;
                bootstrapErrorDetails = details;
@@ -1022,11 +1037,6 @@ const TorConnect = (() => {
      this._changeState(TorConnectState.AutoBootstrapping, countryCode);
    },

    cancelAutoBootstrap() {
      console.log("TorConnect: cancelAutoBootstrap()");
      this._changeState(TorConnectState.Configuring);
    },

    /*
        Further external commands and helper methods
        */