mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
snowflake proxy continues to poll broker until at capacity (#11)
This commit is contained in:
parent
490b8b33b7
commit
afd814773a
1 changed files with 15 additions and 11 deletions
|
@ -85,11 +85,14 @@ class Snowflake
|
||||||
return if COPY_PASTE_ENABLED
|
return if COPY_PASTE_ENABLED
|
||||||
log 'ProxyPair Slots: ' + @proxyPairs.length
|
log 'ProxyPair Slots: ' + @proxyPairs.length
|
||||||
log 'Snowflake IDs: ' + (@proxyPairs.map (p) -> p.id).join ' | '
|
log 'Snowflake IDs: ' + (@proxyPairs.map (p) -> p.id).join ' | '
|
||||||
|
@pollBroker()
|
||||||
|
|
||||||
timer = null
|
# Regularly poll Broker for clients to serve until this snowflake is
|
||||||
# Temporary countdown.
|
# serving at capacity, at which point stop polling.
|
||||||
|
pollBroker: ->
|
||||||
|
# Temporary countdown. TODO: Simplify
|
||||||
countdown = (msg, sec) =>
|
countdown = (msg, sec) =>
|
||||||
@ui.setStatus msg + ' (Retrying in ' + sec + ' seconds...)'
|
@ui.setStatus msg + ' (Polling in ' + sec + ' seconds...)'
|
||||||
sec--
|
sec--
|
||||||
if sec >= 0
|
if sec >= 0
|
||||||
setTimeout((-> countdown(msg, sec)), 1000)
|
setTimeout((-> countdown(msg, sec)), 1000)
|
||||||
|
@ -97,18 +100,18 @@ class Snowflake
|
||||||
findClients()
|
findClients()
|
||||||
# Poll broker for clients.
|
# Poll broker for clients.
|
||||||
findClients = =>
|
findClients = =>
|
||||||
clearTimeout timer
|
pair = @nextAvailableProxyPair()
|
||||||
|
if !pair
|
||||||
|
log 'At client capacity.'
|
||||||
|
# Do nothing until a new proxyPair is available.
|
||||||
|
return
|
||||||
msg = 'polling for client... '
|
msg = 'polling for client... '
|
||||||
msg += '[retries: ' + @retries + ']' if @retries > 0
|
msg += '[retries: ' + @retries + ']' if @retries > 0
|
||||||
@ui.setStatus msg
|
@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)
|
|
||||||
return
|
|
||||||
recv = @broker.getClientOffer pair.id
|
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) ->
|
, (err) ->
|
||||||
countdown(err, DEFAULT_BROKER_POLL_INTERVAL / 1000)
|
countdown(err, DEFAULT_BROKER_POLL_INTERVAL / 1000)
|
||||||
@retries++
|
@retries++
|
||||||
|
@ -144,6 +147,7 @@ class Snowflake
|
||||||
pair.onCleanup = (event) =>
|
pair.onCleanup = (event) =>
|
||||||
# Delete from the list of active proxy pairs.
|
# Delete from the list of active proxy pairs.
|
||||||
@proxyPairs.splice(@proxyPairs.indexOf(pair), 1)
|
@proxyPairs.splice(@proxyPairs.indexOf(pair), 1)
|
||||||
|
@pollBroker()
|
||||||
pair.begin()
|
pair.begin()
|
||||||
|
|
||||||
# Stop all proxypairs.
|
# Stop all proxypairs.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue