From fd1bd507b93e95de7f92b723bd5ea8ab7971bf6f Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Wed, 4 Aug 2021 00:47:22 -0700 Subject: [PATCH] of course it'll dedup cause it just called track on hear, fix --- examples/basic/upload.html | 13 ++++---- gun.js | 12 ++++---- lib/dom.js | 61 ++++++++++++++++++++------------------ lib/upload.js | 2 +- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/examples/basic/upload.html b/examples/basic/upload.html index 77b50274..86e12cb5 100644 --- a/examples/basic/upload.html +++ b/examples/basic/upload.html @@ -9,26 +9,27 @@

Drag & drop videos, songs, or images!

- + \ No newline at end of file diff --git a/gun.js b/gun.js index 54f3db66..8a20ebd8 100644 --- a/gun.js +++ b/gun.js @@ -1393,9 +1393,6 @@ !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? - DBG && (DBG.yh = +new Date); - if(!(raw = meta.raw)){ mesh.raw(msg, peer); return } - DBG && (DBG.yr = +new Date); 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){ // still no peer, then ack daisy chain lost. if(dup.s[ack]){ return } // in dups but no peer hints that this was ack to self, ignore. @@ -1403,6 +1400,9 @@ 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) } + DBG && (DBG.yh = +new Date); + if(!(raw = meta.raw)){ mesh.raw(msg, peer); return } + DBG && (DBG.yr = +new Date); if(!peer || !peer.id){ if(!Object.plain(peer || opt.peers)){ return false } var S = +new Date; @@ -1421,7 +1421,7 @@ console.STAT && console.STAT(S, +new Date - S, 'say loop'); if(!pl.length){ return } puff(go, 0); - dup_track(ack); // keep for later + ack && dup_track(ack); // keep for later }()); return; } @@ -1431,7 +1431,7 @@ if(peer === meta.via){ return false } // don't send back to self. if((tmp = meta.yo) && (tmp[peer.url] || tmp[peer.pid] || tmp[peer.id]) /*&& !o*/){ return false } console.STAT && console.STAT(S, ((DBG||meta).yp = +new Date) - (meta.y || S), 'say prep'); - ack && dup_track(ack); // streaming long responses needs to keep alive the ack. + !loop && ack && dup_track(ack); // streaming long responses needs to keep alive the ack. if(peer.batch){ peer.tail = (tmp = peer.tail || 0) + raw.length; if(peer.tail <= opt.pack){ @@ -1458,7 +1458,7 @@ if('string' == typeof msg){ return msg } var hash = msg['##'], ack = msg['@']; if(hash && ack){ - if(dup_check(ack+hash)){ return false } // memory & storage may ack the same thing, this dedups that. //dup_track(ack+hash);//.it = it(msg); + 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(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. diff --git a/lib/dom.js b/lib/dom.js index f0ed045f..fc0d8da2 100644 --- a/lib/dom.js +++ b/lib/dom.js @@ -1,13 +1,12 @@ ;(function(){ // jQuery shim - // u = undefined, n = null, b = boolean = true/false, n = number, t = text, l = list = array, o = object, cb = callback = function, q = CSS query, k = key, eve = event. + // u = undefined, n = null, b = boolean = true/false, n = number, t = text, l = list = array, o = object, cb = callback = function, q = query CSS, k = key, eve = event. if(window.$){ return } - (($ = window.$ = function(q, tag){ + (($ = window.$ = function(q, tag, I, u){ if(q instanceof $){ return q } - if(!(this instanceof $)){ return new $(q, tag) } - this.tags = ((q && q.tags) - || (('string' != typeof q)? (q?[q]:[]) - : (tag||document).querySelectorAll(q))); - return this; + if(!((I = this) instanceof $)){ return new $(q, tag) } + if('string' != typeof q){ return I.tags = (q = q||[]).tags || (u === q.length)? [q] : q, I } + if('<' === q[0]){ return I.add(q) } + return q.split(",").forEach(function(q){ I.add((tag||document).querySelectorAll(q)) }), I; }).fn = $.prototype).each = function(cb){ return $.each(this.tags, cb), this } $.each = function(o, cb){ Object.keys(o).forEach(function(k){ cb(k, o[k]) }) } $.isPlainObject = function(o){ @@ -15,6 +14,11 @@ || 'Object' === Object.prototype.toString.call(o).match(/^\[object (\w+)\]$/)[1] : false); } + $.fn.add = function(add, tmp, u){ if(!add){ return this } + if('<' === (tmp = add)[0]){ (add = document.createElement('div')).innerHTML = tmp } + add = ('string' == typeof add)? $(add).tags : (u == add.length)? add : [].slice.call(add); + return this.tags = [].slice.call(this.tags||[]).concat(add), this; + } $.fn.get = function(i, l, u){ return l = this.tags, (i === u)? l : l[i] } $.fn.is = function(q, b){ return this.each(function(i, tag){ b = b || tag.matches(q) }), b } $.fn.css = function(o){ return this.each(function(i, tag){ $.each(o, function(k,v){ tag.style[k] = v }) })} @@ -24,40 +28,33 @@ $.fn.val = function(t, k, f, u){ t = (t === u)? '' : (f = 1) && t; k = k || 'value'; - this.each(function(i, tag){ + return this.each(function(i, tag){ if(f){ tag[k] = t } else { t += (tag[k]||'') } - }); - return f? this : t; + }), f? this : t; } $.fn.text = function(t){ return this.val(t, 'textContent') } $.fn.html = function(html){ return this.val(html, 'innerHTML') } - $.fn.find = function(q){ - var I = $(), l = I.tags; - this.each(function(i, tag){ + $.fn.find = function(q, I, l){ + I = $(), l = I.tags; + return this.each(function(i, tag){ $(q, tag).each(function(i, tag){ if(0 > l.indexOf(tag)){ l.push(tag) } }); - }); - return I; + }), I; } - $.fn.add = function(add, tmp){ - if(!add){ return this } - if('<' === (tmp = add)[0]){ (add = document.createElement('div')).innerHTML = tmp } - return this.tags = [].slice.call(this.tags).concat([].slice.call($(add).tags)), this; - } - $.fn.place = function(where, on, f, op){ return this.each(function(i, tag){ $(on).each(function(i, node){ + $.fn.place = function(where, on, f, op, I){ return (I = this).each(function(i, tag){ $(on).each(function(i, node){ (f? tag : node)[op||'insertAdjacentElement'](({ '-1':'beforebegin', '-0.1': 'afterbegin', '0.1':'beforeend', '1': 'afterend' })[where], (f? node : tag)); })})} - $.fn.append = function(html){ return $().add(html).place(0.1, this), this } - $.fn.appendTo = function(html){ return this.place(0.1, $().add(html)) } - function rev(o){ var I = $(); I.tags = [].slice.call(o.tags).reverse(); return I } - $.fn.prependTo = function(html){ return rev(this).place(-0.1, $().add(html)), this } - $.fn.prepend = function(html){ return rev($().add(html)).place(-0.1, this), this } - $.fn.parents = function(q, c){ - var I = $(), l = I.tags, p = 'parentElement'; + $.fn.append = function(html){ return $(html).place(0.1, this), this } + $.fn.appendTo = function(html){ return this.place(0.1, $(html)) } + function rev(o, I){ (I = $()).tags = [].slice.call(o.tags).reverse(); return I }; + $.fn.prependTo = function(html){ return rev(this).place(-0.1, $(html)), this } + $.fn.prepend = function(html){ return rev($(html)).place(-0.1, this), this } + $.fn.parents = function(q, c, I, l, p){ + I = $(), l = I.tags, p = 'parentElement'; this.each(function(i, tag){ if(c){ (c = {})[p] = tag ; tag = c } while(tag){ if((tag = tag[p]) && $(tag).is(q)){ @@ -67,5 +64,11 @@ return I; } $.fn.closest = function(q, c){ return this.parents(q, 1) } - $.fn.clone = function(b){ I = $(), l = I.tags, this.each(function(i, tag){ l.push(tag.cloneNode(true)) }), I } + $.fn.clone = function(b, I, l){ + I = $(), l = I.tags; + this.each(function(i, tag){ + l.push(tag.cloneNode(true)) + }); + return I; + } }()); \ No newline at end of file diff --git a/lib/upload.js b/lib/upload.js index f388d6cb..4fddb83b 100644 --- a/lib/upload.js +++ b/lib/upload.js @@ -4,7 +4,7 @@ opt = $.isPlainObject(opt)? opt : {input: opt}; el.on('drop', function(e){ e.preventDefault(); - upload.drop(((e.originalEvent||{}).dataTransfer||{}).files||[], 0); + upload.drop(((e.originalEvent||e).dataTransfer||{}).files||[], 0); }).on('dragover', function(e){ e.preventDefault(); });