[tor-commits] [snowflake/master] Separate build per use
arlo at torproject.org
arlo at torproject.org
Thu May 16 16:08:58 UTC 2019
commit 4d40f17487fba217490da80186b9674d0302c691
Author: Arlo Breault <arlolra at gmail.com>
Date: Wed May 8 16:46:51 2019 -0400
Separate build per use
---
proxy/Cakefile | 49 +++++++++++++++++++++-----------
proxy/{init.coffee => init-badge.coffee} | 8 ++----
proxy/init-node.coffee | 19 +++++++++++++
proxy/init-webext.coffee | 39 +++++++++++++++++++++++++
proxy/package.json | 2 +-
proxy/shims.coffee | 2 --
6 files changed, 94 insertions(+), 25 deletions(-)
diff --git a/proxy/Cakefile b/proxy/Cakefile
index e0d610c..ba2e5ec 100644
--- a/proxy/Cakefile
+++ b/proxy/Cakefile
@@ -3,41 +3,49 @@ fs = require 'fs'
# All coffeescript files required.
FILES = [
- 'shims.coffee'
- 'util.coffee'
- 'init.coffee'
- 'proxypair.coffee'
- 'websocket.coffee'
'broker.coffee'
- 'ui.coffee'
- 'snowflake.coffee'
'config.coffee'
+ 'proxypair.coffee'
+ 'snowflake.coffee'
+ 'ui.coffee'
+ 'util.coffee'
+ 'websocket.coffee'
+
+ 'shims.coffee'
]
+
+INITS = [
+ 'init-badge.coffee'
+ 'init-node.coffee'
+ 'init-webext.coffee'
+]
+
FILES_SPEC = [
- 'spec/util.spec.coffee'
- 'spec/ui.spec.coffee'
'spec/broker.spec.coffee'
+ 'spec/init.spec.coffee'
'spec/proxypair.spec.coffee'
'spec/snowflake.spec.coffee'
+ 'spec/ui.spec.coffee'
+ 'spec/util.spec.coffee'
'spec/websocket.spec.coffee'
- 'spec/init.spec.coffee'
]
-FILES_ALL = FILES.concat FILES_SPEC
+
OUTFILE = 'snowflake.js'
STATIC = 'static'
copyStaticFiles = ->
exec 'cp ' + STATIC + '/* build/'
-compileCoffee = (outDir) ->
- exec 'cat ' + FILES.join(' ') + ' | coffee -cs > ' + outDir + '/' + OUTFILE, (err, stdout, stderr) ->
+compileCoffee = (outDir, init) ->
+ files = FILES.concat('init-' + init + '.coffee')
+ exec 'cat ' + files.join(' ') + ' | coffee -cs > ' + outDir + '/' + OUTFILE, (err, stdout, stderr) ->
throw err if err
task 'test', 'snowflake unit tests', ->
exec 'mkdir -p test'
exec 'jasmine init >&-'
# Simply concat all the files because we're not using node exports.
- jasmineFiles = FILES_ALL
+ jasmineFiles = FILES.concat('init-badge.coffee', FILES_SPEC)
outFile = 'test/bundle.spec.coffee'
exec 'echo "TESTING = true" > ' + outFile
exec 'cat ' + jasmineFiles.join(' ') + ' | cat >> ' + outFile
@@ -50,15 +58,22 @@ task 'test', 'snowflake unit tests', ->
task 'build', 'build the snowflake proxy', ->
exec 'mkdir -p build'
copyStaticFiles()
- compileCoffee('build')
+ compileCoffee('build', 'badge')
console.log 'Snowflake prepared.'
task 'webext', 'build the webextension', ->
- compileCoffee('webext')
+ exec 'mkdir -p webext'
+ compileCoffee('webext', 'webext')
console.log 'Webextension prepared.'
+task 'node', 'build the node binary', ->
+ exec 'mkdir -p build'
+ compileCoffee('build', 'node')
+ console.log 'Node prepared.'
+
task 'lint', 'ensure idiomatic coffeescript', ->
- proc = spawn 'coffeelint', FILES_ALL, {
+ filesAll = FILES.concat(INITS, FILES_SPEC)
+ proc = spawn 'coffeelint', filesAll, {
file: 'coffeelint.json'
stdio: 'inherit'
}
diff --git a/proxy/init.coffee b/proxy/init-badge.coffee
similarity index 95%
rename from proxy/init.coffee
rename to proxy/init-badge.coffee
index 48a2c39..295f84b 100644
--- a/proxy/init.coffee
+++ b/proxy/init-badge.coffee
@@ -1,3 +1,6 @@
+###
+Entry point.
+###
snowflake = null
@@ -14,9 +17,6 @@ log = (msg) ->
dbg = (msg) -> log msg if debug or (snowflake?.ui instanceof DebugUI)
-###
-Entry point.
-###
init = () ->
config = new Config
@@ -28,8 +28,6 @@ init = () ->
ui = new BadgeUI()
else if (document.getElementById('status') != null)
ui = new DebugUI()
- else if (document.getElementById('webext') != null)
- ui = new WebExtUI()
else
ui = new UI()
diff --git a/proxy/init-node.coffee b/proxy/init-node.coffee
new file mode 100644
index 0000000..814e3fc
--- /dev/null
+++ b/proxy/init-node.coffee
@@ -0,0 +1,19 @@
+###
+Entry point.
+###
+
+config = new Config
+ui = new UI()
+broker = new Broker config.brokerUrl
+snowflake = new Snowflake config, ui, broker
+
+log = (msg) ->
+ console.log 'Snowflake: ' + msg
+
+dbg = log
+
+log '== snowflake proxy =='
+dbg 'Contacting Broker at ' + broker.url
+
+snowflake.setRelayAddr config.relayAddr
+snowflake.beginWebRTC()
diff --git a/proxy/init-webext.coffee b/proxy/init-webext.coffee
new file mode 100644
index 0000000..1ba6391
--- /dev/null
+++ b/proxy/init-webext.coffee
@@ -0,0 +1,39 @@
+###
+Entry point.
+###
+
+debug = false
+snowflake = null
+
+# Log to both console and UI if applicable.
+# Requires that the snowflake and UI objects are hooked up in order to
+# log to console.
+log = (msg) ->
+ console.log 'Snowflake: ' + msg
+ snowflake?.ui.log msg
+
+dbg = (msg) -> log msg if debug
+
+init = () ->
+ config = new Config
+ ui = new WebExtUI()
+ broker = new Broker config.brokerUrl
+ snowflake = new Snowflake config, ui, broker
+
+ log '== snowflake proxy =='
+ # Otherwise, begin setting up WebRTC and acting as a proxy.
+ dbg 'Contacting Broker at ' + broker.url
+ snowflake.setRelayAddr config.relayAddr
+ snowflake.beginWebRTC()
+
+# Notification of closing tab with active proxy.
+window.onbeforeunload = ->
+ if !silenceNotifications && Snowflake.MODE.WEBRTC_READY == snowflake.state
+ return Snowflake.MESSAGE.CONFIRMATION
+ null
+
+window.onunload = ->
+ pair.close() for pair in snowflake.proxyPairs
+ null
+
+window.onload = init
diff --git a/proxy/package.json b/proxy/package.json
index 8bc5fb5..889e2e2 100644
--- a/proxy/package.json
+++ b/proxy/package.json
@@ -12,7 +12,7 @@
"build": "cake build",
"webext": "cake webext",
"clean": "cake clean",
- "prepublish": "npm run build",
+ "prepublish": "cake node",
"start": "node build/snowflake.js"
},
"bin": {
diff --git a/proxy/shims.coffee b/proxy/shims.coffee
index 5c4bae0..dc7412f 100644
--- a/proxy/shims.coffee
+++ b/proxy/shims.coffee
@@ -19,8 +19,6 @@ if module?.exports
WebSocket = require 'ws'
{ XMLHttpRequest } = require 'xmlhttprequest'
- process.nextTick () -> init
-
else
window = this
document = window.document
More information about the tor-commits
mailing list