mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-14 05:11:19 -04:00
parent
c8c5d56b73
commit
e295556254
7 changed files with 52 additions and 23 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -13,3 +13,4 @@ proxy/build
|
||||||
proxy/node_modules
|
proxy/node_modules
|
||||||
proxy/spec/support
|
proxy/spec/support
|
||||||
ignore/
|
ignore/
|
||||||
|
npm-debug.log
|
||||||
|
|
|
@ -35,7 +35,8 @@ task 'test', 'snowflake unit tests', ->
|
||||||
# Simply concat all the files because we're not using node exports.
|
# Simply concat all the files because we're not using node exports.
|
||||||
jasmineFiles = FILES_ALL
|
jasmineFiles = FILES_ALL
|
||||||
outFile = 'test/bundle.spec.coffee'
|
outFile = 'test/bundle.spec.coffee'
|
||||||
exec 'cat ' + jasmineFiles.join(' ') + ' | cat > ' + outFile
|
exec 'echo "TESTING = true" > ' + outFile
|
||||||
|
exec 'cat ' + jasmineFiles.join(' ') + ' | cat >> ' + outFile
|
||||||
execSync 'coffee -cb ' + outFile
|
execSync 'coffee -cb ' + outFile
|
||||||
spawn 'jasmine', ['test/bundle.spec.js'], {
|
spawn 'jasmine', ['test/bundle.spec.js'], {
|
||||||
stdio: 'inherit'
|
stdio: 'inherit'
|
||||||
|
|
|
@ -11,14 +11,24 @@
|
||||||
"lint": "cake lint",
|
"lint": "cake lint",
|
||||||
"build": "cake build",
|
"build": "cake build",
|
||||||
"clean": "cake clean",
|
"clean": "cake clean",
|
||||||
"modern": "modernizr -c modernizr-config.json -d static/"
|
"modern": "modernizr -c modernizr-config.json -d static/",
|
||||||
|
"prepublish": "npm run build",
|
||||||
|
"start": "node build/snowflake.js"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"snowflake": "build/snowflake.js"
|
||||||
},
|
},
|
||||||
"author": "Serene Han",
|
"author": "Serene Han",
|
||||||
"license": "BSD-3-Clause",
|
"license": "BSD-3-Clause",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"coffee-script": "^1.10.0",
|
"coffeelint": "^1.16.0",
|
||||||
"coffeelint": "^1.15.0",
|
"jasmine": "^2.5.2",
|
||||||
"jasmine": "^2.4.1",
|
|
||||||
"modernizr": "^3.3.1"
|
"modernizr": "^3.3.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"coffee-script": "^1.12.2",
|
||||||
|
"wrtc": "^0.0.61",
|
||||||
|
"ws": "^1.1.1",
|
||||||
|
"xmlhttprequest": "^1.8.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,14 +69,14 @@ class ProxyPair
|
||||||
channel.onopen = =>
|
channel.onopen = =>
|
||||||
log 'WebRTC DataChannel opened!'
|
log 'WebRTC DataChannel opened!'
|
||||||
snowflake.state = MODE.WEBRTC_READY
|
snowflake.state = MODE.WEBRTC_READY
|
||||||
snowflake.ui.setActive true
|
snowflake.ui?.setActive true
|
||||||
# This is the point when the WebRTC datachannel is done, so the next step
|
# This is the point when the WebRTC datachannel is done, so the next step
|
||||||
# is to establish websocket to the server.
|
# is to establish websocket to the server.
|
||||||
@connectRelay()
|
@connectRelay()
|
||||||
channel.onclose = =>
|
channel.onclose = =>
|
||||||
log 'WebRTC DataChannel closed.'
|
log 'WebRTC DataChannel closed.'
|
||||||
snowflake.ui.setStatus 'disconnected by webrtc.'
|
snowflake.ui?.setStatus 'disconnected by webrtc.'
|
||||||
snowflake.ui.setActive false
|
snowflake.ui?.setActive false
|
||||||
snowflake.state = MODE.INIT
|
snowflake.state = MODE.INIT
|
||||||
@flush()
|
@flush()
|
||||||
@close()
|
@close()
|
||||||
|
@ -95,11 +95,11 @@ class ProxyPair
|
||||||
clearTimeout @timer
|
clearTimeout @timer
|
||||||
@timer = 0
|
@timer = 0
|
||||||
log @relay.label + ' connected!'
|
log @relay.label + ' connected!'
|
||||||
snowflake.ui.setStatus 'connected'
|
snowflake.ui?.setStatus 'connected'
|
||||||
@relay.onclose = =>
|
@relay.onclose = =>
|
||||||
log @relay.label + ' closed.'
|
log @relay.label + ' closed.'
|
||||||
snowflake.ui.setStatus 'disconnected.'
|
snowflake.ui?.setStatus 'disconnected.'
|
||||||
snowflake.ui.setActive false
|
snowflake.ui?.setActive false
|
||||||
snowflake.state = MODE.INIT
|
snowflake.state = MODE.INIT
|
||||||
@flush()
|
@flush()
|
||||||
@close()
|
@close()
|
||||||
|
|
|
@ -1,11 +1,27 @@
|
||||||
###
|
###
|
||||||
WebrTC shims for multiple browsers.
|
WebRTC shims for multiple browsers.
|
||||||
###
|
###
|
||||||
|
|
||||||
if typeof module isnt 'undefined' and module.exports
|
if module?.exports
|
||||||
window = {}
|
window = {}
|
||||||
|
location = ''
|
||||||
|
|
||||||
|
if not TESTING? or not TESTING
|
||||||
|
webrtc = require 'wrtc'
|
||||||
|
|
||||||
|
PeerConnection = webrtc.RTCPeerConnection
|
||||||
|
IceCandidate = webrtc.RTCIceCandidate
|
||||||
|
SessionDescription = webrtc.RTCSessionDescription
|
||||||
|
|
||||||
|
WebSocket = require 'ws'
|
||||||
|
{ XMLHttpRequest } = require 'xmlhttprequest'
|
||||||
|
|
||||||
|
process.nextTick () -> init true
|
||||||
|
|
||||||
else
|
else
|
||||||
window = this
|
window = this
|
||||||
|
location = window.location.search.substr(1)
|
||||||
|
|
||||||
prop = Modernizr.prefixed 'RTCPeerConnection', window, false
|
prop = Modernizr.prefixed 'RTCPeerConnection', window, false
|
||||||
if not prop
|
if not prop
|
||||||
console.log 'webrtc feature not detected. shutting down'
|
console.log 'webrtc feature not detected. shutting down'
|
||||||
|
@ -18,4 +34,5 @@ else
|
||||||
SessionDescription = window.RTCSessionDescription ||
|
SessionDescription = window.RTCSessionDescription ||
|
||||||
window.mozRTCSessionDescription
|
window.mozRTCSessionDescription
|
||||||
|
|
||||||
location = if window.location then window.location.search.substr(1) else ""
|
WebSocket = window.WebSocket
|
||||||
|
XMLHttpRequest = window.XMLHttpRequest
|
||||||
|
|
|
@ -13,7 +13,6 @@ DEFAULT_RELAY =
|
||||||
port: 9902
|
port: 9902
|
||||||
COPY_PASTE_ENABLED = false
|
COPY_PASTE_ENABLED = false
|
||||||
|
|
||||||
DEBUG = false
|
|
||||||
silenceNotifications = false
|
silenceNotifications = false
|
||||||
query = Query.parse(location)
|
query = Query.parse(location)
|
||||||
DEBUG = Params.getBool(query, 'debug', false)
|
DEBUG = Params.getBool(query, 'debug', false)
|
||||||
|
@ -88,7 +87,8 @@ class Snowflake
|
||||||
pollBroker: ->
|
pollBroker: ->
|
||||||
# Temporary countdown. TODO: Simplify
|
# Temporary countdown. TODO: Simplify
|
||||||
countdown = (msg, sec) =>
|
countdown = (msg, sec) =>
|
||||||
@ui.setStatus msg + ' (Polling in ' + sec + ' seconds...)'
|
dbg msg
|
||||||
|
@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)
|
||||||
|
@ -103,7 +103,7 @@ class Snowflake
|
||||||
return
|
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
|
||||||
recv = @broker.getClientOffer pair.id
|
recv = @broker.getClientOffer pair.id
|
||||||
recv.then (desc) =>
|
recv.then (desc) =>
|
||||||
@receiveOffer pair, desc
|
@receiveOffer pair, desc
|
||||||
|
@ -199,12 +199,12 @@ Signalling =
|
||||||
# Log to both console and UI if applicable.
|
# Log to both console and UI if applicable.
|
||||||
log = (msg) ->
|
log = (msg) ->
|
||||||
console.log 'Snowflake: ' + msg
|
console.log 'Snowflake: ' + msg
|
||||||
snowflake.ui.log msg
|
snowflake.ui?.log msg
|
||||||
|
|
||||||
dbg = (msg) -> log msg if true == snowflake.ui.debug
|
dbg = (msg) -> log msg if DEBUG or snowflake.ui?.debug
|
||||||
|
|
||||||
init = ->
|
init = (isNode) ->
|
||||||
ui = new UI()
|
ui = if isNode then null else new UI()
|
||||||
silenceNotifications = Params.getBool(query, 'silent', false)
|
silenceNotifications = Params.getBool(query, 'silent', false)
|
||||||
brokerUrl = Params.getString(query, 'broker', DEFAULT_BROKER)
|
brokerUrl = Params.getString(query, 'broker', DEFAULT_BROKER)
|
||||||
broker = new Broker brokerUrl
|
broker = new Broker brokerUrl
|
||||||
|
@ -229,4 +229,4 @@ window.onunload = ->
|
||||||
pair.close() for pair in snowflake.proxyPairs
|
pair.close() for pair in snowflake.proxyPairs
|
||||||
null
|
null
|
||||||
|
|
||||||
window.onload = init
|
window.onload = init.bind null, false
|
||||||
|
|
|
@ -3,7 +3,7 @@ All of Snowflake's DOM manipulation and inputs.
|
||||||
###
|
###
|
||||||
|
|
||||||
class UI
|
class UI
|
||||||
debug = false # True when there's no badge
|
debug: false # True when there's no badge
|
||||||
|
|
||||||
# DOM elements references.
|
# DOM elements references.
|
||||||
$msglog: null
|
$msglog: null
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue