have unbuild function wrap to prevent scope leaks & allow RETURN hehehe so I can reject @bmatusiak 's lS change O:) O:) I love you you're a hero!

later with @bmatusiak check sea.then for '../gun.js' vs '../' vs ...
note: src/index -> core.js
TODO: something about WebRTC candidates hitting ack decrement limits?
This commit is contained in:
Mark Nadal 2024-01-17 10:13:00 -08:00
parent 5c52df2eee
commit 638c2c3c23
48 changed files with 216 additions and 78 deletions

6
gun.js
View File

@ -136,7 +136,7 @@
};
})(USE, './onto');
;USE(function(module){ ;(function(){
;USE(function(module){
// TODO: BUG! Unbuild will make these globals... CHANGE unbuild to wrap files in a function.
// Book is a replacement for JS objects, maps, dictionaries.
var sT = setTimeout, B = sT.Book || (sT.Book = function(text){
@ -348,7 +348,6 @@
}
try{module.exports=B}catch(e){}
}());//delete later.
})(USE, './book');
;USE(function(module){
@ -716,7 +715,7 @@
tmp = keys.length;
console.STAT && console.STAT(S, -(S - (S = +new Date)), 'got copied some');
DBG && (DBG.ga = +new Date);
root.on('in', {'@': to, '#': id, put: put, '%': (tmp? (id = text_rand(9)) : u), $: root.$, _: faith, DBG: DBG, FOO: 1});
root.on('in', {'@': to, '#': id, put: put, '%': (tmp? (id = text_rand(9)) : u), $: root.$, _: faith, DBG: DBG});
console.STAT && console.STAT(S, +new Date - S, 'got in');
if(!tmp){ return }
setTimeout.turn(go);
@ -1388,6 +1387,7 @@
var Gun = USE('./root');
USE('./shim');
USE('./onto');
USE('./book');
USE('./valid');
USE('./state');
USE('./dup');

View File

@ -110,6 +110,7 @@ var undent = function(code, n){
if(rcode != code){
console.log("unbuild:","update",file);
}
code = ";(function(){\n"+code+"\n}());";
write(file, code);
recurse();
}());

View File

@ -1,3 +1,4 @@
;(function(){
var shim = require('./shim');
var S = require('./settings');
@ -13,4 +14,5 @@
return await shim.subtle.importKey('jwk', jwkKey, {name:'AES-GCM'}, false, ['encrypt', 'decrypt'])
}
module.exports = importGen;
}());

View File

@ -1,3 +1,4 @@
;(function(){
require('./base64');
// This is Array extended to have .toString(['utf8'|'hex'|'base64'])
@ -22,4 +23,5 @@
}
}
module.exports = SeaArray;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var User = require('./user'), SEA = User.SEA, Gun = User.GUN, noop = function(){};
// now that we have created a user, we want to authenticate them!
@ -7,7 +8,8 @@
var pass = (alias || (pair && !(pair.priv && pair.epriv))) && typeof args[1] === 'string' ? args[1] : null;
var cb = args.filter(arg => typeof arg === 'function')[0] || null; // cb now can stand anywhere, after alias/pass or pair
var opt = args && args.length > 1 && typeof args[args.length-1] === 'object' ? args[args.length-1] : {}; // opt is always the last parameter which typeof === 'object' and stands after cb
var retries = typeof opt.retries === 'number' ? opt.retries : 9;
var gun = this, cat = (gun._), root = gun.back(-1);
if(cat.ing){
@ -30,6 +32,10 @@
var get = (act.list = (act.list||[]).concat(list||[])).shift();
if(u === get){
if(act.name){ return act.err('Your user account is not published for dApps to access, please consider syncing it online, or allowing local access by adding your device as a peer.') }
if(alias && retries--){
root.get('~@'+alias).once(act.a);
return;
}
return act.err('Wrong user or password.')
}
root.get(get).once(act.a);
@ -74,7 +80,7 @@
if(SEA.window && ((gun.back('user')._).opt||opt).remember){
// TODO: this needs to be modular.
try{var sS = {};
sS = window.sessionStorage; // TODO: FIX BUG putting on `.is`!
sS = SEA.window.sessionStorage; // TODO: FIX BUG putting on `.is`!
sS.recall = true;
sS.pair = JSON.stringify(pair); // auth using pair is more reliable than alias/pass
}catch(e){}
@ -154,4 +160,5 @@
}catch(e){o={}};
return o;
}
}());

View File

@ -1,3 +1,4 @@
;(function(){
var u;
if(u+''== typeof btoa){
@ -7,4 +8,5 @@
global.btoa = function(data){ return Buffer.from(data, "binary").toString("base64") };
global.atob = function(data){ return Buffer.from(data, "base64").toString("binary") };
}
}());

View File

@ -1,3 +1,4 @@
;(function(){
require('./base64');
// This is Buffer implementation used in SEA. Functionality is mostly
@ -76,4 +77,5 @@
SafeBuffer.prototype.toString = SeaArray.prototype.toString
module.exports = SafeBuffer;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
// This is to certify that a group of "certificants" can "put" anything at a group of matched "paths" to the certificate authority's graph
@ -69,4 +70,5 @@
}});
module.exports = SEA.certify;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var User = require('./user'), SEA = User.SEA, Gun = User.GUN, noop = function(){};
@ -94,11 +95,12 @@
}
if(SEA.window){
try{var sS = {};
sS = window.sessionStorage;
sS = SEA.window.sessionStorage;
delete sS.recall;
delete sS.pair;
}catch(e){};
}
return gun;
}
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
var shim = require('./shim');
@ -39,4 +40,5 @@
}});
module.exports = SEA.decrypt;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
var shim = require('./shim');
@ -37,4 +38,5 @@
}});
module.exports = SEA.encrypt;
}());

View File

@ -1,12 +1,16 @@
;(function(){
var SEA = require('./root');
try{ if(SEA.window){
if(location.protocol.indexOf('s') < 0
&& location.host.indexOf('localhost') < 0
&& ! /^127\.\d+\.\d+\.\d+$/.test(location.hostname)
&& location.protocol.indexOf('file:') < 0){
&& location.protocol.indexOf('blob:') < 0
&& location.protocol.indexOf('file:') < 0
&& location.origin != 'null'){
console.warn('HTTPS needed for WebCrypto in SEA, redirecting...');
location.protocol = 'https:'; // WebCrypto does NOT work without HTTPS!
}
} }catch(e){}
}());

View File

@ -1,6 +1,7 @@
;(function(){
var SEA = require('./sea'), S = require('./settings'), noop = function() {}, u;
var Gun = (''+u != typeof window)? (window.Gun||{on:noop}) : require((''+u === typeof MODULE?'.':'')+'./gun', 1);
var Gun = (SEA.window||'').GUN || require((''+u === typeof MODULE?'.':'')+'./gun', 1);
// After we have a GUN extension to make user registration/login easy, we then need to handle everything else.
// We do this with a GUN adapter, we first listen to when a gun instance is created (and when its options change)
@ -66,7 +67,7 @@
check.any(eve, msg, val, key, soul, at, no, at.user||''); return;
eve.to.next(msg); // not handled
}
check.hash = function(eve, msg, val, key, soul, at, no){
check.hash = function(eve, msg, val, key, soul, at, no){ // mark unbuilt @i001962 's epic hex contrib!
SEA.work(val, null, function(data){
function hexToBase64(hexStr) {
let base64 = "";
@ -246,3 +247,4 @@
// TODO: Potential bug? If pub/priv key starts with `-`? IDK how possible.
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
var shim = require('./shim');
@ -70,4 +71,5 @@
}});
module.exports = SEA.pair;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var User = require('./user'), SEA = User.SEA, Gun = User.GUN;
User.prototype.recall = function(opt, cb){
@ -7,7 +8,7 @@
if(SEA.window){
try{
var sS = {};
sS = window.sessionStorage; // TODO: FIX BUG putting on `.is`!
sS = SEA.window.sessionStorage; // TODO: FIX BUG putting on `.is`!
if(sS){
(root._).opt.remember = true;
((gun.back('user')._).opt||opt).remember = true;
@ -24,4 +25,5 @@
*/
return gun;
}
}());

View File

@ -1,9 +1,11 @@
;(function(){
// Security, Encryption, and Authorization: SEA.js
// MANDATORY READING: https://gun.eco/explainers/data/security.html
// IT IS IMPLEMENTED IN A POLYFILL/SHIM APPROACH.
// THIS IS AN EARLY ALPHA!
if(typeof self !== "undefined"){ module.window = self } // should be safe for at least browser/worker/nodejs, need to check other envs like RN etc.
if(typeof window !== "undefined"){ module.window = window }
var tmp = module.window || module, u;
@ -13,4 +15,5 @@
try{ if(u+'' !== typeof MODULE){ MODULE.exports = SEA } }catch(e){}
module.exports = SEA;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var shim = require('./shim');
// Practical examples about usage found in tests.
@ -16,7 +17,7 @@
// For documentation see https://nodejs.org/api/buffer.html
SEA.Buffer = SEA.Buffer || require('./buffer');
// These SEA functions support now only Promises or
// These SEA functions support now ony Promises or
// async/await (compatible) code, use those like Promises.
//
// Creates a wrapper library around Web Crypto API
@ -45,7 +46,7 @@
// Obviously it is missing MANY necessary features. This is only an alpha release.
// Please experiment with it, audit what I've done so far, and complain about what needs to be added.
// SEA should be a full suite that is easy and seamless to use.
// Again, scroll near the top, where I provide an EXAMPLE of how to create a user and sign in.
// Again, scroll naer the top, where I provide an EXAMPLE of how to create a user and sign in.
// Once logged in, the rest of the code you just read handled automatically signing/validating data.
// But all other behavior needs to be equally easy, like opinionated ways of
// Adding friends (trusted public keys), sending private messages, etc.
@ -55,4 +56,5 @@
module.exports = SEA
// -------------- END SEA MODULES --------------------
// -- BEGIN SEA+GUN MODULES: BUNDLED BY DEFAULT UNTIL OTHERS USE SEA ON OWN -------
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
var shim = require('./shim');
@ -50,4 +51,5 @@
}
module.exports = SEA.secret;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
var shim = require('./shim');
@ -41,4 +42,5 @@
SEA.opt = s;
module.exports = s
}());

View File

@ -1,3 +1,4 @@
;(function(){
// This internal func returns SHA-1 hashed data for KeyID generation
const __shim = require('./shim')
@ -5,4 +6,5 @@
const ossl = __shim.ossl ? __shim.ossl : subtle
const sha1hash = (b) => ossl.digest({name: 'SHA-1'}, new ArrayBuffer(b))
module.exports = sha1hash
}());

View File

@ -1,3 +1,4 @@
;(function(){
var shim = require('./shim');
module.exports = async function(d, o){
@ -5,4 +6,5 @@
var hash = await shim.subtle.digest({name: o||'SHA-256'}, new shim.TextEncoder().encode(t));
return shim.Buffer.from(hash);
}
}());

View File

@ -1,3 +1,4 @@
;(function(){
var User = require('./user'), SEA = User.SEA, Gun = User.GUN, noop = function(){};
User.prototype.pair = function(){
@ -133,4 +134,5 @@
}
*/
module.exports = User
}());

View File

@ -1,3 +1,4 @@
;(function(){
const SEA = require('./root')
const api = {Buffer: require('./buffer')}
@ -15,10 +16,10 @@
})}
if(SEA.window){
api.crypto = window.crypto || window.msCrypto
api.crypto = SEA.window.crypto || SEA.window.msCrypto
api.subtle = (api.crypto||o).subtle || (api.crypto||o).webkitSubtle;
api.TextEncoder = window.TextEncoder;
api.TextDecoder = window.TextDecoder;
api.TextEncoder = SEA.window.TextEncoder;
api.TextDecoder = SEA.window.TextDecoder;
api.random = (len) => api.Buffer.from(api.crypto.getRandomValues(new Uint8Array(api.Buffer.alloc(len))));
}
if(!api.TextDecoder)
@ -44,4 +45,5 @@
}}
module.exports = api
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
var shim = require('./shim');
@ -41,4 +42,5 @@
}});
module.exports = SEA.sign;
}());

View File

@ -1,9 +1,11 @@
;(function(){
var u, Gun = (''+u != typeof window)? (window.Gun||{chain:{}}) : require((''+u === typeof MODULE?'.':'')+'./gun', 1);
var u, Gun = (''+u != typeof GUN)? (GUN||{chain:{}}) : require((''+u === typeof MODULE?'.':'')+'./gun', 1);
Gun.chain.then = function(cb, opt){
var gun = this, p = (new Promise(function(res, rej){
gun.once(res, opt);
}));
return cb? p.then(cb) : p;
}
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./sea'), Gun, u;
if(SEA.window){
@ -38,4 +39,5 @@
User.GUN = Gun;
User.SEA = Gun.SEA = SEA;
module.exports = User;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
var shim = require('./shim');
@ -77,4 +78,5 @@
}
SEA.opt.fallback = 2;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var SEA = require('./root');
var shim = require('./shim');
@ -39,4 +40,5 @@
}});
module.exports = SEA.work;
}());

View File

@ -1,3 +1,4 @@
;(function(){
// request / response module, for asking and acking messages.
require('./onto'); // depends upon onto!
@ -24,4 +25,5 @@ module.exports = function ask(cb, as){
return id;
}
var random = String.random || function(){ return Math.random().toString(36).slice(2) }
}());

