Skip to content
Snippets Groups Projects
Commit 419ab9b0 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame :jack_o_lantern:
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 fae57477
No related branches found
No related tags found
1 merge request!980Bug 42512: Rebased alpha onto Firefox 115.10.0esr
......@@ -291,20 +291,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 =
......@@ -387,9 +381,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
......@@ -411,9 +403,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();
......@@ -525,10 +515,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;
......@@ -567,9 +554,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
......@@ -613,8 +598,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(
......@@ -644,18 +628,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();
......@@ -824,12 +801,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 */
[
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment