Преглед на файлове

update gundb to 0.2020.514

Nikolay Suslov преди 4 години
родител
ревизия
fd50f6718e
променени са 6 файла, в които са добавени 71 реда и са изтрити 42 реда
  1. 40 23
      package-lock.json
  2. 1 1
      package.json
  3. 24 15
      public/lib/gundb/gun.js
  4. 1 1
      public/lib/gundb/lib/stats.js
  5. 1 1
      public/lib/gundb/lib/store.js
  6. 4 1
      public/lib/gundb/lib/wire.js

+ 40 - 23
package-lock.json

@@ -5,12 +5,14 @@
   "requires": true,
   "dependencies": {
     "@peculiar/asn1-schema": {
-      "version": "1.1.2",
-      "resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-1.1.2.tgz",
-      "integrity": "sha512-ntQ4UnUFgdjs0tfWR6YmEQm/x0glV4OFus/RjxLkaJUKfu/R7VilefBntyUO3MoKWdlCgib30KN+JpCY1HqU2A==",
+      "version": "2.0.3",
+      "resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.0.3.tgz",
+      "integrity": "sha512-STqC+Tfx2dTiIGRmokjsKOeqsfhoV6WaBwFr7BVicSfHLAVSPrZXiugyD8AELrjQdJ9INWpL3N7YSJyU5a1ZwA==",
       "optional": true,
       "requires": {
+        "@types/asn1js": "^0.0.1",
         "asn1js": "^2.0.26",
+        "pvtsutils": "^1.0.10",
         "tslib": "^1.11.1"
       }
     },
@@ -24,16 +26,25 @@
       }
     },
     "@peculiar/webcrypto": {
-      "version": "1.0.29",
-      "resolved": "https://registry.npmjs.org/@peculiar/webcrypto/-/webcrypto-1.0.29.tgz",
-      "integrity": "sha512-3e6CIpjZuj5WxPymGm0kCZA05XA9BSXwBEb/mU9KjBHAmEwMokT0yVIhxqwspCHSynlrTfUB+9KTNpseyB077A==",
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/@peculiar/webcrypto/-/webcrypto-1.1.1.tgz",
+      "integrity": "sha512-Bu2XgOvzirnLcojZYs4KQ8hOLf2ETpa0NL6btQt5NgsAwctI6yVkzgYP+EcG7Mm579RBP+V0LM5rXyMlTVx23A==",
       "optional": true,
       "requires": {
-        "@peculiar/asn1-schema": "^1.1.2",
+        "@peculiar/asn1-schema": "^2.0.3",
         "@peculiar/json-schema": "^1.1.10",
         "pvtsutils": "^1.0.10",
-        "tslib": "^1.11.1",
-        "webcrypto-core": "^1.0.20"
+        "tslib": "^1.11.2",
+        "webcrypto-core": "^1.1.0"
+      }
+    },
+    "@types/asn1js": {
+      "version": "0.0.1",
+      "resolved": "https://registry.npmjs.org/@types/asn1js/-/asn1js-0.0.1.tgz",
+      "integrity": "sha1-74uflwjLFjKhw6nNJ3F8qr55O8I=",
+      "optional": true,
+      "requires": {
+        "@types/pvutils": "*"
       }
     },
     "@types/color-name": {
@@ -41,6 +52,12 @@
       "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
       "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ=="
     },
