-
+
@@ -109,15 +110,21 @@
A mysterious new example app has appeared! It is not finished/ready yet.
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
\ No newline at end of file
diff --git a/test/panic/set.js b/test/panic/set.js
new file mode 100644
index 00000000..7e0c323f
--- /dev/null
+++ b/test/panic/set.js
@@ -0,0 +1,200 @@
+var config = {
+ IP: require('ip').address(),
+ port: 8080,
+ servers: 1,
+ browsers: 2,
+ route: {
+ '/': __dirname + '/index.html',
+ '/gun.js': __dirname + '/../../gun.js',
+ '/jquery.js': __dirname + '/../../examples/jquery.js',
+ '/cryptomodules.js': __dirname + '/../../lib/cryptomodules.js',
+ '/sea.js': __dirname + '/../../sea.js'
+ }
+}
+
+var panic = require('panic-server');
+panic.server().on('request', function(req, res){
+ config.route[req.url] && require('fs').createReadStream(config.route[req.url]).pipe(res);
+}).listen(config.port);
+
+var clients = panic.clients;
+var manager = require('panic-manager')();
+
+manager.start({
+ clients: Array(config.servers).fill().map(function(u, i){
+ return {
+ type: 'node',
+ port: config.port + (i + 1)
+ }
+ }),
+ panic: 'http://' + config.IP + ':' + config.port
+});
+
+var servers = clients.filter('Node.js');
+var server = servers.pluck(1);
+var spawn = servers.excluding(server).pluck(1);
+var browsers = clients.excluding(servers);
+var alice = browsers.pluck(1);
+var bob = browsers.excluding(alice).pluck(1);
+var again = {};
+
+describe("Make sure SEA syncs correctly", function(){
+ //this.timeout(5 * 60 * 1000);
+ this.timeout(10 * 60 * 1000);
+
+ it("Servers have joined!", function(){
+ return servers.atLeast(config.servers);
+ });
+
+ it("GUN started!", function(){
+ return server.run(function(test){
+ var env = test.props;
+ test.async();
+ try{ require('fs').unlinkSync(env.i+'data') }catch(e){}
+ try{ require('fs').unlinkSync((env.i+1)+'data') }catch(e){}
+ var port = env.config.port + env.i;
+ var server = require('http').createServer(function(req, res){
+ res.end("I am "+ env.i +"!");
+ });
+ var Gun = require('gun');
+ var gun = Gun({file: env.i+'data', web: server});
+ server.listen(port, function(){
+ test.done();
+ });
+ }, {i: 1, config: config});
+ });
+
+ it(config.browsers +" browser(s) have joined!", function(){
+ console.log("PLEASE OPEN http://"+ config.IP +":"+ config.port +" IN "+ config.browsers +" BROWSER(S)!");
+ return browsers.atLeast(config.browsers);
+ });
+
+ it("Browsers load SEA!", function(){
+ var tests = [], i = 0;
+ browsers.each(function(client, id){
+ tests.push(client.run(function(test){
+ test.async();
+ //console.log("load?");
+ function load(src, cb){
+ var script = document.createElement('script');
+ script.onload = cb; script.src = src;
+ document.head.appendChild(script);
+ }
+ /*load('cryptomodules.js', function(){
+ load('sea.js', function(){
+ test.done();
+ });
+ });*/
+ test.done();
+ }, {i: i += 1, config: config}));
+ });
+ return Promise.all(tests);
+ });
+
+ it("Browsers initialized gun!", function(){
+ var tests = [], i = 0;
+ browsers.each(function(client, id){
+ tests.push(client.run(function(test){
+ localStorage.clear();
+ var env = test.props;
+ var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
+ window.gun = gun;
+ var user = window.user = gun.get('pub/alice');
+ }, {i: i += 1, config: config}));
+ });
+ return Promise.all(tests);
+ });
+
+ it("Create Alice", function(){
+ return alice.run(function(test){
+ console.log("I AM ALICE");
+ test.async();
+ user.put({pub: 'alice'}, function(ack){
+ if(ack.err){ return }
+ console.log("write...");
+ user.get('who').get('said').set({
+ what: "Hello world!"
+ }, function(ack){
+ if(ack.err){ return }
+ test.done();
+ });
+ });
+ });
+ });
+
+ it("Have Bob listen", function(){
+ return bob.run(function(test){
+ test.async();
+ window.count = [];
+ user.get('who').get('said').map().val(function(data){
+ console.log("read...", data);
+ window.count.push(data);
+ if(window.count.length - 1){ return }
+ test.done();
+ });
+ });
+ });
+
+ it("Alice reloading.", function(){
+ return alice.run(function(test){
+ location.reload();
+ });
+ });
+
+ it("Got Alice.", function(){
+ again.alice = browsers.excluding(new panic.ClientList([alice, bob])).pluck(1);
+ return again.alice.atLeast(1);
+ });
+
+ it("Alice reloaded.", function(){
+ return again.alice.run(function(test){
+ var env = test.props;
+ var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
+ window.gun = gun;
+ var user = window.user = gun.get('pub/alice');
+ }, {i: 1, config: config})
+ });
+
+ it("Alice write.", function(){
+ return again.alice.run(function(test){
+ test.async();
+ console.log("write...");
+ user.get('who').get('said').set({
+ what: "AAA"
+ }, function(ack){
+ if(ack.err){ return }
+ test.done();
+ });
+ });
+ });
+
+ it("Bob got", function(){
+ return bob.run(function(test){
+ test.async();
+ console.log(window.count);
+ setTimeout(function(){
+ if('AAA' === window.count[1].what){
+ test.done();
+ }
+ }, 100);
+ });
+ });
+
+ it("All finished!", function(done){
+ console.log("Done! Cleaning things up...");
+ setTimeout(function(){
+ done();
+ },1000);
+ });
+
+ after("Everything shut down.", function(){
+ browsers.run(function(){
+ //location.reload();
+ //setTimeout(function(){
+ //}, 15 * 1000);
+ });
+ return servers.run(function(){
+ process.exit();
+ });
+ });
+});
\ No newline at end of file
diff --git a/test/panic/who.js b/test/panic/who.js
new file mode 100644
index 00000000..d40c1dd5
--- /dev/null
+++ b/test/panic/who.js
@@ -0,0 +1,250 @@
+var config = {
+ IP: require('ip').address(),
+ port: 8080,
+ servers: 1,
+ browsers: 2,
+ route: {
+ '/': __dirname + '/index.html',
+ '/gun.js': __dirname + '/../../gun.js',
+ '/jquery.js': __dirname + '/../../examples/jquery.js',
+ '/cryptomodules.js': __dirname + '/../../lib/cryptomodules.js',
+ '/sea.js': __dirname + '/../../sea.js'
+ }
+}
+
+var panic = require('panic-server');
+panic.server().on('request', function(req, res){
+ config.route[req.url] && require('fs').createReadStream(config.route[req.url]).pipe(res);
+}).listen(config.port);
+
+var clients = panic.clients;
+var manager = require('panic-manager')();
+
+manager.start({
+ clients: Array(config.servers).fill().map(function(u, i){
+ return {
+ type: 'node',
+ port: config.port + (i + 1)
+ }
+ }),
+ panic: 'http://' + config.IP + ':' + config.port
+});
+
+var servers = clients.filter('Node.js');
+var server = servers.pluck(1);
+var spawn = servers.excluding(server).pluck(1);
+var browsers = clients.excluding(servers);
+var alice = browsers.pluck(1);
+var bob = browsers.excluding(alice).pluck(1);
+var again = {};
+
+describe("Make sure SEA syncs correctly", function(){
+ //this.timeout(5 * 60 * 1000);
+ this.timeout(10 * 60 * 1000);
+
+ it("Servers have joined!", function(){
+ return servers.atLeast(config.servers);
+ });
+
+ it("GUN started!", function(){
+ return server.run(function(test){
+ var env = test.props;
+ test.async();
+ try{ require('fs').unlinkSync(env.i+'data') }catch(e){}
+ try{ require('fs').unlinkSync((env.i+1)+'data') }catch(e){}
+ var port = env.config.port + env.i;
+ var server = require('http').createServer(function(req, res){
+ res.end("I am "+ env.i +"!");
+ });
+ var Gun = require('gun');
+ var gun = Gun({file: env.i+'data', web: server});
+ server.listen(port, function(){
+ test.done();
+ });
+ }, {i: 1, config: config});
+ });
+
+ it(config.browsers +" browser(s) have joined!", function(){
+ console.log("PLEASE OPEN http://"+ config.IP +":"+ config.port +" IN "+ config.browsers +" BROWSER(S)!");
+ return browsers.atLeast(config.browsers);
+ });
+
+ it("Browsers load SEA!", function(){
+ var tests = [], i = 0;
+ browsers.each(function(client, id){
+ tests.push(client.run(function(test){
+ test.async();
+ //console.log("load?");
+ function load(src, cb){
+ var script = document.createElement('script');
+ script.onload = cb; script.src = src;
+ document.head.appendChild(script);
+ }
+ load('cryptomodules.js', function(){
+ load('sea.js', function(){
+ test.done();
+ });
+ });
+ }, {i: i += 1, config: config}));
+ });
+ return Promise.all(tests);
+ });
+
+ it("Browsers initialized gun!", function(){
+ var tests = [], i = 0;
+ browsers.each(function(client, id){
+ tests.push(client.run(function(test){
+ localStorage.clear();
+ var env = test.props;
+ var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
+ window.gun = gun;
+ var user = window.user = gun.user();
+ }, {i: i += 1, config: config}));
+ });
+ return Promise.all(tests);
+ });
+
+ it("Create Alice", function(){
+ return alice.run(function(test){
+ console.log("I AM ALICE");
+ test.async();
+ window.user.create('alice', 'xyzabcmnopq', function(ack){
+ if(ack.err || !ack.pub){ return }
+ window.user.auth('alice', 'xyzabcmnopq', function(ack){
+ if(ack.err || !ack.pub){ return }
+ test.done();
+ user.get('who').get('said').set({
+ what: "Hello world!"
+ }, function(ack){
+ if(ack.err){ return }
+ test.done();
+ });
+ });
+ });
+ });
+ });
+
+ it("Create Bob", function(){
+ return bob.run(function(test){
+ test.async();
+ window.user.create('bob', 'zyxcbaqponm', function(ack){
+ if(ack.err || !ack.pub){ return }
+ window.user.auth('bob', 'zyxcbaqponm', function(ack){
+ if(ack.err || !ack.pub){ return }
+ test.done();
+ });
+ });
+ });
+ });
+
+ it("Have Bob find Alice", function(){
+ return bob.run(function(test){
+ test.async();
+
+ window.gun.get('alias/alice').map().val(function(data){
+ window.ref = gun.get('pub/'+data.pub);
+ test.done();
+ });
+ });
+ });
+
+ it("Have Bob listen", function(){
+ return bob.run(function(test){
+ test.async();
+
+ window.count = [];
+ ref.get('who').get('said').map().val(function(data){
+ console.log("read...", data);
+ window.count.push(data);
+ if(window.count.length - 1){ return }
+ test.done();
+ });
+ });
+ });
+
+ it("Alice reloading.", function(){
+ return alice.run(function(test){
+ location.reload();
+ });
+ });
+
+ it("Got Alice.", function(){
+ again.alice = browsers.excluding(new panic.ClientList([alice, bob])).pluck(1);
+ return again.alice.atLeast(1);
+ });
+
+ it("Alice reloaded.", function(){
+ return again.alice.run(function(test){
+ test.async();
+ //console.log("load?");
+ function load(src, cb){
+ var script = document.createElement('script');
+ script.onload = cb; script.src = src;
+ document.head.appendChild(script);
+ }
+ load('cryptomodules.js', function(){
+ load('sea.js', function(){
+ test.done();
+ });
+ });
+ }, {i: 1, config: config});
+ });
+
+ it("Alice loaded.", function(){
+ return again.alice.run(function(test){
+ test.async();
+
+ var env = test.props;
+ var gun = Gun('http://'+ env.config.IP + ':' + (env.config.port + 1) + '/gun');
+ window.gun = gun;
+ var user = window.user = gun.user();
+ user.auth('alice', 'xyzabcmnopq', function(ack){
+ if(ack.err || !ack.pub){ return }
+ test.done();
+ });
+ }, {i: 1, config: config})
+ });
+
+ it("Alice write.", function(){
+ return again.alice.run(function(test){
+ test.async();
+ console.log("write...");
+ user.get('who').get('said').set({
+ what: "AAA"
+ }, function(ack){
+ if(ack.err){ return }
+ test.done();
+ });
+ });
+ });
+
+ it("Have Bob listen", function(){
+ return bob.run(function(test){
+ test.async();
+ console.log(window.count);
+ setTimeout(function(){
+ if('AAA' === window.count[1].what){
+ test.done();
+ }
+ }, 1200);
+ });
+ });
+
+ it("All finished!", function(done){
+ console.log("Done! Cleaning things up...");
+ setTimeout(function(){
+ done();
+ },1000);
+ });
+
+ after("Everything shut down.", function(){
+ browsers.run(function(){
+ //location.reload();
+ //setTimeout(function(){
+ //}, 15 * 1000);
+ });
+ return servers.run(function(){
+ process.exit();
+ });
+ });
+});
\ No newline at end of file
diff --git a/test/ptsd/streampipe.js b/test/ptsd/streampipe.js
new file mode 100644
index 00000000..10e8ac92
--- /dev/null
+++ b/test/ptsd/streampipe.js
@@ -0,0 +1,134 @@
+const stream = require('stream')
+const Gun = require('gun')
+
+const randomString = length => {
+ const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+ let text = ''
+ for (var i = 0; i < length; i++) {
+ text += possible[Math.floor(Math.random() * possible.length)]
+ }
+ return text
+}
+
+// Generator
+// generates stream of json {id: "", name: "", description: ""}
+class Generator extends stream.Readable {
+ constructor(n) {
+ super()
+
+ this._n = n
+ this._i = 0
+ }
+
+ _read(size) {
+ if (this._i < this._n) {
+ this.push(
+ JSON.stringify({
+ id: `${this._i}`,
+ name: randomString(20),
+ description: randomString(200)
+ })
+ )
+ this.push('\n')
+ this._i++
+ } else {
+ this.push(null)
+ }
+ }
+}
+
+// Line
+// read line by line as stream comes through it
+class Line extends stream.Transform {
+ constructor() {
+ super()
+ this.buff = ''
+ }
+
+ trySendLine() {
+ let index = this.buff.indexOf(`\n`)
+
+ while (index !== -1) {
+ const line = this.buff.slice(0, index)
+ this.buff = this.buff.slice(index + 1)
+
+ this.push(line)
+
+ index = this.buff.indexOf(`\n`)
+ }
+ }
+
+ _transform(chunk, enc, cb) {
+ this.buff += chunk.toString()
+
+ this.trySendLine()
+
+ cb()
+ }
+
+ end() {
+ this.trySendLine()
+
+ if (this.buff.length > 0) {
+ this.push(this.buff)
+ }
+ }
+}
+
+// Graph
+// parse the chunk and tries to add it to table
+class Graph extends stream.Transform {
+ constructor() {
+ super()
+
+ this.db = new Gun({
+ //file: 'graph.json'
+ localStorage: false
+ })
+ this.items = this.db.get('items')
+ }
+
+ _transform(chunk, enc, cb) {
+ const json = JSON.parse(chunk.toString())
+ const item = this.db.get(json.id)
+
+ item.put(
+ {
+ id: json.id,
+ name: json.name,
+ description: json.description
+ },
+ () => {
+ this.items.set(item, () => {
+ this.push(chunk)
+ cb()
+ })
+ }
+ )
+ }
+}
+
+// Report
+// shows how many item has pass through the system
+class Report extends stream.Transform {
+ constructor() {
+ super()
+ this._count = 0
+ }
+
+ _transform(chunk, enc, cb) {
+ this.push(`count: ${this._count++}\r`)
+ cb()
+ }
+}
+
+const generator = new Generator(5000)
+const line = new Line()
+const graph = new Graph()
+const report = new Report()
+
+generator
+ .pipe(line)
+ .pipe(graph)
+ .pipe(report)
+ .pipe(process.stdout)
\ No newline at end of file
diff --git a/test/sea-tmp.html b/test/sea-tmp.html
new file mode 100644
index 00000000..9415de11
--- /dev/null
+++ b/test/sea-tmp.html
@@ -0,0 +1,33 @@
+
+
+
+
\ No newline at end of file