diff --git a/lib/client/index.js b/lib/client/index.js index b2cfec437..fb5753058 100644 --- a/lib/client/index.js +++ b/lib/client/index.js @@ -24,13 +24,15 @@ var createNetwork = Client.createNetwork = function (url, cb) { var info = {}; Netflux.connect(url, function (url) { + // this websocket seems to never close properly if the error is + // ECONNREFUSED info.websocket = new WebSocket(url) .on('error', function (err) { - console.log(err); + CB(err); }) .on('close', function (err) { - console.log("close"); - console.log(err); + console.log("CLOSE_ERROR", err); + delete info.websocket; }); return info.websocket; }).then(function (network) { @@ -77,7 +79,10 @@ Client.create = function (config, cb) { if (config.network) { return; } // connect to the network... createNetwork('ws://localhost:3000/cryptpad_websocket', w(function (err, info) { - //console.log(_network); + if (err) { + w.abort(); + return void CB(err); + } config.network = info.network; config.websocket = info.websocket; })); diff --git a/package.json b/package.json index 8bd93b82d..562035f45 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "lint:less": "./node_modules/lesshint/bin/lesshint -c ./.lesshintrc ./customize.dist/src/less2/", "flow": "./node_modules/.bin/flow", "test": "node scripts/TestSelenium.js", - "test-rpc": "cd scripts && node test-rpc", + "test-rpc": "cd scripts/tests && node test-rpc", "template": "cd customize.dist/src && for page in ../index.html ../privacy.html ../terms.html ../about.html ../contact.html ../what-is-cryptpad.html ../features.html ../../www/login/index.html ../../www/register/index.html ../../www/user/index.html;do echo $page; cp template.html $page; done;" } } diff --git a/scripts/test-rpc.js b/scripts/test-rpc.js deleted file mode 100644 index 79177464d..000000000 --- a/scripts/test-rpc.js +++ /dev/null @@ -1,43 +0,0 @@ -/* globals process */ -var Client = require("../lib/client/"); -var Mailbox = require("../www/bower_components/chainpad-crypto").Mailbox; -var Nacl = require("tweetnacl"); - -var makeKeys = function () { - var pair = Nacl.box.keyPair(); - return { - curvePrivate: Nacl.util.encodeBase64(pair.secretKey), - curvePublic: Nacl.util.encodeBase64(pair.publicKey), - }; -}; - -Client.create(function (err, client) { - if (err) { - console.error(err); - process.exit(1); - } - - var channel = "d34ebe83931382fcad9fe2e2d0e2cb5f"; // channel - var recipient = "e8jvf36S3chzkkcaMrLSW7PPrz7VDp85lIFNI26dTmw="; // curvePublic - - var keys = makeKeys(); - var cryptor = Mailbox.createEncryptor(keys); - - var message = cryptor.encrypt(JSON.stringify({ - type: "CHEESE", - author: keys.curvePublic, - content: { - text: "CAMEMBERT", - } - }), recipient); - - client.anonRpc.send('WRITE_PRIVATE_MESSAGE', [channel, message], function (err, response) { - if (err) { - return void console.error(err); - } - - response = response; - // shutdown doesn't work, so we need to do this instead - client.shutdown(); - }); -}); diff --git a/scripts/tests/index.js b/scripts/tests/index.js new file mode 100644 index 000000000..934246d90 --- /dev/null +++ b/scripts/tests/index.js @@ -0,0 +1 @@ +require("./test-rpc"); diff --git a/scripts/tests/test-rpc.js b/scripts/tests/test-rpc.js new file mode 100644 index 000000000..2c355af3b --- /dev/null +++ b/scripts/tests/test-rpc.js @@ -0,0 +1,74 @@ +var Client = require("../../lib/client/"); +var Mailbox = require("../../www/bower_components/chainpad-crypto").Mailbox; +var Nacl = require("tweetnacl"); +var nThen = require("nthen"); + +var makeCurveKeys = function () { + var pair = Nacl.box.keyPair(); + return { + curvePrivate: Nacl.util.encodeBase64(pair.secretKey), + curvePublic: Nacl.util.encodeBase64(pair.publicKey), + }; +}; + +Client.create(function (err, client) { + if (err) { return void console.error(err); } + + nThen(function () { // BASIC KEY MANAGEMENT + // generate keys with login + // signing keys + // curve keys + // drive + }).nThen(function () { + // make a drive + // pin it + }).nThen(function () { // MAILBOXES + // write to your mailbox + // pin your mailbox + }).nThen(function () { + // create an owned pad + // pin the pad + // write to it + }).nThen(function () { + // get pinned usage + // remember the usage + }).nThen(function () { + // upload a file + // remember its size + }).nThen(function () { + // get pinned usage + // check that it is consistent with the size of your uploaded file + }).nThen(function () { + // delete your uploaded file + // unpin your owned file + }).nThen(function () { // EDITABLE METADATA + // + }).nThen(function () { + + }); + + var channel = "d34ebe83931382fcad9fe2e2d0e2cb5f"; // channel + var recipient = "e8jvf36S3chzkkcaMrLSW7PPrz7VDp85lIFNI26dTmw="; // curvePublic + + // curve keys + var keys = makeCurveKeys(); + var cryptor = Mailbox.createEncryptor(keys); + + var message = cryptor.encrypt(JSON.stringify({ + type: "CHEESE", + author: keys.curvePublic, + content: { + text: "CAMEMBERT", + } + }), recipient); + + client.anonRpc.send('WRITE_PRIVATE_MESSAGE', [channel, message], function (err, response) { + if (err) { + return void console.error(err); + } + + response = response; + // shutdown doesn't work, so we need to do this instead + client.shutdown(); + }); +});