@libp2p/perf 1.1.15 → 2.0.0-fb8a6f188

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/README.md CHANGED
@@ -7,43 +7,54 @@
7
7
 
8
8
  # About
9
9
 
10
- The `performanceService` implements the [perf protocol](https://github.com/libp2p/specs/blob/master/perf/perf.md), which is used to measure performance within and across libp2p implementations
11
- addresses.
10
+ The PerfService implements the [perf protocol](https://github.com/libp2p/specs/blob/master/perf/perf.md), which can be used to measure transfer performance within and across libp2p implementations.
12
11
 
13
12
  ## Example
14
13
 
15
14
  ```typescript
16
- import { createLibp2p } from 'libp2p'
17
- import { perfService } from '@libp2p/perf'
18
-
19
- const node = await createLibp2p({
20
- service: [
21
- perfService()
22
- ]
23
- })
24
- ```
25
-
26
- The `measurePerformance` function can be used to measure the latency and throughput of a connection.
27
- server. This will not work in browsers.
28
-
29
- ## Example
30
-
31
- ```typescript
32
- import { createLibp2p } from 'libp2p'
33
- import { perfService } from 'libp2p/perf'
34
-
35
- const node = await createLibp2p({
36
- services: [
37
- perf: perfService()
38
- ]
39
- })
40
-
41
- const connection = await node.dial(multiaddr(multiaddrAddress))
42
-
43
- const startTime = Date.now()
44
-
45
- await node.services.perf.measurePerformance(startTime, connection, BigInt(uploadBytes), BigInt(downloadBytes))
46
-
15
+ import { noise } from '@chainsafe/libp2p-noise'
16
+ import { yamux } from '@chainsafe/libp2p-yamux'
17
+ import { mplex } from '@libp2p/mplex'
18
+ import { tcp } from '@libp2p/tcp'
19
+ import { createLibp2p, type Libp2p } from 'libp2p'
20
+ import { plaintext } from 'libp2p/insecure'
21
+ import { perfService, type PerfService } from '@libp2p/perf'
22
+
23
+ const ONE_MEG = 1024 * 1024
24
+ const UPLOAD_BYTES = ONE_MEG * 1024
25
+ const DOWNLOAD_BYTES = ONE_MEG * 1024
26
+
27
+ async function createNode (): Promise<Libp2p<{ perf: PerfService }>> {
28
+ return createLibp2p({
29
+ addresses: {
30
+ listen: [
31
+ '/ip4/0.0.0.0/tcp/0'
32
+ ]
33
+ },
34
+ transports: [
35
+ tcp()
36
+ ],
37
+ connectionEncryption: [
38
+ noise(), plaintext()
39
+ ],
40
+ streamMuxers: [
41
+ yamux(), mplex()
42
+ ],
43
+ services: {
44
+ perf: perfService()
45
+ }
46
+ })
47
+ }
48
+
49
+ const libp2p1 = await createNode()
50
+ const libp2p2 = await createNode()
51
+
52
+ for await (const output of libp2p1.services.perf.measurePerformance(libp2p2.getMultiaddrs()[0], UPLOAD_BYTES, DOWNLOAD_BYTES)) {
53
+ console.info(output)
54
+ }
55
+
56
+ await libp2p1.stop()
57
+ await libp2p2.stop()
47
58
  ```
48
59
 
49
60
  # API Docs
package/dist/index.min.js CHANGED
@@ -1,3 +1,3 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPerf = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPerf=(()=>{var ae=Object.create;var N=Object.defineProperty;var ie=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var fe=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var L=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ue=(e,t)=>{for(var r in t)N(e,r,{get:t[r],enumerable:!0})},V=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of ce(t))!le.call(e,s)&&s!==r&&N(e,s,{get:()=>t[s],enumerable:!(o=ie(t,s))||o.enumerable});return e};var de=(e,t,r)=>(r=e!=null?ae(fe(e)):{},V(t||!e||!e.__esModule?N(r,"default",{value:e,enumerable:!0}):r,e)),pe=e=>V(N({},"__esModule",{value:!0}),e);var Z=L((Re,q)=>{var B=1e3,O=B*60,I=O*60,S=I*24,he=S*7,be=S*365.25;q.exports=function(e,t){t=t||{};var r=typeof e;if(r==="string"&&e.length>0)return Ce(e);if(r==="number"&&isFinite(e))return t.long?ge(e):me(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function Ce(e){if(e=String(e),!(e.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var r=parseFloat(t[1]),o=(t[2]||"ms").toLowerCase();switch(o){case"years":case"year":case"yrs":case"yr":case"y":return r*be;case"weeks":case"week":case"w":return r*he;case"days":case"day":case"d":return r*S;case"hours":case"hour":case"hrs":case"hr":case"h":return r*I;case"minutes":case"minute":case"mins":case"min":case"m":return r*O;case"seconds":case"second":case"secs":case"sec":case"s":return r*B;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function me(e){var t=Math.abs(e);return t>=S?Math.round(e/S)+"d":t>=I?Math.round(e/I)+"h":t>=O?Math.round(e/O)+"m":t>=B?Math.round(e/B)+"s":e+"ms"}function ge(e){var t=Math.abs(e);return t>=S?P(e,t,S,"day"):t>=I?P(e,t,I,"hour"):t>=O?P(e,t,O,"minute"):t>=B?P(e,t,B,"second"):e+" ms"}function P(e,t,r,o){var s=t>=r*1.5;return Math.round(e/r)+" "+o+(s?"s":"")}});var G=L((Le,K)=>{function we(e){r.debug=r,r.default=r,r.coerce=b,r.disable=d,r.enable=s,r.enabled=f,r.humanize=Z(),r.destroy=k,Object.keys(e).forEach(n=>{r[n]=e[n]}),r.names=[],r.skips=[],r.formatters={};function t(n){let a=0;for(let u=0;u<n.length;u++)a=(a<<5)-a+n.charCodeAt(u),a|=0;return r.colors[Math.abs(a)%r.colors.length]}r.selectColor=t;function r(n){let a,u=null,U,i;function c(...p){if(!c.enabled)return;let h=c,m=Number(new Date),F=m-(a||m);h.diff=F,h.prev=a,h.curr=m,a=m,p[0]=r.coerce(p[0]),typeof p[0]!="string"&&p.unshift("%O");let C=0;p[0]=p[0].replace(/%([a-zA-Z%])/g,(v,w)=>{if(v==="%%")return"%";C++;let A=r.formatters[w];if(typeof A=="function"){let z=p[C];v=A.call(h,z),p.splice(C,1),C--}return v}),r.formatArgs.call(h,p),(h.log||r.log).apply(h,p)}return c.namespace=n,c.useColors=r.useColors(),c.color=r.selectColor(n),c.extend=o,c.destroy=r.destroy,Object.defineProperty(c,"enabled",{enumerable:!0,configurable:!1,get:()=>u!==null?u:(U!==r.namespaces&&(U=r.namespaces,i=r.enabled(n)),i),set:p=>{u=p}}),typeof r.init=="function"&&r.init(c),c}function o(n,a){let u=r(this.namespace+(typeof a>"u"?":":a)+n);return u.log=this.log,u}function s(n){r.save(n),r.namespaces=n,r.names=[],r.skips=[];let a,u=(typeof n=="string"?n:"").split(/[\s,]+/),U=u.length;for(a=0;a<U;a++)u[a]&&(n=u[a].replace(/\*/g,".*?"),n[0]==="-"?r.skips.push(new RegExp("^"+n.slice(1)+"$")):r.names.push(new RegExp("^"+n+"$")))}function d(){let n=[...r.names.map(l),...r.skips.map(l).map(a=>"-"+a)].join(",");return r.enable(""),n}function f(n){if(n[n.length-1]==="*")return!0;let a,u;for(a=0,u=r.skips.length;a<u;a++)if(r.skips[a].test(n))return!1;for(a=0,u=r.names.length;a<u;a++)if(r.names[a].test(n))return!0;return!1}function l(n){return n.toString().substring(2,n.toString().length-2).replace(/\.\*\?$/,"*")}function b(n){return n instanceof Error?n.stack||n.message:n}function k(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}K.exports=we});var W=L((y,R)=>{y.formatArgs=xe;y.save=Fe;y.load=ve;y.useColors=ye;y.storage=Ae();y.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();y.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function ye(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function xe(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+R.exports.humanize(this.diff),!this.useColors)return;let t="color: "+this.color;e.splice(1,0,t,"color: inherit");let r=0,o=0;e[0].replace(/%[a-zA-Z%]/g,s=>{s!=="%%"&&(r++,s==="%c"&&(o=r))}),e.splice(o,0,t)}y.log=console.debug||console.log||(()=>{});function Fe(e){try{e?y.storage.setItem("debug",e):y.storage.removeItem("debug")}catch{}}function ve(){let e;try{e=y.storage.getItem("debug")}catch{}return!e&&typeof process<"u"&&"env"in process&&(e=process.env.DEBUG),e}function Ae(){try{return localStorage}catch{}}R.exports=G()(y);var{formatters:Ee}=R.exports;Ee.j=function(e){try{return JSON.stringify(e)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}}});var Ne={};ue(Ne,{defaultInit:()=>Ie,perfService:()=>Me});var x=de(W(),1);function Se(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),o=0;o<r.length;o++)r[o]=255;for(var s=0;s<e.length;s++){var d=e.charAt(s),f=d.charCodeAt(0);if(r[f]!==255)throw new TypeError(d+" is ambiguous");r[f]=s}var l=e.length,b=e.charAt(0),k=Math.log(l)/Math.log(256),n=Math.log(256)/Math.log(l);function a(i){if(i instanceof Uint8Array||(ArrayBuffer.isView(i)?i=new Uint8Array(i.buffer,i.byteOffset,i.byteLength):Array.isArray(i)&&(i=Uint8Array.from(i))),!(i instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(i.length===0)return"";for(var c=0,p=0,h=0,m=i.length;h!==m&&i[h]===0;)h++,c++;for(var F=(m-h)*n+1>>>0,C=new Uint8Array(F);h!==m;){for(var E=i[h],v=0,w=F-1;(E!==0||v<p)&&w!==-1;w--,v++)E+=256*C[w]>>>0,C[w]=E%l>>>0,E=E/l>>>0;if(E!==0)throw new Error("Non-zero carry");p=v,h++}for(var A=F-p;A!==F&&C[A]===0;)A++;for(var z=b.repeat(c);A<F;++A)z+=e.charAt(C[A]);return z}function u(i){if(typeof i!="string")throw new TypeError("Expected String");if(i.length===0)return new Uint8Array;var c=0;if(i[c]!==" "){for(var p=0,h=0;i[c]===b;)p++,c++;for(var m=(i.length-c)*k+1>>>0,F=new Uint8Array(m);i[c];){var C=r[i.charCodeAt(c)];if(C===255)return;for(var E=0,v=m-1;(C!==0||E<h)&&v!==-1;v--,E++)C+=l*F[v]>>>0,F[v]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");h=E,c++}if(i[c]!==" "){for(var w=m-h;w!==m&&F[w]===0;)w++;for(var A=new Uint8Array(p+(m-w)),z=p;w!==m;)A[z++]=F[w++];return A}}}function U(i){var c=u(i);if(c)return c;throw new Error(`Non-${t} character`)}return{encode:a,decodeUnsafe:u,decode:U}}var ke=Se,Ue=ke,X=Ue;var $e=new Uint8Array(0);var Q=e=>{if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")};var T=class{constructor(t,r,o){this.name=t,this.prefix=r,this.baseEncode=o}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},$=class{constructor(t,r,o){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=o}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Y(this,t)}},j=class{constructor(t){this.decoders=t}or(t){return Y(this,t)}decode(t){let r=t[0],o=this.decoders[r];if(o)return o.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},Y=(e,t)=>new j({...e.decoders||{[e.prefix]:e},...t.decoders||{[t.prefix]:t}}),D=class{constructor(t,r,o,s){this.name=t,this.prefix=r,this.baseEncode=o,this.baseDecode=s,this.encoder=new T(t,r,o),this.decoder=new $(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}},H=({name:e,prefix:t,encode:r,decode:o})=>new D(e,t,r,o),_=({prefix:e,name:t,alphabet:r})=>{let{encode:o,decode:s}=X(r,t);return H({prefix:e,name:t,encode:o,decode:d=>Q(s(d))})},ze=(e,t,r,o)=>{let s={};for(let n=0;n<t.length;++n)s[t[n]]=n;let d=e.length;for(;e[d-1]==="=";)--d;let f=new Uint8Array(d*r/8|0),l=0,b=0,k=0;for(let n=0;n<d;++n){let a=s[e[n]];if(a===void 0)throw new SyntaxError(`Non-${o} character`);b=b<<r|a,l+=r,l>=8&&(l-=8,f[k++]=255&b>>l)}if(l>=r||255&b<<8-l)throw new SyntaxError("Unexpected end of data");return f},Be=(e,t,r)=>{let o=t[t.length-1]==="=",s=(1<<r)-1,d="",f=0,l=0;for(let b=0;b<e.length;++b)for(l=l<<8|e[b],f+=8;f>r;)f-=r,d+=t[s&l>>f];if(f&&(d+=t[s&l<<r-f]),o)for(;d.length*r&7;)d+="=";return d},g=({name:e,prefix:t,bitsPerChar:r,alphabet:o})=>H({prefix:t,name:e,encode(s){return Be(s,o,r)},decode(s){return ze(s,o,r,e)}});var ee=g({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),qe=g({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ze=g({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ke=g({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ge=g({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),We=g({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Xe=g({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Qe=g({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ye=g({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var re=_({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),rr=_({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var te=g({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),or=g({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),sr=g({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ar=g({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});x.default.formatters.b=e=>e==null?"undefined":re.baseEncode(e);x.default.formatters.t=e=>e==null?"undefined":ee.baseEncode(e);x.default.formatters.m=e=>e==null?"undefined":te.baseEncode(e);x.default.formatters.p=e=>e==null?"undefined":e.toString();x.default.formatters.c=e=>e==null?"undefined":e.toString();x.default.formatters.k=e=>e==null?"undefined":e.toString();x.default.formatters.a=e=>e==null?"undefined":e.toString();function Oe(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function ne(e){let t=Oe(`${e}:trace`);return x.default.enabled(`${e}:trace`)&&x.default.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(t=(0,x.default)(`${e}:trace`)),Object.assign((0,x.default)(e),{error:(0,x.default)(`${e}:error`),trace:t})}var oe="/perf/1.0.0",se=BigInt(65536);var M=ne("libp2p:perf"),Ie={protocolName:"/perf/1.0.0",writeBlockSize:BigInt(65536)},J=class{protocol;components;started;databuf;writeBlockSize;constructor(t,r){this.components=t,this.started=!1,this.protocol=r.protocolName??oe,this.writeBlockSize=r.writeBlockSize??se,this.databuf=new ArrayBuffer(Number(r.writeBlockSize))}async start(){await this.components.registrar.handle(this.protocol,t=>{this.handleMessage(t).catch(r=>{M.error("error handling perf protocol message",r)})}),this.started=!0}async stop(){await this.components.registrar.unhandle(this.protocol),this.started=!1}isStarted(){return this.started}async handleMessage(t){let{stream:r}=t,o=this.writeBlockSize,s=null;for await(let f of r.source)s===null&&(s=BigInt(f.getBigUint64(0,!1)));let d=new Uint8Array(this.databuf);if(s===null)throw new Error("bytesToSendBack was not set");await r.sink(async function*(){for(;s>0n;){let f=o;f>s&&(f=s),s=s-f,yield d.subarray(0,Number(f))}}())}async measurePerformance(t,r,o,s,d={}){M("opening stream on protocol %s to %p",this.protocol,r.remotePeer);let f=new Uint8Array(this.databuf),l=this.writeBlockSize,b=await r.newStream([this.protocol],d);new DataView(this.databuf).setBigInt64(0,s,!1),M("sending %i bytes to %p",o,r.remotePeer);try{await b.sink(async function*(){for(yield f.subarray(0,8);o>0n;){let a=l;a>o&&(a=o),o=o-a,yield f.subarray(0,Number(a))}}());let n=BigInt(0);for await(let a of b.source)n+=BigInt(a.length);if(n!==s)throw new Error(`Expected to receive ${s} bytes, but received ${n}`)}catch(n){throw M("error sending %i bytes to %p: %s",o,r.remotePeer,n),n}finally{M("performed %s to %p",this.protocol,r.remotePeer),await b.close()}return Date.now()-t}};function Me(e={}){return t=>new J(t,e)}return pe(Ne);})();
2
+ "use strict";var Libp2PPerf=(()=>{var le=Object.create;var z=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var $=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),be=(t,e)=>{for(var r in e)z(t,r,{get:e[r],enumerable:!0})},K=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of de(e))!pe.call(t,o)&&o!==r&&z(t,o,{get:()=>e[o],enumerable:!(n=fe(e,o))||n.enumerable});return t};var me=(t,e,r)=>(r=t!=null?le(he(t)):{},K(e||!t||!t.__esModule?z(r,"default",{value:t,enumerable:!0}):r,t)),we=t=>K(z({},"__esModule",{value:!0}),t);var W=$((qe,G)=>{var k=1e3,I=k*60,M=I*60,N=M*24,ge=N*7,Ce=N*365.25;G.exports=function(t,e){e=e||{};var r=typeof t;if(r==="string"&&t.length>0)return ye(t);if(r==="number"&&isFinite(t))return e.long?ve(t):xe(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))};function ye(t){if(t=String(t),!(t.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(t);if(e){var r=parseFloat(e[1]),n=(e[2]||"ms").toLowerCase();switch(n){case"years":case"year":case"yrs":case"yr":case"y":return r*Ce;case"weeks":case"week":case"w":return r*ge;case"days":case"day":case"d":return r*N;case"hours":case"hour":case"hrs":case"hr":case"h":return r*M;case"minutes":case"minute":case"mins":case"min":case"m":return r*I;case"seconds":case"second":case"secs":case"sec":case"s":return r*k;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}}}function xe(t){var e=Math.abs(t);return e>=N?Math.round(t/N)+"d":e>=M?Math.round(t/M)+"h":e>=I?Math.round(t/I)+"m":e>=k?Math.round(t/k)+"s":t+"ms"}function ve(t){var e=Math.abs(t);return e>=N?L(t,e,N,"day"):e>=M?L(t,e,M,"hour"):e>=I?L(t,e,I,"minute"):e>=k?L(t,e,k,"second"):t+" ms"}function L(t,e,r,n){var o=e>=r*1.5;return Math.round(t/r)+" "+n+(o?"s":"")}});var Y=$((Je,Q)=>{function Fe(t){r.debug=r,r.default=r,r.coerce=b,r.disable=d,r.enable=o,r.enabled=h,r.humanize=W(),r.destroy=y,Object.keys(t).forEach(s=>{r[s]=t[s]}),r.names=[],r.skips=[],r.formatters={};function e(s){let a=0;for(let f=0;f<s.length;f++)a=(a<<5)-a+s.charCodeAt(f),a|=0;return r.colors[Math.abs(a)%r.colors.length]}r.selectColor=e;function r(s){let a,f=null,O,u;function l(...i){if(!l.enabled)return;let c=l,m=Number(new Date),w=m-(a||m);c.diff=w,c.prev=a,c.curr=m,a=m,i[0]=r.coerce(i[0]),typeof i[0]!="string"&&i.unshift("%O");let g=0;i[0]=i[0].replace(/%([a-zA-Z%])/g,(A,v)=>{if(A==="%%")return"%";g++;let E=r.formatters[v];if(typeof E=="function"){let U=i[g];A=E.call(c,U),i.splice(g,1),g--}return A}),r.formatArgs.call(c,i),(c.log||r.log).apply(c,i)}return l.namespace=s,l.useColors=r.useColors(),l.color=r.selectColor(s),l.extend=n,l.destroy=r.destroy,Object.defineProperty(l,"enabled",{enumerable:!0,configurable:!1,get:()=>f!==null?f:(O!==r.namespaces&&(O=r.namespaces,u=r.enabled(s)),u),set:i=>{f=i}}),typeof r.init=="function"&&r.init(l),l}function n(s,a){let f=r(this.namespace+(typeof a>"u"?":":a)+s);return f.log=this.log,f}function o(s){r.save(s),r.namespaces=s,r.names=[],r.skips=[];let a,f=(typeof s=="string"?s:"").split(/[\s,]+/),O=f.length;for(a=0;a<O;a++)f[a]&&(s=f[a].replace(/\*/g,".*?"),s[0]==="-"?r.skips.push(new RegExp("^"+s.slice(1)+"$")):r.names.push(new RegExp("^"+s+"$")))}function d(){let s=[...r.names.map(p),...r.skips.map(p).map(a=>"-"+a)].join(",");return r.enable(""),s}function h(s){if(s[s.length-1]==="*")return!0;let a,f;for(a=0,f=r.skips.length;a<f;a++)if(r.skips[a].test(s))return!1;for(a=0,f=r.names.length;a<f;a++)if(r.names[a].test(s))return!0;return!1}function p(s){return s.toString().substring(2,s.toString().length-2).replace(/\.\*\?$/,"*")}function b(s){return s instanceof Error?s.stack||s.message:s}function y(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}Q.exports=Fe});var H=$((F,R)=>{F.formatArgs=Ae;F.save=Ee;F.load=Oe;F.useColors=Se;F.storage=Ne();F.destroy=(()=>{let t=!1;return()=>{t||(t=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})();F.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function Se(){return typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs)?!0:typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)?!1:typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function Ae(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+R.exports.humanize(this.diff),!this.useColors)return;let e="color: "+this.color;t.splice(1,0,e,"color: inherit");let r=0,n=0;t[0].replace(/%[a-zA-Z%]/g,o=>{o!=="%%"&&(r++,o==="%c"&&(n=r))}),t.splice(n,0,e)}F.log=console.debug||console.log||(()=>{});function Ee(t){try{t?F.storage.setItem("debug",t):F.storage.removeItem("debug")}catch{}}function Oe(){let t;try{t=F.storage.getItem("debug")}catch{}return!t&&typeof process<"u"&&"env"in process&&(t=process.env.DEBUG),t}function Ne(){try{return localStorage}catch{}}R.exports=Y()(F);var{formatters:Ue}=R.exports;Ue.j=function(t){try{return JSON.stringify(t)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}});var je={};be(je,{perfService:()=>$e});var S=me(H(),1);function ke(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<t.length;o++){var d=t.charAt(o),h=d.charCodeAt(0);if(r[h]!==255)throw new TypeError(d+" is ambiguous");r[h]=o}var p=t.length,b=t.charAt(0),y=Math.log(p)/Math.log(256),s=Math.log(256)/Math.log(p);function a(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";for(var l=0,i=0,c=0,m=u.length;c!==m&&u[c]===0;)c++,l++;for(var w=(m-c)*s+1>>>0,g=new Uint8Array(w);c!==m;){for(var x=u[c],A=0,v=w-1;(x!==0||A<i)&&v!==-1;v--,A++)x+=256*g[v]>>>0,g[v]=x%p>>>0,x=x/p>>>0;if(x!==0)throw new Error("Non-zero carry");i=A,c++}for(var E=w-i;E!==w&&g[E]===0;)E++;for(var U=b.repeat(l);E<w;++E)U+=t.charAt(g[E]);return U}function f(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;var l=0;if(u[l]!==" "){for(var i=0,c=0;u[l]===b;)i++,l++;for(var m=(u.length-l)*y+1>>>0,w=new Uint8Array(m);u[l];){var g=r[u.charCodeAt(l)];if(g===255)return;for(var x=0,A=m-1;(g!==0||x<c)&&A!==-1;A--,x++)g+=p*w[A]>>>0,w[A]=g%256>>>0,g=g/256>>>0;if(g!==0)throw new Error("Non-zero carry");c=x,l++}if(u[l]!==" "){for(var v=m-c;v!==m&&w[v]===0;)v++;for(var E=new Uint8Array(i+(m-v)),U=i;v!==m;)E[U++]=w[v++];return E}}}function O(u){var l=f(u);if(l)return l;throw new Error(`Non-${e} character`)}return{encode:a,decodeUnsafe:f,decode:O}}var Ie=ke,Me=Ie,ee=Me;var Ze=new Uint8Array(0);var te=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")};var j=class{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},V=class{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return re(this,e)}},q=class{constructor(e){this.decoders=e}or(e){return re(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}},re=(t,e)=>new q({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}}),J=class{constructor(e,r,n,o){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new j(e,r,n),this.decoder=new V(e,r,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}},ne=({name:t,prefix:e,encode:r,decode:n})=>new J(t,e,r,n),X=({prefix:t,name:e,alphabet:r})=>{let{encode:n,decode:o}=ee(r,e);return ne({prefix:t,name:e,encode:n,decode:d=>te(o(d))})},Te=(t,e,r,n)=>{let o={};for(let s=0;s<e.length;++s)o[e[s]]=s;let d=t.length;for(;t[d-1]==="=";)--d;let h=new Uint8Array(d*r/8|0),p=0,b=0,y=0;for(let s=0;s<d;++s){let a=o[t[s]];if(a===void 0)throw new SyntaxError(`Non-${n} character`);b=b<<r|a,p+=r,p>=8&&(p-=8,h[y++]=255&b>>p)}if(p>=r||255&b<<8-p)throw new SyntaxError("Unexpected end of data");return h},Be=(t,e,r)=>{let n=e[e.length-1]==="=",o=(1<<r)-1,d="",h=0,p=0;for(let b=0;b<t.length;++b)for(p=p<<8|t[b],h+=8;h>r;)h-=r,d+=e[o&p>>h];if(h&&(d+=e[o&p<<r-h]),n)for(;d.length*r&7;)d+="=";return d},C=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>ne({prefix:e,name:t,encode(o){return Be(o,n,r)},decode(o){return Te(o,n,r,t)}});var oe=C({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),He=C({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),et=C({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),tt=C({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rt=C({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nt=C({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ot=C({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),st=C({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),it=C({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var se=X({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ct=X({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ie=C({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),dt=C({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ht=C({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pt=C({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});S.default.formatters.b=t=>t==null?"undefined":se.baseEncode(t);S.default.formatters.t=t=>t==null?"undefined":oe.baseEncode(t);S.default.formatters.m=t=>t==null?"undefined":ie.baseEncode(t);S.default.formatters.p=t=>t==null?"undefined":t.toString();S.default.formatters.c=t=>t==null?"undefined":t.toString();S.default.formatters.k=t=>t==null?"undefined":t.toString();S.default.formatters.a=t=>t==null?"undefined":t.toString();function ze(t){let e=()=>{};return e.enabled=!1,e.color="",e.diff=0,e.log=()=>{},e.namespace=t,e.destroy=()=>!0,e.extend=()=>e,e}function ae(t){let e=ze(`${t}:trace`);return S.default.enabled(`${t}:trace`)&&S.default.names.map(r=>r.toString()).find(r=>r.includes(":trace"))!=null&&(e=(0,S.default)(`${t}:trace`)),Object.assign((0,S.default)(t),{error:(0,S.default)(`${t}:error`),trace:e})}function _(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var D=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},T=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new D(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new D(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var Z=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function ue(t={}){return Le(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}},t)}function Le(t,e){e=e??{};let r=e.onEnd,n=new T,o,d,h,p=_(),b=async()=>{try{return n.isEmpty()?h?{done:!0}:await new Promise((i,c)=>{d=m=>{d=null,n.push(m);try{i(t(n))}catch(w){c(w)}return o}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{p.resolve(),p=_()})}},y=i=>d!=null?d(i):(n.push(i),o),s=i=>(n=new T,d!=null?d({error:i}):(n.push({error:i}),o)),a=i=>{if(h)return o;if(e?.objectMode!==!0&&i?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return y({done:!1,value:i})},f=i=>h?o:(h=!0,i!=null?s(i):y({done:!0})),O=()=>(n=new T,f(),{done:!0}),u=i=>(f(i),{done:!0});if(o={[Symbol.asyncIterator](){return this},next:b,return:O,throw:u,push:a,end:f,get readableLength(){return n.size},onEmpty:async i=>{let c=i?.signal;if(c?.throwIfAborted(),n.isEmpty())return;let m,w;c!=null&&(m=new Promise((g,x)=>{w=()=>{x(new Z)},c.addEventListener("abort",w)}));try{await Promise.race([p.promise,m])}finally{w!=null&&c!=null&&c?.removeEventListener("abort",w)}}},r==null)return o;let l=o;return o={[Symbol.asyncIterator](){return this},next(){return l.next()},throw(i){return l.throw(i),r!=null&&(r(i),r=void 0),{done:!0}},return(){return l.return(),r!=null&&(r(),r=void 0),{done:!0}},push:a,end(i){return l.end(i),r!=null&&(r(i),r=void 0),o},get readableLength(){return l.readableLength}},o}var ce="/perf/1.0.0";var B=ae("libp2p:perf"),P=class{protocol;components;started;databuf;writeBlockSize;maxInboundStreams;maxOutboundStreams;runOnTransientConnection;constructor(e,r={}){this.components=e,this.started=!1,this.protocol=r.protocolName??ce,this.writeBlockSize=r.writeBlockSize??65536,this.databuf=new ArrayBuffer(this.writeBlockSize),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.runOnTransientConnection=r.runOnTransientConnection??!1}async start(){await this.components.registrar.handle(this.protocol,e=>{this.handleMessage(e).catch(r=>{B.error("error handling perf protocol message",r)})},{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}async handleMessage(e){let{stream:r}=e;try{let n=this.writeBlockSize,o;for await(let h of r.source)o==null&&(o=Number(h.getBigUint64(0,!1)));if(o==null)throw new Error("bytesToSendBack was not set");let d=new Uint8Array(this.databuf);await r.sink(async function*(){for(;o>0;){let h=n;h>o&&(h=o),o=o-h,yield d.subarray(0,h)}}())}catch(n){r.abort(n)}}async*measurePerformance(e,r,n,o={}){B("opening stream on protocol %s to %a",this.protocol,e);let d=new Uint8Array(this.databuf),h=this.writeBlockSize,p=Date.now(),b=await this.components.connectionManager.openConnection(e,{...o,force:o.reuseExistingConnection!==!0}),y=await b.newStream(this.protocol,o),s=0,a=Date.now(),f=0;new DataView(this.databuf).setBigUint64(0,BigInt(n),!1),B("sending %i bytes to %p",r,b.remotePeer);try{let u=ue({objectMode:!0});y.sink(async function*(){for(yield d.subarray(0,8);r>0;){o.signal?.throwIfAborted();let c=h;c>r&&(c=r),r=r-c,yield d.subarray(0,c),Date.now()-a>1e3&&(u.push({type:"intermediary",timeSeconds:(Date.now()-a)/1e3,uploadBytes:s,downloadBytes:0}),a=Date.now(),s=0),s+=c,f+=c}u.end()}()).catch(c=>{u.end(c)}),yield*u;let l=0;a=Date.now();let i=0;for await(let c of y.source)o.signal?.throwIfAborted(),Date.now()-a>1e3&&(yield{type:"intermediary",timeSeconds:(Date.now()-a)/1e3,uploadBytes:0,downloadBytes:l},a=Date.now(),l=0),l+=c.byteLength,i+=c.byteLength;if(i!==n)throw new Error(`Expected to receive ${n} bytes, but received ${i}`);yield{type:"final",timeSeconds:(Date.now()-p)/1e3,uploadBytes:f,downloadBytes:i},B("performed %s to %p",this.protocol,b.remotePeer),await y.close()}catch(u){throw B("error sending %s bytes to %p: %s",f,b.remotePeer,u),y.abort(u),u}}};function $e(t={}){return e=>new P(e,t)}return we(je);})();
3
3
  return Libp2PPerf}));
@@ -1,3 +1,6 @@
1
1
  export declare const PROTOCOL_NAME = "/perf/1.0.0";
2
- export declare const WRITE_BLOCK_SIZE: bigint;
2
+ export declare const WRITE_BLOCK_SIZE: number;
3
+ export declare const MAX_INBOUND_STREAMS = 1;
4
+ export declare const MAX_OUTBOUND_STREAMS = 1;
5
+ export declare const RUN_ON_TRANSIENT_CONNECTION = false;
3
6
  //# 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,gBAAgB,CAAA;AAC1C,eAAO,MAAM,gBAAgB,QAAmB,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,gBAAgB,CAAA;AAC1C,eAAO,MAAM,gBAAgB,QAAW,CAAA;AACxC,eAAO,MAAM,mBAAmB,IAAI,CAAA;AACpC,eAAO,MAAM,oBAAoB,IAAI,CAAA;AACrC,eAAO,MAAM,2BAA2B,QAAQ,CAAA"}
@@ -1,3 +1,6 @@
1
1
  export const PROTOCOL_NAME = '/perf/1.0.0';
2
- export const WRITE_BLOCK_SIZE = BigInt(64 << 10);
2
+ export const WRITE_BLOCK_SIZE = 64 << 10;
3
+ export const MAX_INBOUND_STREAMS = 1;
4
+ export const MAX_OUTBOUND_STREAMS = 1;
5
+ export const RUN_ON_TRANSIENT_CONNECTION = false;
3
6
  //# 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,aAAa,CAAA;AAC1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,CAAA;AAC1C,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,IAAI,EAAE,CAAA;AACxC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAA;AACrC,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,CAAA"}
@@ -1,59 +1,88 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * The `performanceService` implements the [perf protocol](https://github.com/libp2p/specs/blob/master/perf/perf.md), which is used to measure performance within and across libp2p implementations
5
- * addresses.
4
+ * The {@link PerfService} implements the [perf protocol](https://github.com/libp2p/specs/blob/master/perf/perf.md), which can be used to measure transfer performance within and across libp2p implementations.
6
5
  *
7
6
  * @example
8
7
  *
9
8
  * ```typescript
10
- * import { createLibp2p } from 'libp2p'
11
- * import { perfService } from '@libp2p/perf'
12
- *
13
- * const node = await createLibp2p({
14
- * service: [
15
- * perfService()
16
- * ]
17
- * })
18
- * ```
19
- *
20
- * The `measurePerformance` function can be used to measure the latency and throughput of a connection.
21
- * server. This will not work in browsers.
22
- *
23
- * @example
9
+ * import { noise } from '@chainsafe/libp2p-noise'
10
+ * import { yamux } from '@chainsafe/libp2p-yamux'
11
+ * import { mplex } from '@libp2p/mplex'
12
+ * import { tcp } from '@libp2p/tcp'
13
+ * import { createLibp2p, type Libp2p } from 'libp2p'
14
+ * import { plaintext } from 'libp2p/insecure'
15
+ * import { perfService, type PerfService } from '@libp2p/perf'
24
16
  *
25
- * ```typescript
26
- * import { createLibp2p } from 'libp2p'
27
- * import { perfService } from 'libp2p/perf'
28
- *
29
- * const node = await createLibp2p({
30
- * services: [
31
- * perf: perfService()
32
- * ]
33
- * })
17
+ * const ONE_MEG = 1024 * 1024
18
+ * const UPLOAD_BYTES = ONE_MEG * 1024
19
+ * const DOWNLOAD_BYTES = ONE_MEG * 1024
34
20
  *
35
- * const connection = await node.dial(multiaddr(multiaddrAddress))
21
+ * async function createNode (): Promise<Libp2p<{ perf: PerfService }>> {
22
+ * return createLibp2p({
23
+ * addresses: {
24
+ * listen: [
25
+ * '/ip4/0.0.0.0/tcp/0'
26
+ * ]
27
+ * },
28
+ * transports: [
29
+ * tcp()
30
+ * ],
31
+ * connectionEncryption: [
32
+ * noise(), plaintext()
33
+ * ],
34
+ * streamMuxers: [
35
+ * yamux(), mplex()
36
+ * ],
37
+ * services: {
38
+ * perf: perfService()
39
+ * }
40
+ * })
41
+ * }
36
42
  *
37
- * const startTime = Date.now()
43
+ * const libp2p1 = await createNode()
44
+ * const libp2p2 = await createNode()
38
45
  *
39
- * await node.services.perf.measurePerformance(startTime, connection, BigInt(uploadBytes), BigInt(downloadBytes))
46
+ * for await (const output of libp2p1.services.perf.measurePerformance(libp2p2.getMultiaddrs()[0], UPLOAD_BYTES, DOWNLOAD_BYTES)) {
47
+ * console.info(output)
48
+ * }
40
49
  *
50
+ * await libp2p1.stop()
51
+ * await libp2p2.stop()
41
52
  * ```
42
53
  */
43
- import type { Connection } from '@libp2p/interface/connection';
54
+ import type { AbortOptions } from '@libp2p/interface';
44
55
  import type { ConnectionManager } from '@libp2p/interface-internal/connection-manager';
45
56
  import type { Registrar } from '@libp2p/interface-internal/registrar';
46
- import type { AbortOptions } from '@libp2p/interfaces';
47
- export declare const defaultInit: PerfServiceInit;
57
+ import type { Multiaddr } from '@multiformats/multiaddr';
58
+ export interface PerfOptions extends AbortOptions {
59
+ /**
60
+ * By default measuring perf should include the time it takes to establish a
61
+ * connection, so a new connection will be opened for every performance run.
62
+ *
63
+ * To override this and re-use an existing connection if one is present, pass
64
+ * `true` here. (default: false)
65
+ */
66
+ reuseExistingConnection?: boolean;
67
+ }
48
68
  export interface PerfService {
49
- measurePerformance(startTime: number, connection: Connection, sendBytes: bigint, recvBytes: bigint, options?: AbortOptions): Promise<number>;
69
+ measurePerformance(multiaddr: Multiaddr, sendBytes: number, recvBytes: number, options?: PerfOptions): AsyncGenerator<PerfOutput>;
70
+ }
71
+ export interface PerfOutput {
72
+ type: 'intermediary' | 'final';
73
+ timeSeconds: number;
74
+ uploadBytes: number;
75
+ downloadBytes: number;
50
76
  }
51
77
  export interface PerfServiceInit {
52
78
  protocolName?: string;
53
79
  maxInboundStreams?: number;
54
80
  maxOutboundStreams?: number;
55
- timeout?: number;
56
- writeBlockSize?: bigint;
81
+ runOnTransientConnection?: boolean;
82
+ /**
83
+ * Data sent/received will be sent in chunks of this size (default: 64KiB)
84
+ */
85
+ writeBlockSize?: number;
57
86
  }
58
87
  export interface PerfServiceComponents {
59
88
  registrar: Registrar;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAE9D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+CAA+C,CAAA;AACtF,OAAO,KAAK,EAAsB,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACzF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAItD,eAAO,MAAM,WAAW,EAAE,eAGzB,CAAA;AAED,MAAM,WAAW,WAAW;IAC1B,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAC7I;AAED,MAAM,WAAW,eAAe;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,SAAS,CAAA;IACpB,iBAAiB,EAAE,iBAAiB,CAAA;CACrC;AAsHD,wBAAgB,WAAW,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gB,WAAW,CAAE,IAAI,GAAE,eAAoB,GAAG,CAAC,UAAU,EAAE,qBAAqB,KAAK,WAAW,CAE3G"}
package/dist/src/index.js CHANGED
@@ -1,150 +1,58 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * The `performanceService` implements the [perf protocol](https://github.com/libp2p/specs/blob/master/perf/perf.md), which is used to measure performance within and across libp2p implementations
5
- * addresses.
4
+ * The {@link PerfService} implements the [perf protocol](https://github.com/libp2p/specs/blob/master/perf/perf.md), which can be used to measure transfer performance within and across libp2p implementations.
6
5
  *
7
6
  * @example
8
7
  *
9
8
  * ```typescript
10
- * import { createLibp2p } from 'libp2p'
11
- * import { perfService } from '@libp2p/perf'
12
- *
13
- * const node = await createLibp2p({
14
- * service: [
15
- * perfService()
16
- * ]
17
- * })
18
- * ```
19
- *
20
- * The `measurePerformance` function can be used to measure the latency and throughput of a connection.
21
- * server. This will not work in browsers.
22
- *
23
- * @example
24
- *
25
- * ```typescript
26
- * import { createLibp2p } from 'libp2p'
27
- * import { perfService } from 'libp2p/perf'
28
- *
29
- * const node = await createLibp2p({
30
- * services: [
31
- * perf: perfService()
32
- * ]
33
- * })
34
- *
35
- * const connection = await node.dial(multiaddr(multiaddrAddress))
36
- *
37
- * const startTime = Date.now()
38
- *
39
- * await node.services.perf.measurePerformance(startTime, connection, BigInt(uploadBytes), BigInt(downloadBytes))
40
- *
9
+ * import { noise } from '@chainsafe/libp2p-noise'
10
+ * import { yamux } from '@chainsafe/libp2p-yamux'
11
+ * import { mplex } from '@libp2p/mplex'
12
+ * import { tcp } from '@libp2p/tcp'
13
+ * import { createLibp2p, type Libp2p } from 'libp2p'
14
+ * import { plaintext } from 'libp2p/insecure'
15
+ * import { perfService, type PerfService } from '@libp2p/perf'
16
+ *
17
+ * const ONE_MEG = 1024 * 1024
18
+ * const UPLOAD_BYTES = ONE_MEG * 1024
19
+ * const DOWNLOAD_BYTES = ONE_MEG * 1024
20
+ *
21
+ * async function createNode (): Promise<Libp2p<{ perf: PerfService }>> {
22
+ * return createLibp2p({
23
+ * addresses: {
24
+ * listen: [
25
+ * '/ip4/0.0.0.0/tcp/0'
26
+ * ]
27
+ * },
28
+ * transports: [
29
+ * tcp()
30
+ * ],
31
+ * connectionEncryption: [
32
+ * noise(), plaintext()
33
+ * ],
34
+ * streamMuxers: [
35
+ * yamux(), mplex()
36
+ * ],
37
+ * services: {
38
+ * perf: perfService()
39
+ * }
40
+ * })
41
+ * }
42
+ *
43
+ * const libp2p1 = await createNode()
44
+ * const libp2p2 = await createNode()
45
+ *
46
+ * for await (const output of libp2p1.services.perf.measurePerformance(libp2p2.getMultiaddrs()[0], UPLOAD_BYTES, DOWNLOAD_BYTES)) {
47
+ * console.info(output)
48
+ * }
49
+ *
50
+ * await libp2p1.stop()
51
+ * await libp2p2.stop()
41
52
  * ```
42
53
  */
43
- import { logger } from '@libp2p/logger';
44
- import { PROTOCOL_NAME, WRITE_BLOCK_SIZE } from './constants.js';
45
- const log = logger('libp2p:perf');
46
- export const defaultInit = {
47
- protocolName: '/perf/1.0.0',
48
- writeBlockSize: BigInt(64 << 10)
49
- };
50
- class DefaultPerfService {
51
- protocol;
52
- components;
53
- started;
54
- databuf;
55
- writeBlockSize;
56
- constructor(components, init) {
57
- this.components = components;
58
- this.started = false;
59
- this.protocol = init.protocolName ?? PROTOCOL_NAME;
60
- this.writeBlockSize = init.writeBlockSize ?? WRITE_BLOCK_SIZE;
61
- this.databuf = new ArrayBuffer(Number(init.writeBlockSize));
62
- }
63
- async start() {
64
- await this.components.registrar.handle(this.protocol, (data) => {
65
- void this.handleMessage(data).catch((err) => {
66
- log.error('error handling perf protocol message', err);
67
- });
68
- });
69
- this.started = true;
70
- }
71
- async stop() {
72
- await this.components.registrar.unhandle(this.protocol);
73
- this.started = false;
74
- }
75
- isStarted() {
76
- return this.started;
77
- }
78
- async handleMessage(data) {
79
- const { stream } = data;
80
- const writeBlockSize = this.writeBlockSize;
81
- let bytesToSendBack = null;
82
- for await (const buf of stream.source) {
83
- if (bytesToSendBack === null) {
84
- bytesToSendBack = BigInt(buf.getBigUint64(0, false));
85
- }
86
- // Ingest all the bufs and wait for the read side to close
87
- }
88
- const uint8Buf = new Uint8Array(this.databuf);
89
- if (bytesToSendBack === null) {
90
- throw new Error('bytesToSendBack was not set');
91
- }
92
- await stream.sink(async function* () {
93
- while (bytesToSendBack > 0n) {
94
- let toSend = writeBlockSize;
95
- if (toSend > bytesToSendBack) {
96
- toSend = bytesToSendBack;
97
- }
98
- bytesToSendBack = bytesToSendBack - toSend;
99
- yield uint8Buf.subarray(0, Number(toSend));
100
- }
101
- }());
102
- }
103
- async measurePerformance(startTime, connection, sendBytes, recvBytes, options = {}) {
104
- log('opening stream on protocol %s to %p', this.protocol, connection.remotePeer);
105
- const uint8Buf = new Uint8Array(this.databuf);
106
- const writeBlockSize = this.writeBlockSize;
107
- const stream = await connection.newStream([this.protocol], options);
108
- // Convert sendBytes to uint64 big endian buffer
109
- const view = new DataView(this.databuf);
110
- view.setBigInt64(0, recvBytes, false);
111
- log('sending %i bytes to %p', sendBytes, connection.remotePeer);
112
- try {
113
- await stream.sink((async function* () {
114
- // Send the number of bytes to receive
115
- yield uint8Buf.subarray(0, 8);
116
- // Send the number of bytes to send
117
- while (sendBytes > 0n) {
118
- let toSend = writeBlockSize;
119
- if (toSend > sendBytes) {
120
- toSend = sendBytes;
121
- }
122
- sendBytes = sendBytes - toSend;
123
- yield uint8Buf.subarray(0, Number(toSend));
124
- }
125
- })());
126
- // Read the received bytes
127
- let actualRecvdBytes = BigInt(0);
128
- for await (const buf of stream.source) {
129
- actualRecvdBytes += BigInt(buf.length);
130
- }
131
- if (actualRecvdBytes !== recvBytes) {
132
- throw new Error(`Expected to receive ${recvBytes} bytes, but received ${actualRecvdBytes}`);
133
- }
134
- }
135
- catch (err) {
136
- log('error sending %i bytes to %p: %s', sendBytes, connection.remotePeer, err);
137
- throw err;
138
- }
139
- finally {
140
- log('performed %s to %p', this.protocol, connection.remotePeer);
141
- await stream.close();
142
- }
143
- // Return the latency
144
- return Date.now() - startTime;
145
- }
146
- }
54
+ import { PerfService as PerfServiceClass } from './perf-service.js';
147
55
  export function perfService(init = {}) {
148
- return (components) => new DefaultPerfService(components, init);
56
+ return (components) => new PerfServiceClass(components, init);
149
57
  }
150
58
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAOhE,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAEjC,MAAM,CAAC,MAAM,WAAW,GAAoB;IAC1C,YAAY,EAAE,aAAa;IAC3B,cAAc,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;CACjC,CAAA;AAmBD,MAAM,kBAAkB;IACN,QAAQ,CAAQ;IACf,UAAU,CAAuB;IAC1C,OAAO,CAAS;IACP,OAAO,CAAa;IACpB,cAAc,CAAQ;IAEvC,YAAa,UAAiC,EAAE,IAAqB;QACnE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,YAAY,IAAI,aAAa,CAAA;QAClD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,cAAc,IAAI,gBAAgB,CAAA;QAC7D,IAAI,CAAC,OAAO,GAAG,IAAI,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,CAAA;IAC7D,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,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AAW,CAAE,OAAwB,EAAE;IACrD,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AAC/D,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { PerfOptions, PerfOutput, PerfServiceComponents, PerfServiceInit, PerfService as PerfServiceInterface } from './index.js';
2
+ import type { Startable } from '@libp2p/interface/startable';
3
+ import type { IncomingStreamData } from '@libp2p/interface-internal/registrar';
4
+ import type { Multiaddr } from '@multiformats/multiaddr';
5
+ export declare class PerfService implements Startable, PerfServiceInterface {
6
+ readonly protocol: string;
7
+ private readonly components;
8
+ private started;
9
+ private readonly databuf;
10
+ private readonly writeBlockSize;
11
+ private readonly maxInboundStreams;
12
+ private readonly maxOutboundStreams;
13
+ private readonly runOnTransientConnection;
14
+ constructor(components: PerfServiceComponents, init?: PerfServiceInit);
15
+ start(): Promise<void>;
16
+ stop(): Promise<void>;
17
+ isStarted(): boolean;
18
+ handleMessage(data: IncomingStreamData): Promise<void>;
19
+ measurePerformance(ma: Multiaddr, sendBytes: number, receiveBytes: number, options?: PerfOptions): AsyncGenerator<PerfOutput>;
20
+ }
21
+ //# sourceMappingURL=perf-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perf-service.d.ts","sourceRoot":"","sources":["../../src/perf-service.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,qBAAqB,EAAE,eAAe,EAAE,WAAW,IAAI,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACtI,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAIxD,qBAAa,WAAY,YAAW,SAAS,EAAE,oBAAoB;IACjE,SAAgB,QAAQ,EAAE,MAAM,CAAA;I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