[tor-commits] [snowflake/master] snowflake proxy continues to poll broker until at capacity (#11)
arlo at torproject.org
arlo at torproject.org
Fri Mar 18 17:48:36 UTC 2016
commit afd814773ac8cdc4ad4f3d2eac05b0e41ff6f964
Author: Serene Han <keroserene+git at gmail.com>
Date: Thu Mar 17 15:57:38 2016 -0700
snowflake proxy continues to poll broker until at capacity (#11)
---
proxy/snowflake.coffee | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/proxy/snowflake.coffee b/proxy/snowflake.coffee
index 4f38029..9686f30 100644
--- a/proxy/snowflake.coffee
+++ b/proxy/snowflake.coffee
@@ -85,11 +85,14 @@ class Snowflake
return if COPY_PASTE_ENABLED
log 'ProxyPair Slots: ' + @proxyPairs.length
log 'Snowflake IDs: ' + (@proxyPairs.map (p) -> p.id).join ' | '
+ @pollBroker()
- timer = null
- # Temporary countdown.
+ # Regularly poll Broker for clients to serve until this snowflake is
+ # serving at capacity, at which point stop polling.
+ pollBroker: ->
+ # Temporary countdown. TODO: Simplify
countdown = (msg, sec) =>
- @ui.setStatus msg + ' (Retrying in ' + sec + ' seconds...)'
+ @ui.setStatus msg + ' (Polling in ' + sec + ' seconds...)'
sec--
if sec >= 0
setTimeout((-> countdown(msg, sec)), 1000)
@@ -97,18 +100,18 @@ class Snowflake
findClients()
# Poll broker for clients.
findClients = =>
- clearTimeout timer
- msg = 'polling for client... '
- msg += '[retries: ' + @retries + ']' if @retries > 0
- @ui.setStatus msg
- # Pick an available ProxyPair to poll with.
pair = @nextAvailableProxyPair()
if !pair
- log 'No more available ProxyPair slots.'
- countdown(err, DEFAULT_BROKER_POLL_INTERVAL / 1000)
+ log 'At client capacity.'
+ # Do nothing until a new proxyPair is available.
return
+ msg = 'polling for client... '
+ msg += '[retries: ' + @retries + ']' if @retries > 0
+ @ui.setStatus msg
recv = @broker.getClientOffer pair.id
- recv.then (desc) => @receiveOffer pair, desc
+ recv.then (desc) =>
+ @receiveOffer pair, desc
+ countdown('Serving 1 new client.', DEFAULT_BROKER_POLL_INTERVAL / 1000)
, (err) ->
countdown(err, DEFAULT_BROKER_POLL_INTERVAL / 1000)
@retries++
@@ -144,6 +147,7 @@ class Snowflake
pair.onCleanup = (event) =>
# Delete from the list of active proxy pairs.
@proxyPairs.splice(@proxyPairs.indexOf(pair), 1)
+ @pollBroker()
pair.begin()
# Stop all proxypairs.
More information about the tor-commits
mailing list