diff --git a/examples/http.js b/examples/http.js index 889470d4..5fd4f8fb 100644 --- a/examples/http.js +++ b/examples/http.js @@ -16,7 +16,7 @@ config.server = require('http').createServer(Gun.serve(__dirname)); } - var gun = Gun({web: config.server.listen(config.port), rad: false, localStorage: false}); // TODO: ONLY TEMPORARILY!!! UNDO TO GET RAD ONCE TESTED!!!! + var gun = Gun({web: config.server.listen(config.port), rad: false, radisk: false, localStorage: false}); // TODO: ONLY TEMPORARILY!!! UNDO TO GET RAD ONCE TESTED!!!! console.log('Relay peer started on port ' + config.port + ' with /gun'); module.exports = gun; diff --git a/examples/stats.html b/examples/stats.html index 2dab5e23..c874606c 100644 --- a/examples/stats.html +++ b/examples/stats.html @@ -29,7 +29,7 @@ .tall { height: 5em; } -
0 peers 0 min 0 nodes 0 hours 0 block
+
0 peers 0 min 0 nodes 0 hours 0 block 0 stack
@@ -51,7 +51,8 @@ var data = await (await fetch(url.value||(location.origin+'/gun/stats.radata'), {method: 'GET',mode: 'cors'})).json(); $('#block').text(((br += (+new Date - S)/1000) / ++bt).toFixed(1)); data.over = (data.over/1000) || 15; - $('#peers').text(data.peers.count); + $('#stack').text(data.cpu.stack); + $('#peers').text(data.peers.count); $('#time').text((data.peers.time / 1000 / 60).toFixed(0)); $('#nodes').text(data.node.count); $('#hours').text((data.up.time / 60 / 60).toFixed(1)); diff --git a/gun.js b/gun.js index 5eb4445a..b9009e89 100644 --- a/gun.js +++ b/gun.js @@ -381,7 +381,7 @@ } function ack(msg){ // aggregate ACKs. var id = msg['@'] || '', root = (msg.$._||'').root, tmp; - if(msg.err && root && root.dup.s[id]){ console.log('add err to original message to not send') } + if(msg.err && root && (tmp = root.dup.s[id])){ tmp.err = msg.err; } // add error to original message. if(!(tmp = id._)){ /*console.log("TODO: handle ack id.");*/ return } tmp.acks = (tmp.acks||0) + 1; if(0 == tmp.stun && tmp.acks == tmp.all){ // TODO: if ack is synchronous this may not work? @@ -1232,7 +1232,7 @@ var meta = msg._||(msg._=function(){}); if(!(id = msg['#'])){ id = msg['#'] = String.random(9) } !loop && dup_track(id);//.it = it(msg); // track for 9 seconds, default. Earth<->Mars would need more! // always track, maybe move this to the 'after' logic if we split function. - if(msg.put && msg.err){ return false } // stop relaying a invalid message, like failed SEA. + if(msg.put && (msg.err || (dup.s[id]||'').err)){ return false } // stop relaying a invalid message, like failed SEA. if(!(hash = msg['##']) && u !== msg.put && !meta.via && ack){ mesh.hash(msg, peer); return } // TODO: Should broadcasts be hashed? if(!(raw = meta.raw)){ mesh.raw(msg, peer); return } S && console.STAT && console.STAT(S, +new Date - S, 'say prep'); diff --git a/lib/stats.js b/lib/stats.js index c83dcdf8..6de79476 100644 --- a/lib/stats.js +++ b/lib/stats.js @@ -6,6 +6,7 @@ Gun.on('opt', function(root){ if(typeof process === 'undefined'){ return } if(typeof require === 'undefined'){ return } if(false === root.opt.stats){ return } + var file = root.opt.file || 'radata'; var noop = function(){}; var os = require('os') || {}; var fs = require('fs') || {}; @@ -21,7 +22,7 @@ Gun.on('opt', function(root){ os.cpus = os.cpus || noop; var obj_ify = function(o){try{o = JSON.parse(o)}catch(e){o={}};return o;} setTimeout(function(){ - root.stats = obj_ify((fs.existsSync(__dirname+'/../stats.'+root.opt.file) && fs.readFileSync(__dirname+'/../stats.'+root.opt.file).toString())) || {}; + root.stats = obj_ify((fs.existsSync(__dirname+'/../stats.'+(root.opt.file||file)) && fs.readFileSync(__dirname+'/../stats.'+(root.opt.file||file)).toString())) || {}; root.stats.up = root.stats.up || {}; root.stats.up.start = root.stats.up.start || +(new Date); root.stats.up.count = (root.stats.up.count || 0) + 1; @@ -40,6 +41,7 @@ Gun.on('opt', function(root){ stats.memory.freemem = os.freemem(); stats.cpu = process.cpuUsage() || {}; stats.cpu.loadavg = os.loadavg(); + stats.cpu.stack = (((setTimeout||'').turn||'').s||'').length; stats.peers = {}; stats.peers.count = Object.keys(root.opt.peers||{}).length; // TODO: .keys( is slow stats.node = {}; @@ -58,8 +60,8 @@ Gun.on('opt', function(root){ } console.STAT && console.STAT(S, +new Date - S, 'stats'); S = +new Date; - JSON.stringifyAsync(stats, function(err, raw){ if(err){ return } - fs.writeFile(__dirname+'/../stats.'+root.opt.file, raw, function(err){ console.STAT && console.STAT(S, +new Date - S, 'stats stash') }); + JSON.stringifyAsync(stats, function(err, raw){ console.log("stats?", err, __dirname+'/../stats.'+(root.opt.file||file)); if(err){ return } + fs.writeFile(__dirname+'/../stats.'+(root.opt.file||file), raw, function(err){ console.STAT && console.STAT(S, +new Date - S, 'stats stash') }); }); stats.over = S; stats.gap = {};