From c03a03c2c1dc77d155ad88197c7f77981b2b6e77 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 7 Jul 2017 00:29:20 -0700 Subject: [PATCH] some quick fixes --- gun.js | 2 +- lib/radisk.js | 8 ++++++++ lib/s3.js | 2 ++ nts.js | 22 +++++++++++----------- package.json | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/gun.js b/gun.js index a17719b1..b865d46b 100644 --- a/gun.js +++ b/gun.js @@ -1642,7 +1642,7 @@ var ack = acks; acks = {}; try{store.setItem(opt.file, JSON.stringify(disk)); - }catch(e){ err = e || "localStorage failure" } + }catch(e){ Gun.log(err = e || "localStorage failure") } if(!err && !Gun.obj.empty(opt.peers)){ return } // only ack if there are no peers. Gun.obj.map(ack, function(yes, id){ ctx.on('in', { diff --git a/lib/radisk.js b/lib/radisk.js index 933096cf..2e0fb512 100644 --- a/lib/radisk.js +++ b/lib/radisk.js @@ -10,6 +10,13 @@ function Radisk(opt){ 3. If a batch exceeds a certain number of writes, force atomic batch to disk. (This caps total performance, but reduces potential loss) */ var radisk = function(key, val, cb){ + if(0 <= key.indexOf('_') || 0 <= key.indexOf('$')){ // TODO: BUG! Fix! + var err = "ERROR: Radix and Radisk not tested against _ or $ keys!"; + console.log(err); + cb = cb || val; + if(cb instanceof Function){ cb(err) } + return; + } if(val instanceof Function){ cb = val; val = radisk.batch(key); @@ -143,6 +150,7 @@ function Radisk(opt){ var rest = step.rest; step.rest = ""; fs.writeFile(opt.file +'/'+ file, rest, cb); + if(opt.disk){ opt.disk(opt.file+'/'+file, rest, cb) } }, slice: function(val, key){ if(key < step.file){ return } diff --git a/lib/s3.js b/lib/s3.js index f8a12eab..6b2b7c22 100644 --- a/lib/s3.js +++ b/lib/s3.js @@ -5,6 +5,8 @@ var Gun = require('../gun'); var S3 = require('./aws'); + // TODO: BUG! Mark, upgrade S3 in v0.8.1! And try to integrate with Radix Storage Engine! + Gun.on('opt', function(at){ var opt = at.opt.s3 || (at.opt.s3 = {}); var s3 = opt.store || S3(opt); diff --git a/nts.js b/nts.js index aff17017..e8389f69 100644 --- a/nts.js +++ b/nts.js @@ -1,5 +1,7 @@ ;(function(){ - + // NOTE: While the algorithm is P2P, + // the current implementation is one sided, + // only browsers self-modify, servers do not. var env; if(typeof global !== "undefined"){ env = global } if(typeof window !== "undefined"){ var Gun = (env = window).Gun } @@ -7,11 +9,10 @@ if(typeof require !== "undefined"){ var Gun = require('./gun') } } - Gun.on('opt', function(at){ - this.to.next(at); - if(at.once){ return } - var root = at.gun; - root.on('in', function(at){ + Gun.on('opt', function(ctx){ + this.to.next(ctx); + if(ctx.once){ return } + ctx.on('in', function(at){ if(!at.NTS){ return this.to.next(at); } @@ -24,13 +25,12 @@ } this.to.next({'@': at['#'], NTS: Gun.time.is()}); }); - var ask = {}, noop = function(){}; if(!env.window){ return } Gun.state.drift = Gun.state.drift || 0; - function ping(){ - var NTS = {}, ack = Gun.text.random(), msg = {'#': ack, NTS: true, gun: root}; + setTimeout(function ping(){ + var NTS = {}, ack = Gun.text.random(), msg = {'#': ack, NTS: true, gun: ctx.gun}; NTS.start = Gun.state(); ask[ack] = function(at){ NTS.end = Gun.state(); @@ -41,8 +41,8 @@ Gun.state.drift -= (NTS.end - NTS.calc)/2; setTimeout(ping, 1000); } - Gun.on('out', msg); - }; ping(); + ctx.on('out', msg); + }, 1); }); // test by opening up examples/game/nts.html on devices that aren't NTP synced. }()); diff --git a/package.json b/package.json index 61fb26d5..bc4ff99e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.8.0", + "version": "0.8.1", "description": "Graph engine", "main": "index.js", "browser": "gun.min.js",