mirror of
https://github.com/amark/gun.git
synced 2025-06-03 20:56:43 +00:00
set gun ref with SEA causes race condition while crypto op happen, cache dub
This commit is contained in:
parent
7f4bfd4a60
commit
a96a80ce66
@ -5,7 +5,7 @@
|
||||
<input id="pass" type="password" placeholder="passphrase">
|
||||
<input id="in" type="submit" value="sign in">
|
||||
<input id="up" type="button" value="sign up">
|
||||
<input id="mask" type="button" value="MetaMask Login">
|
||||
<input id="mask" type="button" value="Identifi Login">
|
||||
</form>
|
||||
|
||||
<ul></ul>
|
||||
|
11
gun.js
11
gun.js
@ -1160,7 +1160,10 @@
|
||||
if(!(at.has || at.soul)){ return }
|
||||
var tmp = at.map, root = at.root;
|
||||
at.map = null;
|
||||
if(at.has){ at.link = null }
|
||||
if(at.has){
|
||||
if(at.dub && at.root.stop){ at.dub = null }
|
||||
at.link = null;
|
||||
}
|
||||
//if(!root.now || !root.now[at.id]){
|
||||
if(!at.pass){
|
||||
if((!msg['@']) && null === tmp){ return }
|
||||
@ -1286,8 +1289,7 @@
|
||||
}
|
||||
function soul(gun, cb, opt, as){
|
||||
var cat = gun._, acks = 0, tmp;
|
||||
if(tmp = cat.soul){ return cb(tmp, as, cat), gun }
|
||||
if(tmp = cat.link){ return cb(tmp, as, cat), gun }
|
||||
if(tmp = cat.soul || cat.link || cat.dub){ return cb(tmp, as, cat), gun }
|
||||
gun.get(function(msg, ev){
|
||||
if(u === msg.put && (tmp = (obj_map(cat.root.opt.peers, function(v,k,t){t(k)})||[]).length) && ++acks < tmp){
|
||||
return;
|
||||
@ -1397,6 +1399,7 @@
|
||||
}, true);
|
||||
return gun;
|
||||
}
|
||||
if(at.has && (tmp = Gun.val.link.is(data))){ at.dub = tmp }
|
||||
as.ref = as.ref || (root._ === (tmp = at.back))? gun : tmp.$;
|
||||
if(as.ref._.soul && Gun.val.is(as.data) && at.get){
|
||||
as.data = obj_put({}, at.get, as.data);
|
||||
@ -1551,7 +1554,7 @@
|
||||
if(node_ == at.get){
|
||||
as.soul = (at.put||empty)['#'] || at.dub;
|
||||
}
|
||||
as.soul = as.soul || at.soul || at.soul || (opt.uuid || as.via.back('opt.uuid') || Gun.text.random)();
|
||||
as.soul = as.soul || at.soul || at.link || (opt.uuid || as.via.back('opt.uuid') || Gun.text.random)();
|
||||
}
|
||||
if(!as.soul){ // polyfill async uuid for SEA
|
||||
as.via.back('opt.uuid')(function(err, soul){ // TODO: improve perf without anonymous callback
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "gun",
|
||||
"version": "0.9.999999",
|
||||
"version": "0.9.9999991",
|
||||
"description": "A realtime, decentralized, offline-first, graph data synchronization engine.",
|
||||
"main": "index.js",
|
||||
"browser": "gun.min.js",
|
||||
|
@ -1265,13 +1265,14 @@ describe('Gun', function(){
|
||||
describe('API', function(){
|
||||
var gopt = {wire:{put:function(n,cb){cb()},get:function(k,cb){cb()}}};
|
||||
if(Gun.window && location.search){
|
||||
console.log("LOCALHOST PEER MUST BE ON!");
|
||||
/*console.log("LOCALHOST PEER MUST BE ON!");
|
||||
var peer = {url: 'http://localhost:8765/gun'};
|
||||
Gun.on('opt', function(root){
|
||||
if(root.opt.test_no_peer){ return this.to.next(root) }
|
||||
root.opt.peers = root.opt.peers || {};
|
||||
root.opt.peers['http://localhost:8765/gun'] = {url: 'http://localhost:8765/gun'};
|
||||
root.opt.peers['http://localhost:8765/gun'] = peer;
|
||||
this.to.next(root);
|
||||
});
|
||||
});*/
|
||||
}
|
||||
var gun = Gun();
|
||||
|
||||
@ -3755,6 +3756,19 @@ describe('Gun', function(){
|
||||
});
|
||||
//});
|
||||
});
|
||||
|
||||
it('Set a ref should be found', function(done){
|
||||
var gun = Gun();
|
||||
var msg = {what: 'hello world'};
|
||||
//var ref = user.get('who').get('all').set(msg);
|
||||
//user.get('who').get('said').set(ref);
|
||||
var ref = gun.get('who').get('all').set(msg);
|
||||
gun.get('who').get('said').set(ref);
|
||||
gun.get('who').get('said').map().once(function(data){
|
||||
expect(data.what).to.be.ok();
|
||||
done();
|
||||
})
|
||||
});
|
||||
return;
|
||||
it('Nested listener should be called', function(done){
|
||||
|
||||
|
@ -317,6 +317,45 @@ describe('SEA', function(){
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
it('set user ref should be found', function(done){
|
||||
var gun = Gun();
|
||||
var user = gun.user();
|
||||
var msg = {what: 'hello world'};
|
||||
user.create('zach', 'password');
|
||||
gun.on('auth', function(){
|
||||
var ref = user.get('who').get('all').set(msg);
|
||||
user.get('who').get('said').set(ref);
|
||||
user.get('who').get('said').map().once(function(data){
|
||||
expect(data.what).to.be.ok();
|
||||
done();
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
it('set user ref null override', function(done){
|
||||
var gun = Gun();
|
||||
var user = gun.user();
|
||||
var msg = {what: 'hello world'};
|
||||
user.create('xavier', 'password');
|
||||
gun.on('auth', function(){
|
||||
var ref = user.get('who').get('all').set(msg);
|
||||
var tmp = ref._.dub || ref._.link;
|
||||
setTimeout(function(){
|
||||
user.get('who').put(1);
|
||||
setTimeout(function(){
|
||||
user.get('who').get('all').get(tmp).put({boom: 'ah'});
|
||||
setTimeout(function(){
|
||||
user.get('who').get('all').map().once(function(data){
|
||||
expect(data).to.be.ok();
|
||||
expect(data.what).to.not.be.ok();
|
||||
done();
|
||||
});
|
||||
},9);
|
||||
},9);
|
||||
},9);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user