diff --git a/gun.min.js b/gun.min.js index 41456ee7..6165d35d 100644 --- a/gun.min.js +++ b/gun.min.js @@ -1 +1 @@ -!function(){var t;"undefined"!=typeof window&&(t=window),"undefined"!=typeof global&&(t=global);var e=(t=t||{}).console||{log:function(){}};function _(e,t){return t?require(e):e.slice?_[o(e)]:function(t,n){e(t={exports:{}}),_[o(n)]=t.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}if("undefined"!=typeof module)var m=module;_(function(t){var p={fn:{is:function(t){return!!t&&"function"==typeof t}}};p.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},p.num={is:function(t){return!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},p.text={is:function(t){return"string"==typeof t}},p.text.ify=function(t){return p.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},p.text.random=function(t,n){var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0"]||n["<"])||o===n["="]&&(e=n["*"]||n[">"]||n["<"],t.slice(0,(e||"").length)===e||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},p.list={is:function(t){return t instanceof Array}},p.list.slit=Array.prototype.slice,p.list.sort=function(e){return function(t,n){return t&&n?(t=t[e])<(n=n[e])?-1:n",s.drift=0,s.is=function(t,n,e){var o=n&&t&&t[m]&&t[m][s._]||e;if(o)return g(o=o[n])?o:-1/0},s.lex=function(){return s().toString(36).replace(".","")},s.ify=function(t,n,e,o,i){if(!t||!t[m]){if(!i)return;t=a.soul.ify(t,i)}var r=c(t[m],s._);return void 0!==n&&n!==m&&(g(e)&&(r[n]=e),void 0!==o&&(t[n]=o)),t},s.to=function(t,n,e){var o=(t||{})[n];return p(o)&&(o=d(o)),s.ify(e,n,s.is(t,n),o,a.soul(t))},function(){function u(t,n){m!==n&&s.ify(this.o,n,this.s)}s.map=function(i,r,a){var t=p(t=i||r)?t:null;return i=v(i=i||r)?i:null,t&&!i?(r=g(r)?r:s(),t[m]=t[m]||{},h(t,u,{o:t,s:r}),t):(a=a||p(r)?r:void 0,r=g(r)?r:s(),function(t,n,e,o){if(!i)return u.call({o:e,s:r},t,n),t;i.call(a||this||{},t,n,e,o),l(e,n)&&void 0===e[n]||u.call({o:e,s:r},t,n)})}}();var f=n.obj,c=f.as,l=f.has,p=f.is,h=f.map,d=f.copy,g=n.num.is,v=n.fn.is,m=a._;t.exports=s})(_,"./state"),_(function(t){var a=_("./type"),f=_("./val"),c=_("./node"),r={};!function(){function i(t,n){if(!t||n!==c.soul(t)||!c.is(t,this.fn,this.as))return!0;this.cb&&(e.n=t,e.as=this.as,this.cb.call(e.as,t,n,e))}function e(t){t&&c.is(e.n,t,e.as)}r.is=function(t,n,e,o){return!(!t||!l(t)||u(t))&&!s(t,i,{cb:n,fn:e,as:o})}}(),function(){function u(t,n){var e;return(e=function(t,n){var e,o=t.seen,i=o.length;for(;i--;)if(e=o[i],n.obj===e.obj)return e;o.push(n)}(t,n))?e:(n.env=t,n.soul=i,c.ify(n.obj,o,n)&&(n.link=n.link||f.link.ify(c.soul(n.node)),n.obj!==t.shell&&(t.graph[f.link.is(n.link)]=n.node)),n)}function o(t,n,e){var o,i,r=this,a=r.env;if(c._===n&&h(t,f.link._))return e._;if(o=s(t,n,e,r,a)){if(n||(r.node=r.node||e||{},h(t,c._)&&c.soul(t)&&(r.node._=d(t._)),r.node=c.soul.ify(r.node,f.link.is(r.link)),r.link=r.link||f.link.ify(c.soul(r.node))),(i=a.map)&&(i.call(a.as||{},t,n,e,r),h(e,n))){if(void 0===(t=e[n]))return void p(e,n);if(!(o=s(t,n,e,r,a)))return}if(!n)return r.node;if(!0===o)return t;if((i=u(a,{obj:t,path:r.path.concat(n)})).node)return i.link}}function i(t){var n=this,e=f.link.is(n.link),o=n.env.graph;n.link=n.link||f.link.ify(t),n.link[f.link._]=t,n.node&&n.node[c._]&&(n.node[c._][f.link._]=t),h(o,e)&&(o[t]=o[e],p(o,e))}function s(t,n,e,o,i){var r;return!!f.is(t)||(l(t)?1:(r=i.invalid)?s(t=r.call(i.as||{},t,n,e),n,e,o,i):(i.err="Invalid value at '"+o.path.concat(n).join(".")+"'!",void(a.list.is(t)&&(i.err+=" Use `.set(item)` instead of an Array."))))}r.ify=function(t,n,e){var o={path:[],obj:t};return n?"string"==typeof n?n={soul:n}:n instanceof Function&&(n.map=n):n={},n.soul&&(o.link=f.link.ify(n.soul)),n.shell=(e||{}).shell,n.graph=n.graph||{},n.seen=n.seen||[],n.as=n.as||e,u(n,o),n.root=o.node,n.graph}}(),r.node=function(t){var n=c.soul(t);if(n)return e({},n,t)},function(){function i(t,n){var e,o;if(c._!==n)(e=f.link.is(t))?(o=this.opt.seen[e])?this.obj[n]=o:this.obj[n]=this.opt.seen[e]=r.to(this.graph,e,this.opt):this.obj[n]=t;else{if(u(t,f.link._))return;this.obj[n]=d(t)}}r.to=function(t,n,e){if(t){var o={};return e=e||{seen:{}},s(t[n],i,{obj:o,graph:t,opt:e}),o}}}();a.fn.is;var n=a.obj,l=n.is,p=n.del,h=n.has,u=n.empty,e=n.put,s=n.map,d=n.copy;t.exports=r})(_,"./graph"),_(function(t){_("./onto"),t.exports=function(t,n){if(this.on){if(!(t instanceof Function)){if(!t||!n)return;var e=t["#"]||t,o=(this.tag||empty)[e];if(!o)return;return o=this.on(e,n),clearTimeout(o.err),!0}e=n&&n["#"]||Math.random().toString(36).slice(2);if(!t)return e;var i=this.on(e,t,n);return i.err=i.err||setTimeout(function(){i.next({err:"Error: No ACK received yet.",lack:!0}),i.off()},(this.opt||{}).lack||9e3),e}}})(_,"./ask"),_(function(t){var r=_("./type");var a=r.time.is;t.exports=function(o){var i={s:{}};return o=o||{max:1e3,age:9e3},i.check=function(t){var n;return!!(n=i.s[t])&&(n.pass?n.pass=!1:i.track(t))},i.track=function(t,n){var e=i.s[t]||(i.s[t]={});return e.was=a(),n&&(e.pass=!0),i.to||(i.to=setTimeout(function(){var e=a();r.obj.map(i.s,function(t,n){t&&o.age>e-t.was||r.obj.del(i.s,n)}),i.to=null},o.age+9)),e},i}})(_,"./dup"),_(function(t){function c(t){return t instanceof c?(this._={gun:this,$:this}).$:this instanceof c?c.create(this._={gun:this,$:this,opt:t}):new c(t)}c.is=function(t){return t instanceof c||t&&t._&&t===t._.$||!1},c.version=.9,(c.chain=c.prototype).toJSON=function(){};var n=_("./type");n.obj.to(n,c),c.HAM=_("./HAM"),c.val=_("./val"),c.node=_("./node"),c.state=_("./state"),c.graph=_("./graph"),c.on=_("./onto"),c.ask=_("./ask"),c.dup=_("./dup"),function(){function a(t){var n,e,o=this.as,i=o.at||o,r=i.$;(e=t["#"])||(e=t["#"]=u(9)),(n=i.dup).check(e)?o.out===t.out&&(t.out=void 0,this.to.next(t)):(n.track(e),i.ask(t["@"],t)||(t.get&&c.on.get(t,r),t.put&&c.on.put(t,r)),this.to.next(t),o.out||(t.out=a,i.on("out",t)))}c.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||c.on,t.ask=t.ask||c.ask,t.dup=t.dup||c.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",a,t),t.on("out",a,{at:t,out:a}),c.on("create",t),t.on("create",t)),t.once=1,n}}(),function(){function i(t,n,e,o){var i=this,r=c.state.is(e,n);if(!r)return i.err="Error: No state on '"+n+"' in node '"+o+"'!";var a=i.graph[o]||v,u=c.state.is(a,n,!0),s=a[n],f=c.HAM(i.machine,r,u,t,s);f.incoming?(i.put[o]=c.state.to(e,n,i.put[o]),(i.diff||(i.diff={}))[o]=c.state.to(e,n,i.diff[o]),i.souls[o]=!0):f.defer&&(i.defer=r<(i.defer||1/0)?r:i.defer)}function r(t,n){var e=this,o=e.$._,i=(o.next||v)[n];if(!i){if(!(o.opt||v).super)return void(e.souls[n]=!1);i=e.$.get(n)._}var r=e.map[n]={put:t,get:n,$:i.$},a={ctx:e,msg:r};e.async=!!o.tag.node,e.ack&&(r["@"]=e.ack),h(t,u,a),e.async&&(e.and||o.on("node",function(t){this.to.next(t),t===e.map[t.get]&&(e.souls[t.get]=!1,h(t.put,s,t),h(e.souls,function(t){if(t)return t})||e.c||(e.c=1,this.off(),h(e.map,f,e)))}),e.and=!0,o.on("node",r))}function u(t,n){var e=this.ctx,o=e.graph,i=this.msg,r=i.get,a=i.put,u=i.$._;o[r]=c.state.to(a,n,o[r]),e.async||(u.put=c.state.to(a,n,u.put))}function s(t,n){var e=this.put,o=this.$._;o.put=c.state.to(e,n,o.put)}function f(t,n){t.$&&(this.cat.stop=this.stop,t.$._.on("in",t),this.cat.stop=null)}c.on.put=function(t,n){var e=n._,o={$:n,graph:e.graph,put:{},map:{},souls:{},machine:c.state(),ack:t["@"],cat:e,stop:{}};if(c.graph.is(t.put,null,i,o)||(o.err="Error: Invalid graph!"),o.err)return e.on("in",{"@":t["#"],err:c.log(o.err)});h(o.put,r,o),o.async||h(o.map,f,o),void 0!==o.defer&&setTimeout(function(){c.on.put(t,n)},o.defer-o.machine),o.diff&&e.on("put",p(t,{put:o.diff}))},c.on.get=function(t,n){var e=n._,o=t.get,i=o[d],r=e.graph[i],a=o[g],u=(e.next||(e.next={}))[i];if(!r)return e.on("get",t);if(a){if("string"!=typeof a||!l(r,a))return e.on("get",t);r=c.state.to(r,a)}else r=c.obj.copy(r);r=c.graph.node(r),(u||v).ack,e.on("in",{"@":t["#"],how:"mem",put:r,$:n}),e.on("get",t)}}(),c.chain.opt=function(t){t=t||{};var n=this._,e=t.peers||t;return s(t)||(t={}),s(n.opt)||(n.opt=t),r(e)&&(e=[e]),o(e)&&(e=h(e,function(t,n,e){(n={}).id=n.url=t,e(t,n)}),s(n.opt.peers)||(n.opt.peers={}),n.opt.peers=p(e,n.opt.peers)),n.opt.peers=n.opt.peers||{},h(t,function t(n,e){!l(this,e)||i.is(n)||a.empty(n)?this[e]=n:n&&n.constructor!==Object&&!o(n)||h(n,t,this[e])},n.opt),c.on("opt",n),n.opt.uuid=n.opt.uuid||function(){return f()+u(12)},this};var o=c.list.is,i=c.text,r=i.is,u=i.random,a=c.obj,s=a.is,l=a.has,p=a.to,h=a.map,f=(a.copy,c.state.lex),d=c.val.link._,g=".",v=(c.node._,c.val.link.is,{});e.only=function(t,n){return e.only.i&&t===e.only.i&&e.only.i++&&(e.log.apply(e,arguments)||n)},(c.log=function(){return!c.log.off&&e.log.apply(e,arguments),[].slice.call(arguments).join(" ")}).once=function(t,n,e){return(e=c.log.once)[t]=e[t]||0,e[t]++||c.log(n)},c.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!"),"undefined"!=typeof window&&((window.GUN=window.Gun=c).window=window);try{void 0!==m&&(m.exports=c)}catch(t){}t.exports=c})(_,"./root"),_(function(t){var u=_("./root");u.chain.back=function(t,n){if(-1===(t=t||1)||1/0===t)return this._.root.$;if(1===t)return(this._.back||this._).$;var e=this._;if("string"==typeof t&&(t=t.split(".")),t instanceof Array){for(var o=0,i=t.length,r=e;o(r.acks||0)&&this.off(),r.ack&&r.ack(t,this)},r.opt),e=0,o=n.root.now;h.del(n.root,"now");var i=n.root.mum;n.root.mum={},r.ref._.on("out",{$:r.ref,put:r.out=r.env.graph,opt:r.opt,"#":t}),n.root.mum=i?h.to(i,n.root.mum):i,n.root.now=o},r),r.res&&r.res())}function n(t,n){if(t)return!0}function c(r,t,n,a){var u=this,s=f.is(r);!t&&a.path.length&&(u.res||o)(function(){for(var t=a.path,n=u.ref,e=(u.opt,0),o=t.length;e .once, apologies unexpected."),this.once(t,n)},f.chain.once=function(t,n){var e=this,o=e._,i=o.put;if(0=(o.batch||1e3))return f();i||(i=setTimeout(f,o.wait||1))}),r.on("get",function(n){this.to.next(n);var e,o,i=n.get;function t(){if(i&&(e=i["#"])){var t=i["."];(o=s[e]||void 0)&&t&&(o=Gun.state.to(o,t)),r.on("in",{"@":n["#"],put:Gun.graph.node(o),how:"lS",lS:n.$})}}Gun.debug?setTimeout(t,1):t()});var n=function(t,n,e,o){s[o]=Gun.state.to(e,n,s[o])},f=function(t){var e;u=0,clearTimeout(i),i=!1;var n=a;a={},t&&(s=t);try{p.setItem(o.prefix,JSON.stringify(s))}catch(t){Gun.log(e=(t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),r.on("localStorage:error",{err:e,file:o.prefix,flush:s,retry:f})}(e||Gun.obj.empty(o.peers))&&Gun.obj.map(n,function(t,n){r.on("in",{"@":n,err:e,ok:0})})}}})}})(_,"./adapters/localStorage"),_(function(t){var g=_("../type"),f="undefined"!=typeof setImmediate?setImmediate:setTimeout;!function(){g.text.hash=function(t){if("string"!=typeof t)return{err:1};var n=0;if(!t.length)return n;for(var e=0,o=t.length;e<"])&&(r._.to=g.obj.map(o.split(","),s)),r.dam?void((o=l.hear[r.dam])&&o(r,i,u)):(v&&(a=+new Date),u.on("in",r),void(v&&!r.nts&&p.log(a,+new Date-a,"msg",r["#"])));var a}}};var s=function(t,n,e){e(t,!0)};function d(n,e){try{var t,o=e.wire;v&&(t=+new Date),e.say?e.say(n):o.send&&o.send(n),v&&p.log(t,+new Date-t,"wire send",n.length),l.say.d+=n.length||0,++l.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}l.hear.c=l.hear.d=0,function(){var s;function f(t){l.say(s,t)}function c(t){var n=t.batch;if(t.batch=t.tail=null,n&&n.length){var e;v&&(e=+new Date);try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return p.log("DAM JSON stringify error",t)}v&&p.log(e,+new Date-e,"say stringify",n.length),n&&d(n,t)}}l.say=function(t,n){if(this.to&&this.to.next(t),!t)return!1;var e,o,i,r;v&&(a=+new Date);var a,u=t._||(t._=function(){});if((e=t["#"])||(e=t["#"]=g.text.random(9)),(o=t["##"])||void 0===t.put||(o=t["##"]=g.obj.hash(t.put)),!(r=u.raw)&&(r=u.raw=l.raw(t),o&&(i=t["@"])&&(h.track(i+o).it=t,i=(h.s[i]||!0).it))){if(o===i["##"])return!1;i["##"]=o}if(v&&p.log(a,+new Date-a,"say prep"),h.track(e).it=t,n||(n=(i=h.s[t["@"]])&&(i=i.it)&&(i=i._)&&(i=i.via)),!n&&l.way)return l.way(t);if(!n||!n.id)return s=t,!!g.obj.is(n||p.peers)&&(v&&(a=+new Date),g.obj.map(n||p.peers,f),void(v&&p.log(a,+new Date-a,"say loop")));if(!n.wire&&l.wire&&l.wire(n),e!==n.last){if(n.last=e,n===u.via)return!1;if((i=u.to)&&(i[n.url]||i[n.pid]||i[n.id]))return!1;if(n.batch){if(n.tail=(i=n.tail||0)+r.length,n.tail<=p.pack)return void n.batch.push(r);c(n)}n.batch=[],setTimeout(function(){c(n)},p.gap),d(r,n)}},l.say.c=l.say.d=0}(),function(){l.raw=function(t){if(!t)return"";var n,e=t._||{};if(n=e.raw)return n;if("string"==typeof t)return t;if(!t.dam){var o=0,i=[];g.obj.map(p.peers,function(t){if(i.push(t.url||t.pid||t.id),9<++o)return!0}),1<"]=i.join())}var r=a(t);return e&&(e.raw=r),r};var a=JSON.stringify}(),l.hi=function(n){var t=n.wire||{};n.id?p.peers[n.url||n.id]=n:(t=n.id=n.id||g.text.random(9),l.say({dam:"?",pid:u.opt.pid},p.peers[t]=n),delete h.s[n.last]),n.met=n.met||+new Date,t.hied||u.on(t.hied="hi",n),t=n.queue,n.queue=[],g.obj.map(t,function(t){d(t,n)})},l.bye=function(t){u.on("bye",t);var n=+new Date;n-=t.met||n,l.bye.time=((l.bye.time||n)+n)/2,v=e.LOG},l.hear["!"]=function(t,n){p.log("Error:",t.err)},l.hear["?"]=function(t,n){t.pid&&(n.pid||(n.pid=t.pid),t["@"])||(l.say({dam:"?",pid:p.pid,"@":t["#"]},n),delete h.s[n.last])},u.on("create",function(t){t.opt.pid=t.opt.pid||g.text.random(9),this.to.next(t),t.on("out",l.say)}),u.on("bye",function(t,n){t=p.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),g.obj.del(p.peers,t.id),t.wire=null});var i={};return u.on("bye",function(t,n){this.to.next(t),(n=t.url)&&(i[n]=!0,setTimeout(function(){delete i[n]},p.lack||9e3))}),u.on("hi",function(e,o){this.to.next(e),(o=e.url)&&i[o]&&(delete i[o],g.obj.map(u.next,function(t,n){(o={})[n]=u.graph[n],l.say({"##":g.obj.hash(o),get:{"#":n}},e)}))}),l}}catch(t){}})(_,"./adapters/mesh"),_(function(t){var f=_("../index");f.Mesh=_("./mesh"),f.on("opt",function(t){this.to.next(t);var o=t.opt;if(!t.once&&!1!==o.WebSocket){var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var e=o.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket;if(e){o.WebSocket=e;var i=o.mesh=o.mesh||f.Mesh(t);i.wire||o.wire;i.wire=o.wire=u,setTimeout(function(){t.on("out",{dam:"hi"})},1);var r=2e3,a="undefined"!=typeof document&&document}}function u(n){try{if(!n||!n.url)return e&&e(n);var t=n.url.replace("http","ws"),e=n.wire=new o.WebSocket(t);return e.onclose=function(){o.mesh.bye(n),s(n)},e.onerror=function(t){s(n)},e.onopen=function(){o.mesh.hi(n)},e.onmessage=function(t){t&&o.mesh.hear(t.data||t,n)},e}catch(t){}}function s(n){clearTimeout(n.defer),a&&n.retry<=0||(n.retry=(n.retry||o.retry||60)-1,n.defer=setTimeout(function t(){if(a&&a.hidden)return setTimeout(t,r);u(n)},r))}})})(_,"./adapters/websocket")}(); \ No newline at end of file +!function(){var t;"undefined"!=typeof window&&(t=window),"undefined"!=typeof global&&(t=global);var e=(t=t||{}).console||{log:function(){}};function _(e,t){return t?require(e):e.slice?_[o(e)]:function(t,n){e(t={exports:{}}),_[o(n)]=t.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}if("undefined"!=typeof module)var l=module;_(function(t){var n,c,l={};function e(t,n){v(this,n)&&void 0!==this[n]||(this[n]=t)}function o(t,n){var e=this.n;if(!e||!(n===e||g(e)&&v(e,n)))return!!n||void 0}function p(t,n){2!==arguments.length?(p.r=p.r||[]).push(t):(p.r=p.r||{})[t]=n}l.fn={is:function(t){return!!t&&"function"==typeof t}},l.bi={is:function(t){return t instanceof Boolean||"boolean"==typeof t}},l.num={is:function(t){return!d(t)&&(0<=t-parseFloat(t)+1||1/0===t||-1/0===t)}},l.text={is:function(t){return"string"==typeof t}},l.text.ify=function(t){return l.text.is(t)?t:"undefined"!=typeof JSON?JSON.stringify(t):t&&t.toString?t.toString():t},l.text.random=function(t,n){var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";0"]||n["<"])||o===n["="]&&(e=n["*"]||n[">"]||n["<"],t.slice(0,(e||"").length)===e||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},l.list={is:function(t){return t instanceof Array}},l.list.slit=Array.prototype.slice,l.list.sort=function(e){return function(t,n){return t&&n?(t=t[e])<(n=n[e])?-1:n",u.drift=0,u.is=function(t,n,e){var o=n&&t&&t[k]&&t[k][u._]||e;if(o)return v(o=o[n])?o:-1/0},u.lex=function(){return u().toString(36).replace(".","")},u.ify=function(t,n,e,o,i){if(!t||!t[k]){if(!i)return;t=a.soul.ify(t,i)}var r=l(t[k],u._);return void 0!==n&&n!==k&&(v(e)&&(r[n]=e),void 0!==o&&(t[n]=o)),t},u.to=function(t,n,e){var o=(t||{})[n];return h(o)&&(o=g(o)),u.ify(e,n,u.is(t,n),o,a.soul(t))},u.map=function(i,r,a){var t=h(t=i||r)?t:null;return i=m(i=i||r)?i:null,t&&!i?(r=v(r)?r:u(),t[k]=t[k]||{},d(t,f,{o:t,s:r}),t):(a=a||h(r)?r:void 0,r=v(r)?r:u(),function(t,n,e,o){if(!i)return f.call({o:e,s:r},t,n),t;i.call(a||this||{},t,n,e,o),p(e,n)&&void 0===e[n]||f.call({o:e,s:r},t,n)})};var c=n.obj,l=c.as,p=c.has,h=c.is,d=c.map,g=c.copy,v=n.num.is,m=n.fn.is,k=a._;t.exports=u})(_,"./state"),_(function(t){var a=_("./type"),u=_("./val"),s=_("./node"),i={};function r(t,n){if(!t||n!==s.soul(t)||!s.is(t,this.fn,this.as))return!0;this.cb&&(e.n=t,e.as=this.as,this.cb.call(e.as,t,n,e))}function e(t){t&&s.is(e.n,t,e.as)}function f(t,n){var e;return(e=function(t,n){var e,o=t.seen,i=o.length;for(;i--;)if(e=o[i],n.obj===e.obj)return e;o.push(n)}(t,n))?e:(n.env=t,n.soul=c,s.ify(n.obj,o,n)&&(n.link=n.link||u.link.ify(s.soul(n.node)),n.obj!==t.shell&&(t.graph[u.link.is(n.link)]=n.node)),n)}function o(t,n,e){var o,i,r=this,a=r.env;if(s._===n&&g(t,u.link._))return e._;if(o=l(t,n,e,r,a)){if(n||(r.node=r.node||e||{},g(t,s._)&&s.soul(t)&&(r.node._=b(t._)),r.node=s.soul.ify(r.node,u.link.is(r.link)),r.link=r.link||u.link.ify(s.soul(r.node))),(i=a.map)&&(i.call(a.as||{},t,n,e,r),g(e,n))){if(void 0===(t=e[n]))return void d(e,n);if(!(o=l(t,n,e,r,a)))return}if(!n)return r.node;if(!0===o)return t;if((i=f(a,{obj:t,path:r.path.concat(n)})).node)return i.link}}function c(t){var n=this,e=u.link.is(n.link),o=n.env.graph;n.link=n.link||u.link.ify(t),n.link[u.link._]=t,n.node&&n.node[s._]&&(n.node[s._][u.link._]=t),g(o,e)&&(o[t]=o[e],d(o,e))}function l(t,n,e,o,i){var r;return!!u.is(t)||(h(t)?1:(r=i.invalid)?l(t=r.call(i.as||{},t,n,e),n,e,o,i):(i.err="Invalid value at '"+o.path.concat(n).join(".")+"'!",void(a.list.is(t)&&(i.err+=" Use `.set(item)` instead of an Array."))))}function p(t,n){var e,o;if(s._!==n)(e=u.link.is(t))?(o=this.opt.seen[e])?this.obj[n]=o:this.obj[n]=this.opt.seen[e]=i.to(this.graph,e,this.opt):this.obj[n]=t;else{if(v(t,u.link._))return;this.obj[n]=b(t)}}i.is=function(t,n,e,o){return!(!t||!h(t)||v(t))&&!k(t,r,{cb:n,fn:e,as:o})},i.ify=function(t,n,e){var o={path:[],obj:t};return n?"string"==typeof n?n={soul:n}:n instanceof Function&&(n.map=n):n={},n.soul&&(o.link=u.link.ify(n.soul)),n.shell=(e||{}).shell,n.graph=n.graph||{},n.seen=n.seen||[],n.as=n.as||e,f(n,o),n.root=o.node,n.graph},i.node=function(t){var n=s.soul(t);if(n)return m({},n,t)},i.to=function(t,n,e){if(t){var o={};return e=e||{seen:{}},k(t[n],p,{obj:o,graph:t,opt:e}),o}};a.fn.is;var n=a.obj,h=n.is,d=n.del,g=n.has,v=n.empty,m=n.put,k=n.map,b=n.copy;t.exports=i})(_,"./graph"),_(function(t){_("./onto"),t.exports=function(t,n){if(this.on){if(!(t instanceof Function)){if(!t||!n)return;var e=t["#"]||t,o=(this.tag||empty)[e];if(!o)return;return o=this.on(e,n),clearTimeout(o.err),!0}e=n&&n["#"]||Math.random().toString(36).slice(2);if(!t)return e;var i=this.on(e,t,n);return i.err=i.err||setTimeout(function(){i.next({err:"Error: No ACK received yet.",lack:!0}),i.off()},(this.opt||{}).lack||9e3),e}}})(_,"./ask"),_(function(t){var a=_("./type");var u=a.time.is;t.exports=function(i){var r={s:{}};return i=i||{max:1e3,age:27e3},r.check=function(t){var n;return!!(n=r.s[t])&&(n.pass?n.pass=!1:r.track(t))},r.track=function(t,n){var e=r.s[t]||(r.s[t]={});return e.was=u(),n&&(e.pass=!0),r.to||(r.to=setTimeout(r.drop,i.age+9)),e},r.drop=function(e){var o=u();a.obj.map(r.s,function(t,n){t&&(e||i.age)>o-t.was||a.obj.del(r.s,n)}),r.to=null},r}})(_,"./dup"),_(function(t){function p(t){return t instanceof p?(this._={gun:this,$:this}).$:this instanceof p?p.create(this._={gun:this,$:this,opt:t}):new p(t)}p.is=function(t){return t instanceof p||t&&t._&&t===t._.$||!1},p.version=.9,(p.chain=p.prototype).toJSON=function(){};var n=_("./type");function a(t){var n,e,o=this.as,i=o.at||o,r=i.$;(e=t["#"])||(e=t["#"]=u(9)),(n=i.dup).check(e)?o.out===t.out&&(t.out=void 0,this.to.next(t)):(n.track(e),(e=t["@"])&&n.track(e),i.ask(e,t)||(t.get&&p.on.get(t,r),t.put&&p.on.put(t,r)),this.to.next(t),o.out||(t.out=a,i.on("out",t)))}n.obj.to(n,p),p.HAM=_("./HAM"),p.val=_("./val"),p.node=_("./node"),p.state=_("./state"),p.graph=_("./graph"),p.on=_("./onto"),p.ask=_("./ask"),p.dup=_("./dup"),p.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||p.on,t.ask=t.ask||p.ask,t.dup=t.dup||p.dup();var n=t.$.opt(t.opt);return t.once||(t.on("in",a,t),t.on("out",a,{at:t,out:a}),p.on("create",t),t.on("create",t)),t.once=1,n},function(){p.on.put=function(t,n){var e=n._,o={$:n,graph:e.graph,put:{},map:{},souls:{},machine:p.state(),ack:t["@"],cat:e,stop:{}};if(p.obj.map(t.put,l,o)){if(p.graph.is(t.put,null,a,o)||(o.err="Error: Invalid graph!"),o.err)return e.on("in",{"@":t["#"],err:p.log(o.err)});if(g(o.put,u,o),o.async||g(o.map,c,o),void 0!==o.defer){var i=o.defer-o.machine;setTimeout(function(){p.on.put(t,n)},r(r.acks||0)&&this.off(),r.ack&&r.ack(t,this)},r.opt),e=0,o=n.root.now;h.del(n.root,"now");var i=n.root.mum;n.root.mum={},r.ref._.on("out",{$:r.ref,put:r.out=r.env.graph,opt:r.opt,"#":t}),n.root.mum=i?h.to(i,n.root.mum):i,n.root.now=o},r),r.res&&r.res())}function n(t,n){if(t)return!0}function c(r,t,n,a){var u=this,s=f.is(r);!t&&a.path.length&&(u.res||o)(function(){for(var t=a.path,n=u.ref,e=(u.opt,0),o=t.length;e .once, apologies unexpected."),this.once(t,n)},f.chain.once=function(t,n){var e=this,o=e._,i=o.put;if(0=(o.batch||1e3))return f();i=i||setTimeout(f,o.wait||1)}),a.on("get",function(n){this.to.next(n);var e,o,i,r=n.get;function t(){if(r&&(e=r["#"])){var t=r["."];(o=s[e]||i)&&t&&(o=Gun.state.to(o,t)),a.on("in",{"@":n["#"],put:Gun.graph.node(o),how:"lS",lS:n.$})}}Gun.debug?setTimeout(t,1):t()});var n=function(t,n,e,o){s[o]=Gun.state.to(e,n,s[o])},f=function(t){var e;u=0,clearTimeout(i),i=!1;var n=r;r={},t&&(s=t);try{p.setItem(o.prefix,JSON.stringify(s))}catch(t){Gun.log(e=(t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),a.on("localStorage:error",{err:e,file:o.prefix,flush:s,retry:f})}(e||Gun.obj.empty(o.peers))&&Gun.obj.map(n,function(t,n){a.on("in",{"@":n,err:e,ok:0})})}}})}})(_,"./adapters/localStorage"),_(function(t){var m=_("../type"),k="undefined"!=typeof setImmediate?setImmediate:setTimeout;function b(t){return t||{_:t._,"##":t["##"]}}!function(){m.text.hash=function(t){if("string"!=typeof t)return{err:1};var n=0;if(!t.length)return n;for(var e=0,o=t.length;e<"])&&(r._.to=m.obj.map(o.split(","),h)),r.dam?void((o=f.hear[r.dam])&&o(r,i,s)):(y&&(a=+new Date),s.on("in",r),void(y&&!r.nts&&9<(u=new Date-a)&&c.log(a,u,"msg",r["#"])));var a,u}}};var u,p,h=function(t,n,e){e(t,!0)};function d(t){f.say(u,t)}function g(t){var n=t.batch;if(t.batch=t.tail=null,n&&n.length){var e;y&&(e=+new Date);try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return c.log("DAM JSON stringify error",t)}y&&c.log(e,new Date-e,"say stringify",n.length),n&&v(n,t)}}function v(n,e){try{var t,o,i=e.wire;y&&(t=+new Date),e.say?e.say(n):i.send&&i.send(n),y&&9<(o=new Date-t)&&c.log(t,o,"wire send",n.length),f.say.d+=n.length||0,++f.say.c}catch(t){(e.queue=e.queue||[]).push(n)}}f.hear.c=f.hear.d=0,p=0,f.say=function(t,n){if(this.to&&this.to.next(t),!t)return!1;var e,o,i,r;y&&new Date;var a=t._||(t._=function(){});if((e=t["#"])||(e=t["#"]=m.text.random(9)),(o=t["##"])||void 0===t.put||(o=t["##"]=m.obj.hash(t.put)),!(r=a.raw)&&(r=f.raw(t),o&&(i=t["@"])&&(l.track(i+o).it=b(t),i=(l.s[i]||!0).it))){if(o===i["##"])return!1;i["##"]=o}if(l.track(e).it=b(t),!(n=n||(i=l.s[t["@"]])&&(i=i.it)&&(i=i._)&&(i=i.via))&&t["@"])return y&&c.log(+new Date,++p,"total no peer to ack to"),!1;if(!n&&f.way)return f.way(t);if(!n||!n.id)return u=t,!!m.obj.is(n||c.peers)&&void m.obj.map(n||c.peers,d);if(!n.wire&&f.wire&&f.wire(n),e!==n.last){if(n.last=e,n===a.via)return!1;if((i=a.to)&&(i[n.url]||i[n.pid]||i[n.id]))return!1;if(n.batch){if(n.tail=(i=n.tail||0)+r.length,n.tail<=c.pack)return void n.batch.push(r);g(n)}n.batch=[],setTimeout(function(){g(n)},c.gap),v(r,n)}},f.say.c=f.say.d=0,function(){f.raw=function(t){if(!t)return"";var n,e=t._||{};if(n=e.raw)return n;if("string"==typeof t)return t;if(!t.dam){var o=0,i=[];m.obj.map(c.peers,function(t){if(i.push(t.url||t.pid||t.id),3<++o)return!0}),1<"]=i.join())}var r=a(t);return e&&(r||"").length<1e5&&(e.raw=r),r};var a=JSON.stringify}(),f.hi=function(n){var t=n.wire||{};n.id?c.peers[n.url||n.id]=n:(t=n.id=n.id||m.text.random(9),f.say({dam:"?",pid:s.opt.pid},c.peers[t]=n),delete l.s[n.last]),n.met=n.met||+new Date,t.hied||s.on(t.hied="hi",n),t=n.queue,n.queue=[],m.obj.map(t,function(t){v(t,n)})},f.bye=function(t){s.on("bye",t);var n=+new Date;n-=t.met||n,f.bye.time=((f.bye.time||n)+n)/2,y=e.LOG},f.hear["!"]=function(t,n){c.log("Error:",t.err)},f.hear["?"]=function(t,n){t.pid&&(n.pid||(n.pid=t.pid),t["@"])||(f.say({dam:"?",pid:c.pid,"@":t["#"]},n),delete l.s[n.last])},s.on("create",function(t){t.opt.pid=t.opt.pid||m.text.random(9),this.to.next(t),t.on("out",f.say)}),s.on("bye",function(t,n){t=c.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),m.obj.del(c.peers,t.id),t.wire=null});var i={};return s.on("bye",function(t,n){this.to.next(t),(n=t.url)&&(i[n]=!0,setTimeout(function(){delete i[n]},c.lack||9e3))}),s.on("hi",function(e,o){this.to.next(e),(o=e.url)&&i[o]&&(delete i[o],m.obj.map(s.next,function(t,n){(o={})[n]=s.graph[n],f.say({"##":m.obj.hash(o),get:{"#":n}},e)}))}),f}}catch(t){}})(_,"./adapters/mesh"),_(function(t){var f=_("../index");f.Mesh=_("./mesh"),f.on("opt",function(t){this.to.next(t);var o=t.opt;if(!t.once&&!1!==o.WebSocket){var n;"undefined"!=typeof window&&(n=window),"undefined"!=typeof global&&(n=global),n=n||{};var e=o.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket;if(e){o.WebSocket=e;var i=o.mesh=o.mesh||f.Mesh(t);i.wire||o.wire;i.wire=o.wire=u,setTimeout(function(){t.on("out",{dam:"hi"})},1);var r=2e3,a="undefined"!=typeof document&&document}}function u(n){try{if(!n||!n.url)return e&&e(n);var t=n.url.replace("http","ws"),e=n.wire=new o.WebSocket(t);return e.onclose=function(){o.mesh.bye(n),s(n)},e.onerror=function(t){s(n)},e.onopen=function(){o.mesh.hi(n)},e.onmessage=function(t){t&&o.mesh.hear(t.data||t,n)},e}catch(t){}}function s(n){clearTimeout(n.defer),a&&n.retry<=0||(n.retry=(n.retry||o.retry||60)-1,n.defer=setTimeout(function t(){if(a&&a.hidden)return setTimeout(t,r);u(n)},r))}})})(_,"./adapters/websocket")}(); \ No newline at end of file diff --git a/lib/server.js b/lib/server.js index 15539622..ad8c8a5c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -2,7 +2,7 @@ var Gun = require('../gun'), u; Gun.serve = require('./serve'); //process.env.GUN_ENV = process.env.GUN_ENV || 'debug'; - console.LOG = true; // only temporarily, REVERT THIS IN FUTURE! + //console.LOG = true; // only do this for dev. Gun.on('opt', function(root){ if(u === root.opt.super){ root.opt.super = true } if(u === root.opt.faith){ root.opt.faith = true } // HNPERF: This should probably be off, but we're testing performance improvements, please audit. diff --git a/sea.js b/sea.js index bb027444..213fe57f 100644 --- a/sea.js +++ b/sea.js @@ -659,7 +659,7 @@ SEA.verify = USE('./verify'); SEA.encrypt = USE('./encrypt'); SEA.decrypt = USE('./decrypt'); - SEA.aeskey = USE('./aeskey'); + SEA.opt.aeskey = USE('./aeskey'); // not official! SEA.random = SEA.random || shim.random; diff --git a/src/adapters/mesh.js b/src/adapters/mesh.js index 9e52f427..7a557c06 100644 --- a/src/adapters/mesh.js +++ b/src/adapters/mesh.js @@ -11,6 +11,7 @@ function Mesh(root){ var dup = root.dup; + // TODO: somewhere in here caused a out-of-memory crash! How? It is inbound! mesh.hear = function(raw, peer){ if(!raw){ return } var msg, id, hash, tmp = raw[0]; @@ -39,11 +40,11 @@ function Mesh(root){ if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) } if(msg.DBG_s){ opt.log(+new Date - msg.DBG_s, 'to hear', id) } if(dup.check(id)){ return } - dup.track(id, true).it = msg; // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore? + dup.track(id, true).it = it(msg); // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore? if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) } if(hash && (tmp = msg['@'] || (msg.get && id))){ // Reduces backward daisy in case varying hashes at different daisy depths are the same. if(dup.check(tmp+hash)){ return } - dup.track(tmp+hash, true).it = msg; // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore? + dup.track(tmp+hash, true).it = it(msg); // GUN core also dedups, so `true` is needed. // Does GUN core need to dedup anymore? } (msg._ = function(){}).via = peer; if(tmp = msg['><']){ (msg._).to = Type.obj.map(tmp.split(','), tomap) } @@ -53,9 +54,9 @@ function Mesh(root){ } return; } - var S; LOG && (S = +new Date); + var S, ST; LOG && (S = +new Date); root.on('in', msg); - LOG && !msg.nts && opt.log(S, +new Date - S, 'msg', msg['#']); + LOG && !msg.nts && (ST = +new Date - S) > 9 && opt.log(S, ST, 'msg', msg['#']); return; } } @@ -63,6 +64,7 @@ function Mesh(root){ mesh.hear.c = mesh.hear.d = 0; ;(function(){ + var SMIA = 0; var message; function each(peer){ mesh.say(message, peer) } mesh.say = function(msg, peer){ @@ -74,24 +76,28 @@ function Mesh(root){ if(!(id = msg['#'])){ id = msg['#'] = Type.text.random(9) } if(!(hash = msg['##']) && u !== msg.put){ hash = msg['##'] = Type.obj.hash(msg.put) } if(!(raw = meta.raw)){ - raw = meta.raw = mesh.raw(msg); + raw = mesh.raw(msg); if(hash && (tmp = msg['@'])){ - dup.track(tmp+hash).it = msg; + dup.track(tmp+hash).it = it(msg); if(tmp = (dup.s[tmp]||ok).it){ if(hash === tmp['##']){ return false } tmp['##'] = hash; } } } - LOG && opt.log(S, +new Date - S, 'say prep'); - dup.track(id).it = msg; // track for 9 seconds, default. Earth<->Mars would need more! + //LOG && opt.log(S, +new Date - S, 'say prep'); + dup.track(id).it = it(msg); // track for 9 seconds, default. Earth<->Mars would need more! if(!peer){ peer = (tmp = dup.s[msg['@']]) && (tmp = tmp.it) && (tmp = tmp._) && (tmp = tmp.via) } + if(!peer && msg['@']){ + LOG && opt.log(+new Date, ++SMIA, 'total no peer to ack to'); + return false; + } // TODO: Temporary? If ack via trace has been lost, acks will go to all peers, which trashes browser bandwidth. Not relaying the ack will force sender to ask for ack again. Note, this is technically wrong for mesh behavior. if(!peer && mesh.way){ return mesh.way(msg) } if(!peer || !peer.id){ message = msg; if(!Type.obj.is(peer || opt.peers)){ return false } - var S; LOG && (S = +new Date); + //var S; LOG && (S = +new Date); Type.obj.map(peer || opt.peers, each); // in case peer is a peer list. - LOG && opt.log(S, +new Date - S, 'say loop'); + //LOG && opt.log(S, +new Date - S, 'say loop'); return; } if(!peer.wire && mesh.wire){ mesh.wire(peer) } @@ -128,20 +134,21 @@ function Mesh(root){ // for now - find better place later. function send(raw, peer){ try{ var wire = peer.wire; - var S; LOG && (S = +new Date); + var S, ST; LOG && (S = +new Date); if(peer.say){ peer.say(raw); } else if(wire.send){ wire.send(raw); } - LOG && opt.log(S, +new Date - S, 'wire send', raw.length); + LOG && (ST = +new Date - S) > 9 && opt.log(S, ST, 'wire send', raw.length); mesh.say.d += raw.length||0; ++mesh.say.c; // STATS! }catch(e){ (peer.queue = peer.queue || []).push(raw); }} ;(function(){ + // TODO: this caused a out-of-memory crash! mesh.raw = function(msg){ // TODO: Clean this up / delete it / move logic out! if(!msg){ return '' } var meta = (msg._) || {}, put, hash, tmp; @@ -149,7 +156,7 @@ function Mesh(root){ if(typeof msg === 'string'){ return msg } if(!msg.dam){ var i = 0, to = []; Type.obj.map(opt.peers, function(p){ - to.push(p.url || p.pid || p.id); if(++i > 9){ return true } // limit server, fast fix, improve later! // For "tower" peer, MUST include 6 surrounding ids. + to.push(p.url || p.pid || p.id); if(++i > 3){ return true } // limit server, fast fix, improve later! // For "tower" peer, MUST include 6 surrounding ids. // REDUCED THIS TO 3 for temporary relay peer performance, towers still should list neighbors. }); if(i > 1){ msg['><'] = to.join() } } var raw = $(msg); // optimize by reusing put = the JSON.stringify from .hash? @@ -158,7 +165,7 @@ function Mesh(root){ raw = raw.slice(0, tmp-1) + put + raw.slice(tmp + _.length + 1); //raw = raw.replace('"'+ _ +'"', put); // NEVER USE THIS! ALSO NEVER DELETE IT TO NOT MAKE SAME MISTAKE! https://github.com/amark/gun/wiki/@$$ Heisenbug }*/ - if(meta){ meta.raw = raw } + if(meta && (raw||'').length < (1000 * 100)){ meta.raw = raw } // HNPERF: If string too big, don't keep in memory. return raw; } var $ = JSON.stringify, _ = ':])([:'; @@ -260,6 +267,8 @@ function Mesh(root){ } }()); +function it(msg){ return msg || {_: msg._, '##': msg['##']} } // HNPERF: Only need some meta data, not full reference (took up too much memory). // HNPERF: Garrrgh! We add meta data to msg over time, copying the object happens to early. + var empty = {}, ok = true, u; var LOG = console.LOG; diff --git a/src/dup.js b/src/dup.js index aae15467..2a61b0b3 100644 --- a/src/dup.js +++ b/src/dup.js @@ -2,7 +2,7 @@ var Type = require('./type'); function Dup(opt){ var dup = {s:{}}; - opt = opt || {max: 1000, age: 1000 * 9};//1000 * 60 * 2}; + opt = opt || {max: 1000, age: /*1000 * 9};//*/ 1000 * 9 * 3}; dup.check = function(id){ var tmp; if(!(tmp = dup.s[id])){ return false } if(tmp.pass){ return tmp.pass = false } @@ -12,18 +12,17 @@ function Dup(opt){ var it = dup.s[id] || (dup.s[id] = {}); it.was = time_is(); if(pass){ it.pass = true } - if(!dup.to){ - dup.to = setTimeout(function(){ - var now = time_is(); - Type.obj.map(dup.s, function(it, id){ - if(it && opt.age > (now - it.was)){ return } - Type.obj.del(dup.s, id); - }); - dup.to = null; - }, opt.age + 9); - } + if(!dup.to){ dup.to = setTimeout(dup.drop, opt.age + 9) } return it; } + dup.drop = function(age){ + var now = time_is(); + Type.obj.map(dup.s, function(it, id){ + if(it && (age || opt.age) > (now - it.was)){ return } + Type.obj.del(dup.s, id); + }); + dup.to = null; + } return dup; } var time_is = Type.time.is; diff --git a/src/root.js b/src/root.js index 187a3bdc..2abbc22e 100644 --- a/src/root.js +++ b/src/root.js @@ -53,7 +53,8 @@ Gun.dup = require('./dup'); return; } dup.track(tmp); - if(!at.ask(msg['@'], msg)){ + if(tmp = msg['@']){ dup.track(tmp) } // HNPERF: Bump original request's liveliness. + if(!at.ask(tmp, msg)){ if(msg.get){ Gun.on.get(msg, gun); //at.on('get', get(msg)); } @@ -72,18 +73,21 @@ Gun.dup = require('./dup'); ;(function(){ Gun.on.put = function(msg, gun){ var at = gun._, ctx = {$: gun, graph: at.graph, put: {}, map: {}, souls: {}, machine: Gun.state(), ack: msg['@'], cat: at, stop: {}}; + if(!Gun.obj.map(msg.put, perf, ctx)){ return } // HNPERF: performance test, not core code, do not port. if(!Gun.graph.is(msg.put, null, verify, ctx)){ ctx.err = "Error: Invalid graph!" } if(ctx.err){ return at.on('in', {'@': msg['#'], err: Gun.log(ctx.err) }) } obj_map(ctx.put, merge, ctx); if(!ctx.async){ obj_map(ctx.map, map, ctx) } if(u !== ctx.defer){ + var to = ctx.defer - ctx.machine; setTimeout(function(){ Gun.on.put(msg, gun); - }, ctx.defer - ctx.machine); + }, to > MD? MD : to ); // setTimeout Max Defer 32bit :( } if(!ctx.diff){ return } at.on('put', obj_to(msg, {put: ctx.diff})); }; + var MD = 2147483647; function verify(val, key, node, soul){ var ctx = this; var state = Gun.state.is(node, key), tmp; if(!state){ return ctx.err = "Error: No state on '"+key+"' in node '"+soul+"'!" } @@ -149,6 +153,7 @@ Gun.dup = require('./dup'); (msg.$._).on('in', msg); this.cat.stop = null; // temporary fix till a better solution? } + function perf(node, soul){ if(node !== this.graph[soul]){ return true } } // HNPERF: do not port! Gun.on.get = function(msg, gun){ var root = gun._, get = msg.get, soul = get[_soul], node = root.graph[soul], has = get[_has], tmp; @@ -162,15 +167,17 @@ Gun.dup = require('./dup'); // Maybe... in case the in-memory key we have is a local write // we still need to trigger a pull/merge from peers. } else { - node = Gun.obj.copy(node); + node = Gun.window? Gun.obj.copy(node) : node; // HNPERF: If !browser bump Performance? Is this too dangerous to reference root graph? Copy / shallow copy too expensive for big nodes. Gun.obj.to(node); // 1 layer deep copy // Gun.obj.copy(node); // too slow on big nodes } node = Gun.graph.node(node); tmp = (at||empty).ack; + var faith = function(){}; faith.faith = true; // HNPERF: We're testing performance improvement by skipping going through security again, but this should be audited. root.on('in', { '@': msg['#'], how: 'mem', put: node, - $: gun + $: gun, + _: faith }); //if(0 < tmp){ return } root.on('get', msg); diff --git a/test/sea/sea.js b/test/sea/sea.js index 469669d7..1a166804 100644 --- a/test/sea/sea.js +++ b/test/sea/sea.js @@ -38,7 +38,9 @@ describe('SEA', function(){ var pub; describe('Utility', function(){ it('generates aeskey from jwk', function(done) { - SEA.aeskey('x','x').then(k => { + console.log("WARNING: THIS DOES NOT WORK IN BROWSER!!!! NEEDS FIX"); + SEA.opt.aeskey('x','x').then(k => { + //console.log("DATA", k.data); expect(k.data.toString('base64')).to.be('Xd6JaIf2dUybFb/jpEGuSAbfL96UABMR4IvxEGIuC74=') done() })