commit 9b470fbe4b8429070559d2e895b9be45509cdf78 Author: Cecylia Bocovich cohosh@torproject.org Date: Fri Oct 18 15:10:03 2019 -0400
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. --- proxy/init-badge.js | 2 +- proxy/init-testing.js | 4 ++-- proxy/init-webext.js | 12 ------------ proxy/proxypair.js | 5 +---- proxy/snowflake.js | 9 --------- proxy/spec/init.spec.js | 15 +++++++-------- 6 files changed, 11 insertions(+), 36 deletions(-)
diff --git a/proxy/init-badge.js b/proxy/init-badge.js index fe8cc91..2cc5b07 100644 --- a/proxy/init-badge.js +++ b/proxy/init-badge.js @@ -193,7 +193,7 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific if ( !silenceNotifications && snowflake !== null && - Snowflake.MODE.WEBRTC_READY === snowflake.state + ui.active ) { return Snowflake.MESSAGE.CONFIRMATION; } diff --git a/proxy/init-testing.js b/proxy/init-testing.js index 5b63099..90026a9 100644 --- a/proxy/init-testing.js +++ b/proxy/init-testing.js @@ -46,7 +46,7 @@ DebugUI.prototype.$status = null; Entry point. */
-var snowflake, query, debug, silenceNotifications, log, dbg, init; +var snowflake, query, debug, ui, silenceNotifications, log, dbg, init;
(function() {
@@ -108,7 +108,7 @@ var snowflake, query, debug, silenceNotifications, log, dbg, init; if ( !silenceNotifications && snowflake !== null && - Snowflake.MODE.WEBRTC_READY === snowflake.state + ui.active ) { return Snowflake.MESSAGE.CONFIRMATION; } diff --git a/proxy/init-webext.js b/proxy/init-webext.js index 6789ffd..ad345fa 100644 --- a/proxy/init-webext.js +++ b/proxy/init-webext.js @@ -193,18 +193,6 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific 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() { if (snowflake !== null) { snowflake.disable(); } return null; diff --git a/proxy/proxypair.js b/proxy/proxypair.js index 58efa1a..9f6a7b2 100644 --- a/proxy/proxypair.js +++ b/proxy/proxypair.js @@ -1,4 +1,4 @@ -/* global snowflake, log, dbg, Util, PeerConnection, Snowflake, Parse, WS */ +/* global snowflake, log, dbg, Util, PeerConnection, Parse, WS */
/* Represents a single: @@ -89,7 +89,6 @@ class ProxyPair { return; } this.running = true; - snowflake.state = Snowflake.MODE.WEBRTC_READY; snowflake.ui.setActive(true); // This is the point when the WebRTC datachannel is done, so the next step // is to establish websocket to the server. @@ -99,7 +98,6 @@ class ProxyPair { log('WebRTC DataChannel closed.'); snowflake.ui.setStatus('disconnected by webrtc.'); snowflake.ui.setActive(false); - snowflake.state = Snowflake.MODE.INIT; this.flush(); return this.close(); }; @@ -139,7 +137,6 @@ class ProxyPair { log(relay.label + ' closed.'); snowflake.ui.setStatus('disconnected.'); snowflake.ui.setActive(false); - snowflake.state = Snowflake.MODE.INIT; this.flush(); return this.close(); }; diff --git a/proxy/snowflake.js b/proxy/snowflake.js index cdc59fb..78b1d0e 100644 --- a/proxy/snowflake.js +++ b/proxy/snowflake.js @@ -22,7 +22,6 @@ class Snowflake { this.config = config; this.ui = ui; this.broker = broker; - this.state = Snowflake.MODE.INIT; this.proxyPairs = []; if (void 0 === this.config.rateLimitBytes) { this.rateLimit = new DummyRateLimit(); @@ -44,7 +43,6 @@ class Snowflake { // Initialize WebRTC PeerConnection, which requires beginning the signalling // process. |pollBroker| automatically arranges signalling. beginWebRTC() { - this.state = Snowflake.MODE.WEBRTC_CONNECTING; log('ProxyPair Slots: ' + this.proxyPairs.length); log('Snowflake IDs: ' + (this.proxyPairs.map(function(p) { return p.id; @@ -173,13 +171,6 @@ Snowflake.prototype.pollInterval = null;
Snowflake.prototype.retries = 0;
-// Janky state machine -Snowflake.MODE = { - INIT: 0, - WEBRTC_CONNECTING: 1, - WEBRTC_READY: 2 -}; - Snowflake.MESSAGE = { CONFIRMATION: 'You're currently serving a Tor user via Snowflake.' }; diff --git a/proxy/spec/init.spec.js b/proxy/spec/init.spec.js index 748bc86..593add9 100644 --- a/proxy/spec/init.spec.js +++ b/proxy/spec/init.spec.js @@ -6,29 +6,28 @@ var snowflake = { ui: new UI, broker: { sendAnswer: function() {} - }, - state: Snowflake.MODE.INIT + } };
describe('Init', function() {
it('gives a dialog when closing, only while active', function() { silenceNotifications = false; - snowflake.state = Snowflake.MODE.WEBRTC_READY; + ui.setActive(true); var msg = window.onbeforeunload(); - expect(snowflake.state).toBe(Snowflake.MODE.WEBRTC_READY); + expect(ui.active).toBe(true); expect(msg).toBe(Snowflake.MESSAGE.CONFIRMATION); - snowflake.state = Snowflake.MODE.INIT; + ui.setActive(false); msg = window.onbeforeunload(); - expect(snowflake.state).toBe(Snowflake.MODE.INIT); + expect(ui.active).toBe(false); expect(msg).toBe(null); });
it('does not give a dialog when silent flag is on', function() { silenceNotifications = true; - snowflake.state = Snowflake.MODE.WEBRTC_READY; + ui.setActive(true); var msg = window.onbeforeunload(); - expect(snowflake.state).toBe(Snowflake.MODE.WEBRTC_READY); + expect(ui.active).toBe(true); expect(msg).toBe(null); });
tor-commits@lists.torproject.org