[tbb-commits] [tor-browser] 27/33: fixup! fixup! Bug 40597: Implement TorSettings module
gitolite role
git at cupani.torproject.org
Tue May 3 22:40:35 UTC 2022
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 907f3ed2bddd0e7bb6648f667df0178adfe6443c
Author: Pier Angelo Vendrame <pierov at torproject.org>
AuthorDate: Thu Apr 14 18:49:50 2022 +0200
fixup! fixup! Bug 40597: Implement TorSettings module
Try to use the fallback settings if getting localized settings fails.
---
browser/modules/Moat.jsm | 21 +++++++++++++++++++++
browser/modules/TorConnect.jsm | 24 ++++++++++++++++++------
2 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/browser/modules/Moat.jsm b/browser/modules/Moat.jsm
index bdcf6cb631561..35931172f3ee4 100644
--- a/browser/modules/Moat.jsm
+++ b/browser/modules/Moat.jsm
@@ -787,4 +787,25 @@ class MoatRPC {
return map;
}
+
+ // Request a copy of the defaul/fallback bridge settings, takes the following parameters:
+ // - transports: optional, an array of transports available to the client; if empty (or not
+ // given) returns settings using all working transports known to the server
+ //
+ // returns an array of settings objects in roughly the same format as the _settings
+ // object on the TorSettings module
+ async circumvention_defaults(transports) {
+ const args = {
+ transports: transports ? transports : [],
+ };
+ const response = await this._makeRequest("circumvention/defaults", args);
+ if ("errors" in response) {
+ const code = response.errors[0].code;
+ const detail = response.errors[0].detail;
+ throw new Error(`MoatRPC: ${detail} (${code})`);
+ } else if ("settings" in response) {
+ return this._fixupSettingsList(response.settings);
+ }
+ return [];
+ }
}
diff --git a/browser/modules/TorConnect.jsm b/browser/modules/TorConnect.jsm
index 6b501209d844e..59d59b70eaad8 100644
--- a/browser/modules/TorConnect.jsm
+++ b/browser/modules/TorConnect.jsm
@@ -496,12 +496,24 @@ const TorConnect = (() => {
if (this.transitioning) return;
- if (this.settings === null) {
- // unable to determine country
- throw_error(TorStrings.torConnect.autoBootstrappingFailed, TorStrings.torConnect.cannotDetermineCountry);
- } else if (this.settings.length === 0) {
- // no settings available for country
- throw_error(TorStrings.torConnect.autoBootstrappingFailed, TorStrings.torConnect.noSettingsForCountry);
+ const noCountry = this.settings !== null;
+ const noLocalizedSettings = this.settings && this.settings.length === 0;
+ if (noCountry || noLocalizedSettings) {
+ 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);
+ }
+ }
+ if (this.settings === null || this.settings.length === 0) {
+ // The fallback has failed as well, so throw the original error
+ if (noCountry) {
+ // unable to determine country
+ throw_error(TorStrings.torConnect.autoBootstrappingFailed, TorStrings.torConnect.cannotDetermineCountry);
+ } else {
+ // no settings available for country
+ throw_error(TorStrings.torConnect.autoBootstrappingFailed, TorStrings.torConnect.noSettingsForCountry);
+ }
}
// apply each of our settings and try to bootstrap with each
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the tbb-commits
mailing list