@libp2p/ping 1.1.6-df330695a → 1.1.6-e1ca9cced

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPing = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPing=(()=>{var v=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var Q=(e,t)=>{for(var r in t)v(e,r,{get:t[r],enumerable:!0})},Y=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of J(t))!K.call(e,o)&&o!==r&&v(e,o,{get:()=>t[o],enumerable:!(n=H(t,o))||n.enumerable});return e};var Z=e=>Y(v({},"__esModule",{value:!0}),e);var pt={};Q(pt,{PING_PROTOCOL:()=>j,ping:()=>lt});var g=class extends Error{constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var b=class extends Error{constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var w=class extends Error{constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}},x=class extends Error{constructor(t="Protocol error"){super(t),this.name="ProtocolError"}},E=class extends Error{constructor(t="Timed out"){super(t),this.name="TimeoutError"}};function U(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var f=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var gt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var bt={}.toString;function R(e=32){if(f&&typeof f.getRandomValues=="function")return f.getRandomValues(new Uint8Array(e));if(f&&typeof f.randomBytes=="function")return f.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function O(e){if(isNaN(e)||e<=0)throw new b("random bytes length must be a Number bigger than 0");return R(e)}function tt(e){return e[Symbol.asyncIterator]!=null}function et(e){if(tt(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var C=et;function L(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var I=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},m=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new I(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new I(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var P=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function S(e={}){return rt(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function rt(e,t){t=t??{};let r=t.onEnd,n=new m,o,i,u,a=L(),c=async()=>{try{return n.isEmpty()?u?{done:!0}:await new Promise((s,p)=>{i=y=>{i=null,n.push(y);try{s(e(n))}catch(h){p(h)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=L()})}},l=s=>i!=null?i(s):(n.push(s),o),A=s=>(n=new m,i!=null?i({error:s}):(n.push({error:s}),o)),k=s=>{if(u)return o;if(t?.objectMode!==!0&&s?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:s})},_=s=>u?o:(u=!0,s!=null?A(s):l({done:!0})),$=()=>(n=new m,_(),{done:!0}),q=s=>(_(s),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:$,throw:q,push:k,end:_,get readableLength(){return n.size},onEmpty:async s=>{let p=s?.signal;if(p?.throwIfAborted(),n.isEmpty())return;let y,h;p!=null&&(y=new Promise((ft,W)=>{h=()=>{W(new P)},p.addEventListener("abort",h)}));try{await Promise.race([a.promise,y])}finally{h!=null&&p!=null&&p?.removeEventListener("abort",h)}}},r==null)return o;let d=o;return o={[Symbol.asyncIterator](){return this},next(){return d.next()},throw(s){return d.throw(s),r!=null&&(r(s),r=void 0),{done:!0}},return(){return d.return(),r!=null&&(r(),r=void 0),{done:!0}},push:k,end(s){return d.end(s),r!=null&&(r(s),r=void 0),o},get readableLength(){return d.readableLength},onEmpty:s=>d.onEmpty(s)},o}function nt(e){return e[Symbol.asyncIterator]!=null}function ot(...e){let t=[];for(let r of e)nt(r)||t.push(r);return t.length===e.length?function*(){for(let r of t)yield*r}():async function*(){let r=S({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(e.map(async n=>{for await(let o of n)r.push(o)})),r.end()}catch(n){r.end(n)}}),yield*r}()}var B=ot;function M(e,...t){if(e==null)throw new Error("Empty pipeline");if(N(e)){let n=e;e=()=>n.source}else if(z(e)||D(e)){let n=e;e=()=>n}let r=[e,...t];if(r.length>1&&N(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)N(r[n])&&(r[n]=it(r[n]));return st(...r)}var st=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},D=e=>e?.[Symbol.asyncIterator]!=null,z=e=>e?.[Symbol.iterator]!=null,N=e=>e==null?!1:e.sink!=null&&e.source!=null,it=e=>t=>{let r=e.sink(t);if(r?.then!=null){let n=S({objectMode:!0});r.then(()=>{n.end()},u=>{n.end(u)});let o,i=e.source;if(D(i))o=async function*(){yield*i,n.end()};else if(z(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return B(n,o())}return e.source};var j="/ipfs/ping/1.0.0";var V="1.0.0",X="ping",F="ipfs";var T=class{protocol;components;started;timeout;maxInboundStreams;maxOutboundStreams;runOnLimitedConnection;log;constructor(t,r={}){this.components=t,this.log=t.logger.forComponent("libp2p:ping"),this.started=!1,this.protocol=`/${r.protocolPrefix??F}/${X}/${V}`,this.timeout=r.timeout??1e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??1,this.runOnLimitedConnection=r.runOnLimitedConnection??!0,this.handleMessage=this.handleMessage.bind(this)}[Symbol.toStringTag]="@libp2p/ping";async start(){await this.components.registrar.handle(this.protocol,this.handleMessage,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}handleMessage(t){this.log("incoming ping from %p",t.connection.remotePeer);let{stream:r}=t,n=Date.now();AbortSignal.timeout(this.timeout).addEventListener("abort",()=>{r?.abort(new E("ping timeout"))}),M(r,async function*(i){let u=0;for await(let a of i){if(u+=a.byteLength,u>32){r?.abort(new w("Too much data received"));return}yield a}},r).catch(i=>{this.log.error("incoming ping from %p failed with error",t.connection.remotePeer,i),r?.abort(i)}).finally(()=>{let i=Date.now()-n;this.log("incoming ping from %p complete in %dms",t.connection.remotePeer,i)})}async ping(t,r={}){this.log("pinging %p",t);let n=Date.now(),o=O(32),i=await this.components.connectionManager.openConnection(t,r),u,a=()=>{};if(r.signal==null){let c=AbortSignal.timeout(this.timeout);r={...r,signal:c}}try{u=await i.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),a=()=>{u?.abort(new g)},r.signal?.addEventListener("abort",a,{once:!0});let c=await M([o],u,async A=>C(A)),l=Date.now()-n;if(c==null)throw new x(`Did not receive a ping ack after ${l}ms`);if(!U(o,c.subarray()))throw new x(`Received wrong ping ack after ${l}ms`);return this.log("ping %p complete in %dms",i.remotePeer,l),l}catch(c){throw this.log.error("error while pinging %p",i.remotePeer,c),u?.abort(c),c}finally{r.signal?.removeEventListener("abort",a),u!=null&&await u.close()}}};function lt(e={}){return t=>new T(t,e)}return Z(pt);})();
2
+ "use strict";var Libp2PPing=(()=>{var A=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var Q=(e,t)=>{for(var r in t)A(e,r,{get:t[r],enumerable:!0})},Y=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of H(t))!J.call(e,o)&&o!==r&&A(e,o,{get:()=>t[o],enumerable:!(n=W(t,o))||n.enumerable});return e};var Z=e=>Y(A({},"__esModule",{value:!0}),e);var pt={};Q(pt,{PING_PROTOCOL:()=>j,ping:()=>lt});var b=class extends Error{static name="AbortError";constructor(t="The operation was aborted"){super(t),this.name="AbortError"}};var g=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}};var E=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}},x=class extends Error{static name="ProtocolError";constructor(t="Protocol error"){super(t),this.name="ProtocolError"}},w=class extends Error{static name="TimeoutError";constructor(t="Timed out"){super(t),this.name="TimeoutError"}};function U(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}var d=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var bt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var gt={}.toString;function k(e=32){if(d&&typeof d.getRandomValues=="function")return d.getRandomValues(new Uint8Array(e));if(d&&typeof d.randomBytes=="function")return d.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function O(e){if(isNaN(e)||e<=0)throw new g("random bytes length must be a Number bigger than 0");return k(e)}function tt(e){return e[Symbol.asyncIterator]!=null}function et(e){if(tt(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var R=et;function I(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var L=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||t-1&t)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(t),this.mask=t-1,this.top=0,this.btm=0,this.next=null}push(t){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=t,this.top=this.top+1&this.mask,!0)}shift(){let t=this.buffer[this.btm];if(t!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,t}isEmpty(){return this.buffer[this.btm]===void 0}},h=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new L(this.hwm),this.tail=this.head,this.size=0}calculateSize(t){return t?.byteLength!=null?t.byteLength:1}push(t){if(t?.value!=null&&(this.size+=this.calculateSize(t.value)),!this.head.push(t)){let r=this.head;this.head=r.next=new L(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var _=class extends Error{type;code;constructor(t,r){super(t??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function S(e={}){return rt(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},e)}function rt(e,t){t=t??{};let r=t.onEnd,n=new h,o,i,a,u=I(),c=async()=>{try{return n.isEmpty()?a?{done:!0}:await new Promise((s,p)=>{i=y=>{i=null,n.push(y);try{s(e(n))}catch(f){p(f)}return o}}):e(n)}finally{n.isEmpty()&&queueMicrotask(()=>{u.resolve(),u=I()})}},l=s=>i!=null?i(s):(n.push(s),o),T=s=>(n=new h,i!=null?i({error:s}):(n.push({error:s}),o)),N=s=>{if(a)return o;if(t?.objectMode!==!0&&s?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:s})},P=s=>a?o:(a=!0,s!=null?T(s):l({done:!0})),$=()=>(n=new h,P(),{done:!0}),q=s=>(P(s),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:$,throw:q,push:N,end:P,get readableLength(){return n.size},onEmpty:async s=>{let p=s?.signal;if(p?.throwIfAborted(),n.isEmpty())return;let y,f;p!=null&&(y=new Promise((dt,K)=>{f=()=>{K(new _)},p.addEventListener("abort",f)}));try{await Promise.race([u.promise,y])}finally{f!=null&&p!=null&&p?.removeEventListener("abort",f)}}},r==null)return o;let m=o;return o={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(s){return m.throw(s),r!=null&&(r(s),r=void 0),{done:!0}},return(){return m.return(),r!=null&&(r(),r=void 0),{done:!0}},push:N,end(s){return m.end(s),r!=null&&(r(s),r=void 0),o},get readableLength(){return m.readableLength},onEmpty:s=>m.onEmpty(s)},o}function nt(e){return e[Symbol.asyncIterator]!=null}function ot(...e){let t=[];for(let r of e)nt(r)||t.push(r);return t.length===e.length?function*(){for(let r of t)yield*r}():async function*(){let r=S({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(e.map(async n=>{for await(let o of n)r.push(o)})),r.end()}catch(n){r.end(n)}}),yield*r}()}var B=ot;function C(e,...t){if(e==null)throw new Error("Empty pipeline");if(M(e)){let n=e;e=()=>n.source}else if(z(e)||D(e)){let n=e;e=()=>n}let r=[e,...t];if(r.length>1&&M(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)M(r[n])&&(r[n]=it(r[n]));return st(...r)}var st=(...e)=>{let t;for(;e.length>0;)t=e.shift()(t);return t},D=e=>e?.[Symbol.asyncIterator]!=null,z=e=>e?.[Symbol.iterator]!=null,M=e=>e==null?!1:e.sink!=null&&e.source!=null,it=e=>t=>{let r=e.sink(t);if(r?.then!=null){let n=S({objectMode:!0});r.then(()=>{n.end()},a=>{n.end(a)});let o,i=e.source;if(D(i))o=async function*(){yield*i,n.end()};else if(z(i))o=function*(){yield*i,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return B(n,o())}return e.source};var j="/ipfs/ping/1.0.0";var F="1.0.0",V="ping",X="ipfs";var v=class{protocol;components;started;timeout;maxInboundStreams;maxOutboundStreams;runOnLimitedConnection;log;constructor(t,r={}){this.components=t,this.log=t.logger.forComponent("libp2p:ping"),this.started=!1,this.protocol=`/${r.protocolPrefix??X}/${V}/${F}`,this.timeout=r.timeout??1e4,this.maxInboundStreams=r.maxInboundStreams??2,this.maxOutboundStreams=r.maxOutboundStreams??1,this.runOnLimitedConnection=r.runOnLimitedConnection??!0,this.handleMessage=this.handleMessage.bind(this)}[Symbol.toStringTag]="@libp2p/ping";async start(){await this.components.registrar.handle(this.protocol,this.handleMessage,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams,runOnLimitedConnection:this.runOnLimitedConnection}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}handleMessage(t){this.log("incoming ping from %p",t.connection.remotePeer);let{stream:r}=t,n=Date.now();AbortSignal.timeout(this.timeout).addEventListener("abort",()=>{r?.abort(new w("ping timeout"))}),C(r,async function*(i){let a=0;for await(let u of i){if(a+=u.byteLength,a>32){r?.abort(new E("Too much data received"));return}yield u}},r).catch(i=>{this.log.error("incoming ping from %p failed with error",t.connection.remotePeer,i),r?.abort(i)}).finally(()=>{let i=Date.now()-n;this.log("incoming ping from %p complete in %dms",t.connection.remotePeer,i)})}async ping(t,r={}){this.log("pinging %p",t);let n=Date.now(),o=O(32),i=await this.components.connectionManager.openConnection(t,r),a,u=()=>{};if(r.signal==null){let c=AbortSignal.timeout(this.timeout);r={...r,signal:c}}try{a=await i.newStream(this.protocol,{...r,runOnLimitedConnection:this.runOnLimitedConnection}),u=()=>{a?.abort(new b)},r.signal?.addEventListener("abort",u,{once:!0});let c=await C([o],a,async T=>R(T)),l=Date.now()-n;if(c==null)throw new x(`Did not receive a ping ack after ${l}ms`);if(!U(o,c.subarray()))throw new x(`Received wrong ping ack after ${l}ms`);return this.log("ping %p complete in %dms",i.remotePeer,l),l}catch(c){throw this.log.error("error while pinging %p",i.remotePeer,c),a?.abort(c),c}finally{r.signal?.removeEventListener("abort",u),a!=null&&await a.close()}}};function lt(e={}){return t=>new v(t,e)}return Z(pt);})();
3
3
  /*! Bundled license information:
4
4
 
5
5
  @noble/hashes/esm/utils.js:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/ping",
3
- "version": "1.1.6-df330695a",
3
+ "version": "1.1.6-e1ca9cced",
4
4
  "description": "Implementation of Ping Protocol",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/protocol-ping#readme",
@@ -50,17 +50,17 @@
50
50
  "doc-check": "aegir doc-check"
51
51
  },
52
52
  "dependencies": {
53
- "@libp2p/crypto": "4.1.9-df330695a",
54
- "@libp2p/interface": "1.7.0-df330695a",
55
- "@libp2p/interface-internal": "1.3.4-df330695a",
53
+ "@libp2p/crypto": "4.1.9-e1ca9cced",
54
+ "@libp2p/interface": "1.7.0-e1ca9cced",
55
+ "@libp2p/interface-internal": "1.3.4-e1ca9cced",
56
56
  "@multiformats/multiaddr": "^12.2.3",
57
57
  "it-first": "^3.0.6",
58
58
  "it-pipe": "^3.0.1",
59
59
  "uint8arrays": "^5.1.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@libp2p/logger": "4.0.20-df330695a",
63
- "@libp2p/peer-id": "4.2.4-df330695a",
62
+ "@libp2p/logger": "4.0.20-e1ca9cced",
63
+ "@libp2p/peer-id": "4.2.4-e1ca9cced",
64
64
  "aegir": "^44.0.1",
65
65
  "it-byte-stream": "^1.0.10",
66
66
  "it-pair": "^2.0.6",