View File

@ -1,3 +1,4 @@
;(function(){
var Gun = require('./root');
Gun.chain.back = function(n, opt){ var tmp;
@ -37,4 +38,5 @@ Gun.chain.back = function(n, opt){ var tmp;
return this;
}
var empty = {}, u;
}());

View File

@ -1,4 +1,5 @@
;(function(){
;(function(){
// TODO: BUG! Unbuild will make these globals... CHANGE unbuild to wrap files in a function.
// Book is a replacement for JS objects, maps, dictionaries.
var sT = setTimeout, B = sT.Book || (sT.Book = function(text){
@ -210,5 +211,5 @@ function decord(t){
}
try{module.exports=B}catch(e){}
}());//delete later.
}());

View File

@ -1,3 +1,4 @@
;(function(){
// WARNING: GUN is very simple, but the JavaScript chaining API around GUN
// is complicated and was extremely hard to build. If you port GUN to another
@ -28,6 +29,7 @@ function output(msg){
if(at.lex){ Object.keys(at.lex).forEach(function(k){ tmp[k] = at.lex[k] }, tmp = msg.get = msg.get || {}) }
if(get['#'] || at.soul){
get['#'] = get['#'] || at.soul;
//root.graph[get['#']] = root.graph[get['#']] || {_:{'#':get['#'],'>':{}}};
msg['#'] || (msg['#'] = text_rand(9)); // A3120 ?
back = (root.$.get(get['#'])._);
if(!(get = get['.'])){ // soul
@ -247,4 +249,5 @@ function ack(msg, ev){
}
var empty = {}, u, text_rand = String.random, valid = Gun.valid, obj_has = function(o, k){ return o && Object.prototype.hasOwnProperty.call(o, k) }, state = Gun.state, state_is = state.is, state_ify = state.ify;
}());

10
src/core.js Normal file
View File

@ -0,0 +1,10 @@
;(function(){
var Gun = require('./root');
require('./chain');
require('./back');
require('./put');
require('./get');
module.exports = Gun;
}());

View File

@ -1,3 +1,4 @@
;(function(){
require('./shim');
function Dup(opt){
@ -11,6 +12,7 @@ function Dup(opt){
var it = s[id] || (s[id] = {});
it.was = dup.now = +new Date;
if(!dup.to){ dup.to = setTimeout(dup.drop, opt.age + 9) }
if(dt.ed){ dt.ed(id) }
return it;
}
dup.drop = function(age){
@ -26,4 +28,5 @@ function Dup(opt){
return dup;
}
module.exports = Dup;
}());

View File

@ -1,3 +1,4 @@
;(function(){
var Gun = require('./root');
Gun.chain.get = function(key, cb, as){
@ -110,6 +111,7 @@ function cache(key, back){
next[at.get = key] = at;
if(back === cat.root.$){
at.soul = key;
//at.put = {};
} else
if(cat.soul || cat.has){
at.has = key;
@ -153,4 +155,5 @@ function rid(at){
return;
}
var empty = {}, valid = Gun.valid, u;
}());

View File

@ -1,8 +1,20 @@
;(function(){
var Gun = require('./root');
require('./chain');
require('./back');
require('./put');
require('./get');
require('./shim');
require('./onto');
require('./book');
require('./valid');
require('./state');
require('./dup');
require('./ask');
require('./core');
require('./on');
require('./map');
require('./set');
require('./mesh');
require('./websocket');
require('./localStorage');
module.exports = Gun;
}());

View File

@ -1,3 +1,4 @@
;(function(){
if(typeof Gun === 'undefined'){ return }
@ -64,4 +65,5 @@ Gun.on('create', function lg(root){
}
});
}());

View File

@ -1,5 +1,6 @@
;(function(){
var Gun = require('./index'), next = Gun.chain.get.next;
var Gun = require('./root'), next = Gun.chain.get.next;
Gun.chain.get.next = function(gun, lex){ var tmp;
if(!Object.plain(lex)){ return (next||noop)(gun, lex) }
if(tmp = ((tmp = lex['#'])||'')['='] || tmp){ return gun.get(tmp) }
@ -41,4 +42,5 @@ function map(msg){ this.to.next(msg);
Gun.on.link(msg, cat);
}
var noop = function(){}, event = {stun: noop, off: noop}, u;
}());

View File

@ -1,3 +1,4 @@
;(function(){
require('./shim');
@ -84,12 +85,17 @@ function Mesh(root){
if(tmp = msg.ok){ msg._.near = tmp['/'] }
var S = +new Date;
DBG && (DBG.is = S); peer.SI = id;
dup_track.ed = function(d){
if(id !== d){ return }
dup_track.ed = 0;
if(!(d = dup.s[id])){ return }
d.via = peer;
if(msg.get){ d.it = msg }
}
root.on('in', mesh.last = msg);
//ECHO = msg.put || ECHO; !(msg.ok !== -3740) && mesh.say({ok: -3740, put: ECHO, '@': msg['#']}, peer);
DBG && (DBG.hd = +new Date);
console.STAT && console.STAT(S, +new Date - S, msg.get? 'msg get' : msg.put? 'msg put' : 'msg');
(tmp = dup_track(id)).via = peer; // don't dedup message ID till after, cause GUN has internal dedup check.
if(msg.get){ tmp.it = msg }
dup_track(id); // in case 'in' does not call track.
if(ash){ dup_track(ash) } //dup.track(tmp+hash, true).it = it(msg);
mesh.leap = mesh.last = null; // warning! mesh.leap could be buggy.
}
@ -129,12 +135,13 @@ function Mesh(root){
!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 || (dup.s[id]||'').err)){ return false } // TODO: in theory we should not be able to stun a message, but for now going to check if it can help network performance preventing invalid data to relay.
if(!(hash = msg['##']) && u !== msg.put && !meta.via && ack){ mesh.hash(msg, peer); return } // TODO: Should broadcasts be hashed?
if(!peer && ack){ peer = ((tmp = dup.s[ack]) && (tmp.via || ((tmp = tmp.it) && (tmp = tmp._) && tmp.via))) || ((tmp = mesh.last) && ack === tmp['#'] && mesh.leap) } // warning! mesh.leap could be buggy! mesh last check reduces this.
if(!peer && ack){ peer = ((tmp = dup.s[ack]) && (tmp.via || ((tmp = tmp.it) && (tmp = tmp._) && tmp.via))) || ((tmp = mesh.last) && ack === tmp['#'] && mesh.leap) } // warning! mesh.leap could be buggy! mesh last check reduces this. // TODO: CLEAN UP THIS LINE NOW? `.it` should be reliable.
if(!peer && ack){ // still no peer, then ack daisy chain 'tunnel' got lost.
if(dup.s[ack]){ return } // in dups but no peer hints that this was ack to ourself, ignore.
console.STAT && console.STAT(+new Date, ++SMIA, 'total no peer to ack to'); // TODO: Delete this now. Dropping lost ACKs is protocol fine now.
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(ack && !msg.put && !hash && ((dup.s[ack]||'').it||'')['##']){ return false } // If we're saying 'not found' but a relay had data, do not bother sending our not found. // Is this correct, return false? // NOTE: ADD PANIC TEST FOR THIS!
if(!peer && mesh.way){ return mesh.way(msg) }
DBG && (DBG.yh = +new Date);
if(!(raw = meta.raw)){ mesh.raw(msg, peer); return }
@ -195,7 +202,7 @@ function Mesh(root){
var hash = msg['##'], ack = msg['@'];
if(hash && ack){
if(!meta.via && dup_check(ack+hash)){ return false } // for our own out messages, memory & storage may ack the same thing, so dedup that. Tho if via another peer, we already tracked it upon hearing, so this will always trigger false positives, so don't do that!
if((tmp = (dup.s[ack]||'').it) || ((tmp = mesh.last) && ack === tmp['#'])){
if(tmp = (dup.s[ack]||'').it){
if(hash === tmp['##']){ return false } // if ask has a matching hash, acking is optional.
if(!tmp['##']){ tmp['##'] = hash } // if none, add our hash to ask so anyone we relay to can dedup. // NOTE: May only check against 1st ack chunk, 2nd+ won't know and still stream back to relaying peers which may then dedup. Any way to fix this wasted bandwidth? I guess force rate limiting breaking change, that asking peer has to ask for next lexical chunk.
}
@ -343,4 +350,5 @@ function Mesh(root){
try{ module.exports = Mesh }catch(e){}
}());

View File

@ -1,5 +1,6 @@
;(function(){
var Gun = require('./index');
var Gun = require('./root');
Gun.chain.on = function(tag, arg, eas, as){ // don't rewrite!
var gun = this, cat = gun._, root = cat.root, act, off, id, tmp;
if(typeof tag === 'string'){
@ -103,6 +104,10 @@ Gun.chain.off = function(){
}
}
// TODO: delete cat.one[map.id]?
if (tmp = cat.any) {
delete cat.any;
cat.any = {};
}
if(tmp = cat.ask){
delete tmp[at.get];
}
@ -128,4 +133,5 @@ Gun.chain.off = function(){
return gun;
}
var empty = {}, noop = function(){}, u;
}());

View File

@ -1,3 +1,4 @@
;(function(){
// On event emitter generic javascript utility.
module.exports = function onto(tag, arg, as){
@ -33,4 +34,5 @@ module.exports = function onto(tag, arg, as){
if((tag = tag.to) && u !== arg){ tag.next(arg) }
return tag;
};
}());

View File

@ -1,3 +1,4 @@
;(function(){
var Gun = require('./root');
Gun.chain.put = function(data, cb, as){ // I rewrote it :)
@ -152,4 +153,5 @@ function check(d, tmp){ return ((d && (tmp = d.constructor) && tmp.name) || type
var u, empty = {}, noop = function(){}, turn = setTimeout.turn, valid = Gun.valid, state_ify = Gun.state.ify;
var iife = function(fn,as){fn.call(as||empty)}
}());

View File

@ -1,3 +1,4 @@
;(function(){
function Gun(o){
@ -201,6 +202,9 @@ Gun.ask = require('./ask');
Gun.on.get = function(msg, gun){
var root = gun._, get = msg.get, soul = get['#'], node = root.graph[soul], has = get['.'];
var next = root.next || (root.next = {}), at = next[soul];
// TODO: Azarattum bug, what is in graph is not same as what is in next. Fix!
// queue concurrent GETs?
// TODO: consider tagging original message into dup for DAM.
// TODO: ^ above? In chat app, 12 messages resulted in same peer asking for `#user.pub` 12 times. (same with #user GET too, yipes!) // DAM note: This also resulted in 12 replies from 1 peer which all had same ##hash but none of them deduped because each get was different.
@ -221,10 +225,14 @@ Gun.ask = require('./ask');
}*/
var ctx = msg._||{}, DBG = ctx.DBG = msg.DBG;
DBG && (DBG.g = +new Date);
//console.log("GET:", get, node, has);
//console.log("GET:", get, node, has, at);
//if(!node && !at){ return root.on('get', msg) }
//if(has && node){ // replace 2 below lines to continue dev?
if(!node){ return root.on('get', msg) }
if(has){
if('string' != typeof has || u === node[has]){ return root.on('get', msg) }
if('string' != typeof has || u === node[has]){
if(!((at||'').next||'')[has]){ root.on('get', msg); return }
}
node = state_ify({}, has, state_is(node, has), node[has], soul);
// If we have a key in-memory, do we really need to fetch?
// Maybe... in case the in-memory key we have is a local write
@ -301,4 +309,5 @@ module.exports = Gun;
;"Please do not remove welcome log unless you are paying for a monthly sponsorship, thanks!";
Gun.log.once("welcome", "Hello wonderful person! :) Thanks for using GUN, please ask for help on http://chat.gun.eco if anything takes you longer than 5min to figure out!");
}());

View File

@ -1,5 +1,6 @@
;(function(){
var Gun = require('./index');
var Gun = require('./root');
Gun.chain.set = function(item, cb, opt){
var gun = this, root = gun.back(-1), soul, tmp;
cb = cb || function(){};
@ -20,4 +21,5 @@ Gun.chain.set = function(item, cb, opt){
})
return item;
}
}());

View File

@ -1,3 +1,4 @@
;(function(){
// Shim for generic javascript utilities.
String.random = function(l, c){
@ -82,4 +83,5 @@ Object.keys = Object.keys || function(o){
} e && e(r);
}())})();
}());
}());

View File

@ -1,3 +1,4 @@
;(function(){
require('./shim');
function State(){
@ -25,4 +26,5 @@ State.ify = function(n, k, s, v, soul){ // put a key's state on a node.
return n;
}
module.exports = State;
}());

View File

@ -1,9 +1,10 @@
;(function(){
// Valid values are a subset of JSON: null, binary, number (!Infinity), text,
// or a soul relation. Arrays need special algorithms to handle concurrency,
// so they are not supported directly. Use an extension that supports them if
// needed but research their problems first.
module.exports = function (v) {
module.exports = function(v){
// "deletes", nulling out keys.
return v === null ||
"string" === typeof v ||
@ -13,4 +14,5 @@ module.exports = function (v) {
("number" === typeof v && v != Infinity && v != -Infinity && v === v) ||
(!!v && "string" == typeof v["#"] && Object.keys(v).length === 1 && v["#"]);
}
}());

View File

@ -1,5 +1,6 @@
;(function(){
var Gun = require('./index');
var Gun = require('./root');
Gun.Mesh = require('./mesh');
// TODO: resync upon reconnect online/offline
@ -57,4 +58,5 @@ Gun.on('opt', function(root){
var doc = (''+u !== typeof document) && document;
});
var noop = function(){}, u;
}());