mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 11:11:30 -04:00
Close over init so that we can return if a feature isn't detected
I guess alternatively, just use an if/else block.
This commit is contained in:
parent
f97c37fe5d
commit
27a92ab03a
2 changed files with 130 additions and 121 deletions
|
@ -2,72 +2,78 @@
|
||||||
Entry point.
|
Entry point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) {
|
var snowflake, query, debug, silenceNotifications, log, dbg, init;
|
||||||
console.log('webrtc feature not detected. shutting down');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var snowflake = null;
|
;(function() {
|
||||||
|
|
||||||
var query = Query.parse(location);
|
if (((typeof TESTING === "undefined" || TESTING === null) || !TESTING) && !Util.featureDetect()) {
|
||||||
|
console.log('webrtc feature not detected. shutting down');
|
||||||
var debug = Params.getBool(query, 'debug', false);
|
|
||||||
|
|
||||||
var silenceNotifications = Params.getBool(query, 'silent', false);
|
|
||||||
|
|
||||||
// Log to both console and UI if applicable.
|
|
||||||
// Requires that the snowflake and UI objects are hooked up in order to
|
|
||||||
// log to console.
|
|
||||||
var log = function(msg) {
|
|
||||||
console.log('Snowflake: ' + msg);
|
|
||||||
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
var dbg = function(msg) {
|
|
||||||
if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) {
|
|
||||||
return log(msg);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var init = function() {
|
|
||||||
var broker, config, ui;
|
|
||||||
config = new Config;
|
|
||||||
if ('off' !== query['ratelimit']) {
|
|
||||||
config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes);
|
|
||||||
}
|
|
||||||
ui = null;
|
|
||||||
if (document.getElementById('badge') !== null) {
|
|
||||||
ui = new BadgeUI();
|
|
||||||
} else if (document.getElementById('status') !== null) {
|
|
||||||
ui = new DebugUI();
|
|
||||||
} else {
|
|
||||||
ui = new UI();
|
|
||||||
}
|
|
||||||
broker = new Broker(config.brokerUrl);
|
|
||||||
snowflake = new Snowflake(config, ui, broker);
|
|
||||||
log('== snowflake proxy ==');
|
|
||||||
if (Util.snowflakeIsDisabled(config.cookieName)) {
|
|
||||||
// Do not activate the proxy if any number of conditions are true.
|
|
||||||
log('Currently not active.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Otherwise, begin setting up WebRTC and acting as a proxy.
|
|
||||||
dbg('Contacting Broker at ' + broker.url);
|
|
||||||
snowflake.setRelayAddr(config.relayAddr);
|
|
||||||
return snowflake.beginWebRTC();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Notification of closing tab with active proxy.
|
snowflake = null;
|
||||||
window.onbeforeunload = function() {
|
|
||||||
if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) {
|
|
||||||
return Snowflake.MESSAGE.CONFIRMATION;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onunload = function() {
|
query = Query.parse(location);
|
||||||
snowflake.disable();
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onload = init;
|
debug = Params.getBool(query, 'debug', false);
|
||||||
|
|
||||||
|
silenceNotifications = Params.getBool(query, 'silent', false);
|
||||||
|
|
||||||
|
// Log to both console and UI if applicable.
|
||||||
|
// Requires that the snowflake and UI objects are hooked up in order to
|
||||||
|
// log to console.
|
||||||
|
log = function(msg) {
|
||||||
|
console.log('Snowflake: ' + msg);
|
||||||
|
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
dbg = function(msg) {
|
||||||
|
if (debug || ((snowflake != null ? snowflake.ui : void 0) instanceof DebugUI)) {
|
||||||
|
return log(msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
init = function() {
|
||||||
|
var broker, config, ui;
|
||||||
|
config = new Config;
|
||||||
|
if ('off' !== query['ratelimit']) {
|
||||||
|
config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes);
|
||||||
|
}
|
||||||
|
ui = null;
|
||||||
|
if (document.getElementById('badge') !== null) {
|
||||||
|
ui = new BadgeUI();
|
||||||
|
} else if (document.getElementById('status') !== null) {
|
||||||
|
ui = new DebugUI();
|
||||||
|
} else {
|
||||||
|
ui = new UI();
|
||||||
|
}
|
||||||
|
broker = new Broker(config.brokerUrl);
|
||||||
|
snowflake = new Snowflake(config, ui, broker);
|
||||||
|
log('== snowflake proxy ==');
|
||||||
|
if (Util.snowflakeIsDisabled(config.cookieName)) {
|
||||||
|
// Do not activate the proxy if any number of conditions are true.
|
||||||
|
log('Currently not active.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Otherwise, begin setting up WebRTC and acting as a proxy.
|
||||||
|
dbg('Contacting Broker at ' + broker.url);
|
||||||
|
snowflake.setRelayAddr(config.relayAddr);
|
||||||
|
return snowflake.beginWebRTC();
|
||||||
|
};
|
||||||
|
|
||||||
|
// Notification of closing tab with active proxy.
|
||||||
|
window.onbeforeunload = function() {
|
||||||
|
if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) {
|
||||||
|
return Snowflake.MESSAGE.CONFIRMATION;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onunload = function() {
|
||||||
|
snowflake.disable();
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onload = init;
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
|
@ -2,73 +2,76 @@
|
||||||
Entry point.
|
Entry point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var debug = false;
|
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications;
|
||||||
|
|
||||||
var snowflake = null;
|
;(function () {
|
||||||
|
|
||||||
var config = null;
|
silenceNotifications = false;
|
||||||
|
debug = false;
|
||||||
|
snowflake = null;
|
||||||
|
config = null;
|
||||||
|
broker = null;
|
||||||
|
ui = null;
|
||||||
|
|
||||||
var broker = null;
|
// Log to both console and UI if applicable.
|
||||||
|
// Requires that the snowflake and UI objects are hooked up in order to
|
||||||
|
// log to console.
|
||||||
|
log = function(msg) {
|
||||||
|
console.log('Snowflake: ' + msg);
|
||||||
|
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
||||||
|
};
|
||||||
|
|
||||||
var ui = null;
|
dbg = function(msg) {
|
||||||
|
if (debug) {
|
||||||
|
return log(msg);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Log to both console and UI if applicable.
|
if (!Util.featureDetect()) {
|
||||||
// Requires that the snowflake and UI objects are hooked up in order to
|
chrome.runtime.onConnect.addListener(function(port) {
|
||||||
// log to console.
|
return port.postMessage({
|
||||||
var log = function(msg) {
|
missingFeature: true
|
||||||
console.log('Snowflake: ' + msg);
|
});
|
||||||
return snowflake != null ? snowflake.ui.log(msg) : void 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
var dbg = function(msg) {
|
|
||||||
if (debug) {
|
|
||||||
return log(msg);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!Util.featureDetect()) {
|
|
||||||
chrome.runtime.onConnect.addListener(function(port) {
|
|
||||||
return port.postMessage({
|
|
||||||
missingFeature: true
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var init = function() {
|
|
||||||
config = new Config;
|
|
||||||
ui = new WebExtUI();
|
|
||||||
broker = new Broker(config.brokerUrl);
|
|
||||||
snowflake = new Snowflake(config, ui, broker);
|
|
||||||
log('== snowflake proxy ==');
|
|
||||||
return ui.initToggle();
|
|
||||||
};
|
|
||||||
|
|
||||||
var update = function() {
|
|
||||||
if (!ui.enabled) {
|
|
||||||
// Do not activate the proxy if any number of conditions are true.
|
|
||||||
snowflake.disable();
|
|
||||||
log('Currently not active.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Otherwise, begin setting up WebRTC and acting as a proxy.
|
|
||||||
dbg('Contacting Broker at ' + broker.url);
|
|
||||||
log('Starting snowflake');
|
|
||||||
snowflake.setRelayAddr(config.relayAddr);
|
|
||||||
return snowflake.beginWebRTC();
|
|
||||||
};
|
|
||||||
|
|
||||||
// Notification of closing tab with active proxy.
|
init = function() {
|
||||||
window.onbeforeunload = function() {
|
config = new Config;
|
||||||
if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) {
|
ui = new WebExtUI();
|
||||||
return Snowflake.MESSAGE.CONFIRMATION;
|
broker = new Broker(config.brokerUrl);
|
||||||
}
|
snowflake = new Snowflake(config, ui, broker);
|
||||||
return null;
|
log('== snowflake proxy ==');
|
||||||
};
|
return ui.initToggle();
|
||||||
|
};
|
||||||
|
|
||||||
window.onunload = function() {
|
update = function() {
|
||||||
snowflake.disable();
|
if (!ui.enabled) {
|
||||||
return null;
|
// Do not activate the proxy if any number of conditions are true.
|
||||||
};
|
snowflake.disable();
|
||||||
|
log('Currently not active.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Otherwise, begin setting up WebRTC and acting as a proxy.
|
||||||
|
dbg('Contacting Broker at ' + broker.url);
|
||||||
|
log('Starting snowflake');
|
||||||
|
snowflake.setRelayAddr(config.relayAddr);
|
||||||
|
return snowflake.beginWebRTC();
|
||||||
|
};
|
||||||
|
|
||||||
window.onload = init;
|
// Notification of closing tab with active proxy.
|
||||||
|
window.onbeforeunload = function() {
|
||||||
|
if (!silenceNotifications && Snowflake.MODE.WEBRTC_READY === snowflake.state) {
|
||||||
|
return Snowflake.MESSAGE.CONFIRMATION;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onunload = function() {
|
||||||
|
snowflake.disable();
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.onload = init;
|
||||||
|
|
||||||
|
}());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue