mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Removed "janky" snowflake state machine
The only place it was used was in window.onpageunload, and we have a better way of determining if the proxy is active there (through the ui). I also removed that code from the webextension since the proxy won't stop running unless you close the browser and after testing it looks like that code doesn't notify the user anyway.
This commit is contained in:
parent
338f1792b8
commit
9b470fbe4b
6 changed files with 11 additions and 36 deletions
|
@ -193,7 +193,7 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
|
||||||
if (
|
if (
|
||||||
!silenceNotifications &&
|
!silenceNotifications &&
|
||||||
snowflake !== null &&
|
snowflake !== null &&
|
||||||
Snowflake.MODE.WEBRTC_READY === snowflake.state
|
ui.active
|
||||||
) {
|
) {
|
||||||
return Snowflake.MESSAGE.CONFIRMATION;
|
return Snowflake.MESSAGE.CONFIRMATION;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ DebugUI.prototype.$status = null;
|
||||||
Entry point.
|
Entry point.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var snowflake, query, debug, silenceNotifications, log, dbg, init;
|
var snowflake, query, debug, ui, silenceNotifications, log, dbg, init;
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ var snowflake, query, debug, silenceNotifications, log, dbg, init;
|
||||||
if (
|
if (
|
||||||
!silenceNotifications &&
|
!silenceNotifications &&
|
||||||
snowflake !== null &&
|
snowflake !== null &&
|
||||||
Snowflake.MODE.WEBRTC_READY === snowflake.state
|
ui.active
|
||||||
) {
|
) {
|
||||||
return Snowflake.MESSAGE.CONFIRMATION;
|
return Snowflake.MESSAGE.CONFIRMATION;
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,18 +193,6 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
|
||||||
return snowflake.beginWebRTC();
|
return snowflake.beginWebRTC();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Notification of closing tab with active proxy.
|
|
||||||
window.onbeforeunload = function() {
|
|
||||||
if (
|
|
||||||
!silenceNotifications &&
|
|
||||||
snowflake !== null &&
|
|
||||||
Snowflake.MODE.WEBRTC_READY === snowflake.state
|
|
||||||
) {
|
|
||||||
return Snowflake.MESSAGE.CONFIRMATION;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onunload = function() {
|
window.onunload = function() {
|
||||||
if (snowflake !== null) { snowflake.disable(); }
|
if (snowflake !== null) { snowflake.disable(); }
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* global snowflake, log, dbg, Util, PeerConnection, Snowflake, Parse, WS */
|
/* global snowflake, log, dbg, Util, PeerConnection, Parse, WS */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Represents a single:
|
Represents a single:
|
||||||
|
@ -89,7 +89,6 @@ class ProxyPair {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.running = true;
|
this.running = true;
|
||||||
snowflake.state = Snowflake.MODE.WEBRTC_READY;
|
|
||||||
snowflake.ui.setActive(true);
|
snowflake.ui.setActive(true);
|
||||||
// This is the point when the WebRTC datachannel is done, so the next step
|
// This is the point when the WebRTC datachannel is done, so the next step
|
||||||
// is to establish websocket to the server.
|
// is to establish websocket to the server.
|
||||||
|
@ -99,7 +98,6 @@ class ProxyPair {
|
||||||
log('WebRTC DataChannel closed.');
|
log('WebRTC DataChannel closed.');
|
||||||
snowflake.ui.setStatus('disconnected by webrtc.');
|
snowflake.ui.setStatus('disconnected by webrtc.');
|
||||||
snowflake.ui.setActive(false);
|
snowflake.ui.setActive(false);
|
||||||
snowflake.state = Snowflake.MODE.INIT;
|
|
||||||
this.flush();
|
this.flush();
|
||||||
return this.close();
|
return this.close();
|
||||||
};
|
};
|
||||||
|
@ -139,7 +137,6 @@ class ProxyPair {
|
||||||
log(relay.label + ' closed.');
|
log(relay.label + ' closed.');
|
||||||
snowflake.ui.setStatus('disconnected.');
|
snowflake.ui.setStatus('disconnected.');
|
||||||
snowflake.ui.setActive(false);
|
snowflake.ui.setActive(false);
|
||||||
snowflake.state = Snowflake.MODE.INIT;
|
|
||||||
this.flush();
|
this.flush();
|
||||||
return this.close();
|
return this.close();
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,7 +22,6 @@ class Snowflake {
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.ui = ui;
|
this.ui = ui;
|
||||||
this.broker = broker;
|
this.broker = broker;
|
||||||
this.state = Snowflake.MODE.INIT;
|
|
||||||
this.proxyPairs = [];
|
this.proxyPairs = [];
|
||||||
if (void 0 === this.config.rateLimitBytes) {
|
if (void 0 === this.config.rateLimitBytes) {
|
||||||
this.rateLimit = new DummyRateLimit();
|
this.rateLimit = new DummyRateLimit();
|
||||||
|
@ -44,7 +43,6 @@ class Snowflake {
|
||||||
// Initialize WebRTC PeerConnection, which requires beginning the signalling
|
// Initialize WebRTC PeerConnection, which requires beginning the signalling
|
||||||
// process. |pollBroker| automatically arranges signalling.
|
// process. |pollBroker| automatically arranges signalling.
|
||||||
beginWebRTC() {
|
beginWebRTC() {
|
||||||
this.state = Snowflake.MODE.WEBRTC_CONNECTING;
|
|
||||||
log('ProxyPair Slots: ' + this.proxyPairs.length);
|
log('ProxyPair Slots: ' + this.proxyPairs.length);
|
||||||
log('Snowflake IDs: ' + (this.proxyPairs.map(function(p) {
|
log('Snowflake IDs: ' + (this.proxyPairs.map(function(p) {
|
||||||
return p.id;
|
return p.id;
|
||||||
|
@ -173,13 +171,6 @@ Snowflake.prototype.pollInterval = null;
|
||||||
|
|
||||||
Snowflake.prototype.retries = 0;
|
Snowflake.prototype.retries = 0;
|
||||||
|
|
||||||
// Janky state machine
|
|
||||||
Snowflake.MODE = {
|
|
||||||
INIT: 0,
|
|
||||||
WEBRTC_CONNECTING: 1,
|
|
||||||
WEBRTC_READY: 2
|
|
||||||
};
|
|
||||||
|
|
||||||
Snowflake.MESSAGE = {
|
Snowflake.MESSAGE = {
|
||||||
CONFIRMATION: 'You\'re currently serving a Tor user via Snowflake.'
|
CONFIRMATION: 'You\'re currently serving a Tor user via Snowflake.'
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,29 +6,28 @@ var snowflake = {
|
||||||
ui: new UI,
|
ui: new UI,
|
||||||
broker: {
|
broker: {
|
||||||
sendAnswer: function() {}
|
sendAnswer: function() {}
|
||||||
},
|
}
|
||||||
state: Snowflake.MODE.INIT
|
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('Init', function() {
|
describe('Init', function() {
|
||||||
|
|
||||||
it('gives a dialog when closing, only while active', function() {
|
it('gives a dialog when closing, only while active', function() {
|
||||||
silenceNotifications = false;
|
silenceNotifications = false;
|
||||||
snowflake.state = Snowflake.MODE.WEBRTC_READY;
|
ui.setActive(true);
|
||||||
var msg = window.onbeforeunload();
|
var msg = window.onbeforeunload();
|
||||||
expect(snowflake.state).toBe(Snowflake.MODE.WEBRTC_READY);
|
expect(ui.active).toBe(true);
|
||||||
expect(msg).toBe(Snowflake.MESSAGE.CONFIRMATION);
|
expect(msg).toBe(Snowflake.MESSAGE.CONFIRMATION);
|
||||||
snowflake.state = Snowflake.MODE.INIT;
|
ui.setActive(false);
|
||||||
msg = window.onbeforeunload();
|
msg = window.onbeforeunload();
|
||||||
expect(snowflake.state).toBe(Snowflake.MODE.INIT);
|
expect(ui.active).toBe(false);
|
||||||
expect(msg).toBe(null);
|
expect(msg).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not give a dialog when silent flag is on', function() {
|
it('does not give a dialog when silent flag is on', function() {
|
||||||
silenceNotifications = true;
|
silenceNotifications = true;
|
||||||
snowflake.state = Snowflake.MODE.WEBRTC_READY;
|
ui.setActive(true);
|
||||||
var msg = window.onbeforeunload();
|
var msg = window.onbeforeunload();
|
||||||
expect(snowflake.state).toBe(Snowflake.MODE.WEBRTC_READY);
|
expect(ui.active).toBe(true);
|
||||||
expect(msg).toBe(null);
|
expect(msg).toBe(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue