[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/master] Make MODE a class constant



commit 9df66b15b1385a6fd314a4f4d9954ab54832f813
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Wed May 8 13:24:37 2019 -0400

    Make MODE a class constant
---
 proxy/init.coffee                |  8 +-------
 proxy/proxypair.coffee           |  6 +++---
 proxy/snowflake.coffee           | 11 +++++++++--
 proxy/spec/snowflake.spec.coffee | 14 +++++++-------
 4 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/proxy/init.coffee b/proxy/init.coffee
index 22d4315..d3101c3 100644
--- a/proxy/init.coffee
+++ b/proxy/init.coffee
@@ -29,12 +29,6 @@ config = {
   ]
 }
 
-# Janky state machine
-MODE =
-  INIT:              0
-  WEBRTC_CONNECTING: 1
-  WEBRTC_READY:      2
-
 CONFIRMATION_MESSAGE = 'You\'re currently serving a Tor user via Snowflake.'
 
 snowflake = null
@@ -80,7 +74,7 @@ init = () ->
 
 # Notification of closing tab with active proxy.
 window.onbeforeunload = ->
-  if !silenceNotifications && MODE.WEBRTC_READY == snowflake.state
+  if !silenceNotifications && Snowflake.MODE.WEBRTC_READY == snowflake.state
     return CONFIRMATION_MESSAGE
   null
 
diff --git a/proxy/proxypair.coffee b/proxy/proxypair.coffee
index 5a11f9a..da45784 100644
--- a/proxy/proxypair.coffee
+++ b/proxy/proxypair.coffee
@@ -68,7 +68,7 @@ class ProxyPair
   prepareDataChannel: (channel) =>
     channel.onopen = =>
       log 'WebRTC DataChannel opened!'
-      snowflake.state = MODE.WEBRTC_READY
+      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.
@@ -77,7 +77,7 @@ class ProxyPair
       log 'WebRTC DataChannel closed.'
       snowflake.ui?.setStatus 'disconnected by webrtc.'
       snowflake.ui?.setActive false
-      snowflake.state = MODE.INIT
+      snowflake.state = Snowflake.MODE.INIT
       @flush()
       @close()
       # TODO: Change this for multiplexing.
@@ -114,7 +114,7 @@ class ProxyPair
       log @relay.label + ' closed.'
       snowflake.ui?.setStatus 'disconnected.'
       snowflake.ui?.setActive false
-      snowflake.state = MODE.INIT
+      snowflake.state = Snowflake.MODE.INIT
       @flush()
       @close()
     @relay.onerror = @onError
diff --git a/proxy/snowflake.coffee b/proxy/snowflake.coffee
index 1cf6582..07c90c6 100644
--- a/proxy/snowflake.coffee
+++ b/proxy/snowflake.coffee
@@ -14,11 +14,18 @@ class Snowflake
   relayAddr:  null
   proxyPairs: []
   rateLimit:  null
-  state:      MODE.INIT
   retries:    0
 
+  # Janky state machine
+  @MODE =
+    INIT:              0
+    WEBRTC_CONNECTING: 1
+    WEBRTC_READY:      2
+
   # Prepare the Snowflake with a Broker (to find clients) and optional UI.
   constructor: (@broker, @ui) ->
+    @state = Snowflake.MODE.INIT
+
     rateLimitBytes = undefined
     if 'off' != query['ratelimit']
       rateLimitBytes = Params.getByteCount(query, 'ratelimit',
@@ -41,7 +48,7 @@ class Snowflake
   # Initialize WebRTC PeerConnection, which requires beginning the signalling
   # process. |pollBroker| automatically arranges signalling.
   beginWebRTC: ->
-    @state = MODE.WEBRTC_CONNECTING
+    @state = Snowflake.MODE.WEBRTC_CONNECTING
     for i in [1..CONNECTIONS_PER_CLIENT]
       @makeProxyPair @relayAddr
     log 'ProxyPair Slots: ' + @proxyPairs.length
diff --git a/proxy/spec/snowflake.spec.coffee b/proxy/spec/snowflake.spec.coffee
index 8c11a22..6986883 100644
--- a/proxy/spec/snowflake.spec.coffee
+++ b/proxy/spec/snowflake.spec.coffee
@@ -25,7 +25,7 @@ snowflake =
   ui: fakeUI
   broker:
     sendAnswer: ->
-  state: MODE.INIT
+  state: Snowflake.MODE.INIT
 
 describe 'Snowflake', ->
 
@@ -72,19 +72,19 @@ describe 'Snowflake', ->
 
   it 'gives a dialog when closing, only while active', ->
     silenceNotifications = false
-    snowflake.state = MODE.WEBRTC_READY
+    snowflake.state = Snowflake.MODE.WEBRTC_READY
     msg = window.onbeforeunload()
-    expect(snowflake.state).toBe MODE.WEBRTC_READY
+    expect(snowflake.state).toBe Snowflake.MODE.WEBRTC_READY
     expect(msg).toBe CONFIRMATION_MESSAGE
 
-    snowflake.state = MODE.INIT
+    snowflake.state = Snowflake.MODE.INIT
     msg = window.onbeforeunload()
-    expect(snowflake.state).toBe MODE.INIT
+    expect(snowflake.state).toBe Snowflake.MODE.INIT
     expect(msg).toBe null
 
   it 'does not give a dialog when silent flag is on', ->
     silenceNotifications = true
-    snowflake.state = MODE.WEBRTC_READY
+    snowflake.state = Snowflake.MODE.WEBRTC_READY
     msg = window.onbeforeunload()
-    expect(snowflake.state).toBe MODE.WEBRTC_READY
+    expect(snowflake.state).toBe Snowflake.MODE.WEBRTC_READY
     expect(msg).toBe null



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits