mirror of
https://github.com/amark/gun.git
synced 2025-03-30 15:08:33 +00:00
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:
parent
5c52df2eee
commit
638c2c3c23
6
gun.js
6
gun.js
@ -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');
|
||||
|
@ -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();
|
||||
}());
|
||||
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var shim = require('./shim');
|
||||
var S = require('./settings');
|
||||
@ -14,3 +15,4 @@
|
||||
}
|
||||
module.exports = importGen;
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
require('./base64');
|
||||
// This is Array extended to have .toString(['utf8'|'hex'|'base64'])
|
||||
@ -23,3 +24,4 @@
|
||||
}
|
||||
module.exports = SeaArray;
|
||||
|
||||
}());
|
@ -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,6 +8,7 @@
|
||||
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);
|
||||
|
||||
@ -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){}
|
||||
@ -155,3 +161,4 @@
|
||||
return o;
|
||||
}
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var u;
|
||||
if(u+''== typeof btoa){
|
||||
@ -8,3 +9,4 @@
|
||||
global.atob = function(data){ return Buffer.from(data, "base64").toString("binary") };
|
||||
}
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
require('./base64');
|
||||
// This is Buffer implementation used in SEA. Functionality is mostly
|
||||
@ -77,3 +78,4 @@
|
||||
|
||||
module.exports = SafeBuffer;
|
||||
|
||||
}());
|
@ -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
|
||||
@ -70,3 +71,4 @@
|
||||
|
||||
module.exports = SEA.certify;
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var User = require('./user'), SEA = User.SEA, Gun = User.GUN, noop = function(){};
|
||||
|
||||
@ -94,7 +95,7 @@
|
||||
}
|
||||
if(SEA.window){
|
||||
try{var sS = {};
|
||||
sS = window.sessionStorage;
|
||||
sS = SEA.window.sessionStorage;
|
||||
delete sS.recall;
|
||||
delete sS.pair;
|
||||
}catch(e){};
|
||||
@ -102,3 +103,4 @@
|
||||
return gun;
|
||||
}
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./root');
|
||||
var shim = require('./shim');
|
||||
@ -40,3 +41,4 @@
|
||||
|
||||
module.exports = SEA.decrypt;
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./root');
|
||||
var shim = require('./shim');
|
||||
@ -38,3 +39,4 @@
|
||||
|
||||
module.exports = SEA.encrypt;
|
||||
|
||||
}());
|
@ -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){}
|
||||
|
||||
}());
|
@ -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.
|
||||
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./root');
|
||||
var shim = require('./shim');
|
||||
@ -71,3 +72,4 @@
|
||||
|
||||
module.exports = SEA.pair;
|
||||
|
||||
}());
|
@ -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;
|
||||
@ -25,3 +26,4 @@
|
||||
return gun;
|
||||
}
|
||||
|
||||
}());
|
@ -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;
|
||||
@ -14,3 +16,4 @@
|
||||
try{ if(u+'' !== typeof MODULE){ MODULE.exports = SEA } }catch(e){}
|
||||
module.exports = SEA;
|
||||
|
||||
}());
|
@ -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.
|
||||
@ -56,3 +57,4 @@
|
||||
// -------------- END SEA MODULES --------------------
|
||||
// -- BEGIN SEA+GUN MODULES: BUNDLED BY DEFAULT UNTIL OTHERS USE SEA ON OWN -------
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./root');
|
||||
var shim = require('./shim');
|
||||
@ -51,3 +52,4 @@
|
||||
|
||||
module.exports = SEA.secret;
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./root');
|
||||
var shim = require('./shim');
|
||||
@ -42,3 +43,4 @@
|
||||
SEA.opt = s;
|
||||
module.exports = s
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
// This internal func returns SHA-1 hashed data for KeyID generation
|
||||
const __shim = require('./shim')
|
||||
@ -6,3 +7,4 @@
|
||||
const sha1hash = (b) => ossl.digest({name: 'SHA-1'}, new ArrayBuffer(b))
|
||||
module.exports = sha1hash
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var shim = require('./shim');
|
||||
module.exports = async function(d, o){
|
||||
@ -6,3 +7,4 @@
|
||||
return shim.Buffer.from(hash);
|
||||
}
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var User = require('./user'), SEA = User.SEA, Gun = User.GUN, noop = function(){};
|
||||
User.prototype.pair = function(){
|
||||
@ -134,3 +135,4 @@
|
||||
*/
|
||||
module.exports = User
|
||||
|
||||
}());
|
@ -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)
|
||||
@ -45,3 +46,4 @@
|
||||
|
||||
module.exports = api
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./root');
|
||||
var shim = require('./shim');
|
||||
@ -42,3 +43,4 @@
|
||||
|
||||
module.exports = SEA.sign;
|
||||
|
||||
}());
|
@ -1,5 +1,6 @@
|
||||
;(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);
|
||||
@ -7,3 +8,4 @@
|
||||
return cb? p.then(cb) : p;
|
||||
}
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./sea'), Gun, u;
|
||||
if(SEA.window){
|
||||
@ -39,3 +40,4 @@
|
||||
User.SEA = Gun.SEA = SEA;
|
||||
module.exports = User;
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./root');
|
||||
var shim = require('./shim');
|
||||
@ -78,3 +79,4 @@
|
||||
SEA.opt.fallback = 2;
|
||||
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var SEA = require('./root');
|
||||
var shim = require('./shim');
|
||||
@ -40,3 +41,4 @@
|
||||
|
||||
module.exports = SEA.work;
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
// request / response module, for asking and acking messages.
|
||||
require('./onto'); // depends upon onto!
|
||||
@ -25,3 +26,4 @@ module.exports = function ask(cb, as){
|
||||
}
|
||||
var random = String.random || function(){ return Math.random().toString(36).slice(2) }
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var Gun = require('./root');
|
||||
Gun.chain.back = function(n, opt){ var tmp;
|
||||
@ -38,3 +39,4 @@ Gun.chain.back = function(n, opt){ var tmp;
|
||||
}
|
||||
var empty = {}, u;
|
||||
|
||||
}());
|
@ -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.
|
||||
|
||||
}());
|
@ -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
|
||||
@ -248,3 +250,4 @@ 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
10
src/core.js
Normal file
@ -0,0 +1,10 @@
|
||||
;(function(){
|
||||
|
||||
var Gun = require('./root');
|
||||
require('./chain');
|
||||
require('./back');
|
||||
require('./put');
|
||||
require('./get');
|
||||
module.exports = Gun;
|
||||
|
||||
}());
|
@ -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){
|
||||
@ -27,3 +29,4 @@ function Dup(opt){
|
||||
}
|
||||
module.exports = Dup;
|
||||
|
||||
}());
|
@ -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;
|
||||
@ -154,3 +156,4 @@ function rid(at){
|
||||
}
|
||||
var empty = {}, valid = Gun.valid, u;
|
||||
|
||||
}());
|
20
src/index.js
20
src/index.js
@ -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;
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
if(typeof Gun === 'undefined'){ return }
|
||||
|
||||
@ -65,3 +66,4 @@ Gun.on('create', function lg(root){
|
||||
|
||||
});
|
||||
|
||||
}());
|
@ -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) }
|
||||
@ -42,3 +43,4 @@ function map(msg){ this.to.next(msg);
|
||||
}
|
||||
var noop = function(){}, event = {stun: noop, off: noop}, u;
|
||||
|
||||
}());
|
18
src/mesh.js
18
src/mesh.js
@ -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.
|
||||
}
|
||||
@ -344,3 +351,4 @@ function Mesh(root){
|
||||
try{ module.exports = Mesh }catch(e){}
|
||||
|
||||
|
||||
}());
|
@ -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];
|
||||
}
|
||||
@ -129,3 +134,4 @@ Gun.chain.off = function(){
|
||||
}
|
||||
var empty = {}, noop = function(){}, u;
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
// On event emitter generic javascript utility.
|
||||
module.exports = function onto(tag, arg, as){
|
||||
@ -34,3 +35,4 @@ module.exports = function onto(tag, arg, as){
|
||||
return tag;
|
||||
};
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
var Gun = require('./root');
|
||||
Gun.chain.put = function(data, cb, as){ // I rewrote it :)
|
||||
@ -153,3 +154,4 @@ 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)}
|
||||
|
||||
}());
|
13
src/root.js
13
src/root.js
@ -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
|
||||
@ -302,3 +310,4 @@ 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!");
|
||||
|
||||
}());
|
@ -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(){};
|
||||
@ -21,3 +22,4 @@ Gun.chain.set = function(item, cb, opt){
|
||||
return item;
|
||||
}
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
// Shim for generic javascript utilities.
|
||||
String.random = function(l, c){
|
||||
@ -83,3 +84,4 @@ Object.keys = Object.keys || function(o){
|
||||
}())})();
|
||||
}());
|
||||
|
||||
}());
|
@ -1,3 +1,4 @@
|
||||
;(function(){
|
||||
|
||||
require('./shim');
|
||||
function State(){
|
||||
@ -26,3 +27,4 @@ State.ify = function(n, k, s, v, soul){ // put a key's state on a node.
|
||||
}
|
||||
module.exports = State;
|
||||
|
||||
}());
|
@ -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 ||
|
||||
@ -14,3 +15,4 @@ module.exports = function (v) {
|
||||
(!!v && "string" == typeof v["#"] && Object.keys(v).length === 1 && v["#"]);
|
||||
}
|
||||
|
||||
}());
|
@ -1,5 +1,6 @@
|
||||
;(function(){
|
||||
|
||||
var Gun = require('./index');
|
||||
var Gun = require('./root');
|
||||
Gun.Mesh = require('./mesh');
|
||||
|
||||
// TODO: resync upon reconnect online/offline
|
||||
@ -58,3 +59,4 @@ Gun.on('opt', function(root){
|
||||
});
|
||||
var noop = function(){}, u;
|
||||
|
||||
}());
|
Loading…
x
Reference in New Issue
Block a user