mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Initial broker registration of browser proxies
- broker.coffee contains the xhr stuff - COR enabled on the go broker - POST body reflection works
This commit is contained in:
parent
f2d8a749f4
commit
28e557fb43
4 changed files with 57 additions and 8 deletions
|
@ -48,7 +48,7 @@ func regHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
log.Println("Invalid data.")
|
log.Println("Invalid data.")
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
// TODO: Get browser snowflake to talkto this appengine instance
|
// TODO: Get browser snowflake to talkto this appengine instance
|
||||||
// so it can reply with an answer, and not just the offer again :)
|
// so it can reply with an answer, and not just the offer again :)
|
||||||
// TODO: Real broker which matches clients and snowflake proxies.
|
// TODO: Real broker which matches clients and snowflake proxies.
|
||||||
|
|
|
@ -7,6 +7,7 @@ FILES = [
|
||||||
'util.coffee'
|
'util.coffee'
|
||||||
'proxypair.coffee'
|
'proxypair.coffee'
|
||||||
'websocket.coffee'
|
'websocket.coffee'
|
||||||
|
'broker.coffee'
|
||||||
'snowflake.coffee'
|
'snowflake.coffee'
|
||||||
]
|
]
|
||||||
FILES_TEST = [
|
FILES_TEST = [
|
||||||
|
|
49
proxy/broker.coffee
Normal file
49
proxy/broker.coffee
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
###
|
||||||
|
Communication with the snowflake broker.
|
||||||
|
|
||||||
|
Browser snowflakes must register with the broker in order
|
||||||
|
to get assigned to clients.
|
||||||
|
###
|
||||||
|
|
||||||
|
# Represents a broker running remotely.
|
||||||
|
class Broker
|
||||||
|
# When interacting with the Broker, snowflake must generate a unique session
|
||||||
|
# ID so the Broker can keep track of which signalling channel it's speaking
|
||||||
|
# to.
|
||||||
|
constructor: (@url) ->
|
||||||
|
log 'Using Broker at ' + @url
|
||||||
|
|
||||||
|
# Snowflake registers with the broker using an HTTP POST request, and expects
|
||||||
|
# a response from the broker containing some client offer
|
||||||
|
register: ->
|
||||||
|
# base_url = this.fac_url.replace(/\?.*/, "");
|
||||||
|
# url = base_url + "?" + build_query_string(params);
|
||||||
|
xhr = new XMLHttpRequest()
|
||||||
|
try
|
||||||
|
xhr.open 'POST', @url
|
||||||
|
xhr
|
||||||
|
catch err
|
||||||
|
###
|
||||||
|
An exception happens here when, for example, NoScript allows the domain on
|
||||||
|
which the proxy badge runs, but not the domain to which it's trying to
|
||||||
|
make the HTTP request. The exception message is like "Component returned
|
||||||
|
failure code: 0x805e0006 [nsIXMLHttpRequest.open]" on Firefox.
|
||||||
|
###
|
||||||
|
log 'Broker: exception while connecting: ' + err.message
|
||||||
|
return
|
||||||
|
|
||||||
|
# xhr.responseType = 'text'
|
||||||
|
xhr.onreadystatechange = ->
|
||||||
|
if xhr.DONE == xhr.readyState
|
||||||
|
if 200 == xhr.status
|
||||||
|
log 'Broker: success'
|
||||||
|
log 'Response: ' + xhr.responseText
|
||||||
|
# @fac_complete xhr.responseText
|
||||||
|
else
|
||||||
|
log 'Broker error ' + xhr.status + ' - ' + xhr.statusText
|
||||||
|
|
||||||
|
xhr.send 'snowflake-testing'
|
||||||
|
|
||||||
|
sendAnswer: (answer) ->
|
||||||
|
log 'Sending answer to broker.'
|
||||||
|
log answer
|
|
@ -8,6 +8,7 @@ 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_WEBSOCKET = '192.81.135.242:9901'
|
||||||
|
DEFAULT_BROKER = 'https://snowflake-reg.appspot.com/reg/test'
|
||||||
DEFAULT_PORTS =
|
DEFAULT_PORTS =
|
||||||
http: 80
|
http: 80
|
||||||
https: 443
|
https: 443
|
||||||
|
@ -207,15 +208,10 @@ Signalling =
|
||||||
|
|
||||||
log = (msg) -> # Log to the message window.
|
log = (msg) -> # Log to the message window.
|
||||||
console.log msg
|
console.log msg
|
||||||
# Scroll to latest
|
if $msglog # Scroll to latest
|
||||||
if $msglog
|
|
||||||
$msglog.value += msg + '\n'
|
$msglog.value += msg + '\n'
|
||||||
$msglog.scrollTop = $msglog.scrollHeight
|
$msglog.scrollTop = $msglog.scrollHeight
|
||||||
|
|
||||||
welcome = ->
|
|
||||||
log '== snowflake browser proxy =='
|
|
||||||
log 'Input desired relay address:'
|
|
||||||
|
|
||||||
init = ->
|
init = ->
|
||||||
$msglog = document.getElementById('msglog')
|
$msglog = document.getElementById('msglog')
|
||||||
$msglog.value = ''
|
$msglog.value = ''
|
||||||
|
@ -227,8 +223,11 @@ init = ->
|
||||||
$input.focus()
|
$input.focus()
|
||||||
$input.onkeydown = (e) -> $send.onclick() if 13 == e.keyCode # enter
|
$input.onkeydown = (e) -> $send.onclick() if 13 == e.keyCode # enter
|
||||||
|
|
||||||
|
log '== snowflake browser proxy =='
|
||||||
snowflake = new Snowflake()
|
snowflake = new Snowflake()
|
||||||
window.snowflake = snowflake
|
window.snowflake = snowflake
|
||||||
welcome()
|
broker = new Broker DEFAULT_BROKER
|
||||||
|
broker.register()
|
||||||
|
log 'Input desired relay address:'
|
||||||
|
|
||||||
window.onload = init if window
|
window.onload = init if window
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue