Nikolay Suslov před 6 roky
rodič
revize
6a24ff0f2f

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

@@ -638,7 +638,7 @@
 					dup.to = setTimeout(function(){
 						var now = time_is();
 						Type.obj.map(dup.s, function(it, id){
-							if(opt.age > (now - it.was)){ return }
+							if(it && opt.age > (now - it.was)){ return }
 							Type.obj.del(dup.s, id);
 						});
 						dup.to = null;
@@ -1902,7 +1902,7 @@
 				if(data){ disk = data }
 				try{store.setItem(opt.prefix, JSON.stringify(disk));
 				}catch(e){ 
-					Gun.log(err = e || "localStorage failure");
+					Gun.log(err = (e || "localStorage failure") + " Consider using GUN's IndexedDB plugin for RAD for more storage space, temporary example at https://github.com/amark/gun/blob/master/test/tmp/indexedDB.html .");
 					root.on('localStorage:error', {err: err, file: opt.prefix, flush: disk, retry: flush});
 				}
 				if(!err && !Gun.obj.empty(opt.peers)){ return } // only ack if there are no peers.
@@ -1922,7 +1922,10 @@
 
 		function Mesh(ctx){
 			var mesh = function(){};
-			var opt = ctx.opt;
+			var opt = ctx.opt || {};
+			opt.log = opt.log || console.log;
+			opt.gap = opt.gap || opt.wait || 1;
+			opt.pack = opt.pack || (opt.memory? (opt.memory * 1000 * 1000) : 1399000000) * 0.3; // max_old_space_size defaults to 1400 MB.
 
 			mesh.out = function(msg){ var tmp;
 				if(this.to){ this.to.next(msg) }
@@ -1948,8 +1951,9 @@
 			mesh.hear = function(raw, peer){
 				if(!raw){ return }
 				var dup = ctx.dup, id, hash, msg, tmp = raw[0];
+				if(opt.pack <= raw.length){ return mesh.say({dam: '!', err: "Message too big!"}, peer) }
 				try{msg = JSON.parse(raw);
-				}catch(e){console.log('DAM JSON parse error', e)}
+				}catch(e){opt.log('DAM JSON parse error', e)}
 				if('{' === tmp){
 					if(!msg){ return }
 					if(dup.check(id = msg['#'])){ return }
@@ -2013,20 +2017,25 @@
 					}
 					if((tmp = msh.to) && (tmp[peer.url] || tmp[peer.id]) && !o){ return } // TODO: still needs to be tested
 					if(peer.batch){
-						peer.batch.push(raw);
-						return;
+						peer.tail = (peer.tail || 0) + raw.length;
+						if(peer.tail <= opt.pack){
+							peer.batch.push(raw);
+							return;
+						}
+						flush(peer);
 					}
 					peer.batch = [];
-					setTimeout(function(){
-						var tmp = peer.batch;
-						if(!tmp){ return }
-						peer.batch = null;
-						if(!tmp.length){ return }
-						send(JSON.stringify(tmp), peer);
-					}, opt.gap || opt.wait || 1);
+					setTimeout(function(){flush(peer)}, opt.gap);
 					send(raw, peer);
 				}
-
+				function flush(peer){
+					var tmp = peer.batch;
+					if(!tmp){ return }
+					peer.batch = peer.tail = null;
+					if(!tmp.length){ return }
+					try{send(JSON.stringify(tmp), peer);
+					}catch(e){opt.log('DAM JSON stringify error', e)}
+				}
 				function send(raw, peer){
 					var wire = peer.wire;
 					try{
@@ -2112,6 +2121,7 @@
 				ctx.on('bye', peer);
 			}
 
+			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) }
 				peer.id = peer.id || msg.pid;

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
public/lib/gundb/gun.min.js


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

@@ -8,7 +8,7 @@
 		var util = process.memoryUsage;
 		if(!util){ return }
 		
-		ev.max = parseFloat(root.opt.memory || process.env.WEB_MEMORY || 512) * 0.8;
+		ev.max = parseFloat(root.opt.memory || process.env.WEB_MEMORY || 1399) * 0.8; // max_old_space_size defaults to 1400 MB. Note: old space !== memory space though.
 		
 		setInterval(check, 1000);
 		function check(){

+ 20 - 7
public/lib/gundb/lib/radisk.js

@@ -3,7 +3,9 @@
 	function Radisk(opt){
 
 		opt = opt || {};
+		opt.log = opt.log || console.log;
 		opt.file = String(opt.file || 'radata');
+		opt.pack = opt.pack || (opt.memory? (opt.memory * 1000 * 1000) : 1399000000) * 0.3; // max_old_space_size defaults to 1400 MB.
 		opt.until = opt.until || opt.wait || 9;
 		opt.batch = opt.batch || 10 * 1000;
 		opt.chunk = opt.chunk || (1024 * 1024 * 10); // 10MB
@@ -14,16 +16,16 @@
 		var map = Gun.obj.map;
 
 		if(!opt.store){
-			return Gun.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
+			return opt.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");
 		}
 		if(!opt.store.put){
-			return Gun.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");
+			return opt.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");
 		}
 		if(!opt.store.get){
-			return Gun.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");
+			return opt.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");
 		}
 		if(!opt.store.list){
-			Gun.log("WARNING: `store.list` interface might be needed!");
+			//opt.log("WARNING: `store.list` interface might be needed!");
 		}
 
 		/*
@@ -73,7 +75,7 @@
 			r.batch.ed = 0;
 			r.save(batch, function(err, ok){
 				if(++i > 1){ return }
-				if(err){ Gun.log('err', err) }
+				if(err){ opt.log('err', err) }
 				map(batch.acks, function(cb){ cb(err, ok) });
 				thrash.at = null;
 				thrash.ing = false;
@@ -141,6 +143,7 @@
 			f.file = file;
 			f.each = function(val, key, k, pre){
 				if(u !== val){ f.count++ }
+				if(opt.pack <= (val||'').length){ return cb("Record too big!"), true }
 				var enc = Radisk.encode(pre.length) +'#'+ Radisk.encode(k) + (u === val? '' : '='+ Radisk.encode(val)) +'\n';
 				if((opt.chunk < f.text.length + enc.length) && (1 < f.count) && !force){
 					f.text = '';
@@ -206,7 +209,7 @@
 					g.file = file;
 				}
 				g.it = function(err, disk){
-					if(g.err = err){ Gun.log('err', err) }
+					if(g.err = err){ opt.log('err', err) }
 					if(disk){ RAD = g.disk = disk }
 					disk = Q[g.file]; delete Q[g.file];
 					map(disk, g.ack);
@@ -243,6 +246,16 @@
 						//return cb(err, u);//map(q, p.ack);
 						return map(q, p.ack);
 					}
+					if(typeof data !== 'string'){
+						try{
+							if(opt.pack <= data.length){
+								p.err = "Chunk too big!";
+							} else {
+								data = data.toString();
+							}
+						}catch(e){ p.err = e }
+						if(p.err){ return map(q, p.ack) }
+					}
 					var tmp = p.split(data), pre = [], i, k, v;
 					while(tmp){
 						k = v = u;
@@ -309,7 +322,7 @@
 			}
 			r.list.init = function(err, disk){
 				if(err){
-					Gun.log('list', err);
+					opt.log('list', err);
 					setTimeout(function(){ r.parse(f, r.list.init) }, 1000);
 					return;
 				}

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

@@ -49,7 +49,7 @@
 		return radix;
 	};
 
-	Radix.map = function map(radix, cb, opt, pre){ pre = pre || []; 
+	Radix.map = function map(radix, cb, opt, pre){ pre = pre || [];
 		var t = radix[_] || radix, keys = radix.sort || (radix.sort = Object.keys(t).sort()), i = 0, l = keys.length;
 		for(;i < l; i++){ var key = keys[i], tree = t[key], tmp;
 			if(u !== (tmp = tree[$])){

+ 0 - 1
public/lib/gundb/lib/rfs.js

@@ -22,7 +22,6 @@ function Store(opt){
 				}
 				Gun.log("ERROR:", err)
 			}
-			if(data){ data = data.toString() }
 			cb(err, data);
 		});
 	};

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

@@ -62,7 +62,7 @@ function Store(opt){
 				if(!ack){ cb(null); return; }
 				cb(err, data);
 			};
-			if(data = (ack||{}).Body){ data = data.toString() }
+			data = (ack||{}).Body; //if(data = (ack||{}).Body){ data = data.toString() }
 			Gun.obj.map(cbs, cbe);
 		});
 	};

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

@@ -41,7 +41,7 @@ Gun.on('create', function(root){
 		var id = msg['#'], soul = msg.get['#'], key = msg.get['.']||'', tmp = soul+'.'+key, node;
 		rad(tmp, function(err, val){
 			if(val){
-				Radix.map(val, each);
+				if(val && typeof val !== 'string'){ Radix.map(val, each) }
 				if(!node){ each(val, key) }
 			}
 			root.on('in', {'@': id, put: Gun.graph.node(node), err: err? err : u, rad: Radix});

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

@@ -65,6 +65,7 @@ Gun.on('opt', function(root){
 
 		opt.mesh = opt.mesh || Gun.Mesh(root);
 		ws.path = ws.path || '/gun';
+		ws.maxPayload = ws.maxPayload; // || opt.pack || (opt.memory? (opt.memory * 1000 * 1000) : 1399000000) * 0.3;
 		ws.web = new opt.WebSocket.Server(ws);
 		ws.web.on('connection', function(wire){ var peer;
 			wire.upgradeReq = wire.upgradeReq || {};

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů