mirror of
https://github.com/amark/gun.git
synced 2025-06-05 13:46:43 +00:00
some quick fixes
This commit is contained in:
parent
388bcd0082
commit
c03a03c2c1
2
gun.js
2
gun.js
@ -1642,7 +1642,7 @@
|
|||||||
var ack = acks;
|
var ack = acks;
|
||||||
acks = {};
|
acks = {};
|
||||||
try{store.setItem(opt.file, JSON.stringify(disk));
|
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.
|
if(!err && !Gun.obj.empty(opt.peers)){ return } // only ack if there are no peers.
|
||||||
Gun.obj.map(ack, function(yes, id){
|
Gun.obj.map(ack, function(yes, id){
|
||||||
ctx.on('in', {
|
ctx.on('in', {
|
||||||
|
@ -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)
|
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){
|
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){
|
if(val instanceof Function){
|
||||||
cb = val;
|
cb = val;
|
||||||
val = radisk.batch(key);
|
val = radisk.batch(key);
|
||||||
@ -143,6 +150,7 @@ function Radisk(opt){
|
|||||||
var rest = step.rest;
|
var rest = step.rest;
|
||||||
step.rest = "";
|
step.rest = "";
|
||||||
fs.writeFile(opt.file +'/'+ file, rest, cb);
|
fs.writeFile(opt.file +'/'+ file, rest, cb);
|
||||||
|
if(opt.disk){ opt.disk(opt.file+'/'+file, rest, cb) }
|
||||||
},
|
},
|
||||||
slice: function(val, key){
|
slice: function(val, key){
|
||||||
if(key < step.file){ return }
|
if(key < step.file){ return }
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
var Gun = require('../gun');
|
var Gun = require('../gun');
|
||||||
var S3 = require('./aws');
|
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){
|
Gun.on('opt', function(at){
|
||||||
var opt = at.opt.s3 || (at.opt.s3 = {});
|
var opt = at.opt.s3 || (at.opt.s3 = {});
|
||||||
var s3 = opt.store || S3(opt);
|
var s3 = opt.store || S3(opt);
|
||||||
|
22
nts.js
22
nts.js
@ -1,5 +1,7 @@
|
|||||||
;(function(){
|
;(function(){
|
||||||
|
// NOTE: While the algorithm is P2P,
|
||||||
|
// the current implementation is one sided,
|
||||||
|
// only browsers self-modify, servers do not.
|
||||||
var env;
|
var env;
|
||||||
if(typeof global !== "undefined"){ env = global }
|
if(typeof global !== "undefined"){ env = global }
|
||||||
if(typeof window !== "undefined"){ var Gun = (env = window).Gun }
|
if(typeof window !== "undefined"){ var Gun = (env = window).Gun }
|
||||||
@ -7,11 +9,10 @@
|
|||||||
if(typeof require !== "undefined"){ var Gun = require('./gun') }
|
if(typeof require !== "undefined"){ var Gun = require('./gun') }
|
||||||
}
|
}
|
||||||
|
|
||||||
Gun.on('opt', function(at){
|
Gun.on('opt', function(ctx){
|
||||||
this.to.next(at);
|
this.to.next(ctx);
|
||||||
if(at.once){ return }
|
if(ctx.once){ return }
|
||||||
var root = at.gun;
|
ctx.on('in', function(at){
|
||||||
root.on('in', function(at){
|
|
||||||
if(!at.NTS){
|
if(!at.NTS){
|
||||||
return this.to.next(at);
|
return this.to.next(at);
|
||||||
}
|
}
|
||||||
@ -24,13 +25,12 @@
|
|||||||
}
|
}
|
||||||
this.to.next({'@': at['#'], NTS: Gun.time.is()});
|
this.to.next({'@': at['#'], NTS: Gun.time.is()});
|
||||||
});
|
});
|
||||||
|
|
||||||
var ask = {}, noop = function(){};
|
var ask = {}, noop = function(){};
|
||||||
if(!env.window){ return }
|
if(!env.window){ return }
|
||||||
|
|
||||||
Gun.state.drift = Gun.state.drift || 0;
|
Gun.state.drift = Gun.state.drift || 0;
|
||||||
function ping(){
|
setTimeout(function ping(){
|
||||||
var NTS = {}, ack = Gun.text.random(), msg = {'#': ack, NTS: true, gun: root};
|
var NTS = {}, ack = Gun.text.random(), msg = {'#': ack, NTS: true, gun: ctx.gun};
|
||||||
NTS.start = Gun.state();
|
NTS.start = Gun.state();
|
||||||
ask[ack] = function(at){
|
ask[ack] = function(at){
|
||||||
NTS.end = Gun.state();
|
NTS.end = Gun.state();
|
||||||
@ -41,8 +41,8 @@
|
|||||||
Gun.state.drift -= (NTS.end - NTS.calc)/2;
|
Gun.state.drift -= (NTS.end - NTS.calc)/2;
|
||||||
setTimeout(ping, 1000);
|
setTimeout(ping, 1000);
|
||||||
}
|
}
|
||||||
Gun.on('out', msg);
|
ctx.on('out', msg);
|
||||||
}; ping();
|
}, 1);
|
||||||
});
|
});
|
||||||
// test by opening up examples/game/nts.html on devices that aren't NTP synced.
|
// test by opening up examples/game/nts.html on devices that aren't NTP synced.
|
||||||
}());
|
}());
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gun",
|
"name": "gun",
|
||||||
"version": "0.8.0",
|
"version": "0.8.1",
|
||||||
"description": "Graph engine",
|
"description": "Graph engine",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"browser": "gun.min.js",
|
"browser": "gun.min.js",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user