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

[tor-commits] [snowflake/master] Move querystring access to init



commit edbbea1d0336098a767b7426bc558c90c7746bd1
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date:   Wed May 8 14:08:22 2019 -0400

    Move querystring access to init
---
 proxy/init.coffee                | 16 ++++++++++------
 proxy/snowflake.coffee           |  6 +-----
 proxy/spec/snowflake.spec.coffee |  2 --
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/proxy/init.coffee b/proxy/init.coffee
index d3101c3..497a54f 100644
--- a/proxy/init.coffee
+++ b/proxy/init.coffee
@@ -9,12 +9,8 @@ RELAY =
   # port: 9902
 COOKIE_NAME = "snowflake-allow"
 
-silenceNotifications = false
-query = Query.parse(location)
-DEBUG = Params.getBool(query, 'debug', false)
-
 # Bytes per second. Set to undefined to disable limit.
-DEFAULT_RATE_LIMIT = DEFAULT_RATE_LIMIT || undefined
+DEFAULT_RATE_LIMIT = undefined
 MIN_RATE_LIMIT = 10 * 1024
 RATE_LIMIT_HISTORY = 5.0
 DEFAULT_BROKER_POLL_INTERVAL = 5.0 * 1000
@@ -31,7 +27,11 @@ config = {
 
 CONFIRMATION_MESSAGE = 'You\'re currently serving a Tor user via Snowflake.'
 
+query = Query.parse(location)
+DEBUG = Params.getBool(query, 'debug', false)
+
 snowflake = null
+silenceNotifications = false
 
 # Log to both console and UI if applicable.
 # Requires that the snowflake and UI objects are hooked up in order to
@@ -57,9 +57,13 @@ init = () ->
   else
     ui = new UI()
 
+  rateLimitBytes = undefined
+  if 'off' != query['ratelimit']
+    rateLimitBytes = Params.getByteCount(query, 'ratelimit', DEFAULT_RATE_LIMIT)
+
   silenceNotifications = Params.getBool(query, 'silent', false)
   broker = new Broker BROKER
-  snowflake = new Snowflake broker, ui
+  snowflake = new Snowflake broker, ui, rateLimitBytes
 
   log '== snowflake proxy =='
   if Util.snowflakeIsDisabled()
diff --git a/proxy/snowflake.coffee b/proxy/snowflake.coffee
index 9656c0b..fa421ee 100644
--- a/proxy/snowflake.coffee
+++ b/proxy/snowflake.coffee
@@ -22,14 +22,10 @@ class Snowflake
     WEBRTC_READY:      2
 
   # Prepare the Snowflake with a Broker (to find clients) and optional UI.
-  constructor: (@broker, @ui) ->
+  constructor: (@broker, @ui, rateLimitBytes) ->
     @state = Snowflake.MODE.INIT
     @proxyPairs = []
 
-    rateLimitBytes = undefined
-    if 'off' != query['ratelimit']
-      rateLimitBytes = Params.getByteCount(query, 'ratelimit',
-                                           DEFAULT_RATE_LIMIT)
     if undefined == rateLimitBytes
       @rateLimit = new DummyRateLimit()
     else
diff --git a/proxy/spec/snowflake.spec.coffee b/proxy/spec/snowflake.spec.coffee
index bb6e348..a619a06 100644
--- a/proxy/spec/snowflake.spec.coffee
+++ b/proxy/spec/snowflake.spec.coffee
@@ -2,7 +2,6 @@
 jasmine tests for Snowflake
 ###
 
-query = {}
 # Fake browser functionality:
 class PeerConnection
   setRemoteDescription: ->
@@ -31,7 +30,6 @@ describe 'Snowflake', ->
 
   it 'constructs correctly', ->
     s = new Snowflake({ fake: 'broker' }, fakeUI)
-    query['ratelimit'] = 'off'
     expect(s.rateLimit).not.toBeNull()
     expect(s.broker).toEqual { fake: 'broker' }
     expect(s.ui).not.toBeNull()



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