mirror of
https://github.com/amark/gun.git
synced 2025-07-03 11:22:32 +00:00
state machine!!!
This commit is contained in:
parent
805aaa7571
commit
3e64d4d0e6
3
axe.js
3
axe.js
@ -29,6 +29,7 @@
|
|||||||
(Gun.AXE = AXE).GUN = AXE.Gun = Gun;
|
(Gun.AXE = AXE).GUN = AXE.Gun = Gun;
|
||||||
var ST = 0;
|
var ST = 0;
|
||||||
|
|
||||||
|
if(!Gun.window){ try{ USE('./lib/axe', 1) }catch(e){} }
|
||||||
Gun.on('opt', function(at){ start(at) ; this.to.next(at) }); // make sure to call the "next" middleware adapter.
|
Gun.on('opt', function(at){ start(at) ; this.to.next(at) }); // make sure to call the "next" middleware adapter.
|
||||||
|
|
||||||
function start(root){
|
function start(root){
|
||||||
@ -47,7 +48,7 @@
|
|||||||
tmp = peers[id = key] = peers[id] || {};
|
tmp = peers[id = key] = peers[id] || {};
|
||||||
tmp.id = tmp.url = id;
|
tmp.id = tmp.url = id;
|
||||||
});
|
});
|
||||||
tmp = peers[id = 'https://gun-manhattan.herokuapp.com/gun'] = peers[id] || {};
|
tmp = peers[id = 'https://mg-gun-manhattan.herokuapp.com/gun'] = peers[id] || {};
|
||||||
tmp.id = tmp.url = id;
|
tmp.id = tmp.url = id;
|
||||||
|
|
||||||
var mesh = opt.mesh = opt.mesh || Gun.Mesh(root); // DAM!
|
var mesh = opt.mesh = opt.mesh || Gun.Mesh(root); // DAM!
|
||||||
|
24
gun.js
24
gun.js
@ -349,29 +349,21 @@
|
|||||||
var ctx = msg._||'', root = ctx.root, graph = root.graph, lot, tmp;
|
var ctx = msg._||'', root = ctx.root, graph = root.graph, lot, tmp;
|
||||||
var vertex = graph[soul] || empty, was = state_is(vertex, key, 1), known = vertex[key];
|
var vertex = graph[soul] || empty, was = state_is(vertex, key, 1), known = vertex[key];
|
||||||
|
|
||||||
if(tmp = console.STAT){ if(!graph[soul] || !known){ tmp.has = (tmp.has || 0) + 1 } }
|
var DBG = ctx.DBG; if(tmp = console.STAT){ if(!graph[soul] || !known){ tmp.has = (tmp.has || 0) + 1 } }
|
||||||
|
|
||||||
var now = State(), u;
|
var now = State(), u;
|
||||||
if(state > now){ console.log("setTo"); /*setTo;*/ return } // TODO: BUG!!!!
|
if(state > now){
|
||||||
if(state < was){ console.log("old"); /*old;*/ if(!ctx.miss){ return } } // but some chains have a cache miss that need to re-fire. // TODO: Improve in future. // for AXE this would reduce rebroadcast, but GUN does it on message forwarding.
|
setTimeout(function(){ ham(val, key, soul, state, msg) }, (tmp = state - now) > MD? MD : tmp); // Max Defer 32bit. :(
|
||||||
|
console.STAT && console.STAT(((DBG||ctx).Hf = +new Date), tmp, 'future');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(state < was){ /*old;*/ if(!ctx.miss){ return } } // but some chains have a cache miss that need to re-fire. // TODO: Improve in future. // for AXE this would reduce rebroadcast, but GUN does it on message forwarding.
|
||||||
if(!ctx.faith){ // TODO: BUG? Can this be used for cache miss as well?
|
if(!ctx.faith){ // TODO: BUG? Can this be used for cache miss as well?
|
||||||
if(state === was && (val === known || L(val) <= L(known))){ /*console.log("same");*/ /*same;*/ return } // same
|
if(state === was && (val === known || L(val) <= L(known))){ /*console.log("same");*/ /*same;*/ return } // same
|
||||||
}
|
}
|
||||||
/*if(!is.incoming){
|
|
||||||
if(is.defer){
|
|
||||||
var to = state - machine;
|
|
||||||
setTimeout(function(){
|
|
||||||
ham(val, key, soul, state, msg);
|
|
||||||
}, to > MD? MD : to); // setTimeout Max Defer 32bit :(
|
|
||||||
if(!ctx.to){ root.on('in', {'@': msg['#'], err: to}) } ctx.to = 1; // TODO: This causes too many problems unless sending peers auto-retry.
|
|
||||||
return to;
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
//ctx.all++;
|
|
||||||
ctx.stun++; // TODO: 'forget' feature in SEA tied to this, bad approach, but hacked in for now. Any changes here must update there.
|
ctx.stun++; // TODO: 'forget' feature in SEA tied to this, bad approach, but hacked in for now. Any changes here must update there.
|
||||||
var aid = msg['#']+ctx.all++, id = {toString: function(){ return aid }, _: ctx}; // this *trick* makes it compatible between old & new versions.
|
var aid = msg['#']+ctx.all++, id = {toString: function(){ return aid }, _: ctx}; // this *trick* makes it compatible between old & new versions.
|
||||||
var DBG = ctx.DBG; DBG && (DBG.ph = DBG.ph || +new Date);
|
DBG && (DBG.ph = DBG.ph || +new Date);
|
||||||
root.on('put', {'#': id, '@': msg['@'], put: {'#': soul, '.': key, ':': val, '>': state}, _: ctx});
|
root.on('put', {'#': id, '@': msg['@'], put: {'#': soul, '.': key, ':': val, '>': state}, _: ctx});
|
||||||
}
|
}
|
||||||
function map(msg){
|
function map(msg){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user