mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
Query string params available in the snowflake proxy for manual mode, broker url, and target relay address
This commit is contained in:
parent
77fbfe0e66
commit
0301ff1879
4 changed files with 43 additions and 23 deletions
|
@ -9,3 +9,17 @@ cake test
|
||||||
|
|
||||||
To run locally, start a webserver and navigate to `snowflake.html`.
|
To run locally, start a webserver and navigate to `snowflake.html`.
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
|
||||||
|
With no parameters,
|
||||||
|
snowflake uses the default relay `192.81.135.242:9901` and
|
||||||
|
uses automatic signaling with the default broker at
|
||||||
|
`https://snowflake-reg.appspot.com/`.
|
||||||
|
|
||||||
|
|
||||||
|
Here are optional parameters to include in the query string.
|
||||||
|
```
|
||||||
|
manual - enables copy-paste signalling mode.
|
||||||
|
relay=<address> - use a custom target relay.
|
||||||
|
broker=<address> - use a custom broker.
|
||||||
|
```
|
||||||
|
|
|
@ -25,6 +25,9 @@ class Broker
|
||||||
@clients = 0
|
@clients = 0
|
||||||
@id = genSnowflakeID()
|
@id = genSnowflakeID()
|
||||||
log 'Contacting Broker at ' + @url + '\nSnowflake ID: ' + @id
|
log 'Contacting Broker at ' + @url + '\nSnowflake ID: ' + @id
|
||||||
|
# Ensure url has the right protocol + trailing slash.
|
||||||
|
@url = 'https://' + @url if 0 != @url.indexOf('https://', 0)
|
||||||
|
@url += '/' if '/' != @url.substr -1
|
||||||
|
|
||||||
# Snowflake registers with the broker using an HTTP POST request, and expects
|
# Snowflake registers with the broker using an HTTP POST request, and expects
|
||||||
# a response from the broker containing some client offer.
|
# a response from the broker containing some client offer.
|
||||||
|
|
|
@ -7,17 +7,21 @@ Uses WebRTC from the client, and websocket to the server.
|
||||||
Assume that the webrtc client plugin is always the offerer, in which case
|
Assume that the webrtc client plugin is always the offerer, in which case
|
||||||
this must always act as the answerer.
|
this must always act as the answerer.
|
||||||
###
|
###
|
||||||
DEFAULT_WEBSOCKET = '192.81.135.242:9901'
|
DEFAULT_BROKER = 'snowflake-reg.appspot.com'
|
||||||
DEFAULT_BROKER = 'https://snowflake-reg.appspot.com/'
|
DEFAULT_RELAY =
|
||||||
|
host: '192.81.135.242'
|
||||||
|
port: 9901
|
||||||
COPY_PASTE_ENABLED = false
|
COPY_PASTE_ENABLED = false
|
||||||
DEFAULT_PORTS =
|
DEFAULT_PORTS =
|
||||||
http: 80
|
http: 80
|
||||||
https: 443
|
https: 443
|
||||||
|
|
||||||
DEBUG = false
|
DEBUG = false
|
||||||
|
query = null
|
||||||
if window && window.location
|
if window && window.location
|
||||||
query = Query.parse(window.location.search.substr(1))
|
query = Query.parse(window.location.search.substr(1))
|
||||||
DEBUG = Params.getBool(query, 'debug', false)
|
DEBUG = Params.getBool(query, 'debug', false)
|
||||||
|
COPY_PASTE_ENABLED = Params.getBool(query, 'manual', false)
|
||||||
# HEADLESS is true if we are running not in a browser with a DOM.
|
# HEADLESS is true if we are running not in a browser with a DOM.
|
||||||
HEADLESS = 'undefined' == typeof(document)
|
HEADLESS = 'undefined' == typeof(document)
|
||||||
|
|
||||||
|
@ -79,34 +83,31 @@ class Snowflake
|
||||||
@rateLimit = new BucketRateLimit(rateLimitBytes * RATE_LIMIT_HISTORY,
|
@rateLimit = new BucketRateLimit(rateLimitBytes * RATE_LIMIT_HISTORY,
|
||||||
RATE_LIMIT_HISTORY)
|
RATE_LIMIT_HISTORY)
|
||||||
|
|
||||||
# TODO: Should fetch from broker later.
|
# TODO: Should potentially fetch from broker later.
|
||||||
|
# Set the target relay address spec, which is expected to be a websocket relay.
|
||||||
setRelayAddr: (relayAddr) ->
|
setRelayAddr: (relayAddr) ->
|
||||||
addr = Parse.address relayAddr
|
@relayAddr = relayAddr
|
||||||
if !addr
|
log 'Using ' + relayAddr.host + ':' + relayAddr.port + ' as Relay.'
|
||||||
log 'Invalid address spec.'
|
|
||||||
return false
|
|
||||||
@relayAddr = addr
|
|
||||||
log 'Using ' + relayAddr + ' as Relay.'
|
|
||||||
log 'Input offer from the snowflake client:' if COPY_PASTE_ENABLED
|
log 'Input offer from the snowflake client:' if COPY_PASTE_ENABLED
|
||||||
return true
|
return true
|
||||||
|
|
||||||
# Initialize WebRTC PeerConnection
|
# Initialize WebRTC PeerConnection
|
||||||
beginWebRTC: ->
|
beginWebRTC: (automatic) ->
|
||||||
@state = MODE.WEBRTC_CONNECTING
|
@state = MODE.WEBRTC_CONNECTING
|
||||||
for i in [1..CONNECTIONS_PER_CLIENT]
|
for i in [1..CONNECTIONS_PER_CLIENT]
|
||||||
@makeProxyPair @relayAddr
|
@makeProxyPair @relayAddr
|
||||||
@proxyPair = @proxyPairs[0]
|
@proxyPair = @proxyPairs[0]
|
||||||
|
return if !automatic
|
||||||
# Poll broker for clients.
|
# Poll broker for clients.
|
||||||
findClients = =>
|
findClients = =>
|
||||||
recv = broker.getClientOffer()
|
recv = broker.getClientOffer()
|
||||||
recv.then((desc) =>
|
recv.then (desc) =>
|
||||||
offer = JSON.parse desc
|
offer = JSON.parse desc
|
||||||
log 'Received:\n\n' + offer.sdp + '\n'
|
log 'Received:\n\n' + offer.sdp + '\n'
|
||||||
@receiveOffer offer
|
@receiveOffer offer
|
||||||
, (err) ->
|
, (err) ->
|
||||||
log err
|
log err
|
||||||
setTimeout(findClients, 1000)
|
setTimeout(findClients, 1000)
|
||||||
)
|
|
||||||
findClients()
|
findClients()
|
||||||
|
|
||||||
# Receive an SDP offer from some client assigned by the Broker.
|
# Receive an SDP offer from some client assigned by the Broker.
|
||||||
|
@ -176,11 +177,6 @@ Interface =
|
||||||
if !COPY_PASTE_ENABLED
|
if !COPY_PASTE_ENABLED
|
||||||
log 'No input expected - Copy Paste Signalling disabled.'
|
log 'No input expected - Copy Paste Signalling disabled.'
|
||||||
else switch snowflake.state
|
else switch snowflake.state
|
||||||
when MODE.INIT
|
|
||||||
# Set target relay.
|
|
||||||
if !(snowflake.setRelayAddr msg)
|
|
||||||
log 'Defaulting to websocket relay at ' + DEFAULT_WEBSOCKET
|
|
||||||
snowflake.setRelayAddr DEFAULT_WEBSOCKET
|
|
||||||
when MODE.WEBRTC_CONNECTING
|
when MODE.WEBRTC_CONNECTING
|
||||||
Signalling.receive msg
|
Signalling.receive msg
|
||||||
when MODE.WEBRTC_READY
|
when MODE.WEBRTC_READY
|
||||||
|
@ -229,13 +225,14 @@ init = ->
|
||||||
$input.onkeydown = (e) -> $send.onclick() if 13 == e.keyCode # enter
|
$input.onkeydown = (e) -> $send.onclick() if 13 == e.keyCode # enter
|
||||||
|
|
||||||
log '== snowflake browser proxy =='
|
log '== snowflake browser proxy =='
|
||||||
broker = new Broker DEFAULT_BROKER
|
log 'Copy-Paste mode detected.' if COPY_PASTE_ENABLED
|
||||||
|
brokerUrl = Params.getString(query, 'broker', DEFAULT_BROKER)
|
||||||
|
broker = new Broker brokerUrl
|
||||||
snowflake = new Snowflake(broker)
|
snowflake = new Snowflake(broker)
|
||||||
window.snowflake = snowflake
|
window.snowflake = snowflake
|
||||||
if COPY_PASTE_ENABLED
|
|
||||||
log 'Input desired relay address:'
|
relayAddr = Params.getAddress(query, 'relay', DEFAULT_RELAY)
|
||||||
else
|
snowflake.setRelayAddr relayAddr
|
||||||
snowflake.setRelayAddr DEFAULT_WEBSOCKET
|
snowflake.beginWebRTC(!COPY_PASTE_ENABLED)
|
||||||
snowflake.beginWebRTC()
|
|
||||||
|
|
||||||
window.onload = init if window
|
window.onload = init if window
|
||||||
|
|
|
@ -117,6 +117,12 @@ Params =
|
||||||
return defaultValue if undefined == val
|
return defaultValue if undefined == val
|
||||||
Parse.address val
|
Parse.address val
|
||||||
|
|
||||||
|
# Get an object value and return it as a string. Returns default_val if param
|
||||||
|
# is not a key.
|
||||||
|
getString: (query, param, defaultValue) ->
|
||||||
|
val = query[param]
|
||||||
|
return defaultValue if undefined == val
|
||||||
|
val
|
||||||
|
|
||||||
class BucketRateLimit
|
class BucketRateLimit
|
||||||
amount: 0.0
|
amount: 0.0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue