GUN - changes to fix peer.id undefined. @amark please validate this change.

This commit is contained in:
Adriano Rogowski 2019-01-01 10:40:11 -02:00
parent 6d12b3d5a9
commit fe7576ee66
2 changed files with 22 additions and 8 deletions

19
gun.js
View File

@ -2027,7 +2027,7 @@
if(peer.batch){
peer.tail = (peer.tail || 0) + raw.length;
if(peer.tail <= opt.pack){
(msg.dam) ? peer.batch.unshift(raw) : peer.batch.push(raw);
peer.batch.push(raw);
return;
}
flush(peer);
@ -2119,10 +2119,10 @@
mesh.say({dam: '?'}, opt.peers[tmp] = peer);
}
if(!tmp.hied){ ctx.on(tmp.hied = 'hi', peer) }
tmp = peer.queue; peer.queue = [];
Type.obj.map(tmp, function(msg){
mesh.say(msg, peer);
});
// tmp = peer.queue; peer.queue = [];
// Type.obj.map(tmp, function(msg){
// mesh.say(msg, peer);
// });
}
mesh.bye = function(peer){
Type.obj.del(opt.peers, peer.id); // assume if peer.url then reconnect
@ -2131,7 +2131,14 @@
mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) }
mesh.hear['?'] = function(msg, peer){
if(!msg.pid){ return mesh.say({dam: '?', pid: opt.pid, '@': msg['#']}, peer) }
if(!msg.pid){
mesh.say({dam: '?', pid: opt.pid, '@': msg['#']}, peer)
var tmp = peer.queue; peer.queue = [];
Type.obj.map(tmp, function(msg){
mesh.say(msg, peer);
});
return;
}
peer.id = peer.id || msg.pid;
mesh.hi(peer);
}

View File

@ -101,7 +101,7 @@ function Mesh(ctx){
if(peer.batch){
peer.tail = (peer.tail || 0) + raw.length;
if(peer.tail <= opt.pack){
(msg.dam) ? peer.batch.unshift(raw) : peer.batch.push(raw);
peer.batch.push(raw);
return;
}
flush(peer);
@ -205,7 +205,14 @@ function Mesh(ctx){
mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) }
mesh.hear['?'] = function(msg, peer){
if(!msg.pid){ return mesh.say({dam: '?', pid: opt.pid, '@': msg['#']}, peer) }
if(!msg.pid){
mesh.say({dam: '?', pid: opt.pid, '@': msg['#']}, peer)
var tmp = peer.queue; peer.queue = [];
Type.obj.map(tmp, function(msg){
mesh.say(msg, peer);
});
return;
}
peer.id = peer.id || msg.pid;
mesh.hi(peer);
}