[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser] 01/02: fixup! Bug 40597: Implement TorSettings module



This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-91.9.0esr-11.5-1
in repository tor-browser.

commit d54aeed8c9409036b02c89e28ef0aea7ae0f5652
Author: Pier Angelo Vendrame <pierov@xxxxxxxxxxxxxx>
AuthorDate: Tue May 17 16:38:11 2022 +0200

    fixup! Bug 40597: Implement TorSettings module
    
    Bug 40923: Make available the country code detected by Moat
---
 browser/modules/Moat.jsm       |  9 ++++++---
 browser/modules/TorConnect.jsm | 24 ++++++++++++++++++------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/browser/modules/Moat.jsm b/browser/modules/Moat.jsm
index 35931172f3ee4..90a6ae4e521cc 100644
--- a/browser/modules/Moat.jsm
+++ b/browser/modules/Moat.jsm
@@ -735,6 +735,7 @@ class MoatRPC {
       country,
     };
     const response = await this._makeRequest("circumvention/settings", args);
+    let settings = {};
     if ("errors" in response) {
       const code = response.errors[0].code;
       const detail = response.errors[0].detail;
@@ -748,10 +749,12 @@ class MoatRPC {
 
       throw new Error(`MoatRPC: ${detail} (${code})`);
     } else if ("settings" in response) {
-      return this._fixupSettingsList(response.settings);
+      settings.settings = this._fixupSettingsList(response.settings);
     }
-
-    return [];
+    if ("country" in response) {
+      settings.country = response.country;
+    }
+    return settings;
   }
 
   // Request a list of country codes with available censorship circumvention settings
diff --git a/browser/modules/TorConnect.jsm b/browser/modules/TorConnect.jsm
index 711134326a14d..0edbb7d70c47f 100644
--- a/browser/modules/TorConnect.jsm
+++ b/browser/modules/TorConnect.jsm
@@ -317,6 +317,7 @@ const TorConnect = (() => {
             }
             return codesNames;
         })()),
+        _detectedLocation: "",
         _errorMessage: null,
         _errorDetails: null,
         _logHasWarningOrError: false,
@@ -380,6 +381,10 @@ const TorConnect = (() => {
                         };
                         await debug_sleep(1500);
                         TorConnect._hasBootstrapEverFailed = true;
+                        if (Services.prefs.getIntPref(TorConnectPrefs.censorship_level, 0) === 2) {
+                            const codes = Object.keys(TorConnect._countryNames);
+                            TorConnect._detectedLocation = codes[Math.floor(Math.random() * codes.length)];
+                        }
                         TorConnect._changeState(TorConnectState.Error, "Bootstrap failed (for debugging purposes)", "Error: Censorship simulation", true);
                         TorProtocolService._torBootstrapDebugSetError();
                         return;
@@ -489,22 +494,25 @@ const TorConnect = (() => {
 
                         if (this.transitioning) return;
 
-                        this.settings = await this.mrpc.circumvention_settings([...TorBuiltinBridgeTypes, "vanilla"], countryCode);
+                        const settings = await this.mrpc.circumvention_settings([...TorBuiltinBridgeTypes, "vanilla"], countryCode);
 
                         if (this.transitioning) return;
 
-                        const noCountry = this.settings !== null;
-                        const noLocalizedSettings = this.settings && this.settings.length === 0;
-                        if (noCountry || noLocalizedSettings) {
+                        if (settings?.country) {
+                            TorConnect._detectedLocation = settings.country;
+                        }
+                        if (settings?.settings && settings.settings.length > 0) {
+                            this.settings = settings.settings;
+                        } else {
                             try {
                                 this.settings = await this.mrpc.circumvention_defaults([...TorBuiltinBridgeTypes, "vanilla"]);
                             } catch (err) {
-                                console.error("We could not get localized settings, but defaults settings failed as well", err);
+                                console.error("We did not get localized settings, and default settings failed as well", err);
                             }
                         }
                         if (this.settings === null || this.settings.length === 0) {
                             // The fallback has failed as well, so throw the original error
-                            if (noCountry) {
+                            if (!TorConnect._detectedLocation) {
                                 // unable to determine country
                                 throw_error(TorStrings.torConnect.autoBootstrappingFailed, TorStrings.torConnect.cannotDetermineCountry);
                             } else {
@@ -750,6 +758,10 @@ const TorConnect = (() => {
             return this._countryNames;
         },
 
+        get detectedLocation() {
+            return this._detectedLocation;
+        },
+
         get errorMessage() {
             return this._errorMessage;
         },

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits