mirror of
https://github.com/amark/gun.git
synced 2025-07-04 11:52:34 +00:00
once fix, clean sea
This commit is contained in:
parent
41482d25cc
commit
774fcc789b
18
gun.js
18
gun.js
@ -1655,19 +1655,19 @@
|
|||||||
var opt = this.as, cat = opt.at, gun = msg.$, at = gun._, data = at.put || msg.put, link, tmp;
|
var opt = this.as, cat = opt.at, gun = msg.$, at = gun._, data = at.put || msg.put, link, tmp;
|
||||||
if(tmp = msg.$$){
|
if(tmp = msg.$$){
|
||||||
link = tmp = (msg.$$._);
|
link = tmp = (msg.$$._);
|
||||||
if(u === tmp.put){
|
if(u !== link.put){
|
||||||
return;
|
data = link.put;
|
||||||
}
|
}
|
||||||
data = tmp.put;
|
|
||||||
}
|
}
|
||||||
if((tmp = eve.wait) && (tmp = tmp[at.id])){ clearTimeout(tmp) }
|
if((tmp = eve.wait) && (tmp = tmp[at.id])){ clearTimeout(tmp) }
|
||||||
if((!to && (u === data || at.soul || at.link || (link && !(0 < link.ack))))
|
if((!to && (u === data || at.soul || at.link || (link && !(0 < link.ack))))
|
||||||
|| (u === data && (tmp = (obj_map(at.root.opt.peers, function(v,k,t){t(k)})||[]).length) && (link||at).ack <= tmp)){
|
|| (u === data && (tmp = (obj_map(at.root.opt.peers, function(v,k,t){t(k)})||[]).length) && (!to && (link||at).ack <= tmp))){
|
||||||
tmp = (eve.wait = {})[at.id] = setTimeout(function(){
|
tmp = (eve.wait = {})[at.id] = setTimeout(function(){
|
||||||
val.call({as:opt}, msg, eve, tmp || 1);
|
val.call({as:opt}, msg, eve, tmp || 1);
|
||||||
}, opt.wait || 99);
|
}, opt.wait || 99);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(link && u === link.put && (tmp = rel.is(data))){ data = Gun.node.ify({}, tmp) }
|
||||||
eve.rid(msg);
|
eve.rid(msg);
|
||||||
opt.ok.call(gun || opt.$, data, msg.get);
|
opt.ok.call(gun || opt.$, data, msg.get);
|
||||||
}
|
}
|
||||||
@ -1774,10 +1774,12 @@
|
|||||||
;USE(function(module){
|
;USE(function(module){
|
||||||
if(typeof Gun === 'undefined'){ return } // TODO: localStorage is Browser only. But it would be nice if it could somehow plugin into NodeJS compatible localStorage APIs?
|
if(typeof Gun === 'undefined'){ return } // TODO: localStorage is Browser only. But it would be nice if it could somehow plugin into NodeJS compatible localStorage APIs?
|
||||||
|
|
||||||
var root, noop = function(){}, u;
|
var root, noop = function(){}, store, u;
|
||||||
if(typeof window !== 'undefined'){ root = window }
|
try{store = (Gun.window||noop).localStorage}catch(e){}
|
||||||
var store = root.localStorage || {setItem: noop, removeItem: noop, getItem: noop};
|
if(!store){
|
||||||
|
console.log("Warning: No localStorage exists to persist data to!");
|
||||||
|
store = {setItem: noop, removeItem: noop, getItem: noop};
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
NOTE: Both `lib/file.js` and `lib/memdisk.js` are based on this design!
|
NOTE: Both `lib/file.js` and `lib/memdisk.js` are based on this design!
|
||||||
If you update anything here, consider updating the other adapters as well.
|
If you update anything here, consider updating the other adapters as well.
|
||||||
|
2
gun.min.js
vendored
2
gun.min.js
vendored
File diff suppressed because one or more lines are too long
21
lib/super.js
Normal file
21
lib/super.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
;(function(){
|
||||||
|
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
|
||||||
|
var Rad = (Gun.window||{}).Radix || require('./radix');
|
||||||
|
function input(msg){
|
||||||
|
var at = this.as, to = this.to, peer = (msg.mesh||empty).via;
|
||||||
|
var get = msg.get, soul, key;
|
||||||
|
if(!peer || !get){ return to.next(msg) }
|
||||||
|
console.log("super", msg);
|
||||||
|
if(soul = get['#']){
|
||||||
|
if(key = get['.']){
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
to.next(msg);
|
||||||
|
}
|
||||||
|
var empty = {}, u;
|
||||||
|
if(Gun.window){ return }
|
||||||
|
try{module.exports = input}catch(e){}
|
||||||
|
}());
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gun",
|
"name": "gun",
|
||||||
"version": "0.9.99995",
|
"version": "0.9.99996",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gun",
|
"name": "gun",
|
||||||
"version": "0.9.99996",
|
"version": "0.9.99997",
|
||||||
"description": "A realtime, decentralized, offline-first, graph data synchronization engine.",
|
"description": "A realtime, decentralized, offline-first, graph data synchronization engine.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"browser": "gun.min.js",
|
"browser": "gun.min.js",
|
||||||
|
80
sea.js
80
sea.js
@ -124,7 +124,7 @@
|
|||||||
}
|
}
|
||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
const byteLength = input.byteLength
|
const byteLength = input.byteLength // what is going on here? FOR MARTTI
|
||||||
const length = input.byteLength ? input.byteLength : input.length
|
const length = input.byteLength ? input.byteLength : input.length
|
||||||
if (length) {
|
if (length) {
|
||||||
let buf
|
let buf
|
||||||
@ -157,45 +157,40 @@
|
|||||||
})(USE, './buffer');
|
})(USE, './buffer');
|
||||||
|
|
||||||
;USE(function(module){
|
;USE(function(module){
|
||||||
|
const SEA = USE('./root')
|
||||||
const Buffer = USE('./buffer')
|
const Buffer = USE('./buffer')
|
||||||
const api = {Buffer: Buffer}
|
const api = {Buffer: Buffer}
|
||||||
|
var o = {};
|
||||||
|
|
||||||
if (typeof window !== 'undefined') {
|
if(SEA.window){
|
||||||
var crypto = window.crypto || window.msCrypto;
|
api.crypto = window.crypto || window.msCrypto;
|
||||||
var subtle = crypto.subtle || crypto.webkitSubtle;
|
api.subtle = (api.crypto||o).subtle || (api.crypto||o).webkitSubtle;
|
||||||
const TextEncoder = window.TextEncoder
|
api.TextEncoder = window.TextEncoder;
|
||||||
const TextDecoder = window.TextDecoder
|
api.TextDecoder = window.TextDecoder;
|
||||||
|
api.random = (len) => Buffer.from(api.crypto.getRandomValues(new Uint8Array(Buffer.alloc(len))))
|
||||||
|
}
|
||||||
|
if(!api.crypto){try{
|
||||||
|
var crypto = USE('crypto', 1);
|
||||||
|
const { subtle } = USE('@trust/webcrypto', 1) // All but ECDH
|
||||||
|
const { TextEncoder, TextDecoder } = USE('text-encoding', 1)
|
||||||
Object.assign(api, {
|
Object.assign(api, {
|
||||||
crypto,
|
crypto,
|
||||||
subtle,
|
subtle,
|
||||||
TextEncoder,
|
TextEncoder,
|
||||||
TextDecoder,
|
TextDecoder,
|
||||||
random: (len) => Buffer.from(crypto.getRandomValues(new Uint8Array(Buffer.alloc(len))))
|
random: (len) => Buffer.from(crypto.randomBytes(len))
|
||||||
})
|
});
|
||||||
} else {
|
//try{
|
||||||
try{
|
const WebCrypto = USE('node-webcrypto-ossl', 1)
|
||||||
var crypto = USE('crypto', 1);
|
api.ossl = new WebCrypto({directory: 'ossl'}).subtle // ECDH
|
||||||
const { subtle } = USE('@trust/webcrypto', 1) // All but ECDH
|
//}catch(e){
|
||||||
const { TextEncoder, TextDecoder } = USE('text-encoding', 1)
|
//console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
|
||||||
Object.assign(api, {
|
//}
|
||||||
crypto,
|
}catch(e){
|
||||||
subtle,
|
console.log("@trust/webcrypto and text-encoding are not included by default, you must add it to your package.json!");
|
||||||
TextEncoder,
|
console.log("node-webcrypto-ossl is temporarily needed for ECDSA signature verification, and optionally needed for ECDH, please install if needed (currently necessary so add them to your package.json for now).");
|
||||||
TextDecoder,
|
TRUST_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED;
|
||||||
random: (len) => Buffer.from(crypto.randomBytes(len))
|
}}
|
||||||
});
|
|
||||||
//try{
|
|
||||||
const WebCrypto = USE('node-webcrypto-ossl', 1)
|
|
||||||
api.ossl = new WebCrypto({directory: 'ossl'}).subtle // ECDH
|
|
||||||
//}catch(e){
|
|
||||||
//console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
|
|
||||||
//}
|
|
||||||
}catch(e){
|
|
||||||
console.log("@trust/webcrypto and text-encoding are not included by default, you must add it to your package.json!");
|
|
||||||
console.log("node-webcrypto-ossl is temporarily needed for ECDSA signature verification, and optionally needed for ECDH, please install if needed (currently necessary so add them to your package.json for now).");
|
|
||||||
TRUST_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = api
|
module.exports = api
|
||||||
})(USE, './shim');
|
})(USE, './shim');
|
||||||
@ -436,6 +431,7 @@
|
|||||||
if(cb){ try{ cb(raw) }catch(e){console.log(e)} }
|
if(cb){ try{ cb(raw) }catch(e){console.log(e)} }
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
if(json === data){ throw "No signature on data." }
|
||||||
const pub = pair.pub || pair
|
const pub = pair.pub || pair
|
||||||
const jwk = S.jwk(pub)
|
const jwk = S.jwk(pub)
|
||||||
const key = await (shim.ossl || shim.subtle).importKey('jwk', jwk, S.ecdsa.pair, false, ['verify'])
|
const key = await (shim.ossl || shim.subtle).importKey('jwk', jwk, S.ecdsa.pair, false, ['verify'])
|
||||||
@ -448,7 +444,7 @@
|
|||||||
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
||||||
return r;
|
return r;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log(e);
|
console.log(e); // mismatched owner FOR MARTTI
|
||||||
SEA.err = e;
|
SEA.err = e;
|
||||||
if(cb){ cb() }
|
if(cb){ cb() }
|
||||||
return;
|
return;
|
||||||
@ -747,10 +743,10 @@
|
|||||||
// TODO: 'salt' needed?
|
// TODO: 'salt' needed?
|
||||||
err = null
|
err = null
|
||||||
if(SEA.window){
|
if(SEA.window){
|
||||||
var tmp = SEA.window.sessionStorage;
|
var tmp; try{tmp = window.sessionStorage}catch(e){}
|
||||||
if(tmp && gunRoot._.opt.remember){ // TODO: Bug! This needs to be moved to finalize?
|
if(tmp && gunRoot._.opt.remember){ // TODO: Bug! This needs to be moved to finalize?
|
||||||
SEA.window.sessionStorage.alias = alias;
|
tmp.alias = alias;
|
||||||
SEA.window.sessionStorage.tmp = pass;
|
tmp.tmp = pass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {priv: priv, pub: a.put.pub, salt: salt, epub: epub, epriv: epriv };
|
return {priv: priv, pub: a.put.pub, salt: salt, epub: epub, epriv: epriv };
|
||||||
@ -1302,8 +1298,8 @@
|
|||||||
delete user._.is;
|
delete user._.is;
|
||||||
delete user._.sea;
|
delete user._.sea;
|
||||||
}
|
}
|
||||||
if(typeof window !== 'undefined'){
|
if(SEA.window){
|
||||||
var tmp = window.sessionStorage;
|
var tmp; try{tmp = window.sessionStorage}catch(e){}; tmp = tmp || {};
|
||||||
delete tmp.alias;
|
delete tmp.alias;
|
||||||
delete tmp.tmp;
|
delete tmp.tmp;
|
||||||
}
|
}
|
||||||
@ -1339,10 +1335,10 @@
|
|||||||
let validity
|
let validity
|
||||||
let opts
|
let opts
|
||||||
|
|
||||||
var o = setvalidity;
|
var o = setvalidity, tmp;
|
||||||
if(o && o.sessionStorage){
|
if(o && o.sessionStorage){
|
||||||
if(typeof window !== 'undefined'){
|
if(SEA.window){
|
||||||
var tmp = window.sessionStorage;
|
try{tmp = window.sessionStorage}catch(e){}
|
||||||
if(tmp){
|
if(tmp){
|
||||||
gunRoot._.opt.remember = true;
|
gunRoot._.opt.remember = true;
|
||||||
if(tmp.alias && tmp.tmp){
|
if(tmp.alias && tmp.tmp){
|
||||||
@ -1658,7 +1654,7 @@
|
|||||||
each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb?
|
each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb?
|
||||||
if(each.err){ return }
|
if(each.err){ return }
|
||||||
if((each.err = ctx.err) || ctx.no){
|
if((each.err = ctx.err) || ctx.no){
|
||||||
console.log('NO!', each.err, msg.put);
|
console.log('NO!', each.err, msg.put); // 451 mistmached data FOR MARTTI
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!each.end.ed){ return }
|
if(!each.end.ed){ return }
|
||||||
|
@ -64,7 +64,7 @@ function soul(gun, cb, opt, as){
|
|||||||
var cat = gun._, tmp;
|
var cat = gun._, tmp;
|
||||||
if(tmp = cat.soul){ return cb(tmp, as, cat), gun }
|
if(tmp = cat.soul){ return cb(tmp, as, cat), gun }
|
||||||
if(tmp = cat.link){ return cb(tmp, as, cat), gun }
|
if(tmp = cat.link){ return cb(tmp, as, cat), gun }
|
||||||
gun.get(function(msg, ev){
|
gun.get(function(msg, ev){ // TODO: Bug! Needs once semantics?
|
||||||
ev.rid(msg);
|
ev.rid(msg);
|
||||||
var at = ((at = msg.$) && at._) || {};
|
var at = ((at = msg.$) && at._) || {};
|
||||||
tmp = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put);
|
tmp = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put);
|
||||||
|
@ -229,7 +229,7 @@ Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++
|
|||||||
Gun.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'!");
|
Gun.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'!");
|
||||||
;"Please do not remove these messages unless you are paying for a monthly sponsorship, thanks!";
|
;"Please do not remove these messages unless you are paying for a monthly sponsorship, thanks!";
|
||||||
|
|
||||||
if(typeof window !== "undefined"){ (window.Gun = Gun).window = window }
|
if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window }
|
||||||
try{ if(typeof common !== "undefined"){ common.exports = Gun } }catch(e){}
|
try{ if(typeof common !== "undefined"){ common.exports = Gun } }catch(e){}
|
||||||
module.exports = Gun;
|
module.exports = Gun;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user