Initialize snowflake instance with a config

This commit is contained in:
Arlo Breault 2019-05-08 16:13:22 -04:00
parent edbbea1d03
commit 2d8a1690ba
11 changed files with 125 additions and 113 deletions

View file

@ -1,37 +1,9 @@
# General snowflake proxy constants.
# For websocket-specific constants, see websocket.coffee.
BROKER = 'snowflake-broker.bamsoftware.com'
RELAY =
host: 'snowflake.bamsoftware.com'
port: '443'
# Original non-wss relay:
# host: '192.81.135.242'
# port: 9902
COOKIE_NAME = "snowflake-allow"
# Bytes per second. Set to undefined to disable limit.
DEFAULT_RATE_LIMIT = undefined
MIN_RATE_LIMIT = 10 * 1024
RATE_LIMIT_HISTORY = 5.0
DEFAULT_BROKER_POLL_INTERVAL = 5.0 * 1000
MAX_NUM_CLIENTS = 1
CONNECTIONS_PER_CLIENT = 1
# TODO: Different ICE servers.
config = {
iceServers: [
{ urls: ['stun:stun.l.google.com:19302'] }
]
}
CONFIRMATION_MESSAGE = 'You\'re currently serving a Tor user via Snowflake.'
query = Query.parse(location)
DEBUG = Params.getBool(query, 'debug', false)
snowflake = null
silenceNotifications = false
query = Query.parse(location)
debug = Params.getBool(query, 'debug', false)
silenceNotifications = Params.getBool(query, 'silent', false)
# Log to both console and UI if applicable.
# Requires that the snowflake and UI objects are hooked up in order to
@ -40,13 +12,17 @@ log = (msg) ->
console.log 'Snowflake: ' + msg
snowflake?.ui.log msg
dbg = (msg) -> log msg if DEBUG or (snowflake?.ui instanceof DebugUI)
dbg = (msg) -> log msg if debug or (snowflake?.ui instanceof DebugUI)
###
Entry point.
###
init = () ->
config = new Config
if 'off' != query['ratelimit']
config.rateLimitBytes = Params.getByteCount(query, 'ratelimit', config.rateLimitBytes)
ui = null
if (document.getElementById('badge') != null)
ui = new BadgeUI()
@ -57,29 +33,24 @@ init = () ->
else
ui = new UI()
rateLimitBytes = undefined
if 'off' != query['ratelimit']
rateLimitBytes = Params.getByteCount(query, 'ratelimit', DEFAULT_RATE_LIMIT)
silenceNotifications = Params.getBool(query, 'silent', false)
broker = new Broker BROKER
snowflake = new Snowflake broker, ui, rateLimitBytes
broker = new Broker config.brokerUrl
snowflake = new Snowflake config, ui, broker
log '== snowflake proxy =='
if Util.snowflakeIsDisabled()
if Util.snowflakeIsDisabled(config.cookieName)
# Do not activate the proxy if any number of conditions are true.
log 'Currently not active.'
return
# Otherwise, begin setting up WebRTC and acting as a proxy.
dbg 'Contacting Broker at ' + broker.url
snowflake.setRelayAddr RELAY
snowflake.setRelayAddr config.relayAddr
snowflake.beginWebRTC()
# Notification of closing tab with active proxy.
window.onbeforeunload = ->
if !silenceNotifications && Snowflake.MODE.WEBRTC_READY == snowflake.state
return CONFIRMATION_MESSAGE
return Snowflake.MESSAGE.CONFIRMATION
null
window.onunload = ->