+    "@types/pvutils": {
+      "version": "0.0.2",
+      "resolved": "https://registry.npmjs.org/@types/pvutils/-/pvutils-0.0.2.tgz",
+      "integrity": "sha512-CgQAm7pjyeF3Gnv78ty4RBVIfluB+Td+2DR8iPaU0prF18pkzptHHP+DoKPfpsJYknKsVZyVsJEu5AuGgAqQ5w==",
+      "optional": true
+    },
     "@unimodules/core": {
       "version": "5.1.2",
       "resolved": "https://registry.npmjs.org/@unimodules/core/-/core-5.1.2.tgz",
@@ -685,9 +702,9 @@
       "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="
     },
     "gun": {
-      "version": "0.2020.430",
-      "resolved": "https://registry.npmjs.org/gun/-/gun-0.2020.430.tgz",
-      "integrity": "sha512-mCRrz/VUflCGaRVOA4pTnRo5YSP5pa0lpSszqQ6offJQC9PzClvl2aofpaaHOXx5rFzw34HP/EjWZP3cxen3gQ==",
+      "version": "0.2020.514",
+      "resolved": "https://registry.npmjs.org/gun/-/gun-0.2020.514.tgz",
+      "integrity": "sha512-gKOUJUenNhVFmWOij7RjuXsluY8dSsFjX2mOA5MXrfvZP4Lqv6pEpSntnQmDmo3PHfECOaPF955JLLpiLVuLbw==",
       "requires": {
         "buffer": "^5.4.3",
         "bufferutil": "^4.0.1",
@@ -1434,9 +1451,9 @@
       "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
     },
     "tslib": {
-      "version": "1.11.1",
-      "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.11.1.tgz",
-      "integrity": "sha512-aZW88SY8kQbU7gpV19lN24LtXh/yD4ZZg6qieAJDDg+YBsJcSmLGK9QpnUjAKVG/xefmvJGd1WUmfpT/g6AJGA==",
+      "version": "1.13.0",
+      "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.13.0.tgz",
+      "integrity": "sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==",
       "optional": true
     },
     "type-is": {
@@ -1488,16 +1505,16 @@
       "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
     },
     "webcrypto-core": {
-      "version": "1.0.21",
-      "resolved": "https://registry.npmjs.org/webcrypto-core/-/webcrypto-core-1.0.21.tgz",
-      "integrity": "sha512-PcSD8Ga3u344LXEcI/1UbGv3dv5rZ8pzkeJIrMf/JOnEq8H5hSMmdTrRIp2WFYYnMNdKQbP564v560ZmERT2HQ==",
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/webcrypto-core/-/webcrypto-core-1.1.1.tgz",
+      "integrity": "sha512-xK61sFRUyZdSAJG7+bJox36+Tnhxw1PaMbmrLLp30HNTJ4mffqsY2jUMlmGq6OOoej3WO/SsH5serzlzBMZ+jg==",
       "optional": true,
       "requires": {
-        "@peculiar/asn1-schema": "^1.1.2",
+        "@peculiar/asn1-schema": "^2.0.1",
         "@peculiar/json-schema": "^1.1.10",
         "asn1js": "^2.0.26",
         "pvtsutils": "^1.0.10",
-        "tslib": "^1.11.1"
+        "tslib": "^1.11.2"
       }
     },
     "webcrypto-shim": {
@@ -1522,9 +1539,9 @@
       }
     },
     "ws": {
-      "version": "7.2.5",
-      "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.5.tgz",
-      "integrity": "sha512-C34cIU4+DB2vMyAbmEKossWq2ZQDr6QEyuuCzWrM9zfw1sGc0mYiJ0UnG9zzNykt49C2Fi34hvr2vssFQRS6EA=="
+      "version": "7.3.0",
+      "resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz",
+      "integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w=="
     },
     "xmlhttprequest-ssl": {
       "version": "1.5.5",

+ 1 - 1
package.json

@@ -20,7 +20,7 @@
     "yargs": "15.3.1",
     "socket.io": "2.2.0",
     "lcs-reflector": "0.3",
-    "gun": "0.2020.430"
+    "gun": "0.2020.514"
   },
   "scripts": {
     "start": "node index.js",

+ 24 - 15
public/lib/gundb/gun.js

@@ -735,10 +735,10 @@
 			}
 			function put(msg){
 				if(!msg){ return }
-				var ctx = msg._||'', root = ctx.root = ((msg.$||'')._||'').root;
+				var ctx = msg._||'', root = ctx.root = ((ctx.$ = msg.$||'')._||'').root;
 				var put = msg.put, id = msg['#'], err, tmp;
 				var DBG = ctx.DBG = msg.DBG;
-				if(put['#'] && put['.']){ root.on('put', msg); return }
+				if(put['#'] && put['.']){ root.on('put', msg); return } // TODO: BUG! This needs to call HAM instead.
 				/*root.on(id, function(m){
 					console.log('ack:', m);
 				});*/
@@ -777,10 +777,11 @@
 						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;
+						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;
+					//return; // it should be this
+					if(!ctx.miss){ return } // but some chains have a cache miss that need to re-fire. // TODO: Improve in future.
 				}
 				(lot = ctx.lot||'').s++; lot.more++;
 				(ctx.stun || (ctx.stun = {}))[soul+key] = 1;
