Skip to content
Snippets Groups Projects
Commit e20606ca authored by henry's avatar henry Committed by Pier Angelo Vendrame
Browse files

fixup! TB 40597: Implement TorSettings module

TB 43463: Load Moat regions from a local file rather than using Moat.

Also rename getCountryCodes to getFrequentRegions.
parent 0f60b12c
Branches
Tags
1 merge request!1500TB 43415: Rebased onto 134.0a1
......@@ -307,4 +307,5 @@ module.exports = [
"browser/app/profile/000-tor-browser.js",
"mobile/android/app/000-tor-browser-android.js",
"toolkit/content/pt_config.json",
"toolkit/content/moat_contries_dev_build.json",
];
......@@ -1537,3 +1537,4 @@ browser/app/profile/001-base-profile.js
browser/app/profile/000-tor-browser.js
mobile/android/app/000-tor-browser-android.js
toolkit/content/pt_config.json
toolkit/content/moat_countries_dev_build.json
......@@ -159,4 +159,9 @@ toolkit.jar:
content/global/third_party/d3/d3.js (/third_party/js/d3/d3.js)
content/global/third_party/cfworker/json-schema.js (/third_party/js/cfworker/json-schema.js)
# The pt_config.json content should be replaced in the omni.ja in
# tor-browser-build. See tor-browser#42343.
content/global/pt_config.json (pt_config.json)
# The moat_countries.json content should be replaced in the omni.ja in
# tor-browser-build. See tor-browser#43463.
content/global/moat_countries.json (moat_countries_dev_build.json)
[
{
"_comment1": "Used for dev build, replaced for release builds in tor-browser-build.",
"_comment2": "List is taken from tpo/anti-censorship/rdsys-admin 810fb24b:conf/circumvention.json and filtered with `jq -c keys`."
},
"by","cn","eg","hk","ir","mm","ru","tm"
]
......@@ -335,20 +335,6 @@ export class MoatRPC {
return settings;
}
// Request a list of country codes with available censorship circumvention
// settings.
//
// returns an array of ISO 3166-1 alpha-2 country codes which we can query
// settings for.
async circumvention_countries() {
const args = {};
const { response } = await this.#makeRequest(
"circumvention/countries",
args
);
return response;
}
// Request a copy of the builtin bridges, takes the following parameters:
// - transports: optional, an array of transports we would like the latest
// bridge strings for; if empty (or not given) returns all of them
......
......@@ -817,8 +817,14 @@ export const TorConnect = {
};
},
// list of country codes Moat has settings for
_countryCodes: [],
/**
* Promise that resolves to a list of region codes that Moat has special
* bridge settings for.
*
* @type {Promise<string[]>}
*/
_moatRegionsPromise: null,
_countryNames: Object.freeze(
(() => {
const codes = Services.intl.getAvailableLocaleDisplayNames("region");
......@@ -892,6 +898,18 @@ export const TorConnect = {
return;
}
this._moatRegionsPromise = fetch(
"chrome://global/content/moat_countries.json"
)
.then(req => req.json())
// Filter out the "_comment" object in the moat_countries_dev_build.json
// file.
.then(regionList => regionList.filter(r => typeof r === "string"))
.catch(e => {
lazy.logger.error("Failed to fetch Moat region codes", e);
return [];
});
let observeTopic = addTopic => {
Services.obs.addObserver(this, addTopic);
lazy.logger.debug(`Observing topic '${addTopic}'`);
......@@ -1113,10 +1131,6 @@ export const TorConnect = {
return null;
},
get countryCodes() {
return this._countryCodes;
},
get countryNames() {
return this._countryNames;
},
......@@ -1526,25 +1540,12 @@ export const TorConnect = {
this._makeStageRequest(TorConnectStage.ChooseRegion);
},
/*
Further external commands and helper methods
/**
* Get the list of regions that Moat has settings for.
*
* @returns {string[]} - The list of region codes.
*/
async getCountryCodes() {
// Difference with the getter: this is to be called by TorConnectParent, and
// downloads the country codes if they are not already in cache.
if (this._countryCodes.length) {
return this._countryCodes;
}
const mrpc = new lazy.MoatRPC();
try {
await mrpc.init();
this._countryCodes = await mrpc.circumvention_countries();
} catch (err) {
lazy.logger.error("An error occurred while fetching country codes", err);
} finally {
mrpc.uninit();
}
return this._countryCodes;
async getFrequentRegions() {
return this._moatRegionsPromise ?? [];
},
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment