@libp2p/ping 1.1.6-737b3ea5b → 1.1.6-a142bb642

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 A=Object.defineProperty;var q=Object.getOwnPropertyDescriptor;var H=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var Y=(n,t)=>{for(var e in t)A(n,e,{get:t[e],enumerable:!0})},J=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of H(t))!K.call(n,o)&&o!==e&&A(n,o,{get:()=>t[o],enumerable:!(r=q(t,o))||r.enumerable});return n};var Q=n=>J(A({},"__esModule",{value:!0}),n);var lt={};Y(lt,{PING_PROTOCOL:()=>G,ping:()=>at});var l=class extends Error{code;props;constructor(t,e,r){super(t),this.code=e,this.name=r?.name??"CodeError",this.props=r??{}}};var T="ERR_TIMEOUT";var M="ERR_INVALID_MESSAGE";function C(n,t){if(n===t)return!0;if(n.byteLength!==t.byteLength)return!1;for(let e=0;e<n.byteLength;e++)if(n[e]!==t[e])return!1;return!0}var h=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var gt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var bt={}.toString;function v(n=32){if(h&&typeof h.getRandomValues=="function")return h.getRandomValues(new Uint8Array(n));if(h&&typeof h.randomBytes=="function")return h.randomBytes(n);throw new Error("crypto.getRandomValues must be defined")}function b(n){if(isNaN(n)||n<=0)throw new l("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return v(n)}function Z(n){return n[Symbol.asyncIterator]!=null}function tt(n){if(Z(n))return(async()=>{for await(let t of n)return t})();for(let t of n)return t}var U=tt;function x(){let n={};return n.promise=new Promise((t,e)=>{n.resolve=t,n.reject=e}),n}var E=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}},y=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new E(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 e=this.head;this.head=e.next=new E(2*this.head.buffer.length),this.head.push(t)}}shift(){let t=this.tail.shift();if(t===void 0&&this.tail.next!=null){let e=this.tail.next;this.tail.next=null,this.tail=e,t=this.tail.shift()}return t?.value!=null&&(this.size-=this.calculateSize(t.value)),t}isEmpty(){return this.head.isEmpty()}};var I=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function w(n={}){return et(e=>{let r=e.shift();if(r==null)return{done:!0};if(r.error!=null)throw r.error;return{done:r.done===!0,value:r.value}},n)}function et(n,t){t=t??{};let e=t.onEnd,r=new y,o,i,u,c=x(),a=async()=>{try{return r.isEmpty()?u?{done:!0}:await new Promise((s,p)=>{i=g=>{i=null,r.push(g);try{s(n(r))}catch(m){p(m)}return o}}):n(r)}finally{r.isEmpty()&&queueMicrotask(()=>{c.resolve(),c=x()})}},f=s=>i!=null?i(s):(r.push(s),o),O=s=>(r=new y,i!=null?i({error:s}):(r.push({error:s}),o)),P=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 f({done:!1,value:s})},R=s=>u?o:(u=!0,s!=null?O(s):f({done:!0})),F=()=>(r=new y,R(),{done:!0}),W=s=>(R(s),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:a,return:F,throw:W,push:P,end:R,get readableLength(){return r.size},onEmpty:async s=>{let p=s?.signal;if(p?.throwIfAborted(),r.isEmpty())return;let g,m;p!=null&&(g=new Promise((ft,$)=>{m=()=>{$(new I)},p.addEventListener("abort",m)}));try{await Promise.race([c.promise,g])}finally{m!=null&&p!=null&&p?.removeEventListener("abort",m)}}},e==null)return o;let d=o;return o={[Symbol.asyncIterator](){return this},next(){return d.next()},throw(s){return d.throw(s),e!=null&&(e(s),e=void 0),{done:!0}},return(){return d.return(),e!=null&&(e(),e=void 0),{done:!0}},push:P,end(s){return d.end(s),e!=null&&(e(s),e=void 0),o},get readableLength(){return d.readableLength},onEmpty:s=>d.onEmpty(s)},o}function nt(n){return n[Symbol.asyncIterator]!=null}function rt(...n){let t=[];for(let e of n)nt(e)||t.push(e);return t.length===n.length?function*(){for(let e of t)yield*e}():async function*(){let e=w({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(n.map(async r=>{for await(let o of r)e.push(o)})),e.end()}catch(r){e.end(r)}}),yield*e}()}var D=rt;function L(n,...t){if(n==null)throw new Error("Empty pipeline");if(S(n)){let r=n;n=()=>r.source}else if(B(n)||k(n)){let r=n;n=()=>r}let e=[n,...t];if(e.length>1&&S(e[e.length-1])&&(e[e.length-1]=e[e.length-1].sink),e.length>2)for(let r=1;r<e.length-1;r++)S(e[r])&&(e[r]=st(e[r]));return ot(...e)}var ot=(...n)=>{let t;for(;n.length>0;)t=n.shift()(t);return t},k=n=>n?.[Symbol.asyncIterator]!=null,B=n=>n?.[Symbol.iterator]!=null,S=n=>n==null?!1:n.sink!=null&&n.source!=null,st=n=>t=>{let e=n.sink(t);if(e?.then!=null){let r=w({objectMode:!0});e.then(()=>{r.end()},u=>{r.end(u)});let o,i=n.source;if(k(i))o=async function*(){yield*i,r.end()};else if(B(i))o=function*(){yield*i,r.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return D(r,o())}return n.source};var G="/ipfs/ping/1.0.0";var V="1.0.0",z="ping",X="ipfs";var N="ERR_WRONG_PING_ACK";var _=class{protocol;components;started;timeout;maxInboundStreams;maxOutboundStreams;runOnTransientConnection;log;constructor(t,e={}){this.components=t,this.log=t.logger.forComponent("libp2p:ping"),this.started=!1,this.protocol=`/${e.protocolPrefix??X}/${z}/${V}`,this.timeout=e.timeout??1e4,this.maxInboundStreams=e.maxInboundStreams??2,this.maxOutboundStreams=e.maxOutboundStreams??1,this.runOnTransientConnection=e.runOnTransientConnection??!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,runOnTransientConnection:this.runOnTransientConnection}),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:e}=t,r=Date.now();AbortSignal.timeout(this.timeout).addEventListener("abort",()=>{e?.abort(new l("ping timeout",T))}),L(e,async function*(i){let u=0;for await(let c of i){if(u+=c.byteLength,u>32){e?.abort(new l("Too much data received",M));return}yield c}},e).catch(i=>{this.log.error("incoming ping from %p failed with error",t.connection.remotePeer,i),e?.abort(i)}).finally(()=>{let i=Date.now()-r;this.log("incoming ping from %p complete in %dms",t.connection.remotePeer,i)})}async ping(t,e={}){this.log("pinging %p",t);let r=Date.now(),o=b(32),i=await this.components.connectionManager.openConnection(t,e),u,c=()=>{};if(e.signal==null){let a=AbortSignal.timeout(this.timeout);e={...e,signal:a}}try{u=await i.newStream(this.protocol,{...e,runOnTransientConnection:this.runOnTransientConnection}),c=()=>{u?.abort(new l("ping timeout",T))},e.signal?.addEventListener("abort",c,{once:!0});let a=await L([o],u,async O=>U(O)),f=Date.now()-r;if(a==null)throw new l(`Did not receive a ping ack after ${f}ms`,N);if(!C(o,a.subarray()))throw new l(`Received wrong ping ack after ${f}ms`,N);return this.log("ping %p complete in %dms",i.remotePeer,f),f}catch(a){throw this.log.error("error while pinging %p",i.remotePeer,a),u?.abort(a),a}finally{e.signal?.removeEventListener("abort",c),u!=null&&await u.close()}}};function at(n={}){return t=>new _(t,n)}return Q(lt);})();
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:
@@ -6,5 +6,4 @@ export declare const PROTOCOL_PREFIX = "ipfs";
6
6
  export declare const TIMEOUT = 10000;
7
7
  export declare const MAX_INBOUND_STREAMS = 2;
8
8
  export declare const MAX_OUTBOUND_STREAMS = 1;
9
- export declare const ERR_WRONG_PING_ACK = "ERR_WRONG_PING_ACK";
10
9
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,qBAAqB,CAAA;AAC/C,eAAO,MAAM,WAAW,KAAK,CAAA;AAC7B,eAAO,MAAM,gBAAgB,UAAU,CAAA;AACvC,eAAO,MAAM,aAAa,SAAS,CAAA;AACnC,eAAO,MAAM,eAAe,SAAS,CAAA;AACrC,eAAO,MAAM,OAAO,QAAQ,CAAA;AAQ5B,eAAO,MAAM,mBAAmB,IAAI,CAAA;AACpC,eAAO,MAAM,oBAAoB,IAAI,CAAA;AAErC,eAAO,MAAM,kBAAkB,uBAAuB,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,qBAAqB,CAAA;AAC/C,eAAO,MAAM,WAAW,KAAK,CAAA;AAC7B,eAAO,MAAM,gBAAgB,UAAU,CAAA;AACvC,eAAO,MAAM,aAAa,SAAS,CAAA;AACnC,eAAO,MAAM,eAAe,SAAS,CAAA;AACrC,eAAO,MAAM,OAAO,QAAQ,CAAA;AAQ5B,eAAO,MAAM,mBAAmB,IAAI,CAAA;AACpC,eAAO,MAAM,oBAAoB,IAAI,CAAA"}
@@ -12,5 +12,4 @@ export const TIMEOUT = 10000;
12
12
  // opening stream A even though the dialing peer is opening stream B and closing stream A).
13
13
  export const MAX_INBOUND_STREAMS = 2;
14
14
  export const MAX_OUTBOUND_STREAMS = 1;
15
- export const ERR_WRONG_PING_ACK = 'ERR_WRONG_PING_ACK';
16
15
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAA;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAA;AAC7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AACvC,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAA;AACnC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAA;AACrC,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAA;AAE5B,+FAA+F;AAC/F,+FAA+F;AAC/F,+FAA+F;AAC/F,yFAAyF;AACzF,yFAAyF;AACzF,2FAA2F;AAC3F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AAErC,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,kBAAkB,CAAA;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,EAAE,CAAA;AAC7B,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AACvC,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAA;AACnC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAA;AACrC,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAA;AAE5B,+FAA+F;AAC/F,+FAA+F;AAC/F,+FAA+F;AAC/F,yFAAyF;AACzF,yFAAyF;AACzF,2FAA2F;AAC3F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA"}
@@ -31,7 +31,7 @@ export interface PingServiceInit {
31
31
  protocolPrefix?: string;
32
32
  maxInboundStreams?: number;
33
33
  maxOutboundStreams?: number;
34
- runOnTransientConnection?: boolean;
34
+ runOnLimitedConnection?: boolean;
35
35
  /**
36
36
  * How long we should wait for a ping response
37
37
  */
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CACtF;AAED,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAElC;;OAEG;I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AK,WAAW,CAEpG;AAED,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA"}
@@ -9,7 +9,7 @@ export declare class PingService implements Startable, PingServiceInterface {
9
9
  private readonly timeout;
10
10
  private readonly maxInboundStreams;
11
11
  private readonly maxOutboundStreams;
12
- private readonly runOnTransientConnection;
12
+ private readonly runOnLimitedConnection;
13
13
  private readonly log;
14
14
  constructor(components: PingServiceComponents, init?: PingServiceInit);
15
15
  readonly [Symbol.toStringTag] = "@libp2p/ping";
@@ -1 +1 @@
1
- {"version":3,"file":"ping.d.ts","sourceRoot":"","sources":["../../src/ping.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,WAAW,IAAI,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAC7G,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AACxF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,qBAAa,WAAY,YAAW,SAAS,EAAE,oBAAoB;IACjE,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;IAC1C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAS;IAClD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,qBAAqB,EAAE,IAAI,GAAE,eAAoB;IAa1E,QAAQ,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,kBAAiB;IAExC,KAAK,IAAK,OAAO,CAAC,IAAI,CA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K5B,SAAS,IAAK,OAAO;IAIrB;;OAEG;IACH,aAAa,CAAE,IAAI,EAAE,kBAAkB,GAAG,IAAI;IAwC9C;;OAEG;IACG,IAAI,CAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;CA+DjG"}
package/dist/src/ping.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { randomBytes } from '@libp2p/crypto';
2
- import { CodeError, ERR_INVALID_MESSAGE, ERR_TIMEOUT } from '@libp2p/interface';
2
+ import { AbortError, InvalidMessageError, ProtocolError, TimeoutError } from '@libp2p/interface';
3
3
  import first from 'it-first';
4
4
  import { pipe } from 'it-pipe';
5
5
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals';
6
- import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, ERR_WRONG_PING_ACK } from './constants.js';
6
+ import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS } from './constants.js';
7
7
  export class PingService {
8
8
  protocol;
9
9
  components;
@@ -11,7 +11,7 @@ export class PingService {
11
11
  timeout;
12
12
  maxInboundStreams;
13
13
  maxOutboundStreams;
14
- runOnTransientConnection;
14
+ runOnLimitedConnection;
15
15
  log;
16
16
  constructor(components, init = {}) {
17
17
  this.components = components;
@@ -21,7 +21,7 @@ export class PingService {
21
21
  this.timeout = init.timeout ?? TIMEOUT;
22
22
  this.maxInboundStreams = init.maxInboundStreams ?? MAX_INBOUND_STREAMS;
23
23
  this.maxOutboundStreams = init.maxOutboundStreams ?? MAX_OUTBOUND_STREAMS;
24
- this.runOnTransientConnection = init.runOnTransientConnection ?? true;
24
+ this.runOnLimitedConnection = init.runOnLimitedConnection ?? true;
25
25
  this.handleMessage = this.handleMessage.bind(this);
26
26
  }
27
27
  [Symbol.toStringTag] = '@libp2p/ping';
@@ -29,7 +29,7 @@ export class PingService {
29
29
  await this.components.registrar.handle(this.protocol, this.handleMessage, {
30
30
  maxInboundStreams: this.maxInboundStreams,
31
31
  maxOutboundStreams: this.maxOutboundStreams,
32
- runOnTransientConnection: this.runOnTransientConnection
32
+ runOnLimitedConnection: this.runOnLimitedConnection
33
33
  });
34
34
  this.started = true;
35
35
  }
@@ -49,14 +49,14 @@ export class PingService {
49
49
  const start = Date.now();
50
50
  const signal = AbortSignal.timeout(this.timeout);
51
51
  signal.addEventListener('abort', () => {
52
- stream?.abort(new CodeError('ping timeout', ERR_TIMEOUT));
52
+ stream?.abort(new TimeoutError('ping timeout'));
53
53
  });
54
54
  void pipe(stream, async function* (source) {
55
55
  let received = 0;
56
56
  for await (const buf of source) {
57
57
  received += buf.byteLength;
58
58
  if (received > PING_LENGTH) {
59
- stream?.abort(new CodeError('Too much data received', ERR_INVALID_MESSAGE));
59
+ stream?.abort(new InvalidMessageError('Too much data received'));
60
60
  return;
61
61
  }
62
62
  yield buf;
@@ -91,20 +91,20 @@ export class PingService {
91
91
  try {
92
92
  stream = await connection.newStream(this.protocol, {
93
93
  ...options,
94
- runOnTransientConnection: this.runOnTransientConnection
94
+ runOnLimitedConnection: this.runOnLimitedConnection
95
95
  });
96
96
  onAbort = () => {
97
- stream?.abort(new CodeError('ping timeout', ERR_TIMEOUT));
97
+ stream?.abort(new AbortError());
98
98
  };
99
99
  // make stream abortable
100
100
  options.signal?.addEventListener('abort', onAbort, { once: true });
101
101
  const result = await pipe([data], stream, async (source) => first(source));
102
102
  const ms = Date.now() - start;
103
103
  if (result == null) {
104
- throw new CodeError(`Did not receive a ping ack after ${ms}ms`, ERR_WRONG_PING_ACK);
104
+ throw new ProtocolError(`Did not receive a ping ack after ${ms}ms`);
105
105
  }
106
106
  if (!uint8ArrayEquals(data, result.subarray())) {
107
- throw new CodeError(`Received wrong ping ack after ${ms}ms`, ERR_WRONG_PING_ACK);
107
+ throw new ProtocolError(`Received wrong ping ack after ${ms}ms`);
108
108
  }
109
109
  this.log('ping %p complete in %dms', connection.remotePeer, ms);
110
110
  return ms;
@@ -1 +1 @@
1
- {"version":3,"file":"ping.js","sourceRoot":"","sources":["../../src/ping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/E,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAMtK,MAAM,OAAO,WAAW;IACN,QAAQ,CAAQ;IACf,UAAU,CAAuB;IAC1C,OAAO,CAAS;IACP,OAAO,CAAQ;IACf,iBAAiB,CAAQ;IACzB,kBAAkB,CAAQ;IAC1B,wBAAwB,CAAS;IACjC,GAAG,CAAQ;IAE5B,YAAa,UAAiC,EAAE,OAAwB,EAAE;QACxE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAA;QACxD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,IAAI,CAAC,cAAc,IAAI,eAAe,IAAI,aAAa,IAAI,gBAAgB,EAAE,CAAA;QACjG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,OAAO,CAAA;QACtC,IAAI,CAAC,iBAAiB,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1.6-a142bb642",
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-737b3ea5b",
54
- "@libp2p/interface": "1.7.0-737b3ea5b",
55
- "@libp2p/interface-internal": "1.3.4-737b3ea5b",
53
+ "@libp2p/crypto": "4.1.9-a142bb642",
54
+ "@libp2p/interface": "1.7.0-a142bb642",
55
+ "@libp2p/interface-internal": "1.3.4-a142bb642",
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-737b3ea5b",
63
- "@libp2p/peer-id-factory": "4.2.4-737b3ea5b",
62
+ "@libp2p/logger": "4.0.20-a142bb642",
63
+ "@libp2p/peer-id": "4.2.4-a142bb642",
64
64
  "aegir": "^44.0.1",
65
65
  "it-byte-stream": "^1.0.10",
66
66
  "it-pair": "^2.0.6",
package/src/constants.ts CHANGED
@@ -13,5 +13,3 @@ export const TIMEOUT = 10000
13
13
  // opening stream A even though the dialing peer is opening stream B and closing stream A).
14
14
  export const MAX_INBOUND_STREAMS = 2
15
15
  export const MAX_OUTBOUND_STREAMS = 1
16
-
17
- export const ERR_WRONG_PING_ACK = 'ERR_WRONG_PING_ACK'
package/src/index.ts CHANGED
@@ -35,7 +35,7 @@ export interface PingServiceInit {
35
35
  protocolPrefix?: string
36
36
  maxInboundStreams?: number
37
37
  maxOutboundStreams?: number
38
- runOnTransientConnection?: boolean
38
+ runOnLimitedConnection?: boolean
39
39
 
40
40
  /**
41
41
  * How long we should wait for a ping response
package/src/ping.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { randomBytes } from '@libp2p/crypto'
2
- import { CodeError, ERR_INVALID_MESSAGE, ERR_TIMEOUT } from '@libp2p/interface'
2
+ import { AbortError, InvalidMessageError, ProtocolError, TimeoutError } from '@libp2p/interface'
3
3
  import first from 'it-first'
4
4
  import { pipe } from 'it-pipe'
5
5
  import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
6
- import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS, ERR_WRONG_PING_ACK } from './constants.js'
6
+ import { PROTOCOL_PREFIX, PROTOCOL_NAME, PING_LENGTH, PROTOCOL_VERSION, TIMEOUT, MAX_INBOUND_STREAMS, MAX_OUTBOUND_STREAMS } from './constants.js'
7
7
  import type { PingServiceComponents, PingServiceInit, PingService as PingServiceInterface } from './index.js'
8
8
  import type { AbortOptions, Logger, Stream, PeerId, Startable } from '@libp2p/interface'
9
9
  import type { IncomingStreamData } from '@libp2p/interface-internal'
@@ -16,7 +16,7 @@ export class PingService implements Startable, PingServiceInterface {
16
16
  private readonly timeout: number
17
17
  private readonly maxInboundStreams: number
18
18
  private readonly maxOutboundStreams: number
19
- private readonly runOnTransientConnection: boolean
19
+ private readonly runOnLimitedConnection: boolean
20
20
  private readonly log: Logger
21
21
 
22
22
  constructor (components: PingServiceComponents, init: PingServiceInit = {}) {
@@ -27,7 +27,7 @@ export class PingService implements Startable, PingServiceInterface {
27
27
  this.timeout = init.timeout ?? TIMEOUT
28
28
  this.maxInboundStreams = init.maxInboundStreams ?? MAX_INBOUND_STREAMS
29
29
  this.maxOutboundStreams = init.maxOutboundStreams ?? MAX_OUTBOUND_STREAMS
30
- this.runOnTransientConnection = init.runOnTransientConnection ?? true
30
+ this.runOnLimitedConnection = init.runOnLimitedConnection ?? true
31
31
 
32
32
  this.handleMessage = this.handleMessage.bind(this)
33
33
  }
@@ -38,7 +38,7 @@ export class PingService implements Startable, PingServiceInterface {
38
38
  await this.components.registrar.handle(this.protocol, this.handleMessage, {
39
39
  maxInboundStreams: this.maxInboundStreams,
40
40
  maxOutboundStreams: this.maxOutboundStreams,
41
- runOnTransientConnection: this.runOnTransientConnection
41
+ runOnLimitedConnection: this.runOnLimitedConnection
42
42
  })
43
43
  this.started = true
44
44
  }
@@ -63,7 +63,7 @@ export class PingService implements Startable, PingServiceInterface {
63
63
 
64
64
  const signal = AbortSignal.timeout(this.timeout)
65
65
  signal.addEventListener('abort', () => {
66
- stream?.abort(new CodeError('ping timeout', ERR_TIMEOUT))
66
+ stream?.abort(new TimeoutError('ping timeout'))
67
67
  })
68
68
 
69
69
  void pipe(
@@ -75,7 +75,7 @@ export class PingService implements Startable, PingServiceInterface {
75
75
  received += buf.byteLength
76
76
 
77
77
  if (received > PING_LENGTH) {
78
- stream?.abort(new CodeError('Too much data received', ERR_INVALID_MESSAGE))
78
+ stream?.abort(new InvalidMessageError('Too much data received'))
79
79
  return
80
80
  }
81
81
 
@@ -119,11 +119,11 @@ export class PingService implements Startable, PingServiceInterface {
119
119
  try {
120
120
  stream = await connection.newStream(this.protocol, {
121
121
  ...options,
122
- runOnTransientConnection: this.runOnTransientConnection
122
+ runOnLimitedConnection: this.runOnLimitedConnection
123
123
  })
124
124
 
125
125
  onAbort = () => {
126
- stream?.abort(new CodeError('ping timeout', ERR_TIMEOUT))
126
+ stream?.abort(new AbortError())
127
127
  }
128
128
 
129
129
  // make stream abortable
@@ -138,11 +138,11 @@ export class PingService implements Startable, PingServiceInterface {
138
138
  const ms = Date.now() - start
139
139
 
140
140
  if (result == null) {
141
- throw new CodeError(`Did not receive a ping ack after ${ms}ms`, ERR_WRONG_PING_ACK)
141
+ throw new ProtocolError(`Did not receive a ping ack after ${ms}ms`)
142
142
  }
143
143
 
144
144
  if (!uint8ArrayEquals(data, result.subarray())) {
145
- throw new CodeError(`Received wrong ping ack after ${ms}ms`, ERR_WRONG_PING_ACK)
145
+ throw new ProtocolError(`Received wrong ping ack after ${ms}ms`)
146
146
  }
147
147
 
148
148
  this.log('ping %p complete in %dms', connection.remotePeer, ms)