@@ -808,7 +809,7 @@
 			function fire(ctx){
 				if(ctx.err){ return }
 				var stop = {};
-				var root = ctx.root, next = root.next||'', put = ctx.put, tmp;
+				var root = ((ctx.$||'')._||'').root, next = (root||'').next||'', put = ctx.put, tmp;
 				var S = +new Date;
 				//Gun.graph.is(put, function(node, soul){
 				for(var soul in put){ var node = put[soul]; // Gun.obj.native() makes this safe.
@@ -931,6 +932,7 @@
 				node = Gun.graph.node(node);
 				tmp = (at||empty).ack;
 				var faith = function(){}; faith.ram = faith.faith = true; // HNPERF: We're testing performance improvement by skipping going through security again, but this should be audited.
+				faith.$ = msg.$;
 				DBG && (DBG.ga = +new Date);
 				root.on('in', {
 					'@': msg['#'],
@@ -1331,6 +1333,9 @@
 				at.on('in', {get: at.get, put: Gun.val.link.ify(get['#']), $: at.$, '@': msg['@']});
 				return;
 			}
+			if(at.$ === (msg._||'').$){ // replying to self, for perf, skip ham/security tho needs audit.
+				(msg._).miss = (at.put === u);
+			}
 			Gun.on.put(msg);
 		}
 		var empty = {}, u;
@@ -1413,7 +1418,7 @@
 			if(cat.jam){ return cat.jam.push([cb, as]) }
 			cat.jam = [[cb,as]];
 			gun.get(function go(msg, eve){
-				if(u === msg.put && (tmp = Object.keys(cat.root.opt.peers).length) && ++acks <= tmp){
+				if(u === msg.put && !cat.root.opt.super && (tmp = Object.keys(cat.root.opt.peers).length) && ++acks <= tmp){ // TODO: super should not be in core code, bring AXE up into core instead to fix?
 					return;
 				}
 				eve.rid(msg);
@@ -1631,9 +1636,12 @@
 		}
 		var G = String.fromCharCode(31);
 		function soul(id, as, msg, eve){
-			var as = as.as, path = as.p, ref = as.ref, cat = as.at; as = as.as;
-			var sat = ref.back(function(at){ return sat = at.soul || at.link || at.dub });
-			var pat = [sat || as.soul].concat(ref._.has || ref._.get || path)
+			var as = as.as, path = as.p, ref = as.ref, cat = as.at, pat = []; as = as.as;
+			ref.back(function(at){
+				if(sat = at.soul || at.link || at.dub){ return sat }
+				pat.push(at.has || at.get);
+			});
+			pat = [sat || as.soul].concat(pat.reverse());
 			var at = ((msg || {}).$ || {})._ || {};
 			id = at.dub = at.dub || id || Gun.node.soul(cat.obj) || Gun.node.soul(msg.put || at.put) || Gun.val.link.is(msg.put || at.put) || pat.join('/') /* || (function(){
 				return (as.soul+'.')+Gun.text.hash(path.join(G)).toString(32);
@@ -1811,9 +1819,10 @@
 			}
 			if((tmp = eve.wait) && (tmp = tmp[at.id])){ clearTimeout(tmp) }
 			eve.ack = (eve.ack||0)+1;
-			if(!to && u === data && eve.ack <= (opt.acks || Object.keys(at.root.opt.peers).length)){ return }
+			// TODO: super should not be in core code, bring AXE up into core instead to fix?
+			if(!to && u === data && !at.root.opt.super && eve.ack <= (opt.acks || Object.keys(at.root.opt.peers).length)){ return }
 			if((!to && (u === data || at.soul || at.link || (link && !(0 < link.ack))))
-			|| (u === data && (tmp = Object.keys(at.root.opt.peers).length) && (!to && (link||at).ack < tmp))){
+			|| (u === data && !at.root.opt.super && (tmp = Object.keys(at.root.opt.peers).length) && (!to && (link||at).ack < tmp))){
 				tmp = (eve.wait = {})[at.id] = setTimeout(function(){
 					val.call({as:opt}, msg, eve, tmp || 1);
 				}, opt.wait || 99);
@@ -2157,10 +2166,10 @@
 				var SMIA = 0;
 				var message, loop;
 				function each(peer){ mesh.say(message, peer) }
-				var say = mesh.say = function(msg, peer){
-					if(this && this.to){ this.to.next(msg) } // compatible with middleware adapters.
+				var say = mesh.say = function(msg, peer){ var tmp;
+					if((tmp = this) && (tmp = tmp.to) && tmp.next){ tmp.next(msg) } // compatible with middleware adapters.
 					if(!msg){ return false }
-					var id, hash, tmp, raw;
+					var id, hash, raw;
 					var DBG = msg.DBG, S; if(!peer){ S = +new Date ; DBG && (DBG.y = S) }
 					var meta = msg._||(msg._=function(){});
 					if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) }
@@ -2404,7 +2413,7 @@
 			mesh.wire = opt.wire = open;
 			function open(peer){ try{
 				if(!peer || !peer.url){ return wire && wire(peer) }
-				var url = peer.url.replace('http', 'ws');
+				var url = peer.url.replace(/^http/, 'ws');
 				var wire = peer.wire = new opt.WebSocket(url);
 				wire.onclose = function(){
 					opt.mesh.bye(peer);

+ 1 - 1
public/lib/gundb/lib/stats.js

@@ -72,6 +72,6 @@ Gun.log = console.STAT = function(a,b,c,d){
 		if(max < tmp.push([a,b])){ all[c] = [] } // reset
 		//return;
 	}
-	if(!console.LOG || log.off){ return }
+	if(!console.LOG || log.off){ return a }
 	return log.apply(Gun, arguments);
 }

+ 1 - 1
public/lib/gundb/lib/store.js

@@ -8,7 +8,7 @@ Gun.on('create', function(root){
     var Radisk = (Gun.window && Gun.window.Radisk) || require('./radisk');
     var Radix = Radisk.Radix;
     var ST = 0;
- 
+    // TODO: BUG! For RN storage, RN does not like the following require:
     opt.store = opt.store || (!Gun.window && require('./rfs')(opt));
     var dare = Radisk(opt), esc = String.fromCharCode(27);
  

+ 4 - 1
public/lib/gundb/lib/wire.js

@@ -62,7 +62,10 @@ Gun.on('opt', function(root){
 	var ws = opt.ws = opt.ws || {};
 	ws.path = ws.path || '/gun';
 	// if we DO need an HTTP server, then choose ws specific one or GUN default one.
-	if(!ws.noServer){ ws.server = ws.server || opt.web }
+	if(!ws.noServer){
+		ws.server = ws.server || opt.web;
+		if(!ws.server){ return }
+	}
 	ws.web = ws.web || new opt.WebSocket.Server(ws); // we still need a WS server.
 	ws.web.on('connection', function(wire){ var peer;
 		wire.upgradeReq = wire.upgradeReq || {};