@libp2p/ping 1.1.5-50b897139 → 1.1.5-e211b46cc
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 +1 -1
- package/dist/src/ping.d.ts.map +1 -1
- package/dist/src/ping.js +2 -17
- package/dist/src/ping.js.map +1 -1
- package/package.json +6 -6
- package/src/ping.ts +2 -25
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
|
|
2
|
+
"use strict";var Libp2PPing=(()=>{var T=Object.defineProperty;var W=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var H=(n,t)=>{for(var e in t)T(n,e,{get:t[e],enumerable:!0})},K=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $(t))!q.call(n,o)&&o!==e&&T(n,o,{get:()=>t[o],enumerable:!(r=W(t,o))||r.enumerable});return n};var Y=n=>K(T({},"__esModule",{value:!0}),n);var at={};H(at,{PING_PROTOCOL:()=>B,ping:()=>ct});var a=class extends Error{code;props;constructor(t,e,r){super(t),this.code=e,this.name=r?.name??"CodeError",this.props=r??{}}};var P="ERR_TIMEOUT";function M(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 x=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var yt=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;var xt={}.toString;function C(n=32){if(x&&typeof x.getRandomValues=="function")return x.getRandomValues(new Uint8Array(n));throw new Error("crypto.getRandomValues must be defined")}function g(n){if(isNaN(n)||n<=0)throw new a("random bytes length must be a Number bigger than 0","ERR_INVALID_LENGTH");return C(n)}function J(n){return n[Symbol.asyncIterator]!=null}function Q(n){if(J(n))return(async()=>{for await(let t of n)return t})();for(let t of n)return t}var U=Q;function b(){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}},m=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 A=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 Z(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 Z(n,t){t=t??{};let e=t.onEnd,r=new m,o,i,u,l=b(),c=async()=>{try{return r.isEmpty()?u?{done:!0}:await new Promise((s,p)=>{i=y=>{i=null,r.push(y);try{s(n(r))}catch(d){p(d)}return o}}):n(r)}finally{r.isEmpty()&&queueMicrotask(()=>{l.resolve(),l=b()})}},f=s=>i!=null?i(s):(r.push(s),o),_=s=>(r=new m,i!=null?i({error:s}):(r.push({error:s}),o)),N=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?_(s):f({done:!0})),X=()=>(r=new m,R(),{done:!0}),j=s=>(R(s),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:c,return:X,throw:j,push:N,end:R,get readableLength(){return r.size},onEmpty:async s=>{let p=s?.signal;if(p?.throwIfAborted(),r.isEmpty())return;let y,d;p!=null&&(y=new Promise((lt,F)=>{d=()=>{F(new A)},p.addEventListener("abort",d)}));try{await Promise.race([l.promise,y])}finally{d!=null&&p!=null&&p?.removeEventListener("abort",d)}}},e==null)return o;let h=o;return o={[Symbol.asyncIterator](){return this},next(){return h.next()},throw(s){return h.throw(s),e!=null&&(e(s),e=void 0),{done:!0}},return(){return h.return(),e!=null&&(e(),e=void 0),{done:!0}},push:N,end(s){return h.end(s),e!=null&&(e(s),e=void 0),o},get readableLength(){return h.readableLength},onEmpty:s=>h.onEmpty(s)},o}function tt(n){return n[Symbol.asyncIterator]!=null}function et(...n){let t=[];for(let e of n)tt(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 v=et;function S(n,...t){if(n==null)throw new Error("Empty pipeline");if(I(n)){let r=n;n=()=>r.source}else if(k(n)||D(n)){let r=n;n=()=>r}let e=[n,...t];if(e.length>1&&I(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++)I(e[r])&&(e[r]=rt(e[r]));return nt(...e)}var nt=(...n)=>{let t;for(;n.length>0;)t=n.shift()(t);return t},D=n=>n?.[Symbol.asyncIterator]!=null,k=n=>n?.[Symbol.iterator]!=null,I=n=>n==null?!1:n.sink!=null&&n.source!=null,rt=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(D(i))o=async function*(){yield*i,r.end()};else if(k(i))o=function*(){yield*i,r.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return v(r,o())}return n.source};var B="/ipfs/ping/1.0.0";var G="1.0.0",V="ping",z="ipfs";var L="ERR_WRONG_PING_ACK";var O=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??z}/${V}/${G}`,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();S(e,e).catch(o=>{this.log.error("incoming ping from %p failed with error",t.connection.remotePeer,o)}).finally(()=>{let o=Date.now()-r;this.log("incoming ping from %p complete in %dms",t.connection.remotePeer,o)})}async ping(t,e={}){this.log("pinging %p",t);let r=Date.now(),o=g(32),i=await this.components.connectionManager.openConnection(t,e),u,l=()=>{};if(e.signal==null){let c=AbortSignal.timeout(this.timeout);e={...e,signal:c}}try{u=await i.newStream(this.protocol,{...e,runOnTransientConnection:this.runOnTransientConnection}),l=()=>{u?.abort(new a("ping timeout",P))},e.signal?.addEventListener("abort",l,{once:!0});let c=await S([o],u,async _=>U(_)),f=Date.now()-r;if(c==null)throw new a(`Did not receive a ping ack after ${f}ms`,L);if(!M(o,c.subarray()))throw new a(`Received wrong ping ack after ${f}ms`,L);return this.log("ping %p complete in %dms",i.remotePeer,f),f}catch(c){throw this.log.error("error while pinging %p",i.remotePeer,c),u?.abort(c),c}finally{e.signal?.removeEventListener("abort",l),u!=null&&await u.close()}}};function ct(n={}){return t=>new O(t,n)}return Y(at);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/hashes/esm/utils.js:
|
package/dist/src/ping.d.ts.map
CHANGED
|
@@ -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,IAA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AM,GAAG,SAAS,GAAG,SAAS,EAAE,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;CA+DjG"}
|
package/dist/src/ping.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from '@libp2p/crypto';
|
|
2
|
-
import { CodeError,
|
|
2
|
+
import { CodeError, ERR_TIMEOUT } 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';
|
|
@@ -47,24 +47,9 @@ export class PingService {
|
|
|
47
47
|
this.log('incoming ping from %p', data.connection.remotePeer);
|
|
48
48
|
const { stream } = data;
|
|
49
49
|
const start = Date.now();
|
|
50
|
-
|
|
51
|
-
signal.addEventListener('abort', () => {
|
|
52
|
-
stream?.abort(new CodeError('ping timeout', ERR_TIMEOUT));
|
|
53
|
-
});
|
|
54
|
-
void pipe(stream, async function* (source) {
|
|
55
|
-
let received = 0;
|
|
56
|
-
for await (const buf of source) {
|
|
57
|
-
received += buf.byteLength;
|
|
58
|
-
if (received > PING_LENGTH) {
|
|
59
|
-
stream?.abort(new CodeError('Too much data received', ERR_INVALID_MESSAGE));
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
yield buf;
|
|
63
|
-
}
|
|
64
|
-
}, stream)
|
|
50
|
+
void pipe(stream, stream)
|
|
65
51
|
.catch(err => {
|
|
66
52
|
this.log.error('incoming ping from %p failed with error', data.connection.remotePeer, err);
|
|
67
|
-
stream?.abort(err);
|
|
68
53
|
})
|
|
69
54
|
.finally(() => {
|
|
70
55
|
const ms = Date.now() - start;
|
package/dist/src/ping.js.map
CHANGED
|
@@ -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,E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211b46cc",
|
|
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-
|
|
54
|
-
"@libp2p/interface": "1.7.0-
|
|
55
|
-
"@libp2p/interface-internal": "1.3.4-
|
|
53
|
+
"@libp2p/crypto": "4.1.9-e211b46cc",
|
|
54
|
+
"@libp2p/interface": "1.7.0-e211b46cc",
|
|
55
|
+
"@libp2p/interface-internal": "1.3.4-e211b46cc",
|
|
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-
|
|
63
|
-
"@libp2p/peer-id-factory": "4.2.4-
|
|
62
|
+
"@libp2p/logger": "4.0.20-e211b46cc",
|
|
63
|
+
"@libp2p/peer-id-factory": "4.2.4-e211b46cc",
|
|
64
64
|
"aegir": "^44.0.1",
|
|
65
65
|
"it-byte-stream": "^1.0.10",
|
|
66
66
|
"it-pair": "^2.0.6",
|
package/src/ping.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomBytes } from '@libp2p/crypto'
|
|
2
|
-
import { CodeError,
|
|
2
|
+
import { CodeError, ERR_TIMEOUT } 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'
|
|
@@ -61,32 +61,9 @@ export class PingService implements Startable, PingServiceInterface {
|
|
|
61
61
|
const { stream } = data
|
|
62
62
|
const start = Date.now()
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
signal.addEventListener('abort', () => {
|
|
66
|
-
stream?.abort(new CodeError('ping timeout', ERR_TIMEOUT))
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
void pipe(
|
|
70
|
-
stream,
|
|
71
|
-
async function * (source) {
|
|
72
|
-
let received = 0
|
|
73
|
-
|
|
74
|
-
for await (const buf of source) {
|
|
75
|
-
received += buf.byteLength
|
|
76
|
-
|
|
77
|
-
if (received > PING_LENGTH) {
|
|
78
|
-
stream?.abort(new CodeError('Too much data received', ERR_INVALID_MESSAGE))
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
yield buf
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
stream
|
|
86
|
-
)
|
|
64
|
+
void pipe(stream, stream)
|
|
87
65
|
.catch(err => {
|
|
88
66
|
this.log.error('incoming ping from %p failed with error', data.connection.remotePeer, err)
|
|
89
|
-
stream?.abort(err)
|
|
90
67
|
})
|
|
91
68
|
.finally(() => {
|
|
92
69
|
const ms = Date.now() - start
|