diff --git a/lib/file.js b/lib/file.js index f5f781c2..08f4291a 100644 --- a/lib/file.js +++ b/lib/file.js @@ -10,6 +10,7 @@ Gun.on('opt', function(ctx){ this.to.next(ctx); var opt = ctx.opt; if(ctx.once){ return } + if(false === opt.localStorage){ return } if(process.env.AWS_S3_BUCKET){ return } opt.file = String(opt.file || 'data.json'); var graph = ctx.graph, acks = {}, count = 0, to; diff --git a/lib/radisk.js b/lib/radisk.js index 01da2da7..cb2d571d 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -6,8 +6,8 @@ function Radisk(opt){ opt = opt || {}; opt.file = String(opt.file || 'radata'); + opt.thrash = opt.thrash || opt.wait || 1; opt.batch = opt.batch || 10 * 1000; - opt.wait = opt.wait || 1; opt.size = opt.size || (1024 * 1024 * 10); // 10MB opt.code = opt.code || {}; opt.code.from = opt.code.from || '!'; @@ -51,7 +51,7 @@ function Radisk(opt){ if(cb){ r.batch.acks.push(cb) } if(++r.batch.ed >= opt.batch){ return r.thrash() } // (2) clearTimeout(r.batch.to); // (1) - r.batch.to = setTimeout(r.thrash, opt.wait); + r.batch.to = setTimeout(r.thrash, opt.thrash || 1); } r.batch = Radix(); diff --git a/lib/rs3.js b/lib/rs3.js index 4f085216..d383d673 100644 --- a/lib/rs3.js +++ b/lib/rs3.js @@ -11,7 +11,7 @@ Gun.on('opt', function(ctx){ if(ctx.once){ return } if(!process.env.AWS_S3_BUCKET){ return } opt.batch = opt.batch || (1000 * 10); - opt.wait = opt.wait || (1000 * 15); + opt.thrash = opt.thrash || (1000 * 15); opt.size = opt.size || (1024 * 1024 * 10); // 10MB var opts = opt.s3 || (opt.s3 = {}); @@ -44,9 +44,7 @@ function Store(opt){ }; store.get = function(file, cb){ var params = {Bucket: opts.bucket, Key: file||''}; - var id = Gun.text.random(3), n = Gun.time.is();console.log('----->', id, file); // debug demo server s3.getObject(params, function(err, ack){ - console.log('<-----', id, file, (Gun.time.is() - n)/1000); // debug demo server if(!ack){ return cb(null) } var data = (ack||{}).Body; if(data){ data = data.toString() } diff --git a/lib/store.js b/lib/store.js index 56cade2d..f0de8230 100644 --- a/lib/store.js +++ b/lib/store.js @@ -8,7 +8,7 @@ Gun.on('opt', function(ctx){ this.to.next(ctx); var opt = ctx.opt; if(ctx.once){ return } - if(!process.env.AWS_S3_BUCKET){ return } // TODO: Remove this after migration. + if(false !== opt.localStorage){ return } // TODO: Remove this after migration. opt.store = opt.store || Store(opt); var rad = Radisk(opt); diff --git a/package.json b/package.json index 9ad6bdc2..f3c1efaa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.9.0", + "version": "0.9.1", "description": "Graph engine", "main": "index.js", "browser": "gun.min.js", diff --git a/test/panic/radisk.js b/test/panic/radisk.js new file mode 100644 index 00000000..936664d5 --- /dev/null +++ b/test/panic/radisk.js @@ -0,0 +1,127 @@ +var config = { + IP: require('ip').address(), + port: 8080, + servers: 1, + browsers: 2, + dir: __dirname, + route: { + '/': __dirname + '/index.html', + '/gun.js': __dirname + '/../../gun.js', + '/jquery.js': __dirname + '/../../examples/jquery.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 browsers = clients.excluding(servers); +var alice = browsers.pluck(1); +var bob = browsers.excluding(alice).pluck(1); + +describe("Make sure the Radix Storage Engine (RSE) works.", 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(); + if(require('fs').existsSync('radata')){ + console.log("Please delete previous data first!"); + explode; + return; + } + 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'); + require('gun/lib/store'); + var gun = Gun({web: server, localStorage: false, thrash: 6000}); + 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 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; + }, {i: i += 1, config: config})); + }); + return Promise.all(tests); + }); + + it("Alice save data", function(){ + return alice.run(function(test){ + console.log("I AM ALICE"); + test.async(); + var n = Gun.time.is(); + window.gun.get('foo').put({hello: "world!"}, function(ack){ + console.log("???", (Gun.time.is() - n)/1000, ack); + test.done(); + }); + }); + }); + + it("Bob read data", function(){ + return bob.run(function(test){ + console.log("I AM BOB"); + test.async(); + var n = Gun.time.is(); + window.gun.get('foo').on(function(data){ + console.log("???", (Gun.time.is() - n)/1000, data); + test.done(); + }); + }); + }); + + 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