mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Stop resetting after every pair closes
This commit is contained in:
parent
58d07788c7
commit
b1116a1c35
4 changed files with 11 additions and 25 deletions
|
@ -54,7 +54,7 @@ window.onbeforeunload = ->
|
|||
null
|
||||
|
||||
window.onunload = ->
|
||||
pair.close() for pair in snowflake.proxyPairs
|
||||
snowflake.disable()
|
||||
null
|
||||
|
||||
window.onload = init
|
||||
|
|
|
@ -45,7 +45,7 @@ window.onbeforeunload = ->
|
|||
null
|
||||
|
||||
window.onunload = ->
|
||||
pair.close() for pair in snowflake.proxyPairs
|
||||
snowflake.disable()
|
||||
null
|
||||
|
||||
window.onload = init
|
||||
|
|
|
@ -78,8 +78,6 @@ class ProxyPair
|
|||
snowflake.state = Snowflake.MODE.INIT
|
||||
@flush()
|
||||
@close()
|
||||
# TODO: Change this for multiplexing.
|
||||
snowflake.reset()
|
||||
channel.onerror = -> log 'Data channel error!'
|
||||
channel.binaryType = "arraybuffer"
|
||||
channel.onmessage = @onClientToRelayMessage
|
||||
|
@ -149,6 +147,7 @@ class ProxyPair
|
|||
@client.close() if @webrtcIsReady()
|
||||
@relay.close() if @relayIsReady()
|
||||
relay = null
|
||||
@onCleanup()
|
||||
|
||||
# Send as much data in both directions as the rate limit currently allows.
|
||||
flush: =>
|
||||
|
|
|
@ -51,8 +51,6 @@ class Snowflake
|
|||
# process. |pollBroker| automatically arranges signalling.
|
||||
beginWebRTC: ->
|
||||
@state = Snowflake.MODE.WEBRTC_CONNECTING
|
||||
for i in [1..@config.connectionsPerClient]
|
||||
@makeProxyPair @relayAddr
|
||||
log 'ProxyPair Slots: ' + @proxyPairs.length
|
||||
log 'Snowflake IDs: ' + (@proxyPairs.map (p) -> p.id).join ' | '
|
||||
@pollBroker()
|
||||
|
@ -82,6 +80,8 @@ class Snowflake
|
|||
|
||||
# Returns the first ProxyPair that's available to connect.
|
||||
nextAvailableProxyPair: ->
|
||||
if @proxyPairs.length < @config.connectionsPerClient
|
||||
return @makeProxyPair @relayAddr
|
||||
return @proxyPairs.find (pp, i, arr) -> return !pp.active
|
||||
|
||||
# Receive an SDP offer from some client assigned by the Broker,
|
||||
|
@ -110,27 +110,14 @@ class Snowflake
|
|||
@proxyPairs.push pair
|
||||
pair.onCleanup = (event) =>
|
||||
# Delete from the list of active proxy pairs.
|
||||
@proxyPairs.splice(@proxyPairs.indexOf(pair), 1)
|
||||
@pollBroker()
|
||||
ind = @proxyPairs.indexOf(pair)
|
||||
if ind > -1 then @proxyPairs.splice(ind, 1)
|
||||
pair.begin()
|
||||
return pair
|
||||
|
||||
# Stop all proxypairs.
|
||||
cease: ->
|
||||
while @proxyPairs.length > 0
|
||||
@proxyPairs.pop().close()
|
||||
clearInterval(@pollInterval)
|
||||
|
||||
disable: ->
|
||||
log 'Disabling Snowflake.'
|
||||
@cease()
|
||||
|
||||
die: ->
|
||||
log 'Snowflake died.'
|
||||
@cease()
|
||||
|
||||
# Close all existing ProxyPairs and begin finding new clients from scratch.
|
||||
reset: ->
|
||||
@cease()
|
||||
log 'Snowflake resetting...'
|
||||
@retries = 0
|
||||
@beginWebRTC()
|
||||
clearInterval(@pollInterval)
|
||||
while @proxyPairs.length > 0
|
||||
@proxyPairs.pop().close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue