Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Tor Browser
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
The Tor Project
Applications
Tor Browser
Commits
01d7d557
Verified
Commit
01d7d557
authored
Apr 9, 2024
by
Pier Angelo Vendrame
Browse files
Options
Downloads
Patches
Plain Diff
fixup! Bug 40597: Implement TorSettings module
Various fixes to address
!968
.
parent
05516a28
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!968
Draft: Bug 42479: Improve TorConnect error handling
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
toolkit/modules/TorConnect.sys.mjs
+31
-52
31 additions, 52 deletions
toolkit/modules/TorConnect.sys.mjs
with
31 additions
and
52 deletions
toolkit/modules/TorConnect.sys.mjs
+
31
−
52
View file @
01d7d557
...
...
@@ -12,6 +12,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
MoatRPC
:
"
resource://gre/modules/Moat.sys.mjs
"
,
TorBootstrapRequest
:
"
resource://gre/modules/TorBootstrapRequest.sys.mjs
"
,
TorProviderBuilder
:
"
resource://gre/modules/TorProviderBuilder.sys.mjs
"
,
TorProviderTopics
:
"
resource://gre/modules/TorProviderBuilder.sys.mjs
"
,
TorLauncherUtil
:
"
resource://gre/modules/TorLauncherUtil.sys.mjs
"
,
TorSettings
:
"
resource://gre/modules/TorSettings.sys.mjs
"
,
});
...
...
@@ -23,11 +24,6 @@ ChromeUtils.defineModuleGetter(
"
resource:///modules/BrowserWindowTracker.jsm
"
);
const
TorTopics
=
Object
.
freeze
({
LogHasWarnOrErr
:
"
TorLogHasWarnOrErr
"
,
ProcessExited
:
"
TorProcessExited
"
,
});
/* Relevant prefs used by tor-launcher */
const
TorLauncherPrefs
=
Object
.
freeze
({
prompt_at_startup
:
"
extensions.torlauncher.prompt_at_startup
"
,
...
...
@@ -56,29 +52,21 @@ export const TorConnectState = Object.freeze({
Disabled
:
"
Disabled
"
,
});
/**
* Errors that can happen during the bootstrap.
*
* BootstrapError should include an exception with more details, if possible.
* ExternalError is used to wrap errors that do not include a code from this
* object, and should always include a cause.
*/
export
const
TorConnectErrors
=
Object
.
freeze
({
Offline
:
"
Offline
"
,
BootstrapError
:
"
BootstrapError
"
,
CannotDetermineCountry
:
"
CannotDetermineCountry
"
,
NoSettingsForCountry
:
"
NoSettingsForCountry
"
,
AllSettingsFailed
:
"
AllSettingsFailed
"
,
ExternalError
:
"
ExternalError
"
,
});
export
class
TorConnectError
extends
Error
{
static
Offline
=
"
Offline
"
;
static
BootstrapError
=
"
BootstrapError
"
;
static
CannotDetermineCountry
=
"
CannotDetermineCountry
"
;
static
NoSettingsForCountry
=
"
NoSettingsForCountry
"
;
static
AllSettingsFailed
=
"
AllSettingsFailed
"
;
static
ExternalError
=
"
ExternalError
"
;
class
TorConnectError
extends
Error
{
constructor
(
code
,
cause
)
{
super
(
cause
?.
message
??
`TorConnectError:
${
code
}
`
,
cause
?
{
cause
}
:
{});
this
.
name
=
"
TorConnectError
"
;
this
.
code
=
code
;
}
}
Object
.
freeze
(
TorConnectError
);
ChromeUtils
.
defineLazyGetter
(
lazy
,
...
...
@@ -142,7 +130,7 @@ export const TorConnectTopics = Object.freeze({
StateChange
:
"
torconnect:state-change
"
,
BootstrapProgress
:
"
torconnect:bootstrap-progress
"
,
BootstrapComplete
:
"
torconnect:bootstrap-complete
"
,
Bootstrap
Error
:
"
torconnect:
bootstrap-
error
"
,
Error
:
"
torconnect:error
"
,
});
// The StateCallback is the base class to implement the various states.
...
...
@@ -310,7 +298,7 @@ class BootstrappingState extends StateCallback {
this
.
#bootstrap
=
new
lazy
.
TorBootstrapRequest
();
this
.
#bootstrap
.
onbootstrapstatus
=
(
progress
,
status
)
=>
{
TorConnect
.
_updateBootstrap
Statu
s
(
progress
,
status
);
TorConnect
.
_updateBootstrap
Progres
s
(
progress
,
status
);
};
this
.
#bootstrap
.
onbootstrapcomplete
=
()
=>
{
this
.
#internetTest
.
cancel
();
...
...
@@ -376,7 +364,7 @@ class BootstrappingState extends StateCallback {
if
(
this
.
#internetTest
.
status
===
InternetStatus
.
Offline
)
{
this
.
changeState
(
TorConnectState
.
Error
,
new
TorConnectError
(
TorConnectError
s
.
Offline
)
new
TorConnectError
(
TorConnectError
.
Offline
)
);
}
else
{
// Give priority to the bootstrap error, in case the Internet test fails
...
...
@@ -384,7 +372,7 @@ class BootstrappingState extends StateCallback {
this
.
changeState
(
TorConnectState
.
Error
,
new
TorConnectError
(
TorConnectError
s
.
BootstrapError
,
TorConnectError
.
BootstrapError
,
this
.
#bootstrapError
)
);
...
...
@@ -413,10 +401,11 @@ class BootstrappingState extends StateCallback {
codes
[
Math
.
floor
(
Math
.
random
()
*
codes
.
length
)];
}
const
err
=
new
Error
(
"
Censorship simulation
"
);
err
.
details
=
{
phase
:
"
conn
"
,
reason
:
"
noroute
"
};
err
.
phase
=
"
conn
"
;
err
.
reason
=
"
noroute
"
;
this
.
changeState
(
TorConnectState
.
Error
,
new
TorConnectError
(
TorConnectError
s
.
BootstrapError
,
err
)
new
TorConnectError
(
TorConnectError
.
BootstrapError
,
err
)
);
return
true
;
}
...
...
@@ -481,7 +470,7 @@ class AutoBootstrappingState extends StateCallback {
if
(
!
this
.
transitioning
)
{
this
.
changeState
(
TorConnectState
.
Error
,
new
TorConnectError
(
TorConnectError
s
.
AllSettingsFailed
)
new
TorConnectError
(
TorConnectError
.
AllSettingsFailed
)
);
}
return
true
;
...
...
@@ -494,7 +483,7 @@ class AutoBootstrappingState extends StateCallback {
if
(
!
this
.
transitioning
)
{
this
.
changeState
(
TorConnectState
.
Error
,
new
TorConnectError
(
TorConnectError
s
.
CannotDetermineCountry
)
new
TorConnectError
(
TorConnectError
.
CannotDetermineCountry
)
);
}
return
true
;
...
...
@@ -556,10 +545,10 @@ class AutoBootstrappingState extends StateCallback {
if
(
!
TorConnect
.
_detectedLocation
)
{
// unable to determine country
throw
new
TorConnectError
(
TorConnectError
s
.
CannotDetermineCountry
);
throw
new
TorConnectError
(
TorConnectError
.
CannotDetermineCountry
);
}
else
{
// no settings available for country
throw
new
TorConnectError
(
TorConnectError
s
.
NoSettingsForCountry
);
throw
new
TorConnectError
(
TorConnectError
.
NoSettingsForCountry
);
}
}
}
...
...
@@ -604,7 +593,7 @@ class AutoBootstrappingState extends StateCallback {
// Build out our bootstrap request.
const
bootstrap
=
new
lazy
.
TorBootstrapRequest
();
bootstrap
.
onbootstrapstatus
=
(
progress
,
status
)
=>
{
TorConnect
.
_updateBootstrap
Statu
s
(
progress
,
status
);
TorConnect
.
_updateBootstrap
Progres
s
(
progress
,
status
);
};
bootstrap
.
onbootstraperror
=
error
=>
{
lazy
.
logger
.
error
(
"
Auto-Bootstrap error
"
,
error
);
...
...
@@ -650,7 +639,7 @@ class AutoBootstrappingState extends StateCallback {
// Only explicitly change state here if something else has not transitioned
// us.
if
(
!
this
.
transitioning
)
{
throw
new
TorConnectError
(
TorConnectError
s
.
AllSettingsFailed
);
throw
new
TorConnectError
(
TorConnectError
.
AllSettingsFailed
);
}
}
...
...
@@ -702,17 +691,14 @@ class ErrorState extends StateCallback {
}
run
(
error
)
{
if
(
!
error
.
code
||
!
(
error
.
code
in
TorConnectError
s
))
{
error
=
new
TorConnectError
(
TorConnectError
s
.
ExternalError
,
error
);
if
(
!
(
error
instanceof
TorConnectError
))
{
error
=
new
TorConnectError
(
TorConnectError
.
ExternalError
,
error
);
}
TorConnect
.
_errorCode
=
error
.
code
;
TorConnect
.
_errorDetails
=
error
;
lazy
.
logger
.
error
(
`Entering error state (
${
error
.
code
}
)`
,
error
);
Services
.
obs
.
notifyObservers
(
{
code
:
error
.
code
,
message
:
error
.
message
,
details
:
error
},
TorConnectTopics
.
BootstrapError
);
Services
.
obs
.
notifyObservers
(
error
,
TorConnectTopics
.
Error
);
this
.
changeState
(
TorConnectState
.
Configuring
);
}
...
...
@@ -839,7 +825,6 @@ class InternetTest {
export
const
TorConnect
=
{
_stateHandler
:
new
InitialState
(),
_bootstrapProgress
:
0
,
_bootstrapStatus
:
null
,
_internetStatus
:
InternetStatus
.
Unknown
,
// list of country codes Moat has settings for
_countryCodes
:
[],
...
...
@@ -929,17 +914,15 @@ export const TorConnect = {
this
.
_stateHandler
.
begin
(...
args
);
},
_updateBootstrap
Statu
s
(
progress
,
status
)
{
_updateBootstrap
Progres
s
(
progress
,
status
)
{
this
.
_bootstrapProgress
=
progress
;
this
.
_bootstrapStatus
=
status
;
lazy
.
logger
.
info
(
`Bootstrapping
${
this
.
_bootstrapProgress
}
% complete (
${
this
.
_bootstrapS
tatus
}
)`
`Bootstrapping
${
this
.
_bootstrapProgress
}
% complete (
${
s
tatus
}
)`
);
Services
.
obs
.
notifyObservers
(
{
progress
:
TorConnect
.
_bootstrapProgress
,
status
:
TorConnect
.
_bootstrapStatus
,
hasWarnings
:
TorConnect
.
_logHasWarningOrError
,
},
TorConnectTopics
.
BootstrapProgress
...
...
@@ -973,8 +956,8 @@ export const TorConnect = {
);
// register the Tor topics we always care about
observeTopic
(
To
rTopics
.
ProcessExited
);
observeTopic
(
To
rTopics
.
Log
HasWarnOrErr
);
observeTopic
(
lazy
.
TorProvide
rTopics
.
ProcessExited
);
observeTopic
(
lazy
.
TorProvide
rTopics
.
HasWarnOrErr
);
}
},
...
...
@@ -982,11 +965,11 @@ export const TorConnect = {
lazy
.
logger
.
debug
(
`Observed
${
topic
}
`
);
switch
(
topic
)
{
case
To
rTopics
.
Log
HasWarnOrErr
:
{
case
lazy
.
TorProvide
rTopics
.
HasWarnOrErr
:
{
this
.
_logHasWarningOrError
=
true
;
break
;
}
case
To
rTopics
.
ProcessExited
:
{
case
lazy
.
TorProvide
rTopics
.
ProcessExited
:
{
// Treat a failure as a possibly broken configuration.
// So, prevent quickstart at the next start.
Services
.
prefs
.
setBoolPref
(
TorLauncherPrefs
.
prompt_at_startup
,
true
);
...
...
@@ -1109,10 +1092,6 @@ export const TorConnect = {
return
this
.
_bootstrapProgress
;
},
get
bootstrapStatus
()
{
return
this
.
_bootstrapStatus
;
},
get
internetStatus
()
{
return
this
.
_internetStatus
;
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment