[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake/master] Query string params available in the snowflake proxy for manual mode, broker url, and target relay address
commit 0301ff1879269e2e820779900c6e1b2c282ce18b
Author: Serene Han <keroserene+git@xxxxxxxxx>
Date: Sat Jan 23 09:27:23 2016 -0800
Query string params available in the snowflake proxy for manual mode, broker url, and target relay address
---
proxy/README.md | 14 ++++++++++++++
proxy/broker.coffee | 3 +++
proxy/snowflake.coffee | 43 ++++++++++++++++++++-----------------------
proxy/util.coffee | 6 ++++++
4 files changed, 43 insertions(+), 23 deletions(-)
diff --git a/proxy/README.md b/proxy/README.md
index 36c2e9c..386d686 100644
--- a/proxy/README.md
+++ b/proxy/README.md
@@ -9,3 +9,17 @@ cake test
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.
+```
diff --git a/proxy/broker.coffee b/proxy/broker.coffee
index 34b5a88..1af18fb 100644
--- a/proxy/broker.coffee
+++ b/proxy/broker.coffee
@@ -25,6 +25,9 @@ class Broker
@clients = 0
@id = genSnowflakeID()
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
# a response from the broker containing some client offer.
diff --git a/proxy/snowflake.coffee b/proxy/snowflake.coffee
index edf5e56..addbaba 100644
--- a/proxy/snowflake.coffee
+++ b/proxy/snowflake.coffee
@@ -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
this must always act as the answerer.
###
-DEFAULT_WEBSOCKET = '192.81.135.242:9901'
-DEFAULT_BROKER = 'https://snowflake-reg.appspot.com/'
+DEFAULT_BROKER = 'snowflake-reg.appspot.com'
+DEFAULT_RELAY =
+ host: '192.81.135.242'
+ port: 9901
COPY_PASTE_ENABLED = false
DEFAULT_PORTS =
http: 80
https: 443
DEBUG = false
+query = null
if window && window.location
query = Query.parse(window.location.search.substr(1))
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 = 'undefined' == typeof(document)
@@ -79,34 +83,31 @@ class Snowflake
@rateLimit = new BucketRateLimit(rateLimitBytes * 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) ->
- addr = Parse.address relayAddr
- if !addr
- log 'Invalid address spec.'
- return false
- @relayAddr = addr
- log 'Using ' + relayAddr + ' as Relay.'
+ @relayAddr = relayAddr
+ log 'Using ' + relayAddr.host + ':' + relayAddr.port + ' as Relay.'
log 'Input offer from the snowflake client:' if COPY_PASTE_ENABLED
return true
# Initialize WebRTC PeerConnection
- beginWebRTC: ->
+ beginWebRTC: (automatic) ->
@state = MODE.WEBRTC_CONNECTING
for i in [1..CONNECTIONS_PER_CLIENT]
@makeProxyPair @relayAddr
@proxyPair = @proxyPairs[0]
+ return if !automatic
# Poll broker for clients.
findClients = =>
recv = broker.getClientOffer()
- recv.then((desc) =>
+ recv.then (desc) =>
offer = JSON.parse desc
log 'Received:\n\n' + offer.sdp + '\n'
@receiveOffer offer
, (err) ->
log err
setTimeout(findClients, 1000)
- )
findClients()
# Receive an SDP offer from some client assigned by the Broker.
@@ -176,11 +177,6 @@ Interface =
if !COPY_PASTE_ENABLED
log 'No input expected - Copy Paste Signalling disabled.'
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
Signalling.receive msg
when MODE.WEBRTC_READY
@@ -229,13 +225,14 @@ init = ->
$input.onkeydown = (e) -> $send.onclick() if 13 == e.keyCode # enter
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)
window.snowflake = snowflake
- if COPY_PASTE_ENABLED
- log 'Input desired relay address:'
- else
- snowflake.setRelayAddr DEFAULT_WEBSOCKET
- snowflake.beginWebRTC()
+
+ relayAddr = Params.getAddress(query, 'relay', DEFAULT_RELAY)
+ snowflake.setRelayAddr relayAddr
+ snowflake.beginWebRTC(!COPY_PASTE_ENABLED)
window.onload = init if window
diff --git a/proxy/util.coffee b/proxy/util.coffee
index eaf8f9d..ea65e63 100644
--- a/proxy/util.coffee
+++ b/proxy/util.coffee
@@ -117,6 +117,12 @@ Params =
return defaultValue if undefined == 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
amount: 0.0
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits