diff --git a/axe.js b/axe.js index 7f06c34e..b9939c03 100644 --- a/axe.js +++ b/axe.js @@ -293,6 +293,27 @@ at.on('bye', function(peer){ this.to.next(peer); }); + + at.on('hi', function(peer){ + this.to.next(peer); + // this code handles disconnecting from self & duplicates + setTimeout(function(){ // must wait + if(peer.pid !== opt.pid){ + // this extra logic checks for duplicate connections between 2 peers. + if(!Gun.obj.map(axe.up, function(p){ + if(peer.pid === p.pid && peer !== p){ + return yes = true; + } + })){ return } + } + mesh.say({dam: '-'}, peer); + delete at.dup.s[peer.last]; + }, Math.random() * 100); + }); + mesh.hear['-'] = function(msg, peer){ + mesh.bye(peer); + peer.url = ''; + } } function joindht(dht, soul, pids) { diff --git a/gun.js b/gun.js index d1f1d05c..868e042b 100644 --- a/gun.js +++ b/gun.js @@ -2122,7 +2122,7 @@ opt.peers[peer.url || peer.id] = peer; } else { tmp = peer.id = peer.id || Type.text.random(9); - mesh.say({dam: '?'}, opt.peers[tmp] = peer); + mesh.say({dam: '?', pid: root.opt.pid}, opt.peers[tmp] = peer); delete dup.s[peer.last]; // IMPORTANT: see https://gun.eco/docs/DAM#self } peer.met = peer.met || +(new Date); @@ -2141,19 +2141,12 @@ } mesh.hear['!'] = function(msg, peer){ opt.log('Error:', msg.err) } mesh.hear['?'] = function(msg, peer){ - if(!msg.pid){ - mesh.say({dam: '?', pid: opt.pid, '@': msg['#']}, peer); - delete dup.s[peer.last]; // IMPORTANT: see https://gun.eco/docs/DAM#self - // @rogowski I want to re-enable this AXE logic with some fix/merge later. - /* var tmp = peer.queue; peer.queue = []; - Type.obj.map(tmp, function(msg){ - mesh.say(msg, peer); - }); */ - // @rogowski 2: I think with my PID fix we can delete this and use the original. - return; + if(msg.pid){ + if(!peer.pid){ peer.pid = msg.pid } + if(msg['@']){ return } } - if(peer.pid){ return } - peer.pid = msg.pid; + mesh.say({dam: '?', pid: opt.pid, '@': msg['#']}, peer); + delete dup.s[peer.last]; // IMPORTANT: see https://gun.eco/docs/DAM#self } root.on('create', function(root){ diff --git a/package-lock.json b/package-lock.json index c25fcdf0..332cccc3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gun", - "version": "0.2019.910", + "version": "0.2019.1211", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -52,7 +52,8 @@ "@types/node": { "version": "10.14.18", "resolved": "https://registry.npmjs.org/@types/node/-/node-10.14.18.tgz", - "integrity": "sha512-ryO3Q3++yZC/+b8j8BdKd/dn9JlzlHBPdm80656xwYUdmPkpTGTjkAdt6BByiNupGPE8w0FhBgvYy/fX9hRNGQ==" + "integrity": "sha512-ryO3Q3++yZC/+b8j8BdKd/dn9JlzlHBPdm80656xwYUdmPkpTGTjkAdt6BByiNupGPE8w0FhBgvYy/fX9hRNGQ==", + "optional": true }, "addressparser": { "version": "0.3.2", @@ -106,6 +107,7 @@ "version": "2.0.26", "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-2.0.26.tgz", "integrity": "sha512-yG89F0j9B4B0MKIcFyWWxnpZPLaNTjCj4tkE3fjbAoo0qmpGw0PYYqSbX/4ebnd9Icn8ZgK4K1fvDyEtW1JYtQ==", + "optional": true, "requires": { "pvutils": "^1.0.17" } @@ -1222,6 +1224,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.0.6.tgz", "integrity": "sha512-0yNrOdJyLE7FZzmeEHTKanwBr5XbmDAd020cKa4ZiTYuGMBYBZmq7vHOhcOqhVllh6gghDBbaz1lnVdOqiB7cw==", + "optional": true, "requires": { "@types/node": "^10.14.17", "tslib": "^1.10.0" @@ -1230,7 +1233,8 @@ "pvutils": { "version": "1.0.17", "resolved": "https://registry.npmjs.org/pvutils/-/pvutils-1.0.17.tgz", - "integrity": "sha512-wLHYUQxWaXVQvKnwIDWFVKDJku9XDCvyhhxoq8dc5MFdIlRenyPI9eSfEtcvgHgD7FlvCyGAlWgOzRnZD99GZQ==" + "integrity": "sha512-wLHYUQxWaXVQvKnwIDWFVKDJku9XDCvyhhxoq8dc5MFdIlRenyPI9eSfEtcvgHgD7FlvCyGAlWgOzRnZD99GZQ==", + "optional": true }, "querystring": { "version": "0.2.0", @@ -1518,7 +1522,8 @@ "tslib": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.10.0.tgz", - "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==" + "integrity": "sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ==", + "optional": true }, "uglify-js": { "version": "3.3.24",