| ... |
... |
@@ -35,23 +35,6 @@ const TorConnectPrefs = Object.freeze({ |
|
35
|
35
|
quickstart: "torbrowser.settings.quickstart.enabled",
|
|
36
|
36
|
});
|
|
37
|
37
|
|
|
38
|
|
-export const TorConnectState = Object.freeze({
|
|
39
|
|
- /* Our initial state */
|
|
40
|
|
- Initial: "Initial",
|
|
41
|
|
- /* In-between initial boot and bootstrapping, users can change tor network settings during this state */
|
|
42
|
|
- Configuring: "Configuring",
|
|
43
|
|
- /* Tor is attempting to bootstrap with settings from censorship-circumvention db */
|
|
44
|
|
- AutoBootstrapping: "AutoBootstrapping",
|
|
45
|
|
- /* Tor is bootstrapping */
|
|
46
|
|
- Bootstrapping: "Bootstrapping",
|
|
47
|
|
- /* Passthrough state back to Configuring */
|
|
48
|
|
- Error: "Error",
|
|
49
|
|
- /* Final state, after successful bootstrap */
|
|
50
|
|
- Bootstrapped: "Bootstrapped",
|
|
51
|
|
- /* If we are using System tor or the legacy Tor-Launcher */
|
|
52
|
|
- Disabled: "Disabled",
|
|
53
|
|
-});
|
|
54
|
|
-
|
|
55
|
38
|
/**
|
|
56
|
39
|
* A class for exceptions thrown during the bootstrap process.
|
|
57
|
40
|
*/
|
| ... |
... |
@@ -92,15 +75,11 @@ ChromeUtils.defineLazyGetter(lazy, "logger", () => |
|
92
|
75
|
/* Topics Notified by the TorConnect module */
|
|
93
|
76
|
export const TorConnectTopics = Object.freeze({
|
|
94
|
77
|
StageChange: "torconnect:stage-change",
|
|
95
|
|
- // TODO: Remove torconnect:state-change when pages have switched to stage.
|
|
96
|
|
- StateChange: "torconnect:state-change",
|
|
97
|
78
|
QuickstartChange: "torconnect:quickstart-change",
|
|
98
|
79
|
InternetStatusChange: "torconnect:internet-status-change",
|
|
99
|
80
|
RegionNamesChange: "torconnect:region-names-change",
|
|
100
|
81
|
BootstrapProgress: "torconnect:bootstrap-progress",
|
|
101
|
82
|
BootstrapComplete: "torconnect:bootstrap-complete",
|
|
102
|
|
- // TODO: Remove torconnect:error when pages have switched to stage.
|
|
103
|
|
- Error: "torconnect:error",
|
|
104
|
83
|
});
|
|
105
|
84
|
|
|
106
|
85
|
/**
|
| ... |
... |
@@ -1025,7 +1004,6 @@ export const TorConnect = { |
|
1025
|
1004
|
}
|
|
1026
|
1005
|
|
|
1027
|
1006
|
lazy.logger.info(`Entering stage ${name}`);
|
|
1028
|
|
- const prevState = this.state;
|
|
1029
|
1007
|
this._stageName = name;
|
|
1030
|
1008
|
this._bootstrappingStatus.hasWarning = false;
|
|
1031
|
1009
|
this._bootstrappingStatus.progress =
|
| ... |
... |
@@ -1033,15 +1011,6 @@ export const TorConnect = { |
|
1033
|
1011
|
|
|
1034
|
1012
|
Services.obs.notifyObservers(this.stage, TorConnectTopics.StageChange);
|
|
1035
|
1013
|
|
|
1036
|
|
- // TODO: Remove when all pages have switched to stage.
|
|
1037
|
|
- const newState = this.state;
|
|
1038
|
|
- if (prevState !== newState) {
|
|
1039
|
|
- Services.obs.notifyObservers(
|
|
1040
|
|
- { state: newState },
|
|
1041
|
|
- TorConnectTopics.StateChange
|
|
1042
|
|
- );
|
|
1043
|
|
- }
|
|
1044
|
|
-
|
|
1045
|
1014
|
// Update the progress after the stage has changed.
|
|
1046
|
1015
|
this._notifyBootstrapProgress();
|
|
1047
|
1016
|
},
|
| ... |
... |
@@ -1117,41 +1086,6 @@ export const TorConnect = { |
|
1117
|
1086
|
);
|
|
1118
|
1087
|
},
|
|
1119
|
1088
|
|
|
1120
|
|
- // TODO: Remove when all pages have switched to "stage".
|
|
1121
|
|
- get state() {
|
|
1122
|
|
- // There is no "Error" stage, but about:torconnect relies on receiving the
|
|
1123
|
|
- // Error state to update its display. So we temporarily set the stage for a
|
|
1124
|
|
- // StateChange signal.
|
|
1125
|
|
- if (this._isErrorState) {
|
|
1126
|
|
- return TorConnectState.Error;
|
|
1127
|
|
- }
|
|
1128
|
|
- switch (this._stageName) {
|
|
1129
|
|
- case TorConnectStage.Disabled:
|
|
1130
|
|
- return TorConnectState.Disabled;
|
|
1131
|
|
- case TorConnectStage.Loading:
|
|
1132
|
|
- return TorConnectState.Initial;
|
|
1133
|
|
- case TorConnectStage.Start:
|
|
1134
|
|
- case TorConnectStage.Offline:
|
|
1135
|
|
- case TorConnectStage.ChooseRegion:
|
|
1136
|
|
- case TorConnectStage.RegionNotFound:
|
|
1137
|
|
- case TorConnectStage.ConfirmRegion:
|
|
1138
|
|
- case TorConnectStage.FinalError:
|
|
1139
|
|
- return TorConnectState.Configuring;
|
|
1140
|
|
- case TorConnectStage.Bootstrapping:
|
|
1141
|
|
- if (
|
|
1142
|
|
- this._bootstrapTrigger === TorConnectStage.Start ||
|
|
1143
|
|
- this._bootstrapTrigger === TorConnectStage.Offline
|
|
1144
|
|
- ) {
|
|
1145
|
|
- return TorConnectState.Bootstrapping;
|
|
1146
|
|
- }
|
|
1147
|
|
- return TorConnectState.AutoBootstrapping;
|
|
1148
|
|
- case TorConnectStage.Bootstrapped:
|
|
1149
|
|
- return TorConnectState.Bootstrapped;
|
|
1150
|
|
- }
|
|
1151
|
|
- lazy.logger.error(`Unknown state at stage ${this._stageName}`);
|
|
1152
|
|
- return null;
|
|
1153
|
|
- },
|
|
1154
|
|
-
|
|
1155
|
1089
|
/**
|
|
1156
|
1090
|
* Get a map of all region codes and their localized names.
|
|
1157
|
1091
|
*
|
| ... |
... |
@@ -1191,38 +1125,6 @@ export const TorConnect = { |
|
1191
|
1125
|
}
|
|
1192
|
1126
|
},
|
|
1193
|
1127
|
|
|
1194
|
|
- /**
|
|
1195
|
|
- * Signal an error to listeners.
|
|
1196
|
|
- *
|
|
1197
|
|
- * @param {Error} error - The error.
|
|
1198
|
|
- */
|
|
1199
|
|
- _signalError(error) {
|
|
1200
|
|
- // TODO: Replace this method with _setError without any signalling when
|
|
1201
|
|
- // pages have switched to stage.
|
|
1202
|
|
- // Currently it simulates the old behaviour for about:torconnect.
|
|
1203
|
|
- lazy.logger.debug("Signalling error", error);
|
|
1204
|
|
-
|
|
1205
|
|
- if (error instanceof lazy.TorBootstrapError) {
|
|
1206
|
|
- error = new TorConnectError(TorConnectError.BootstrapError, error);
|
|
1207
|
|
- } else if (!(error instanceof TorConnectError)) {
|
|
1208
|
|
- error = new TorConnectError(TorConnectError.ExternalError, error);
|
|
1209
|
|
- }
|
|
1210
|
|
- this._errorDetails = error;
|
|
1211
|
|
-
|
|
1212
|
|
- // Temporarily set an error state for listeners.
|
|
1213
|
|
- // We send the Error signal before the "StateChange" signal.
|
|
1214
|
|
- // Expected on android `onBootstrapError` to set lastKnownError.
|
|
1215
|
|
- // Expected in about:torconnect to set the error codes and internet status
|
|
1216
|
|
- // *before* the StateChange signal.
|
|
1217
|
|
- this._isErrorState = true;
|
|
1218
|
|
- Services.obs.notifyObservers(error, TorConnectTopics.Error);
|
|
1219
|
|
- Services.obs.notifyObservers(
|
|
1220
|
|
- { state: this.state },
|
|
1221
|
|
- TorConnectTopics.StateChange
|
|
1222
|
|
- );
|
|
1223
|
|
- this._isErrorState = false;
|
|
1224
|
|
- },
|
|
1225
|
|
-
|
|
1226
|
1128
|
/**
|
|
1227
|
1129
|
* Add simulation options to the bootstrap request.
|
|
1228
|
1130
|
*
|
| ... |
... |
@@ -1463,7 +1365,7 @@ export const TorConnect = { |
|
1463
|
1365
|
// bootstrap being thrown, but we do not want to cancel a bootstrap
|
|
1464
|
1366
|
// attempt prematurely in case the offline state is intermittent or
|
|
1465
|
1367
|
// incorrect.
|
|
1466
|
|
- this._signalError(new TorConnectError(TorConnectError.Offline));
|
|
|
1368
|
+ this._errorDetails = new TorConnectError(TorConnectError.Offline);
|
|
1467
|
1369
|
this._setStage(TorConnectStage.Offline);
|
|
1468
|
1370
|
return;
|
|
1469
|
1371
|
}
|
| ... |
... |
@@ -1472,7 +1374,19 @@ export const TorConnect = { |
|
1472
|
1374
|
// Disable quickstart until we have a successful bootstrap.
|
|
1473
|
1375
|
Services.prefs.setBoolPref(TorConnectPrefs.prompt_at_startup, true);
|
|
1474
|
1376
|
|
|
1475
|
|
- this._signalError(error);
|
|
|
1377
|
+ let connectError = error;
|
|
|
1378
|
+ if (error instanceof lazy.TorBootstrapError) {
|
|
|
1379
|
+ connectError = new TorConnectError(
|
|
|
1380
|
+ TorConnectError.BootstrapError,
|
|
|
1381
|
+ error
|
|
|
1382
|
+ );
|
|
|
1383
|
+ } else if (!(error instanceof TorConnectError)) {
|
|
|
1384
|
+ connectError = new TorConnectError(
|
|
|
1385
|
+ TorConnectError.ExternalError,
|
|
|
1386
|
+ error
|
|
|
1387
|
+ );
|
|
|
1388
|
+ }
|
|
|
1389
|
+ this._errorDetails = connectError;
|
|
1476
|
1390
|
|
|
1477
|
1391
|
let errorStage = TorConnectStage.FinalError;
|
|
1478
|
1392
|
|
| ... |
... |
@@ -1518,12 +1432,6 @@ export const TorConnect = { |
|
1518
|
1432
|
lazy.logger.error(`Unexpected bootstrap result`, result);
|
|
1519
|
1433
|
}
|
|
1520
|
1434
|
|
|
1521
|
|
- // TODO: Remove this Offline hack when pages use "stage".
|
|
1522
|
|
- if (beginStage === TorConnectStage.Offline) {
|
|
1523
|
|
- // Re-send the "Offline" error to push the pages back to "Offline".
|
|
1524
|
|
- this._signalError(new TorConnectError(TorConnectError.Offline));
|
|
1525
|
|
- }
|
|
1526
|
|
-
|
|
1527
|
1435
|
// Return to the previous stage.
|
|
1528
|
1436
|
this._setStage(beginStage);
|
|
1529
|
1437
|
},
|