@libp2p/perf 4.0.25-a4f0db1e9 → 4.0.26-e7e01f58f

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,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 O=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var v=(i,t)=>{for(var e in t)O(i,e,{get:t[e],enumerable:!0})},k=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T(t))!M.call(i,n)&&n!==e&&O(i,n,{get:()=>t[n],enumerable:!(o=I(t,n))||o.enumerable});return i};var A=i=>k(O({},"__esModule",{value:!0}),i);var j={};v(j,{perf:()=>X});function S(){let i={};return i.promise=new Promise((t,e)=>{i.resolve=t,i.reject=e}),i}var g=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}},b=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new g(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 g(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 B=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function N(i={}){return z(e=>{let o=e.shift();if(o==null)return{done:!0};if(o.error!=null)throw o.error;return{done:o.done===!0,value:o.value}},i)}function z(i,t){t=t??{};let e=t.onEnd,o=new b,n,d,u,y=S(),l=async()=>{try{return o.isEmpty()?u?{done:!0}:await new Promise((r,h)=>{d=w=>{d=null,o.push(w);try{r(i(o))}catch(s){h(s)}return n}}):i(o)}finally{o.isEmpty()&&queueMicrotask(()=>{y.resolve(),y=S()})}},c=r=>d!=null?d(r):(o.push(r),n),p=r=>(o=new b,d!=null?d({error:r}):(o.push({error:r}),n)),m=r=>{if(u)return n;if(t?.objectMode!==!0&&r?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:r})},f=r=>u?n:(u=!0,r!=null?p(r):c({done:!0})),E=()=>(o=new b,f(),{done:!0}),D=r=>(f(r),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:l,return:E,throw:D,push:m,end:f,get readableLength(){return o.size},onEmpty:async r=>{let h=r?.signal;if(h?.throwIfAborted(),o.isEmpty())return;let w,s;h!=null&&(w=new Promise((K,L)=>{s=()=>{L(new B)},h.addEventListener("abort",s)}));try{await Promise.race([y.promise,w])}finally{s!=null&&h!=null&&h?.removeEventListener("abort",s)}}},e==null)return n;let a=n;return n={[Symbol.asyncIterator](){return this},next(){return a.next()},throw(r){return a.throw(r),e!=null&&(e(r),e=void 0),{done:!0}},return(){return a.return(),e!=null&&(e(),e=void 0),{done:!0}},push:m,end(r){return a.end(r),e!=null&&(e(r),e=void 0),n},get readableLength(){return a.readableLength},onEmpty:r=>a.onEmpty(r)},n}var _="/perf/1.0.0";var x=class{log;protocol;components;started;databuf;writeBlockSize;maxInboundStreams;maxOutboundStreams;runOnLimitedConnection;constructor(t,e={}){this.components=t,this.log=t.logger.forComponent("libp2p:perf"),this.started=!1,this.protocol=e.protocolName??_,this.writeBlockSize=e.writeBlockSize??65536,this.databuf=new ArrayBuffer(this.writeBlockSize),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.runOnLimitedConnection=e.runOnLimitedConnection??!1}[Symbol.toStringTag]="@libp2p/perf";async start(){await this.components.registrar.handle(this.protocol,t=>{this.handleMessage(t).catch(e=>{this.log.error("error handling perf protocol message",e)})},{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}async handleMessage(t){let{stream:e}=t;try{let o=this.writeBlockSize,n;for await(let u of e.source)n==null&&(n=Number(u.getBigUint64(0,!1)));if(n==null)throw new Error("bytesToSendBack was not set");let d=new Uint8Array(this.databuf,0,this.databuf.byteLength);await e.sink(async function*(){for(;n>0;){let u=o;u>n&&(u=n),n=n-u,yield d.subarray(0,u)}}())}catch(o){e.abort(o)}}async*measurePerformance(t,e,o,n={}){this.log("opening stream on protocol %s to %a",this.protocol,t);let d=new Uint8Array(this.databuf),u=this.writeBlockSize,y=Date.now(),l=Date.now(),c=await this.components.connectionManager.openConnection(t,{...n,force:n.reuseExistingConnection!==!0});this.log("opened connection after %d ms",Date.now()-l),l=Date.now();let p=await c.newStream(this.protocol,n);this.log("opened stream after %d ms",Date.now()-l),l=Date.now();let m=0,f=0,E=Date.now();new DataView(this.databuf).setBigUint64(0,BigInt(o),!1),this.log("sending %i bytes to %p",e,c.remotePeer);try{let a=N({objectMode:!0});p.sink(async function*(){for(yield d.subarray(0,8);e>0;){let s=u;s>e&&(s=e),yield d.subarray(0,s),e-=s,Date.now()-l>1e3&&(a.push({type:"intermediary",timeSeconds:(Date.now()-l)/1e3,uploadBytes:m,downloadBytes:0}),l=Date.now(),m=0),m+=s,f+=s}a.end()}()).catch(s=>{a.end(s)}),yield*a,this.log("upload complete after %d ms",Date.now()-E);let r=0;l=Date.now();let h=0,w=Date.now();for await(let s of p.source)Date.now()-l>1e3&&(yield{type:"intermediary",timeSeconds:(Date.now()-l)/1e3,uploadBytes:0,downloadBytes:r},l=Date.now(),r=0),r+=s.byteLength,h+=s.byteLength;if(this.log("download complete after %d ms",Date.now()-w),h!==o)throw new Error(`Expected to receive ${o} bytes, but received ${h}`);yield{type:"final",timeSeconds:(Date.now()-y)/1e3,uploadBytes:f,downloadBytes:h},this.log("performed %s to %p",this.protocol,c.remotePeer),await p.close()}catch(a){throw this.log("error sending %d/%d bytes to %p: %s",f,e,c.remotePeer,a),p.abort(a),a}}};function X(i={}){return t=>new x(t,i)}return A(j);})();
2
+ "use strict";var Libp2PPerf=(()=>{var O=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var v=(i,t)=>{for(var e in t)O(i,e,{get:t[e],enumerable:!0})},k=(i,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of T(t))!M.call(i,n)&&n!==e&&O(i,n,{get:()=>t[n],enumerable:!(o=I(t,n))||o.enumerable});return i};var A=i=>k(O({},"__esModule",{value:!0}),i);var j={};v(j,{perf:()=>X});function S(){let i={};return i.promise=new Promise((t,e)=>{i.resolve=t,i.reject=e}),i}var g=class{buffer;mask;top;btm;next;constructor(t){if(!(t>0)||(t-1&t)!==0)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}},b=class{size;hwm;head;tail;constructor(t={}){this.hwm=t.splitLimit??16,this.head=new g(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 g(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 B=class extends Error{type;code;constructor(t,e){super(t??"The operation was aborted"),this.type="aborted",this.code=e??"ABORT_ERR"}};function N(i={}){return z(e=>{let o=e.shift();if(o==null)return{done:!0};if(o.error!=null)throw o.error;return{done:o.done===!0,value:o.value}},i)}function z(i,t){t=t??{};let e=t.onEnd,o=new b,n,d,u,y=S(),l=async()=>{try{return o.isEmpty()?u?{done:!0}:await new Promise((r,h)=>{d=w=>{d=null,o.push(w);try{r(i(o))}catch(s){h(s)}return n}}):i(o)}finally{o.isEmpty()&&queueMicrotask(()=>{y.resolve(),y=S()})}},c=r=>d!=null?d(r):(o.push(r),n),p=r=>(o=new b,d!=null?d({error:r}):(o.push({error:r}),n)),m=r=>{if(u)return n;if(t?.objectMode!==!0&&r?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return c({done:!1,value:r})},f=r=>u?n:(u=!0,r!=null?p(r):c({done:!0})),E=()=>(o=new b,f(),{done:!0}),D=r=>(f(r),{done:!0});if(n={[Symbol.asyncIterator](){return this},next:l,return:E,throw:D,push:m,end:f,get readableLength(){return o.size},onEmpty:async r=>{let h=r?.signal;if(h?.throwIfAborted(),o.isEmpty())return;let w,s;h!=null&&(w=new Promise((K,L)=>{s=()=>{L(new B)},h.addEventListener("abort",s)}));try{await Promise.race([y.promise,w])}finally{s!=null&&h!=null&&h?.removeEventListener("abort",s)}}},e==null)return n;let a=n;return n={[Symbol.asyncIterator](){return this},next(){return a.next()},throw(r){return a.throw(r),e!=null&&(e(r),e=void 0),{done:!0}},return(){return a.return(),e!=null&&(e(),e=void 0),{done:!0}},push:m,end(r){return a.end(r),e!=null&&(e(r),e=void 0),n},get readableLength(){return a.readableLength},onEmpty:r=>a.onEmpty(r)},n}var _="/perf/1.0.0";var x=class{log;protocol;components;started;databuf;writeBlockSize;maxInboundStreams;maxOutboundStreams;runOnLimitedConnection;constructor(t,e={}){this.components=t,this.log=t.logger.forComponent("libp2p:perf"),this.started=!1,this.protocol=e.protocolName??_,this.writeBlockSize=e.writeBlockSize??65536,this.databuf=new ArrayBuffer(this.writeBlockSize),this.maxInboundStreams=e.maxInboundStreams??1,this.maxOutboundStreams=e.maxOutboundStreams??1,this.runOnLimitedConnection=e.runOnLimitedConnection??!1}[Symbol.toStringTag]="@libp2p/perf";async start(){await this.components.registrar.handle(this.protocol,t=>{this.handleMessage(t).catch(e=>{this.log.error("error handling perf protocol message",e)})},{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}async handleMessage(t){let{stream:e}=t;try{let o=this.writeBlockSize,n;for await(let u of e.source)n==null&&(n=Number(u.getBigUint64(0,!1)));if(n==null)throw new Error("bytesToSendBack was not set");let d=new Uint8Array(this.databuf,0,this.databuf.byteLength);await e.sink(async function*(){for(;n>0;){let u=o;u>n&&(u=n),n=n-u,yield d.subarray(0,u)}}())}catch(o){e.abort(o)}}async*measurePerformance(t,e,o,n={}){this.log("opening stream on protocol %s to %a",this.protocol,t);let d=new Uint8Array(this.databuf),u=this.writeBlockSize,y=Date.now(),l=Date.now(),c=await this.components.connectionManager.openConnection(t,{...n,force:n.reuseExistingConnection!==!0});this.log("opened connection after %d ms",Date.now()-l),l=Date.now();let p=await c.newStream(this.protocol,n);this.log("opened stream after %d ms",Date.now()-l),l=Date.now();let m=0,f=0,E=Date.now();new DataView(this.databuf).setBigUint64(0,BigInt(o),!1),this.log("sending %i bytes to %p",e,c.remotePeer);try{let a=N({objectMode:!0});p.sink(async function*(){for(yield d.subarray(0,8);e>0;){let s=u;s>e&&(s=e),yield d.subarray(0,s),e-=s,Date.now()-l>1e3&&(a.push({type:"intermediary",timeSeconds:(Date.now()-l)/1e3,uploadBytes:m,downloadBytes:0}),l=Date.now(),m=0),m+=s,f+=s}a.end()}()).catch(s=>{a.end(s)}),yield*a,this.log("upload complete after %d ms",Date.now()-E);let r=0;l=Date.now();let h=0,w=Date.now();for await(let s of p.source)Date.now()-l>1e3&&(yield{type:"intermediary",timeSeconds:(Date.now()-l)/1e3,uploadBytes:0,downloadBytes:r},l=Date.now(),r=0),r+=s.byteLength,h+=s.byteLength;if(this.log("download complete after %d ms",Date.now()-w),h!==o)throw new Error(`Expected to receive ${o} bytes, but received ${h}`);yield{type:"final",timeSeconds:(Date.now()-y)/1e3,uploadBytes:f,downloadBytes:h},this.log("performed %s to %p",this.protocol,c.remotePeer),await p.close()}catch(a){throw this.log("error sending %d/%d bytes to %p: %s",f,e,c.remotePeer,a),p.abort(a),a}}};function X(i={}){return t=>new x(t,i)}return A(j);})();
3
3
  return Libp2PPerf}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/perf",
3
- "version": "4.0.25-a4f0db1e9",
3
+ "version": "4.0.26-e7e01f58f",
4
4
  "description": "Implementation of Perf Protocol",
5
5
  "author": "@maschad / @marcopolo",
6
6
  "license": "Apache-2.0 OR MIT",
@@ -52,14 +52,14 @@
52
52
  "doc-check": "aegir doc-check"
53
53
  },
54
54
  "dependencies": {
55
- "@libp2p/interface": "2.6.0-a4f0db1e9",
56
- "@libp2p/interface-internal": "2.3.3-a4f0db1e9",
55
+ "@libp2p/interface": "2.6.0-e7e01f58f",
56
+ "@libp2p/interface-internal": "2.3.4-e7e01f58f",
57
57
  "@multiformats/multiaddr": "^12.3.3",
58
58
  "it-pushable": "^3.2.3"
59
59
  },
60
60
  "devDependencies": {
61
- "@libp2p/interface-compliance-tests": "6.3.3-a4f0db1e9",
62
- "@libp2p/logger": "5.1.9-a4f0db1e9",
61
+ "@libp2p/interface-compliance-tests": "6.3.4-e7e01f58f",
62
+ "@libp2p/logger": "5.1.9-e7e01f58f",
63
63
  "aegir": "^45.0.5",
64
64
  "it-last": "^3.0.6",
65
65
  "it-pair": "^2.0.6",