This commit is contained in:
Mark Nadal 2019-01-16 10:28:16 -08:00
parent a07cfaaeac
commit c5cd72a631
7 changed files with 43 additions and 60 deletions

2
gun.js
View File

@ -1804,7 +1804,7 @@
}); });
}); });
setTimeout(function(){ setTimeout(function(){
root.on('out', {put: send, '#': root.ask(ack), I: root.$}); root.on('out', {put: send, '#': root.ask(ack)});
},1); },1);
} }

3
gun.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -50,11 +50,11 @@
// signature handles data output, it is a proxy to the security function. // signature handles data output, it is a proxy to the security function.
function signature(msg){ function signature(msg){
if(msg.user){ if((msg._||noop).user){
return this.to.next(msg); return this.to.next(msg);
} }
var ctx = this.as; var ctx = this.as;
msg.user = ctx.user; (msg._||(msg._=function(){})).user = ctx.user;
security.call(this, msg); security.call(this, msg);
} }
@ -95,9 +95,9 @@
each.pubs(val, key, node, soul); return; each.pubs(val, key, node, soul); return;
} }
if('~' === soul.slice(0,1) && 2 === (tmp = soul.slice(1)).split('.').length){ // special case, account data for a public key. if('~' === soul.slice(0,1) && 2 === (tmp = soul.slice(1)).split('.').length){ // special case, account data for a public key.
each.pub(val, key, node, soul, tmp, msg.user); return; each.pub(val, key, node, soul, tmp, (msg._||noop).user); return;
} }
each.any(val, key, node, soul, msg.user); return; each.any(val, key, node, soul, (msg._||noop).user); return;
return each.end({err: "No other data allowed!"}); return each.end({err: "No other data allowed!"});
}; };
each.alias = function(val, key, node, soul){ // Example: {_:#~@, ~@alice: {#~@alice}} each.alias = function(val, key, node, soul){ // Example: {_:#~@, ~@alice: {#~@alice}}
@ -116,7 +116,7 @@
return each.end({err: "Account must match!"}); return each.end({err: "Account must match!"});
} }
check['user'+soul+key] = 1; check['user'+soul+key] = 1;
if(msg.I && user && user.is && pub === user.is.pub){ if(Gun.is(msg.$) && user && user.is && pub === user.is.pub){
SEA.sign(SEA.opt.prep(tmp = SEA.opt.parse(val), key, node, soul), (user._).sea, function(data){ var rel; SEA.sign(SEA.opt.prep(tmp = SEA.opt.parse(val), key, node, soul), (user._).sea, function(data){ var rel;
if(u === data){ return each.end({err: SEA.err || 'Pub signature fail.'}) } if(u === data){ return each.end({err: SEA.err || 'Pub signature fail.'}) }
if(rel = Gun.val.link.is(val)){ if(rel = Gun.val.link.is(val)){
@ -141,20 +141,12 @@
}); });
}; };
each.any = function(val, key, node, soul, user){ var tmp, pub; each.any = function(val, key, node, soul, user){ var tmp, pub;
if(!user || !user.is){ if(!(pub = SEA.opt.pub(soul))){
if(tmp = SEA.opt.pub(soul)){ if(at.opt.secure){
check['any'+soul+key] = 1; each.end({err: "Soul is missing public key at '" + key + "'."});
SEA.verify(SEA.opt.pack(val,key,node,soul), pub = tmp, function(data){ var rel;
data = SEA.opt.unpack(data, key, node);
if(u === data){ return each.end({err: "Mismatched owner on '" + key + "'."}) } // thanks @rogowski !
if((rel = Gun.val.link.is(data)) && pub === SEA.opt.pub(rel)){
(at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
}
check['any'+soul+key] = 0;
each.end({ok: 1});
});
return; return;
} }
// TODO: Ask community if should auto-sign non user-graph data.
check['any'+soul+key] = 1; check['any'+soul+key] = 1;
at.on('secure', function(msg){ this.off(); at.on('secure', function(msg){ this.off();
check['any'+soul+key] = 0; check['any'+soul+key] = 0;
@ -164,24 +156,7 @@
//each.end({err: "Data cannot be modified."}); //each.end({err: "Data cannot be modified."});
return; return;
} }
if(!(tmp = SEA.opt.pub(soul))){ if(Gun.is(msg.$) && user && user.is && pub === user.is.pub){
if(at.opt.secure){
each.end({err: "Soul is missing public key at '" + key + "'."});
return;
}
// TODO: Ask community if should auto-sign non user-graph data.
check['any'+soul+key] = 0;
each.end({ok: 1});
return;
}
if(!msg.I){ // only sign data put out from this instance.
each.any(val, key, node, soul);
return;
}
if((pub = tmp) !== (user.is||noop).pub){
each.any(val, key, node, soul);
return;
}
/*var other = Gun.obj.map(at.sea.own[soul], function(v, p){ /*var other = Gun.obj.map(at.sea.own[soul], function(v, p){
if((user.is||{}).pub !== p){ return p } if((user.is||{}).pub !== p){ return p }
}); });
@ -196,6 +171,18 @@
check['any'+soul+key] = 0; check['any'+soul+key] = 0;
each.end({ok: 1}); each.end({ok: 1});
}, {check: SEA.opt.pack(tmp, key, node, soul), raw: 1}); }, {check: SEA.opt.pack(tmp, key, node, soul), raw: 1});
return;
}
check['any'+soul+key] = 1;
SEA.verify(SEA.opt.pack(val,key,node,soul), pub, function(data){ var rel;
data = SEA.opt.unpack(data, key, node);
if(u === data){ return each.end({err: "Mismatched owner on '" + key + "'."}) } // thanks @rogowski !
if((rel = Gun.val.link.is(data)) && pub === SEA.opt.pub(rel)){
(at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
}
check['any'+soul+key] = 0;
each.end({ok: 1});
});
} }
each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb? each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb?
if(each.err){ return } if(each.err){ return }
@ -207,7 +194,7 @@
if(Gun.obj.map(check, function(no){ if(Gun.obj.map(check, function(no){
if(no){ return true } if(no){ return true }
})){ return } })){ return }
msg.user = at.user; // already been through firewall, does not need to again on out. (msg._||{}).user = at.user || security; // already been through firewall, does not need to again on out.
to.next(msg); to.next(msg);
}; };
Gun.obj.map(msg.put, each.node); Gun.obj.map(msg.put, each.node);
@ -248,7 +235,7 @@
} }
} }
SEA.opt.shuffle_attack = 1546329600000; // Jan 1, 2019 SEA.opt.shuffle_attack = 1546329600000; // Jan 1, 2019
var noop = {}, u; var noop = function(){}, u;
var fl = Math.floor; // TODO: Still need to fix inconsistent state issue. var fl = Math.floor; // TODO: Still need to fix inconsistent state issue.
var rel_is = Gun.val.rel.is; var rel_is = Gun.val.rel.is;
// TODO: Potential bug? If pub/priv key starts with `-`? IDK how possible. // TODO: Potential bug? If pub/priv key starts with `-`? IDK how possible.

View File

@ -36,7 +36,7 @@ Gun.on('create', function(root){
root.on('out', function(msg){ root.on('out', function(msg){
if(msg.lS){ return } if(msg.lS){ return }
if(msg.I && msg.put && !msg['@'] && !empty(opt.peers)){ if(Gun.is(msg.$) && msg.put && !msg['@'] && !empty(opt.peers)){
id = msg['#']; id = msg['#'];
Gun.graph.is(msg.put, null, map); Gun.graph.is(msg.put, null, map);
if(!to){ to = setTimeout(flush, opt.wait || 1) } if(!to){ to = setTimeout(flush, opt.wait || 1) }
@ -112,7 +112,7 @@ Gun.on('create', function(root){
return; // Hmm, what if we have peers but we are disconnected? return; // Hmm, what if we have peers but we are disconnected?
} }
//console.log("lS get", lex, data); //console.log("lS get", lex, data);
root.on('in', {'@': msg['#'], put: Gun.graph.node(data), how: 'lS', lS: msg.I}); root.on('in', {'@': msg['#'], put: Gun.graph.node(data), how: 'lS', lS: msg.$ || root.$});
}; };
Gun.debug? setTimeout(to,1) : to(); Gun.debug? setTimeout(to,1) : to();
}); });

View File

@ -14,8 +14,8 @@ function Mesh(ctx){
if((tmp = msg['@']) if((tmp = msg['@'])
&& (tmp = ctx.dup.s[tmp]) && (tmp = ctx.dup.s[tmp])
&& (tmp = tmp.it) && (tmp = tmp.it)
&& tmp.mesh){ && tmp._){
mesh.say(msg, tmp.mesh.via, 1); mesh.say(msg, (tmp._).via, 1);
tmp['##'] = msg['##']; tmp['##'] = msg['##'];
return; return;
} }
@ -47,9 +47,9 @@ function Mesh(ctx){
(tmp = dup.s)[hash] = tmp[id]; (tmp = dup.s)[hash] = tmp[id];
} }
} }
(msg.mesh = function(){}).via = peer; (msg._ = function(){}).via = peer;
if((tmp = msg['><'])){ if((tmp = msg['><'])){
msg.mesh.to = Type.obj.map(tmp.split(','), function(k,i,m){m(k,true)}); (msg._).to = Type.obj.map(tmp.split(','), function(k,i,m){m(k,true)});
} }
if(msg.dam){ if(msg.dam){
if(tmp = mesh.hear[msg.dam]){ if(tmp = mesh.hear[msg.dam]){
@ -57,7 +57,6 @@ function Mesh(ctx){
} }
return; return;
} }
ctx.on('in', msg); ctx.on('in', msg);
return; return;
@ -88,7 +87,7 @@ function Mesh(ctx){
} }
var tmp, wire = peer.wire || ((opt.wire) && opt.wire(peer)), msh, raw;// || open(peer, ctx); // TODO: Reopen! var tmp, wire = peer.wire || ((opt.wire) && opt.wire(peer)), msh, raw;// || open(peer, ctx); // TODO: Reopen!
if(!wire){ return } if(!wire){ return }
msh = msg.mesh || empty; msh = (msg._) || empty;
if(peer === msh.via){ return } if(peer === msh.via){ return }
if(!(raw = msh.raw)){ raw = mesh.raw(msg) } if(!(raw = msh.raw)){ raw = mesh.raw(msg) }
if((tmp = msg['@']) if((tmp = msg['@'])
@ -139,7 +138,7 @@ function Mesh(ctx){
mesh.raw = function(msg){ mesh.raw = function(msg){
if(!msg){ return '' } if(!msg){ return '' }
var dup = ctx.dup, msh = msg.mesh || {}, put, hash, tmp; var dup = ctx.dup, msh = (msg._) || {}, put, hash, tmp;
if(tmp = msh.raw){ return tmp } if(tmp = msh.raw){ return tmp }
if(typeof msg === 'string'){ return msg } if(typeof msg === 'string'){ return msg }
if(msg['@'] && (tmp = msg.put)){ if(msg['@'] && (tmp = msg.put)){

View File

@ -16,7 +16,6 @@ Gun.chain.chain = function(sub){
function output(msg){ function output(msg){
var put, get, at = this.as, back = at.back, root = at.root, tmp; var put, get, at = this.as, back = at.back, root = at.root, tmp;
if(!msg.I){ msg.I = at.$ }
if(!msg.$){ msg.$ = at.$ } if(!msg.$){ msg.$ = at.$ }
this.to.next(msg); this.to.next(msg);
if(get = msg.get){ if(get = msg.get){
@ -272,7 +271,6 @@ function ack(msg, ev){
at.on('in', {get: at.get, put: Gun.val.link.ify(get['#']), $: at.$, '@': msg['@']}); at.on('in', {get: at.get, put: Gun.val.link.ify(get['#']), $: at.$, '@': msg['@']});
return; return;
} }
msg.$ = at.root.$;
Gun.on.put(msg, at.root.$); Gun.on.put(msg, at.root.$);
} }
var empty = {}, u; var empty = {}, u;

View File

@ -86,7 +86,7 @@ function use(msg){
//else if(!cat.async && msg.put !== at.put && root.stop && root.stop[at.id]){ return } root.stop && (root.stop[at.id] = true); //else if(!cat.async && msg.put !== at.put && root.stop && root.stop[at.id]){ return } root.stop && (root.stop[at.id] = true);
//root.stop && (root.stop.ID = root.stop.ID || Gun.text.random(2)); //root.stop && (root.stop.id = root.stop.id || Gun.text.random(2));
//if((tmp = root.stop) && (tmp = tmp[at.id] || (tmp[at.id] = {})) && tmp[cat.id]){ return } tmp && (tmp[cat.id] = true); //if((tmp = root.stop) && (tmp = tmp[at.id] || (tmp[at.id] = {})) && tmp[cat.id]){ return } tmp && (tmp[cat.id] = true);
if(eve.seen && at.id && eve.seen[at.id]){ return eve.to.next(msg) } if(eve.seen && at.id && eve.seen[at.id]){ return eve.to.next(msg) }
//if((tmp = root.stop)){ if(tmp[at.id]){ return } tmp[at.id] = msg.root; } // temporary fix till a better solution? //if((tmp = root.stop)){ if(tmp[at.id]){ return } tmp[at.id] = msg.root; } // temporary fix till a better solution?