@libp2p/tcp 10.0.9 → 10.0.10
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/listener.d.ts +3 -2
- package/dist/src/listener.d.ts.map +1 -1
- package/dist/src/listener.js +39 -28
- package/dist/src/listener.js.map +1 -1
- package/package.json +5 -4
- package/src/listener.ts +43 -29
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PTcp = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PTcp=(()=>{var $r=Object.create;var ge=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var zr=Object.getOwnPropertyNames;var Vr=Object.getPrototypeOf,Br=Object.prototype.hasOwnProperty;var F=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var U=(r,e)=>{for(var t in e)ge(r,t,{get:e[t],enumerable:!0})},Mt=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of zr(e))!Br.call(r,o)&&o!==t&&ge(r,o,{get:()=>e[o],enumerable:!(n=Or(e,o))||n.enumerable});return r};var ue=(r,e,t)=>(t=r!=null?$r(Vr(r)):{},Mt(e||!r||!r.__esModule?ge(t,"default",{value:r,enumerable:!0}):t,r)),_r=r=>Mt(ge({},"__esModule",{value:!0}),r);var _o={};U(_o,{tcp:()=>Bo});var Fr=ue(F("net"),1);var Nt=Symbol.for("@libp2p/transport");var Lt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Lt||(Lt={}));var Y=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var z=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var ee=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},we=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},be=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Ft=F("events"),$t=(r,...e)=>{try{(0,Ft.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),$t(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var Ot=Symbol.for("@libp2p/service-capabilities"),Jo=Symbol.for("@libp2p/service-dependencies");var Be={};U(Be,{base58btc:()=>T,base58flickr:()=>Hr});var ws=new Uint8Array(0);function zt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Vt(r){return new TextEncoder().encode(r)}function Bt(r){return new TextDecoder().decode(r)}function Rr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,u=r.charAt(0),g=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function w(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var A=0,S=0,h=0,x=l.length;h!==x&&l[h]===0;)h++,A++;for(var D=(x-h)*f+1>>>0,k=new Uint8Array(D);h!==x;){for(var O=l[h],j=0,N=D-1;(O!==0||j<S)&&N!==-1;N--,j++)O+=256*k[N]>>>0,k[N]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");S=j,h++}for(var B=D-S;B!==D&&k[B]===0;)B++;for(var xe=u.repeat(A);B<D;++B)xe+=r.charAt(k[B]);return xe}function v(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var A=0;if(l[A]!==" "){for(var S=0,h=0;l[A]===u;)S++,A++;for(var x=(l.length-A)*g+1>>>0,D=new Uint8Array(x);l[A];){var k=t[l.charCodeAt(A)];if(k===255)return;for(var O=0,j=x-1;(k!==0||O<h)&&j!==-1;j--,O++)k+=a*D[j]>>>0,D[j]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");h=O,A++}if(l[A]!==" "){for(var N=x-h;N!==x&&D[N]===0;)N++;for(var B=new Uint8Array(S+(x-N)),xe=S;N!==x;)B[xe++]=D[N++];return B}}}function p(l){var A=v(l);if(A)return A;throw new Error(`Non-${e} character`)}return{encode:w,decodeUnsafe:v,decode:p}}var jr=Rr,qr=jr,Rt=qr;var $e=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Oe=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 jt(this,e)}},ze=class{decoders;constructor(e){this.decoders=e}or(e){return jt(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function jt(r,e){return new ze({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Ve=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new $e(e,t,n),this.decoder=new Oe(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function te({name:r,prefix:e,encode:t,decode:n}){return new Ve(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Rt(t,r);return te({prefix:e,name:r,encode:n,decode:s=>M(o(s))})}function Wr(r,e,t,n){let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,u=0,g=0;for(let f=0;f<s;++f){let w=o[r[f]];if(w===void 0)throw new SyntaxError(`Non-${n} character`);u=u<<t|w,a+=t,a>=8&&(a-=8,i[g++]=255&u>>a)}if(a>=t||255&u<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Gr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let u=0;u<r.length;++u)for(a=a<<8|r[u],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return te({prefix:e,name:r,encode(o){return Gr(o,n,t)},decode(o){return Wr(o,n,t,r)}})}var T=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Hr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _e={};U(_e,{base32:()=>_,base32hex:()=>Kr,base32hexpad:()=>Yr,base32hexpadupper:()=>en,base32hexupper:()=>Zr,base32pad:()=>Xr,base32padupper:()=>Qr,base32upper:()=>Jr,base32z:()=>tn});var _=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Jr=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xr=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Qr=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Kr=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Zr=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Yr=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),en=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),tn=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Re={};U(Re,{base36:()=>le,base36upper:()=>rn});var le=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),rn=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var nn=Gt,qt=128,on=127,sn=~on,cn=Math.pow(2,31);function Gt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=cn;)e[t++]=r&255|qt,r/=128;for(;r&sn;)e[t++]=r&255|qt,r>>>=7;return e[t]=r|0,Gt.bytes=t-n+1,e}var an=je,dn=128,Wt=127;function je(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw je.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Wt)<<o:(i&Wt)*Math.pow(2,o),o+=7}while(i>=dn);return je.bytes=s-n,t}var un=Math.pow(2,7),ln=Math.pow(2,14),pn=Math.pow(2,21),fn=Math.pow(2,28),hn=Math.pow(2,35),mn=Math.pow(2,42),xn=Math.pow(2,49),gn=Math.pow(2,56),wn=Math.pow(2,63),bn=function(r){return r<un?1:r<ln?2:r<pn?3:r<fn?4:r<hn?5:r<mn?6:r<xn?7:r<gn?8:r<wn?9:10},yn={encode:nn,decode:an,encodingLength:bn},vn=yn,pe=vn;function fe(r,e=0){return[pe.decode(r,e),pe.decode.bytes]}function re(r,e,t=0){return pe.encode(r,e,t),e}function ne(r){return pe.encodingLength(r)}function J(r,e){let t=e.byteLength,n=ne(r),o=n+ne(t),s=new Uint8Array(o+t);return re(r,s,0),re(t,s,n),s.set(e,o),new oe(r,t,e,s)}function Ee(r){let e=M(r),[t,n]=fe(e),[o,s]=fe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new oe(t,o,i,e)}function Ht(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&zt(r.bytes,t.bytes)}}var oe=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Jt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return An(t,qe(r),e??T.encoder);default:return Cn(t,qe(r),e??_.encoder)}}var Xt=new WeakMap;function qe(r){let e=Xt.get(r);if(e==null){let t=new Map;return Xt.set(r,t),t}return e}var W=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==he)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==In)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=J(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Ht(e.multihash,n.multihash)}toString(e){return Jt(this,e)}toJSON(){return{"/":Jt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??Qt(n,o,s.bytes))}else if(t[Sn]===!0){let{version:n,multihash:o,code:s}=t,i=Ee(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==he)throw new Error(`Version 0 CID must use dag-pb (code: ${he}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=Qt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,he,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=M(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new oe(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[w,v]=fe(e.subarray(t));return t+=v,w},o=n(),s=he;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),u=n(),g=t+u,f=g-i;return{version:o,codec:s,multihashCode:a,digestSize:u,multihashSize:f,size:g}}static parse(e,t){let[n,o]=En(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return qe(s).set(n,e),s}};function En(r,e){switch(r[0]){case"Q":{let t=e??T;return[T.prefix,t.decode(`${T.prefix}${r}`)]}case T.prefix:{let t=e??T;return[T.prefix,t.decode(r)]}case _.prefix:{let t=e??_;return[_.prefix,t.decode(r)]}case le.prefix:{let t=e??le;return[le.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function An(r,e,t){let{prefix:n}=t;if(n!==T.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Cn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var he=112,In=18;function Qt(r,e,t){let n=ne(r),o=n+ne(e),s=new Uint8Array(o+t.byteLength);return re(r,s,0),re(e,s,n),s.set(t,o),s}var Sn=Symbol.for("@ipld/js-cid/CID");function Kt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var sr=F("node:buffer");var We={};U(We,{base10:()=>Tn});var Tn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var Ge={};U(Ge,{base16:()=>Pn,base16upper:()=>Dn});var Pn=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var He={};U(He,{base2:()=>Un});var Un=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Je={};U(Je,{base256emoji:()=>Fn});var Zt=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),kn=Zt.reduce((r,e,t)=>(r[t]=e,r),[]),Mn=Zt.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Ln(r){return r.reduce((e,t)=>(e+=kn[t],e),"")}function Nn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Mn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var Fn=te({prefix:"\u{1F680}",name:"base256emoji",encode:Ln,decode:Nn});var Xe={};U(Xe,{base64:()=>$n,base64pad:()=>On,base64url:()=>zn,base64urlpad:()=>Vn});var $n=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),On=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),zn=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Vn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Qe={};U(Qe,{base8:()=>Bn});var Bn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ke={};U(Ke,{identity:()=>_n});var _n=te({prefix:"\0",name:"identity",encode:r=>Bt(r),decode:r=>Vt(r)});var qs=new TextEncoder,Ws=new TextDecoder;var Ze={};U(Ze,{identity:()=>Gn});var Yt=0,qn="identity",er=M;function Wn(r){return J(Yt,er(r))}var Gn={code:Yt,name:qn,encode:er,digest:Wn};var rt={};U(rt,{sha256:()=>Hn,sha512:()=>Jn});var tt=ue(F("crypto"),1);function et({name:r,code:e,encode:t}){return new Ye(r,e,t)}var Ye=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?J(this.code,t):t.then(n=>J(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Hn=et({name:"sha2-256",code:18,encode:r=>M(tt.default.createHash("sha256").update(r).digest())}),Jn=et({name:"sha2-512",code:19,encode:r=>M(tt.default.createHash("sha512").update(r).digest())});var me={...Ke,...He,...Qe,...We,...Ge,..._e,...Re,...Be,...Xe,...Je},si={...rt,...Ze};var rr=F("node:buffer");function ie(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ae(r=0){return ie(rr.Buffer.allocUnsafe(r))}function or(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var nr=or("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),nt=or("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ae(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Xn={utf8:nr,"utf-8":nr,hex:me.base16,latin1:nt,ascii:nt,binary:nt,...me},Ce=Xn;function P(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?sr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Qn=Math.pow(2,7),Kn=Math.pow(2,14),Zn=Math.pow(2,21),ot=Math.pow(2,28),st=Math.pow(2,35),it=Math.pow(2,42),ct=Math.pow(2,49),m=128,I=127;function V(r){if(r<Qn)return 1;if(r<Kn)return 2;if(r<Zn)return 3;if(r<ot)return 4;if(r<st)return 5;if(r<it)return 6;if(r<ct)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Yn(r,e,t=0){switch(V(r)){case 8:e[t++]=r&255|m,r/=128;case 7:e[t++]=r&255|m,r/=128;case 6:e[t++]=r&255|m,r/=128;case 5:e[t++]=r&255|m,r/=128;case 4:e[t++]=r&255|m,r>>>=7;case 3:e[t++]=r&255|m,r>>>=7;case 2:e[t++]=r&255|m,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function eo(r,e,t=0){switch(V(r)){case 8:e.set(t++,r&255|m),r/=128;case 7:e.set(t++,r&255|m),r/=128;case 6:e.set(t++,r&255|m),r/=128;case 5:e.set(t++,r&255|m),r/=128;case 4:e.set(t++,r&255|m),r>>>=7;case 3:e.set(t++,r&255|m),r>>>=7;case 2:e.set(t++,r&255|m),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function to(r,e){let t=r[e],n=0;if(n+=t&I,t<m||(t=r[e+1],n+=(t&I)<<7,t<m)||(t=r[e+2],n+=(t&I)<<14,t<m)||(t=r[e+3],n+=(t&I)<<21,t<m)||(t=r[e+4],n+=(t&I)*ot,t<m)||(t=r[e+5],n+=(t&I)*st,t<m)||(t=r[e+6],n+=(t&I)*it,t<m)||(t=r[e+7],n+=(t&I)*ct,t<m))return n;throw new RangeError("Could not decode varint")}function ro(r,e){let t=r.get(e),n=0;if(n+=t&I,t<m||(t=r.get(e+1),n+=(t&I)<<7,t<m)||(t=r.get(e+2),n+=(t&I)<<14,t<m)||(t=r.get(e+3),n+=(t&I)<<21,t<m)||(t=r.get(e+4),n+=(t&I)*ot,t<m)||(t=r.get(e+5),n+=(t&I)*st,t<m)||(t=r.get(e+6),n+=(t&I)*it,t<m)||(t=r.get(e+7),n+=(t&I)*ct,t<m))return n;throw new RangeError("Could not decode varint")}function ce(r,e,t=0){return e==null&&(e=Ae(V(r))),e instanceof Uint8Array?Yn(r,e,t):eo(r,e,t)}function X(r,e=0){return r instanceof Uint8Array?to(r,e):ro(r,e)}var cr=F("node:buffer");function R(r,e){return ie(cr.Buffer.concat(r,e))}var Ie=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let u=a==="0",g=2**(8*o)-1;for(;;){let f=this.readAtomically(()=>{let w=this.readChar();if(w===void 0)return;let v=Number.parseInt(w,e);if(!Number.isNaN(v))return v});if(f===void 0)break;if(s*=e,s+=f,s>g||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&u&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var yi=new Ie;var Pi=parseInt("0xFFFF",16),Di=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var ur=F("node:buffer");function at(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?ie(ur.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var L=F("node:net");function Se(r){return!!(0,L.isIP)(r)}var lr=L.isIPv4,ao=L.isIPv6,dt=function(r){let e=0;if(r=r.toString().trim(),lr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(ao(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=lr(t[n]),i;s&&(i=dt(t[n]),t[n]=P(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,P(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},pr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ae={},ut={},lo=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];lo.forEach(r=>{let e=po(...r);ut[e.code]=e,ae[e.name]=e});function po(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function b(r){if(typeof r=="number"){if(ut[r]!=null)return ut[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ae[r]!=null)return ae[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var xc=b("ip4"),gc=b("ip6"),wc=b("ipcidr");function ht(r,e){switch(b(r).code){case 4:case 41:return ho(e);case 42:return ft(e);case 6:case 273:case 33:case 132:return mr(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ft(e);case 421:return wo(e);case 444:return hr(e);case 445:return hr(e);case 466:return go(e);case 481:return globalThis.encodeURIComponent(ft(e));default:return P(e,"base16")}}function mt(r,e){switch(b(r).code){case 4:return fr(e);case 41:return fr(e);case 42:return pt(e);case 6:case 273:case 33:case 132:return xt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return pt(e);case 421:return mo(e);case 444:return bo(e);case 445:return yo(e);case 466:return xo(e);case 481:return pt(globalThis.decodeURIComponent(e));default:return at(e,"base16")}}var lt=Object.values(me).map(r=>r.decoder),fo=function(){let r=lt[0].or(lt[1]);return lt.slice(2).forEach(e=>r=r.or(e)),r}();function fr(r){if(!Se(r))throw new Error("invalid ip address");return dt(r)}function ho(r){let e=pr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Se(e))throw new Error("invalid ip address");return e}function xt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function mr(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function pt(r){let e=at(r),t=Uint8Array.from(ce(e.length));return R([t,e],t.length+e.length)}function ft(r){let e=X(r);if(r=r.slice(V(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function mo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ee(T.decode(`z${r}`)).bytes:e=W.parse(r).multihash.bytes;let t=Uint8Array.from(ce(e.length));return R([t,e],t.length+e.length)}function xo(r){let e=fo.decode(r),t=Uint8Array.from(ce(e.length));return R([t,e],t.length+e.length)}function go(r){let e=X(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function wo(r){let e=X(r),t=r.slice(V(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function bo(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=_.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=xt(n);return R([t,o],t.length+o.length)}function yo(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=_.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=xt(n);return R([t,o],t.length+o.length)}function hr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=mr(t);return`${n}:${o}`}function xr(r){r=gt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=b(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw wr("invalid address: "+r);if(a.path===!0){n=gt(o.slice(s).join("/")),e.push([a.code,mt(a.code,n)]),t.push([a.code,n]);break}let u=mt(a.code,o[s]);e.push([a.code,u]),t.push([a.code,ht(a.code,u)])}return{string:gr(t),bytes:bt(e),tuples:e,stringTuples:t,path:n}}function wt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=X(r,o),i=V(s),a=b(s),u=vo(a,r.slice(o+i));if(u===0){e.push([s]),t.push([s]),o+=i;continue}let g=r.slice(o+i,o+i+u);if(o+=u+i,o>r.length)throw wr("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,g]);let f=ht(s,g);if(t.push([s,f]),a.path===!0){n=f;break}}return{bytes:Uint8Array.from(r),string:gr(t),tuples:e,stringTuples:t,path:n}}function gr(r){let e=[];return r.map(t=>{let n=b(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),gt(e.join("/"))}function bt(r){return R(r.map(e=>{let t=b(e[0]),n=Uint8Array.from(ce(t.code));return e.length>1&&e[1]!=null&&(n=R([n,e[1]])),n}))}function vo(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=X(e instanceof Uint8Array?e:Uint8Array.from(e));return t+V(t)}}function gt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function wr(r){return new Error("Error parsing address: "+r)}var Eo=Symbol.for("nodejs.util.inspect.custom"),vt=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Ao=[b("dns").code,b("dns4").code,b("dns6").code,b("dnsaddr").code],yt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Te=class r{bytes;#e;#t;#r;#n;[vt]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=wt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=xr(e)}else if(yr(e))t=wt(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=b("tcp"),a=b("udp"),u=b("ip4"),g=b("ip6"),f=b("dns6"),w=b("ip6zone");for(let[p,l]of this.stringTuples())p===w.code&&(s=`%${l??""}`),Ao.includes(p)&&(t=i.name,o=443,n=`${l??""}${s}`,e=p===f.code?6:4),(p===i.code||p===a.code)&&(t=b(p).name,o=parseInt(l??"")),(p===u.code||p===g.code)&&(t=b(p).name,n=`${l??""}${s}`,e=p===g.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},b(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>b(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(bt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ae.p2p.code&&e.push([n,o]),n===ae["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?P(T.decode(`z${n}`),"base58btc"):P(W.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return Kt(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=br.get(t.name);if(n==null)throw new yt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>$(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Eo](){return`Multiaddr(${this.#e})`}};var br=new Map;function yr(r){return!!r?.[vt]}function $(r){return new Te(r)}var Co=c("dns4"),Io=c("dns6"),So=c("dnsaddr"),K=E(c("dns"),So,Co,Io),Ue=E(c("ip4"),c("ip6")),H=E(d(Ue,c("tcp")),d(K,c("tcp"))),ke=d(Ue,c("udp")),To=d(ke,c("utp")),Po=d(ke,c("quic")),Do=d(ke,c("quic-v1")),Et=E(d(H,c("ws")),d(K,c("ws"))),Pe=E(d(Et,c("p2p")),Et),At=E(d(H,c("wss")),d(K,c("wss")),d(H,c("tls"),c("ws")),d(K,c("tls"),c("ws"))),De=E(d(At,c("p2p")),At),Ct=E(d(H,c("http")),d(Ue,c("http")),d(K,c("http"))),It=E(d(H,c("https")),d(Ue,c("https")),d(K,c("https"))),vr=d(ke,c("webrtc-direct"),c("certhash")),Cr=E(d(vr,c("p2p")),vr),Er=d(Do,c("webtransport"),c("certhash"),c("certhash")),Ir=E(d(Er,c("p2p")),Er),Sr=E(d(Pe,c("p2p-webrtc-star"),c("p2p")),d(De,c("p2p-webrtc-star"),c("p2p")),d(Pe,c("p2p-webrtc-star")),d(De,c("p2p-webrtc-star"))),jc=E(d(Pe,c("p2p-websocket-star"),c("p2p")),d(De,c("p2p-websocket-star"),c("p2p")),d(Pe,c("p2p-websocket-star")),d(De,c("p2p-websocket-star"))),Tr=E(d(Ct,c("p2p-webrtc-direct"),c("p2p")),d(It,c("p2p-webrtc-direct"),c("p2p")),d(Ct,c("p2p-webrtc-direct")),d(It,c("p2p-webrtc-direct"))),Z=E(Et,At,Ct,It,Sr,Tr,H,To,Po,K,Cr,Ir),qc=E(d(Z,c("p2p-stardust"),c("p2p")),d(Z,c("p2p-stardust"))),G=E(d(Z,c("p2p")),Sr,Tr,Cr,Ir,c("p2p")),Ar=E(d(G,c("p2p-circuit"),G),d(G,c("p2p-circuit")),d(c("p2p-circuit"),G),d(Z,c("p2p-circuit")),d(c("p2p-circuit"),Z),c("p2p-circuit")),Pr=()=>E(d(Ar,Pr),Ar),Q=Pr(),Wc=E(d(Q,G,Q),d(G,Q),d(Q,G),Q,G);var Gc=E(d(Q,c("webrtc"),c("p2p")),d(Q,c("webrtc")),d(Z,c("webrtc"),c("p2p")),d(Z,c("webrtc")),c("webrtc"));function Dr(r){function e(t){let n;try{n=$(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function d(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Dr(e),partialMatch:e}}function E(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Dr(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=$(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var Me=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Nr=ue(F("net"),1);function Ur(r,e){if(typeof r!="string")throw new z(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new z(`invalid port provided: ${e}`);if((0,L.isIPv4)(r))return $(`/ip4/${r}/tcp/${e}`);if((0,L.isIPv6)(r))return $(`/ip6/${r}/tcp/${e}`);throw new z(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function St(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Tt=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Pt(r,e,t,n){let o=new Tt(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){t?.removeEventListener("abort",f),r.removeEventListener(e,u),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,g)}let u=w=>{try{if(n?.filter?.(w)===!1)return}catch(v){a(),i(v);return}a(),s(w)},g=w=>{a(),i(w.detail)},f=()=>{a(),i(o)};t?.addEventListener("abort",f),r.addEventListener(e,u),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,g)})}function kr(r){if(Mo(r))return async function*(){let e=r.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)return;yield n}}finally{e.releaseLock()}}();if(ko(r))return r;throw new Error("unknown stream")}function ko(r){return r[Symbol.asyncIterator]!=null}function Mo(r){return typeof r?.getReader=="function"}function Mr(r){return async e=>{let t=async()=>{Lo(e)&&await e.return(void 0)},n,o,s=h=>{n=h,t().catch(x=>{x=new AggregateError([n,x],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(h)})},i,a=!1,u=()=>{a=!0,i?.()},g,f=!1,w=()=>{f=!0,g?.()},v,p=()=>{v?.()},l=async()=>new Promise((h,x)=>{i=v=h,o=x,r.once("drain",p)}),A=async()=>(await t(),new Promise((h,x)=>{if(a||f||n!=null){h();return}g=i=h,o=x})),S=()=>{r.removeListener("error",s),r.removeListener("close",u),r.removeListener("finish",w),r.removeListener("drain",p)};r.once("error",s),r.once("close",u),r.once("finish",w);try{for await(let h of e){if(!r.writable||r.destroyed||n!=null)break;r.write(h)||await l()}}catch(h){n==null&&r.destroy(h),n=h}try{if(r.writable&&r.end(),await A(),n!=null)throw n}finally{S()}}}function Lo(r){return r.return!=null}function Dt(r){return{sink:Mr(r),source:kr(r)}}var Ut=ue(F("os"),1),Lr=ue(F("path"),1);var No={ip4:"IPv4",ip6:"IPv6"};function de(r,e={}){let t=r.getPath();return t!=null?Ut.default.platform()==="win32"?{path:Lr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function kt(r,e,t){let n=o=>$(`/${r}/${o}/tcp/${t}`);return(Fo(e)?Oo(No[r]):[e]).map(n)}function Fo(r){return["0.0.0.0","::"].includes(r)}var $o=Ut.default.networkInterfaces();function Oo(r){let e=[];for(let[,t]of Object.entries($o))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Le=(r,e)=>{let t,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.direction,s=e.metrics,i=e.metricPrefix??"",a=e.socketInactivityTimeout??12e4,u=e.socketCloseTimeout??500,g=!1,f=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",h=>{f=!0,g||(n.error("%s socket error - %e",o,h),s?.increment({[`${i}error`]:!0})),r.destroy(),S.timeline.close=Date.now()});let w;if(e.remoteAddr!=null)w=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new z("Could not determine remote address or port");w=Ur(r.remoteAddress,r.remotePort)}let v=de(w),p=v.path??`${v.host??""}:${v.port??""}`,{sink:l,source:A}=Dt(r);r.setTimeout(a),r.once("timeout",()=>{g=!0,n("%s %s socket read timeout",o,p),s?.increment({[`${i}timeout`]:!0}),r.destroy(new ee),S.timeline.close=Date.now()}),r.once("close",()=>{!g&&!f&&(n("%s %s socket close",o,p),s?.increment({[`${i}close`]:!0})),r.destroy(),S.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,p),s?.increment({[`${i}end`]:!0})});let S={async sink(h){try{await l(async function*(){for await(let x of h)x instanceof Uint8Array?yield x:yield x.subarray()}())}catch(x){x.type!=="aborted"&&n.error("%s %s error in sink - %e",o,p,x)}r.end()},source:A,remoteAddr:w,timeline:{open:Date.now()},async close(h={}){if(r.closed){n("the %s %s socket is already closed",o,p);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,p);return}if(t!=null)return t.promise;try{t=St(),r.end();let x=zo(r),D=h.signal??AbortSignal.timeout(u);r.writableLength>0&&(n("%s %s draining socket",o,p),await Pt(x,"drain",D,{errorEvent:"error"}),n("%s %s socket drained",o,p)),await Promise.all([Pt(x,"close",D,{errorEvent:"error"}),r.destroy()])}catch(x){this.abort(x)}finally{t.resolve()}},abort:h=>{n("%s %s socket abort due to error - %e",o,p,h),r.destroy(),S.timeline.close=Date.now()},log:n};return S};function zo(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var C;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(C||(C={}));var Ne=class extends ye{context;server;connections=new Set;status={code:C.INACTIVE};metrics;addr;log;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Nr.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new z("closeAbove must be >= listenBelow");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.connections.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:C.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==C.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics?.events.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics?.events.increment({[`${this.addr} connection`]:!0}),this.status.code!==C.ACTIVE)throw e.destroy(),new we("Server is not listening yet");let t;try{t=Le(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger,direction:"inbound"})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.context.upgrader.upgradeInbound(t).then(n=>{this.log("inbound connection upgraded %s",t.remoteAddr),this.connections.add(t),e.once("close",()=>{this.connections.delete(t),this.context.closeServerOnMaxConnections!=null&&this.connections.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.connections.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(!1).catch(o=>{this.log.error("error attempting to close server once connection count over limit",o)}),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),t.abort(n)})}getAddrs(){if(this.status.code===C.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat(kt("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat(kt("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}async listen(e){if(this.status.code===C.ACTIVE||this.status.code===C.PAUSED)throw new be("server is already listening");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:C.ACTIVE,listeningAddr:n,peerId:t,netConfig:de(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:C.INACTIVE},s}}async close(){let e=new Y("Listener is closing");this.connections.forEach(t=>{t.abort(e)}),await this.pause(!0)}async resume(){if(this.server.listening||this.status.code===C.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:C.ACTIVE},this.log("listening on %s",this.server.address())}async pause(e){if(!this.server.listening&&this.status.code===C.PAUSED&&e){this.status={code:C.INACTIVE};return}!this.server.listening||this.status.code!==C.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:C.INACTIVE}:{...this.status,code:C.PAUSED},await new Promise((t,n)=>{this.server.close(o=>{if(o!=null){n(o);return}t()})}))}};var Fe=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[Nt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[Ot]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=Le(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal?.throwIfAborted(),t.onProgress?.(new Me("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=de(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=Fr.default.connect(a);let u=p=>{this.log.error("dial to %a errored - %e",e,p);let l=a.path??`${a.host??""}:${a.port}`;p.message=`connection error ${l}: ${p.message}`,this.metrics?.events.increment({error:!0}),v(p)},g=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let p=new ee(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",p)},f=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),v()},w=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),v(new Y)},v=p=>{if(n.removeListener("error",u),n.removeListener("timeout",g),n.removeListener("connect",f),t.signal!=null&&t.signal.removeEventListener("abort",w),p!=null){s(p);return}o(n)};n.on("error",u),n.on("timeout",g),n.on("connect",f),t.signal!=null&&t.signal.addEventListener("abort",w)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new Ne({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:H.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Bo(r={}){return e=>new Fe(e,r)}return _r(_o);})();
|
|
2
|
+
"use strict";var Libp2PTcp=(()=>{var Rr=Object.create;var xe=Object.defineProperty;var jr=Object.getOwnPropertyDescriptor;var qr=Object.getOwnPropertyNames;var Wr=Object.getPrototypeOf,Gr=Object.prototype.hasOwnProperty;var F=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var D=(r,e)=>{for(var t in e)xe(r,t,{get:e[t],enumerable:!0})},Ot=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qr(e))!Gr.call(r,o)&&o!==t&&xe(r,o,{get:()=>e[o],enumerable:!(n=jr(e,o))||n.enumerable});return r};var le=(r,e,t)=>(t=r!=null?Rr(Wr(r)):{},Ot(e||!r||!r.__esModule?xe(t,"default",{value:r,enumerable:!0}):t,r)),Hr=r=>Ot(xe({},"__esModule",{value:!0}),r);var Qo={};D(Qo,{tcp:()=>Jo});var _r=le(F("net"),1);var zt=Symbol.for("@libp2p/transport");var Vt;(function(r){r[r.FATAL_ALL=0]="FATAL_ALL",r[r.NO_FATAL=1]="NO_FATAL"})(Vt||(Vt={}));var ge=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var V=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}};var Z=class extends Error{static name="TimeoutError";constructor(e="Timed out"){super(e),this.name="TimeoutError"}},we=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}},be=class extends Error{static name="AlreadyStartedError";constructor(e="Already started"){super(e),this.name="AlreadyStartedError"}};var Bt=F("events"),ve=(r,...e)=>{try{(0,Bt.setMaxListeners)(r,...e)}catch{}};var ye=class extends EventTarget{#e=new Map;constructor(){super(),ve(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let o=this.#e.get(e);o==null&&(o=[],this.#e.set(e,o)),o.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let o=this.#e.get(e);o!=null&&(o=o.filter(({callback:s})=>s!==t),this.#e.set(e,o))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:o})=>!o),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};var _t=Symbol.for("@libp2p/service-capabilities"),rs=Symbol.for("@libp2p/service-dependencies");var _e={};D(_e,{base58btc:()=>S,base58flickr:()=>Zr});var Ts=new Uint8Array(0);function Rt(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function M(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function jt(r){return new TextEncoder().encode(r)}function qt(r){return new TextDecoder().decode(r)}function Jr(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var a=r.length,d=r.charAt(0),h=Math.log(a)/Math.log(256),p=Math.log(256)/Math.log(a);function x(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var I=0,T=0,g=0,b=f.length;g!==b&&f[g]===0;)g++,I++;for(var L=(b-g)*p+1>>>0,k=new Uint8Array(L);g!==b;){for(var O=f[g],j=0,U=L-1;(O!==0||j<T)&&U!==-1;U--,j++)O+=256*k[U]>>>0,k[U]=O%a>>>0,O=O/a>>>0;if(O!==0)throw new Error("Non-zero carry");T=j,g++}for(var B=L-T;B!==L&&k[B]===0;)B++;for(var me=d.repeat(I);B<L;++B)me+=r.charAt(k[B]);return me}function m(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var I=0;if(f[I]!==" "){for(var T=0,g=0;f[I]===d;)T++,I++;for(var b=(f.length-I)*h+1>>>0,L=new Uint8Array(b);f[I];){var k=t[f.charCodeAt(I)];if(k===255)return;for(var O=0,j=b-1;(k!==0||O<g)&&j!==-1;j--,O++)k+=a*L[j]>>>0,L[j]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");g=O,I++}if(f[I]!==" "){for(var U=b-g;U!==b&&L[U]===0;)U++;for(var B=new Uint8Array(T+(b-U)),me=T;U!==b;)B[me++]=L[U++];return B}}}function u(f){var I=m(f);if(I)return I;throw new Error(`Non-${e} character`)}return{encode:x,decodeUnsafe:m,decode:u}}var Qr=Jr,Xr=Qr,Gt=Xr;var Oe=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Ve=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let o=t.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,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 Ht(this,e)}},ze=class{decoders;constructor(e){this.decoders=e}or(e){return Ht(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Ht(r,e){return new ze({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Be=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new Oe(e,t,n),this.decoder=new Ve(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function ee({name:r,prefix:e,encode:t,decode:n}){return new Be(r,e,t,n)}function q({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=Gt(t,r);return ee({prefix:e,name:r,encode:n,decode:s=>M(o(s))})}function Kr(r,e,t,n){let o={};for(let p=0;p<e.length;++p)o[e[p]]=p;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),a=0,d=0,h=0;for(let p=0;p<s;++p){let x=o[r[p]];if(x===void 0)throw new SyntaxError(`Non-${n} character`);d=d<<t|x,a+=t,a>=8&&(a-=8,i[h++]=255&d>>a)}if(a>=t||255&d<<8-a)throw new SyntaxError("Unexpected end of data");return i}function Yr(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,a=0;for(let d=0;d<r.length;++d)for(a=a<<8|r[d],i+=8;i>t;)i-=t,s+=e[o&a>>i];if(i!==0&&(s+=e[o&a<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function y({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return ee({prefix:e,name:r,encode(o){return Yr(o,n,t)},decode(o){return Kr(o,n,t,r)}})}var S=q({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Zr=q({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Re={};D(Re,{base32:()=>_,base32hex:()=>nn,base32hexpad:()=>sn,base32hexpadupper:()=>cn,base32hexupper:()=>on,base32pad:()=>tn,base32padupper:()=>rn,base32upper:()=>en,base32z:()=>an});var _=y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),en=y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),tn=y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),rn=y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),nn=y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),on=y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),sn=y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cn=y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),an=y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var je={};D(je,{base36:()=>ue,base36upper:()=>ln});var ue=q({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),ln=q({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var un=Xt,Jt=128,dn=127,pn=~dn,fn=Math.pow(2,31);function Xt(r,e,t){e=e||[],t=t||0;for(var n=t;r>=fn;)e[t++]=r&255|Jt,r/=128;for(;r&pn;)e[t++]=r&255|Jt,r>>>=7;return e[t]=r|0,Xt.bytes=t-n+1,e}var hn=qe,mn=128,Qt=127;function qe(r,n){var t=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw qe.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Qt)<<o:(i&Qt)*Math.pow(2,o),o+=7}while(i>=mn);return qe.bytes=s-n,t}var xn=Math.pow(2,7),gn=Math.pow(2,14),wn=Math.pow(2,21),bn=Math.pow(2,28),vn=Math.pow(2,35),yn=Math.pow(2,42),En=Math.pow(2,49),In=Math.pow(2,56),An=Math.pow(2,63),Cn=function(r){return r<xn?1:r<gn?2:r<wn?3:r<bn?4:r<vn?5:r<yn?6:r<En?7:r<In?8:r<An?9:10},Tn={encode:un,decode:hn,encodingLength:Cn},Sn=Tn,de=Sn;function pe(r,e=0){return[de.decode(r,e),de.decode.bytes]}function te(r,e,t=0){return de.encode(r,e,t),e}function re(r){return de.encodingLength(r)}function J(r,e){let t=e.byteLength,n=re(r),o=n+re(t),s=new Uint8Array(o+t);return te(r,s,0),te(t,s,n),s.set(e,o),new ne(r,t,e,s)}function Ie(r){let e=M(r),[t,n]=pe(e),[o,s]=pe(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new ne(t,o,i,e)}function Kt(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Rt(r.bytes,t.bytes)}}var ne=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};function Yt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Ln(t,We(r),e??S.encoder);default:return Dn(t,We(r),e??_.encoder)}}var Zt=new WeakMap;function We(r){let e=Zt.get(r);if(e==null){let t=new Map;return Zt.set(r,t),t}return e}var W=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==fe)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==kn)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=J(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Kt(e.multihash,n.multihash)}toString(e){return Yt(this,e)}toJSON(){return{"/":Yt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??er(n,o,s.bytes))}else if(t[Mn]===!0){let{version:n,multihash:o,code:s}=t,i=Ie(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==fe)throw new Error(`Version 0 CID must use dag-pb (code: ${fe}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=er(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,fe,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=M(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new ne(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[x,m]=pe(e.subarray(t));return t+=m,x},o=n(),s=fe;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,a=n(),d=n(),h=t+d,p=h-i;return{version:o,codec:s,multihashCode:a,digestSize:d,multihashSize:p,size:h}}static parse(e,t){let[n,o]=Pn(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return We(s).set(n,e),s}};function Pn(r,e){switch(r[0]){case"Q":{let t=e??S;return[S.prefix,t.decode(`${S.prefix}${r}`)]}case S.prefix:{let t=e??S;return[S.prefix,t.decode(r)]}case _.prefix:{let t=e??_;return[_.prefix,t.decode(r)]}case ue.prefix:{let t=e??ue;return[ue.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Ln(r,e,t){let{prefix:n}=t;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Dn(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var fe=112,kn=18;function er(r,e,t){let n=re(r),o=n+re(e),s=new Uint8Array(o+t.byteLength);return te(r,s,0),te(e,s,n),s.set(t,o),s}var Mn=Symbol.for("@ipld/js-cid/CID");function tr(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}var lr=F("node:buffer");var Ge={};D(Ge,{base10:()=>Nn});var Nn=q({prefix:"9",name:"base10",alphabet:"0123456789"});var He={};D(He,{base16:()=>Un,base16upper:()=>Fn});var Un=y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Fn=y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Je={};D(Je,{base2:()=>$n});var $n=y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Qe={};D(Qe,{base256emoji:()=>_n});var rr=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),On=rr.reduce((r,e,t)=>(r[t]=e,r),[]),Vn=rr.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function zn(r){return r.reduce((e,t)=>(e+=On[t],e),"")}function Bn(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let o=Vn[n];if(o==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(o)}return new Uint8Array(e)}var _n=ee({prefix:"\u{1F680}",name:"base256emoji",encode:zn,decode:Bn});var Xe={};D(Xe,{base64:()=>Rn,base64pad:()=>jn,base64url:()=>qn,base64urlpad:()=>Wn});var Rn=y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),jn=y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qn=y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Wn=y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ke={};D(Ke,{base8:()=>Gn});var Gn=y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ye={};D(Ye,{identity:()=>Hn});var Hn=ee({prefix:"\0",name:"identity",encode:r=>qt(r),decode:r=>jt(r)});var Ys=new TextEncoder,Zs=new TextDecoder;var Ze={};D(Ze,{identity:()=>Yn});var nr=0,Xn="identity",or=M;function Kn(r){return J(nr,or(r))}var Yn={code:nr,name:Xn,encode:or,digest:Kn};var nt={};D(nt,{sha256:()=>Zn,sha512:()=>eo});var rt=le(F("crypto"),1);function tt({name:r,code:e,encode:t}){return new et(r,e,t)}var et=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?J(this.code,t):t.then(n=>J(this.code,n))}else throw Error("Unknown type, must be binary type")}};var Zn=tt({name:"sha2-256",code:18,encode:r=>M(rt.default.createHash("sha256").update(r).digest())}),eo=tt({name:"sha2-512",code:19,encode:r=>M(rt.default.createHash("sha512").update(r).digest())});var he={...Ye,...Je,...Ke,...Ge,...He,...Re,...je,..._e,...Xe,...Qe},fi={...nt,...Ze};var ir=F("node:buffer");function se(r){return new Uint8Array(r.buffer,r.byteOffset,r.byteLength)}function Ae(r=0){return se(ir.Buffer.allocUnsafe(r))}function ar(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var cr=ar("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ot=ar("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=Ae(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),to={utf8:cr,"utf-8":cr,hex:he.base16,latin1:ot,ascii:ot,binary:ot,...he},Ce=to;function P(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?lr.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var ro=Math.pow(2,7),no=Math.pow(2,14),oo=Math.pow(2,21),st=Math.pow(2,28),it=Math.pow(2,35),ct=Math.pow(2,42),at=Math.pow(2,49),w=128,C=127;function z(r){if(r<ro)return 1;if(r<no)return 2;if(r<oo)return 3;if(r<st)return 4;if(r<it)return 5;if(r<ct)return 6;if(r<at)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function so(r,e,t=0){switch(z(r)){case 8:e[t++]=r&255|w,r/=128;case 7:e[t++]=r&255|w,r/=128;case 6:e[t++]=r&255|w,r/=128;case 5:e[t++]=r&255|w,r/=128;case 4:e[t++]=r&255|w,r>>>=7;case 3:e[t++]=r&255|w,r>>>=7;case 2:e[t++]=r&255|w,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function io(r,e,t=0){switch(z(r)){case 8:e.set(t++,r&255|w),r/=128;case 7:e.set(t++,r&255|w),r/=128;case 6:e.set(t++,r&255|w),r/=128;case 5:e.set(t++,r&255|w),r/=128;case 4:e.set(t++,r&255|w),r>>>=7;case 3:e.set(t++,r&255|w),r>>>=7;case 2:e.set(t++,r&255|w),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function co(r,e){let t=r[e],n=0;if(n+=t&C,t<w||(t=r[e+1],n+=(t&C)<<7,t<w)||(t=r[e+2],n+=(t&C)<<14,t<w)||(t=r[e+3],n+=(t&C)<<21,t<w)||(t=r[e+4],n+=(t&C)*st,t<w)||(t=r[e+5],n+=(t&C)*it,t<w)||(t=r[e+6],n+=(t&C)*ct,t<w)||(t=r[e+7],n+=(t&C)*at,t<w))return n;throw new RangeError("Could not decode varint")}function ao(r,e){let t=r.get(e),n=0;if(n+=t&C,t<w||(t=r.get(e+1),n+=(t&C)<<7,t<w)||(t=r.get(e+2),n+=(t&C)<<14,t<w)||(t=r.get(e+3),n+=(t&C)<<21,t<w)||(t=r.get(e+4),n+=(t&C)*st,t<w)||(t=r.get(e+5),n+=(t&C)*it,t<w)||(t=r.get(e+6),n+=(t&C)*ct,t<w)||(t=r.get(e+7),n+=(t&C)*at,t<w))return n;throw new RangeError("Could not decode varint")}function ie(r,e,t=0){return e==null&&(e=Ae(z(r))),e instanceof Uint8Array?so(r,e,t):io(r,e,t)}function Q(r,e=0){return r instanceof Uint8Array?co(r,e):ao(r,e)}var dr=F("node:buffer");function R(r,e){return se(dr.Buffer.concat(r,e))}var Te=class{index=0;input="";new(e){return this.index=0,this.input=e,this}readAtomically(e){let t=this.index,n=e();return n===void 0&&(this.index=t),n}parseWith(e){let t=e();if(this.index===this.input.length)return t}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(e){return this.readAtomically(()=>{let t=this.readChar();if(t===e)return t})}readSeparator(e,t,n){return this.readAtomically(()=>{if(!(t>0&&this.readGivenChar(e)===void 0))return n()})}readNumber(e,t,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let d=a==="0",h=2**(8*o)-1;for(;;){let p=this.readAtomically(()=>{let x=this.readChar();if(x===void 0)return;let m=Number.parseInt(x,e);if(!Number.isNaN(m))return m});if(p===void 0)break;if(s*=e,s+=p,s>h||(i+=1,t!==void 0&&i>t))return}if(i!==0)return!n&&d&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let e=new Uint8Array(4);for(let t=0;t<e.length;t++){let n=this.readSeparator(".",t,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;e[t]=n}return e})}readIPv6Addr(){let e=t=>{for(let n=0;n<t.length/2;n++){let o=n*2;if(n<t.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return t[o]=i[0],t[o+1]=i[1],t[o+2]=i[2],t[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];t[o]=s>>8,t[o+1]=s&255}return[t.length,!1]};return this.readAtomically(()=>{let t=new Uint8Array(16),[n,o]=e(t);if(n===16)return t;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=e(s.subarray(0,i));return t.set(s.subarray(0,a),16-a),t})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Pi=new Te;var $i=parseInt("0xFFFF",16),Oi=new Uint8Array([0,0,0,0,0,0,0,0,0,0,255,255]);var hr=F("node:buffer");function lt(r,e="utf8"){let t=Ce[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return e==="utf8"||e==="utf-8"?se(hr.Buffer.from(r,"utf-8")):t.decoder.decode(`${t.prefix}${r}`)}var N=F("node:net");function Se(r){return!!(0,N.isIP)(r)}var mr=N.isIPv4,mo=N.isIPv6,ut=function(r){let e=0;if(r=r.toString().trim(),mr(r)){let t=new Uint8Array(e+4);return r.split(/\./g).forEach(n=>{t[e++]=parseInt(n,10)&255}),t}if(mo(r)){let t=r.split(":",8),n;for(n=0;n<t.length;n++){let s=mr(t[n]),i;s&&(i=ut(t[n]),t[n]=P(i.slice(0,2),"base16")),i!=null&&++n<8&&t.splice(n,0,P(i.slice(2,4),"base16"))}if(t[0]==="")for(;t.length<8;)t.unshift("0");else if(t[t.length-1]==="")for(;t.length<8;)t.push("0");else if(t.length<8){for(n=0;n<t.length&&t[n]!=="";n++);let s=[n,1];for(n=9-t.length;n>0;n--)s.push("0");t.splice.apply(t,s)}let o=new Uint8Array(e+16);for(n=0;n<t.length;n++){let s=parseInt(t[n],16);o[e++]=s>>8&255,o[e++]=s&255}return o}throw new Error("invalid ip address")},xr=function(r,e=0,t){e=~~e,t=t??r.length-e;let n=new DataView(r.buffer);if(t===4){let o=[];for(let s=0;s<t;s++)o.push(r[e+s]);return o.join(".")}if(t===16){let o=[];for(let s=0;s<t;s+=2)o.push(n.getUint16(e+s).toString(16));return o.join(":").replace(/(^|:)0(:0)*:0(:|$)/,"$1::$3").replace(/:{3,4}/,"::")}return""};var ce={},dt={},go=[[4,32,"ip4"],[6,16,"tcp"],[33,16,"dccp"],[41,128,"ip6"],[42,-1,"ip6zone"],[43,8,"ipcidr"],[53,-1,"dns",!0],[54,-1,"dns4",!0],[55,-1,"dns6",!0],[56,-1,"dnsaddr",!0],[132,16,"sctp"],[273,16,"udp"],[275,0,"p2p-webrtc-star"],[276,0,"p2p-webrtc-direct"],[277,0,"p2p-stardust"],[280,0,"webrtc-direct"],[281,0,"webrtc"],[290,0,"p2p-circuit"],[301,0,"udt"],[302,0,"utp"],[400,-1,"unix",!1,!0],[421,-1,"ipfs"],[421,-1,"p2p"],[443,0,"https"],[444,96,"onion"],[445,296,"onion3"],[446,-1,"garlic64"],[448,0,"tls"],[449,-1,"sni"],[460,0,"quic"],[461,0,"quic-v1"],[465,0,"webtransport"],[466,-1,"certhash"],[477,0,"ws"],[478,0,"wss"],[479,0,"p2p-websocket-star"],[480,0,"http"],[481,-1,"http-path"],[777,-1,"memory"]];go.forEach(r=>{let e=wo(...r);dt[e.code]=e,ce[e.name]=e});function wo(r,e,t,n,o){return{code:r,size:e,name:t,resolvable:!!n,path:!!o}}function v(r){if(typeof r=="number"){if(dt[r]!=null)return dt[r];throw new Error(`no protocol with code: ${r}`)}else if(typeof r=="string"){if(ce[r]!=null)return ce[r];throw new Error(`no protocol with name: ${r}`)}throw new Error(`invalid protocol id type: ${typeof r}`)}var Ac=v("ip4"),Cc=v("ip6"),Tc=v("ipcidr");function mt(r,e){switch(v(r).code){case 4:case 41:return vo(e);case 42:return ht(e);case 6:case 273:case 33:case 132:return br(e).toString();case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ht(e);case 421:return Ao(e);case 444:return wr(e);case 445:return wr(e);case 466:return Io(e);case 481:return globalThis.encodeURIComponent(ht(e));default:return P(e,"base16")}}function xt(r,e){switch(v(r).code){case 4:return gr(e);case 41:return gr(e);case 42:return ft(e);case 6:case 273:case 33:case 132:return gt(parseInt(e,10));case 53:case 54:case 55:case 56:case 400:case 449:case 777:return ft(e);case 421:return yo(e);case 444:return Co(e);case 445:return To(e);case 466:return Eo(e);case 481:return ft(globalThis.decodeURIComponent(e));default:return lt(e,"base16")}}var pt=Object.values(he).map(r=>r.decoder),bo=function(){let r=pt[0].or(pt[1]);return pt.slice(2).forEach(e=>r=r.or(e)),r}();function gr(r){if(!Se(r))throw new Error("invalid ip address");return ut(r)}function vo(r){let e=xr(r,0,r.length);if(e==null)throw new Error("ipBuff is required");if(!Se(e))throw new Error("invalid ip address");return e}function gt(r){let e=new ArrayBuffer(2);return new DataView(e).setUint16(0,r),new Uint8Array(e)}function br(r){return new DataView(r.buffer).getUint16(r.byteOffset)}function ft(r){let e=lt(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function ht(r){let e=Q(r);if(r=r.slice(z(e)),r.length!==e)throw new Error("inconsistent lengths");return P(r)}function yo(r){let e;r[0]==="Q"||r[0]==="1"?e=Ie(S.decode(`z${r}`)).bytes:e=W.parse(r).multihash.bytes;let t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Eo(r){let e=bo.decode(r),t=Uint8Array.from(ie(e.length));return R([t,e],t.length+e.length)}function Io(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return"u"+P(t,"base64url")}function Ao(r){let e=Q(r),t=r.slice(z(e));if(t.length!==e)throw new Error("inconsistent lengths");return P(t,"base58btc")}function Co(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==16)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion address.`);let t=_.decode("b"+e[0]),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=gt(n);return R([t,o],t.length+o.length)}function To(r){let e=r.split(":");if(e.length!==2)throw new Error(`failed to parse onion addr: ["'${e.join('", "')}'"]' does not contain a port number`);if(e[0].length!==56)throw new Error(`failed to parse onion addr: ${e[0]} not a Tor onion3 address.`);let t=_.decode(`b${e[0]}`),n=parseInt(e[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=gt(n);return R([t,o],t.length+o.length)}function wr(r){let e=r.slice(0,r.length-2),t=r.slice(r.length-2),n=P(e,"base32"),o=br(t);return`${n}:${o}`}function vr(r){r=wt(r);let e=[],t=[],n=null,o=r.split("/").slice(1);if(o.length===1&&o[0]==="")return{bytes:new Uint8Array,string:"/",tuples:[],stringTuples:[],path:null};for(let s=0;s<o.length;s++){let i=o[s],a=v(i);if(a.size===0){e.push([a.code]),t.push([a.code]);continue}if(s++,s>=o.length)throw Er("invalid address: "+r);if(a.path===!0){n=wt(o.slice(s).join("/")),e.push([a.code,xt(a.code,n)]),t.push([a.code,n]);break}let d=xt(a.code,o[s]);e.push([a.code,d]),t.push([a.code,mt(a.code,d)])}return{string:yr(t),bytes:vt(e),tuples:e,stringTuples:t,path:n}}function bt(r){let e=[],t=[],n=null,o=0;for(;o<r.length;){let s=Q(r,o),i=z(s),a=v(s),d=So(a,r.slice(o+i));if(d===0){e.push([s]),t.push([s]),o+=i;continue}let h=r.slice(o+i,o+i+d);if(o+=d+i,o>r.length)throw Er("Invalid address Uint8Array: "+P(r,"base16"));e.push([s,h]);let p=mt(s,h);if(t.push([s,p]),a.path===!0){n=p;break}}return{bytes:Uint8Array.from(r),string:yr(t),tuples:e,stringTuples:t,path:n}}function yr(r){let e=[];return r.map(t=>{let n=v(t[0]);return e.push(n.name),t.length>1&&t[1]!=null&&e.push(t[1]),null}),wt(e.join("/"))}function vt(r){return R(r.map(e=>{let t=v(e[0]),n=Uint8Array.from(ie(t.code));return e.length>1&&e[1]!=null&&(n=R([n,e[1]])),n}))}function So(r,e){if(r.size>0)return r.size/8;if(r.size===0)return 0;{let t=Q(e instanceof Uint8Array?e:Uint8Array.from(e));return t+z(t)}}function wt(r){return"/"+r.trim().split("/").filter(e=>e).join("/")}function Er(r){return new Error("Error parsing address: "+r)}var Po=Symbol.for("nodejs.util.inspect.custom"),Et=Symbol.for("@multiformats/js-multiaddr/multiaddr"),Lo=[v("dns").code,v("dns4").code,v("dns6").code,v("dnsaddr").code],yt=class extends Error{constructor(e="No available resolver"){super(e),this.name="NoAvailableResolverError"}},Pe=class r{bytes;#e;#t;#r;#n;[Et]=!0;constructor(e){e==null&&(e="");let t;if(e instanceof Uint8Array)t=bt(e);else if(typeof e=="string"){if(e.length>0&&e.charAt(0)!=="/")throw new Error(`multiaddr "${e}" must start with a "/"`);t=vr(e)}else if(Ar(e))t=bt(e.bytes);else throw new Error("addr must be a string, Buffer, or another Multiaddr");this.bytes=t.bytes,this.#e=t.string,this.#t=t.tuples,this.#r=t.stringTuples,this.#n=t.path}toString(){return this.#e}toJSON(){return this.toString()}toOptions(){let e,t,n,o,s="",i=v("tcp"),a=v("udp"),d=v("ip4"),h=v("ip6"),p=v("dns6"),x=v("ip6zone");for(let[u,f]of this.stringTuples())u===x.code&&(s=`%${f??""}`),Lo.includes(u)&&(t=i.name,o=443,n=`${f??""}${s}`,e=u===p.code?6:4),(u===i.code||u===a.code)&&(t=v(u).name,o=parseInt(f??"")),(u===d.code||u===h.code)&&(t=v(u).name,n=`${f??""}${s}`,e=u===h.code?6:4);if(e==null||t==null||n==null||o==null)throw new Error('multiaddr must have a valid format: "/{ip4, ip6, dns4, dns6, dnsaddr}/{address}/{tcp, udp}/{port}".');return{family:e,host:n,transport:t,port:o}}protos(){return this.#t.map(([e])=>Object.assign({},v(e)))}protoCodes(){return this.#t.map(([e])=>e)}protoNames(){return this.#t.map(([e])=>v(e).name)}tuples(){return this.#t}stringTuples(){return this.#r}encapsulate(e){return e=new r(e),new r(this.toString()+e.toString())}decapsulate(e){let t=e.toString(),n=this.toString(),o=n.lastIndexOf(t);if(o<0)throw new Error(`Address ${this.toString()} does not contain subaddress: ${e.toString()}`);return new r(n.slice(0,o))}decapsulateCode(e){let t=this.tuples();for(let n=t.length-1;n>=0;n--)if(t[n][0]===e)return new r(vt(t.slice(0,n)));return this}getPeerId(){try{let e=[];this.stringTuples().forEach(([n,o])=>{n===ce.p2p.code&&e.push([n,o]),n===ce["p2p-circuit"].code&&(e=[])});let t=e.pop();if(t?.[1]!=null){let n=t[1];return n[0]==="Q"||n[0]==="1"?P(S.decode(`z${n}`),"base58btc"):P(W.parse(n).multihash.bytes,"base58btc")}return null}catch{return null}}getPath(){return this.#n}equals(e){return tr(this.bytes,e.bytes)}async resolve(e){let t=this.protos().find(s=>s.resolvable);if(t==null)return[this];let n=Ir.get(t.name);if(n==null)throw new yt(`no available resolver for ${t.name}`);return(await n(this,e)).map(s=>$(s))}nodeAddress(){let e=this.toOptions();if(e.transport!=="tcp"&&e.transport!=="udp")throw new Error(`multiaddr must have a valid format - no protocol with name: "${e.transport}". Must have a valid transport protocol: "{tcp, udp}"`);return{family:e.family,address:e.host,port:e.port}}isThinWaistAddress(e){let t=(e??this).protos();return!(t.length!==2||t[0].code!==4&&t[0].code!==41||t[1].code!==6&&t[1].code!==273)}[Po](){return`Multiaddr(${this.#e})`}};var Ir=new Map;function Ar(r){return!!r?.[Et]}function $(r){return new Pe(r)}var Do=c("dns4"),ko=c("dns6"),Mo=c("dnsaddr"),K=E(c("dns"),Mo,Do,ko),ke=E(c("ip4"),c("ip6")),H=E(l(ke,c("tcp")),l(K,c("tcp"))),Me=l(ke,c("udp")),No=l(Me,c("utp")),Uo=l(Me,c("quic")),Fo=l(Me,c("quic-v1")),It=E(l(H,c("ws")),l(K,c("ws"))),Le=E(l(It,c("p2p")),It),At=E(l(H,c("wss")),l(K,c("wss")),l(H,c("tls"),c("ws")),l(K,c("tls"),c("ws"))),De=E(l(At,c("p2p")),At),Ct=E(l(H,c("http")),l(ke,c("http")),l(K,c("http"))),Tt=E(l(H,c("https")),l(ke,c("https")),l(K,c("https"))),Cr=l(Me,c("webrtc-direct"),c("certhash")),Pr=E(l(Cr,c("p2p")),Cr),Tr=l(Fo,c("webtransport"),c("certhash"),c("certhash")),Lr=E(l(Tr,c("p2p")),Tr),Dr=E(l(Le,c("p2p-webrtc-star"),c("p2p")),l(De,c("p2p-webrtc-star"),c("p2p")),l(Le,c("p2p-webrtc-star")),l(De,c("p2p-webrtc-star"))),Kc=E(l(Le,c("p2p-websocket-star"),c("p2p")),l(De,c("p2p-websocket-star"),c("p2p")),l(Le,c("p2p-websocket-star")),l(De,c("p2p-websocket-star"))),kr=E(l(Ct,c("p2p-webrtc-direct"),c("p2p")),l(Tt,c("p2p-webrtc-direct"),c("p2p")),l(Ct,c("p2p-webrtc-direct")),l(Tt,c("p2p-webrtc-direct"))),Y=E(It,At,Ct,Tt,Dr,kr,H,No,Uo,K,Pr,Lr),Yc=E(l(Y,c("p2p-stardust"),c("p2p")),l(Y,c("p2p-stardust"))),G=E(l(Y,c("p2p")),Dr,kr,Pr,Lr,c("p2p")),Sr=E(l(G,c("p2p-circuit"),G),l(G,c("p2p-circuit")),l(c("p2p-circuit"),G),l(Y,c("p2p-circuit")),l(c("p2p-circuit"),Y),c("p2p-circuit")),Mr=()=>E(l(Sr,Mr),Sr),X=Mr(),Zc=E(l(X,G,X),l(G,X),l(X,G),X,G);var ea=E(l(X,c("webrtc"),c("p2p")),l(X,c("webrtc")),l(Y,c("webrtc"),c("p2p")),l(Y,c("webrtc")),c("webrtc"));function Nr(r){function e(t){let n;try{n=$(t)}catch{return!1}let o=r(n.protoNames());return o===null?!1:o===!0||o===!1?o:o.length===0}return e}function l(...r){function e(t){if(t.length<r.length)return null;let n=t;return r.some(o=>(n=typeof o=="function"?o().partialMatch(t):o.partialMatch(t),Array.isArray(n)&&(t=n),n===null)),n}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Nr(e),partialMatch:e}}function E(...r){function e(n){let o=null;return r.some(s=>{let i=typeof s=="function"?s().partialMatch(n):s.partialMatch(n);return i!=null?(o=i,!0):!1}),o}return{toString:function(){return"{ "+r.join(" ")+" }"},input:r,matches:Nr(e),partialMatch:e}}function c(r){let e=r;function t(o){let s;try{s=$(o)}catch{return!1}let i=s.protoNames();return i.length===1&&i[0]===e}function n(o){return o.length===0?null:o[0]===e?o.slice(1):null}return{toString:function(){return e},matches:t,partialMatch:n}}var Ne=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var Br=le(F("net"),1);var St=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Pt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ur=r=>globalThis.DOMException===void 0?new Pt(r):new DOMException(r),Fr=r=>{let e=r.reason===void 0?Ur("This operation was aborted."):r.reason;return e instanceof Error?e:Ur(e)};function Lt(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,d=new Promise((h,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&p(Fr(m));let u=()=>{p(Fr(m))};m.addEventListener("abort",u,{once:!0}),r.finally(()=>{m.removeEventListener("abort",u)})}if(t===Number.POSITIVE_INFINITY){r.then(h,p);return}let x=new St;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(m){p(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?p(o):(x.message=o??`Promise timed out after ${t} milliseconds`,p(x))},t),(async()=>{try{h(await r)}catch(m){p(m)}})()}).finally(()=>{d.clear()});return d.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},d}var Oo=r=>{let e=r.addEventListener||r.on||r.addListener,t=r.removeEventListener||r.off||r.removeListener;if(!e||!t)throw new TypeError("Emitter is not compatible");return{addListener:e.bind(r),removeListener:t.bind(r)}};function Vo(r,e,t){let n,o=new Promise((s,i)=>{if(t={rejectionEvents:["error"],multiArgs:!1,resolveImmediately:!1,...t},!(t.count>=0&&(t.count===Number.POSITIVE_INFINITY||Number.isInteger(t.count))))throw new TypeError("The `count` option should be at least 0 or more");t.signal?.throwIfAborted();let a=[e].flat(),d=[],{addListener:h,removeListener:p}=Oo(r),x=(...u)=>{let f=t.multiArgs?u:u[0];t.filter&&!t.filter(f)||(d.push(f),t.count===d.length&&(n(),s(d)))},m=u=>{n(),i(u)};n=()=>{for(let u of a)p(u,x);for(let u of t.rejectionEvents)p(u,m)};for(let u of a)h(u,x);for(let u of t.rejectionEvents)h(u,m);t.signal&&t.signal.addEventListener("abort",()=>{m(t.signal.reason)},{once:!0}),t.resolveImmediately&&s(d)});if(o.cancel=n,typeof t.timeout=="number"){let s=Lt(o,{milliseconds:t.timeout});return s.cancel=n,s}return o}function Dt(r,e,t){typeof t=="function"&&(t={filter:t}),t={...t,count:1,resolveImmediately:!1};let n=Vo(r,e,t),o=n.then(s=>s[0]);return o.cancel=n.cancel,o}function $r(r,e){if(typeof r!="string")throw new V(`invalid ip provided: ${r}`);if(typeof e=="string"&&(e=parseInt(e)),isNaN(e))throw new V(`invalid port provided: ${e}`);if((0,N.isIPv4)(r))return $(`/ip4/${r}/tcp/${e}`);if((0,N.isIPv6)(r))return $(`/ip6/${r}/tcp/${e}`);throw new V(`invalid ip:port for creating a multiaddr: ${r}:${e}`)}function kt(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var Mt=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.name="AbortError",this.code=t??"ABORT_ERR"}};async function Nt(r,e,t,n){let o=new Mt(n?.errorMessage,n?.errorCode);return t?.aborted===!0?Promise.reject(o):new Promise((s,i)=>{function a(){t?.removeEventListener("abort",p),r.removeEventListener(e,d),n?.errorEvent!=null&&r.removeEventListener(n.errorEvent,h)}let d=x=>{try{if(n?.filter?.(x)===!1)return}catch(m){a(),i(m);return}a(),s(x)},h=x=>{a(),i(x.detail)},p=()=>{a(),i(o)};t?.addEventListener("abort",p),r.addEventListener(e,d),n?.errorEvent!=null&&r.addEventListener(n.errorEvent,h)})}function Or(r){if(Bo(r))return async function*(){let e=r.getReader();try{for(;;){let{done:t,value:n}=await e.read();if(t)return;yield n}}finally{e.releaseLock()}}();if(zo(r))return r;throw new Error("unknown stream")}function zo(r){return r[Symbol.asyncIterator]!=null}function Bo(r){return typeof r?.getReader=="function"}function Vr(r){return async e=>{let t=async()=>{_o(e)&&await e.return(void 0)},n,o,s=g=>{n=g,t().catch(b=>{b=new AggregateError([n,b],"The Writable emitted an error, additionally an error occurred while ending the Source")}).finally(()=>{o?.(g)})},i,a=!1,d=()=>{a=!0,i?.()},h,p=!1,x=()=>{p=!0,h?.()},m,u=()=>{m?.()},f=async()=>new Promise((g,b)=>{i=m=g,o=b,r.once("drain",u)}),I=async()=>(await t(),new Promise((g,b)=>{if(a||p||n!=null){g();return}h=i=g,o=b})),T=()=>{r.removeListener("error",s),r.removeListener("close",d),r.removeListener("finish",x),r.removeListener("drain",u)};r.once("error",s),r.once("close",d),r.once("finish",x);try{for await(let g of e){if(!r.writable||r.destroyed||n!=null)break;r.write(g)||await f()}}catch(g){n==null&&r.destroy(g),n=g}try{if(r.writable&&r.end(),await I(),n!=null)throw n}finally{T()}}}function _o(r){return r.return!=null}function Ut(r){return{sink:Vr(r),source:Or(r)}}var Ft=le(F("os"),1),zr=le(F("path"),1);var Ro={ip4:"IPv4",ip6:"IPv6"};function ae(r,e={}){let t=r.getPath();return t!=null?Ft.default.platform()==="win32"?{path:zr.default.join("\\\\.\\pipe\\",t)}:{path:t}:{...e,...r.toOptions()}}function $t(r,e,t){let n=o=>$(`/${r}/${o}/tcp/${t}`);return(jo(e)?Wo(Ro[r]):[e]).map(n)}function jo(r){return["0.0.0.0","::"].includes(r)}var qo=Ft.default.networkInterfaces();function Wo(r){let e=[];for(let[,t]of Object.entries(qo))if(t!=null)for(let n of t)n.family===r&&e.push(n.address);return e}var Ue=(r,e)=>{let t,n=e.logger.forComponent("libp2p:tcp:socket"),o=e.direction,s=e.metrics,i=e.metricPrefix??"",a=e.socketInactivityTimeout??12e4,d=e.socketCloseTimeout??500,h=!1,p=!1;e.listeningAddr?.getPath()!=null&&(e.remoteAddr=e.listeningAddr),e.remoteAddr?.getPath()!=null&&(e.localAddr=e.remoteAddr),r.on("error",g=>{p=!0,h||(n.error("%s socket error - %e",o,g),s?.increment({[`${i}error`]:!0})),r.destroy(),T.timeline.close=Date.now()});let x;if(e.remoteAddr!=null)x=e.remoteAddr;else{if(r.remoteAddress==null||r.remotePort==null)throw new V("Could not determine remote address or port");x=$r(r.remoteAddress,r.remotePort)}let m=ae(x),u=m.path??`${m.host??""}:${m.port??""}`,{sink:f,source:I}=Ut(r);r.setTimeout(a),r.once("timeout",()=>{h=!0,n("%s %s socket read timeout",o,u),s?.increment({[`${i}timeout`]:!0}),r.destroy(new Z),T.timeline.close=Date.now()}),r.once("close",()=>{!h&&!p&&(n("%s %s socket close",o,u),s?.increment({[`${i}close`]:!0})),r.destroy(),T.timeline.close=Date.now()}),r.once("end",()=>{n("%s %s socket end",o,u),s?.increment({[`${i}end`]:!0})});let T={async sink(g){try{await f(async function*(){for await(let b of g)b instanceof Uint8Array?yield b:yield b.subarray()}())}catch(b){b.type!=="aborted"&&n.error("%s %s error in sink - %e",o,u,b)}r.end()},source:I,remoteAddr:x,timeline:{open:Date.now()},async close(g={}){if(r.closed){n("the %s %s socket is already closed",o,u);return}if(r.destroyed){n("the %s %s socket is already destroyed",o,u);return}if(t!=null)return t.promise;try{t=kt(),r.end();let b=Go(r),L=g.signal??AbortSignal.timeout(d);r.writableLength>0&&(n("%s %s draining socket",o,u),await Nt(b,"drain",L,{errorEvent:"error"}),n("%s %s socket drained",o,u)),await Promise.all([Nt(b,"close",L,{errorEvent:"error"}),r.destroy()])}catch(b){this.abort(b)}finally{t.resolve()}},abort:g=>{n("%s %s socket abort due to error - %e",o,u,g),r.destroy(),T.timeline.close=Date.now()},log:n};return T};function Go(r){return{addEventListener:(t,n)=>{r.addListener(t,n)},removeEventListener:(t,n)=>{r.removeListener(t,n)}}}var A;(function(r){r[r.INACTIVE=0]="INACTIVE",r[r.ACTIVE=1]="ACTIVE",r[r.PAUSED=2]="PAUSED"})(A||(A={}));var Fe=class extends ye{context;server;sockets=new Set;status={code:A.INACTIVE};metrics;addr;log;shutdownController;constructor(e){if(super(),this.context=e,e.keepAlive=e.keepAlive??!0,e.noDelay=e.noDelay??!0,this.shutdownController=new AbortController,ve(1/0,this.shutdownController.signal),this.log=e.logger.forComponent("libp2p:tcp:listener"),this.addr="unknown",this.server=Br.default.createServer(e,this.onSocket.bind(this)),e.maxConnections!==void 0&&(this.server.maxConnections=e.maxConnections),e.closeServerOnMaxConnections!=null&&e.closeServerOnMaxConnections.closeAbove<e.closeServerOnMaxConnections.listenBelow)throw new V("closeAbove must be >= listenBelow");this.server.on("listening",()=>{if(e.metrics!=null){let t=this.server.address();t==null?this.addr="unknown":typeof t=="string"?this.addr=t:this.addr=`${t.address}:${t.port}`,e.metrics?.registerMetricGroup("libp2p_tcp_inbound_connections_total",{label:"address",help:"Current active connections in TCP listener",calculate:()=>({[this.addr]:this.sockets.size})}),this.metrics={status:e.metrics.registerMetricGroup("libp2p_tcp_listener_status_info",{label:"address",help:"Current status of the TCP listener socket"}),errors:e.metrics.registerMetricGroup("libp2p_tcp_listener_errors_total",{label:"address",help:"Total count of TCP listener errors by type"}),events:e.metrics.registerMetricGroup("libp2p_tcp_listener_events_total",{label:"address",help:"Total count of TCP listener events by type"})},this.metrics?.status.update({[this.addr]:A.ACTIVE})}this.safeDispatchEvent("listening")}).on("error",t=>{this.metrics?.errors.increment({[`${this.addr} listen_error`]:!0}),this.safeDispatchEvent("error",{detail:t})}).on("close",()=>{this.metrics?.status.update({[this.addr]:this.status.code}),this.status.code!==A.PAUSED&&this.safeDispatchEvent("close")}).on("drop",()=>{this.metrics?.events.increment({[`${this.addr} drop`]:!0})})}onSocket(e){if(this.metrics?.events.increment({[`${this.addr} connection`]:!0}),this.status.code!==A.ACTIVE)throw e.destroy(),new we("Server is not listening yet");let t;try{t=Ue(e,{listeningAddr:this.status.listeningAddr,socketInactivityTimeout:this.context.socketInactivityTimeout,socketCloseTimeout:this.context.socketCloseTimeout,metrics:this.metrics?.events,metricPrefix:`${this.addr} `,logger:this.context.logger,direction:"inbound"})}catch(n){this.log.error("inbound connection failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_to_connection`]:!0}),e.destroy();return}this.log("new inbound connection %s",t.remoteAddr),this.sockets.add(e),this.context.upgrader.upgradeInbound(t,{signal:this.shutdownController.signal}).then(n=>{this.log("inbound connection upgraded %s",t.remoteAddr),e.once("close",()=>{this.sockets.delete(e),this.context.closeServerOnMaxConnections!=null&&this.sockets.size<this.context.closeServerOnMaxConnections.listenBelow&&this.resume().catch(o=>{this.log.error("error attempting to listen server once connection count under limit",o),this.context.closeServerOnMaxConnections?.onListenError?.(o)})}),this.context.handler!=null&&this.context.handler(n),this.context.closeServerOnMaxConnections!=null&&this.sockets.size>=this.context.closeServerOnMaxConnections.closeAbove&&this.pause(),this.safeDispatchEvent("connection",{detail:n})}).catch(async n=>{this.log.error("inbound connection upgrade failed",n),this.metrics?.errors.increment({[`${this.addr} inbound_upgrade`]:!0}),this.sockets.delete(e),t.abort(n)})}getAddrs(){if(this.status.code===A.INACTIVE)return[];let e=[],t=this.server.address(),{listeningAddr:n,peerId:o}=this.status;if(t==null)return[];if(typeof t=="string")e=[n];else try{n.toString().startsWith("/ip4")?e=e.concat($t("ip4",t.address,t.port)):t.family==="IPv6"&&(e=e.concat($t("ip6",t.address,t.port)))}catch(s){this.log.error("could not turn %s:%s into multiaddr",t.address,t.port,s)}return e.map(s=>o!=null?s.encapsulate(`/p2p/${o}`):s)}async listen(e){if(this.status.code===A.ACTIVE||this.status.code===A.PAUSED)throw new be("server is already listening");let t=e.getPeerId(),n=t==null?e.decapsulateCode(421):e,{backlog:o}=this.context;try{this.status={code:A.ACTIVE,listeningAddr:n,peerId:t,netConfig:ae(n,{backlog:o})},await this.resume()}catch(s){throw this.status={code:A.INACTIVE},s}}async close(){let e=[];this.server.listening&&e.push(Dt(this.server,"close")),this.pause(!0),this.shutdownController.abort(),this.sockets.forEach(t=>{t.readable&&(e.push(Dt(t,"close")),t.destroy())}),await Promise.all(e)}async resume(){if(this.server.listening||this.status.code===A.INACTIVE)return;let e=this.status.netConfig;await new Promise((t,n)=>{this.server.once("error",n),this.server.listen(e,t)}),this.status={...this.status,code:A.ACTIVE},this.log("listening on %s",this.server.address())}pause(e=!1){if(!this.server.listening&&this.status.code===A.PAUSED&&e){this.status={code:A.INACTIVE};return}!this.server.listening||this.status.code!==A.ACTIVE||(this.log("closing server on %s",this.server.address()),this.status=e?{code:A.INACTIVE}:{...this.status,code:A.PAUSED},this.server.close())}};var $e=class{opts;metrics;components;log;constructor(e,t={}){this.log=e.logger.forComponent("libp2p:tcp"),this.opts=t,this.components=e,e.metrics!=null&&(this.metrics={events:e.metrics.registerCounterGroup("libp2p_tcp_dialer_events_total",{label:"event",help:"Total count of TCP dialer events by type"}),errors:e.metrics.registerCounterGroup("libp2p_tcp_dialer_errors_total",{label:"event",help:"Total count of TCP dialer events by type"})})}[zt]=!0;[Symbol.toStringTag]="@libp2p/tcp";[_t]=["@libp2p/transport"];async dial(e,t){t.keepAlive=t.keepAlive??!0,t.noDelay=t.noDelay??!0;let n=await this._connect(e,t),o;try{o=Ue(n,{remoteAddr:e,socketInactivityTimeout:this.opts.outboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.metrics?.events,logger:this.components.logger,direction:"outbound"})}catch(s){throw this.metrics?.errors.increment({outbound_to_connection:!0}),n.destroy(s),s}try{return this.log("new outbound connection %s",o.remoteAddr),await t.upgrader.upgradeOutbound(o,t)}catch(s){throw this.metrics?.errors.increment({outbound_upgrade:!0}),this.log.error("error upgrading outbound connection",s),o.abort(s),s}}async _connect(e,t){t.signal?.throwIfAborted(),t.onProgress?.(new Ne("tcp:open-connection"));let n;return new Promise((o,s)=>{let i=Date.now(),a=ae(e,{...this.opts.dialOpts??{},...t});this.log("dialing %a",e),n=_r.default.connect(a);let d=u=>{this.log.error("dial to %a errored - %e",e,u);let f=a.path??`${a.host??""}:${a.port}`;u.message=`connection error ${f}: ${u.message}`,this.metrics?.events.increment({error:!0}),m(u)},h=()=>{this.log("connection timeout %a",e),this.metrics?.events.increment({timeout:!0});let u=new Z(`Connection timeout after ${Date.now()-i}ms`);n.emit("error",u)},p=()=>{this.log("connection opened %a",e),this.metrics?.events.increment({connect:!0}),m()},x=()=>{this.log("connection aborted %a",e),this.metrics?.events.increment({abort:!0}),m(new ge)},m=u=>{if(n.removeListener("error",d),n.removeListener("timeout",h),n.removeListener("connect",p),t.signal!=null&&t.signal.removeEventListener("abort",x),u!=null){s(u);return}o(n)};n.on("error",d),n.on("timeout",h),n.on("connect",p),t.signal!=null&&t.signal.addEventListener("abort",x)}).catch(o=>{throw n?.destroy(),o})}createListener(e){return new Fe({...this.opts.listenOpts??{},...e,maxConnections:this.opts.maxConnections,backlog:this.opts.backlog,closeServerOnMaxConnections:this.opts.closeServerOnMaxConnections,socketInactivityTimeout:this.opts.inboundSocketInactivityTimeout,socketCloseTimeout:this.opts.socketCloseTimeout,metrics:this.components.metrics,logger:this.components.logger})}listenFilter(e){return e=Array.isArray(e)?e:[e],e.filter(t=>t.protoCodes().includes(290)?!1:t.protoCodes().includes(400)?!0:H.matches(t.decapsulateCode(421)))}dialFilter(e){return this.listenFilter(e)}};function Jo(r={}){return e=>new $e(e,r)}return Hr(Qo);})();
|
|
3
3
|
return Libp2PTcp}));
|
package/dist/src/listener.d.ts
CHANGED
|
@@ -35,12 +35,13 @@ export interface TCPListenerMetrics {
|
|
|
35
35
|
export declare class TCPListener extends TypedEventEmitter<ListenerEvents> implements Listener {
|
|
36
36
|
private readonly context;
|
|
37
37
|
private readonly server;
|
|
38
|
-
/** Keep track of open
|
|
39
|
-
private readonly
|
|
38
|
+
/** Keep track of open sockets to destroy in case of timeout */
|
|
39
|
+
private readonly sockets;
|
|
40
40
|
private status;
|
|
41
41
|
private metrics?;
|
|
42
42
|
private addr;
|
|
43
43
|
private readonly log;
|
|
44
|
+
private readonly shutdownController;
|
|
44
45
|
constructor(context: Context);
|
|
45
46
|
private onSocket;
|
|
46
47
|
getAddrs(): Multiaddr[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../src/listener.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../src/listener.ts"],"names":[],"mappings":"AACA,OAAO,EAAgE,iBAAiB,EAAmB,MAAM,mBAAmB,CAAA;AASpI,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAA+B,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACzK,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IAEnB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,aAAa,CAAC,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,CAAA;CACjC;AAED,UAAU,OAAQ,SAAQ,wBAAwB;IAChD,OAAO,CAAC,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAA;IAChC,QAAQ,EAAE,QAAQ,CAAA;IAClB,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,2BAA2B,CAAC,EAAE,+BAA+B,CAAA;IAC7D,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAA;IACnB,MAAM,EAAE,YAAY,CAAA;IACpB,MAAM,EAAE,YAAY,CAAA;CACrB;AAqBD,qBAAa,WAAY,SAAQ,iBAAiB,CAAC,cAAc,CAAE,YAAW,QAAQ;IAUvE,OAAO,CAAC,QAAQ,CAAC,OAAO;IATrC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,MAAM,CAAmD;IACjE,OAAO,CAAC,OAAO,CAAC,CAAoB;IACpC,OAAO,CAAC,IAAI,CAAQ;IACpB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAiB;gBAEtB,OAAO,EAAE,OAAO;IAiG9C,OAAO,CAAC,QAAQ;IA4EhB,QAAQ,IAAK,SAAS,EAAE;IAgClB,MAAM,CAAE,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBrC,KAAK,IAAK,OAAO,CAAC,IAAI,CAAC;IAyB7B;;OAEG;YACW,MAAM;IAkBpB,OAAO,CAAC,KAAK;CAmCd"}
|
package/dist/src/listener.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import net from 'net';
|
|
2
|
-
import {
|
|
2
|
+
import { AlreadyStartedError, InvalidParametersError, NotStartedError, TypedEventEmitter, setMaxListeners } from '@libp2p/interface';
|
|
3
|
+
import { pEvent } from 'p-event';
|
|
3
4
|
import { CODE_P2P } from './constants.js';
|
|
4
5
|
import { toMultiaddrConnection } from './socket-to-conn.js';
|
|
5
6
|
import { getMultiaddrs, multiaddrToNetConfig } from './utils.js';
|
|
@@ -18,17 +19,20 @@ var TCPListenerStatusCode;
|
|
|
18
19
|
export class TCPListener extends TypedEventEmitter {
|
|
19
20
|
context;
|
|
20
21
|
server;
|
|
21
|
-
/** Keep track of open
|
|
22
|
-
|
|
22
|
+
/** Keep track of open sockets to destroy in case of timeout */
|
|
23
|
+
sockets = new Set();
|
|
23
24
|
status = { code: TCPListenerStatusCode.INACTIVE };
|
|
24
25
|
metrics;
|
|
25
26
|
addr;
|
|
26
27
|
log;
|
|
28
|
+
shutdownController;
|
|
27
29
|
constructor(context) {
|
|
28
30
|
super();
|
|
29
31
|
this.context = context;
|
|
30
32
|
context.keepAlive = context.keepAlive ?? true;
|
|
31
33
|
context.noDelay = context.noDelay ?? true;
|
|
34
|
+
this.shutdownController = new AbortController();
|
|
35
|
+
setMaxListeners(Infinity, this.shutdownController.signal);
|
|
32
36
|
this.log = context.logger.forComponent('libp2p:tcp:listener');
|
|
33
37
|
this.addr = 'unknown';
|
|
34
38
|
this.server = net.createServer(context, this.onSocket.bind(this));
|
|
@@ -65,7 +69,7 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
65
69
|
help: 'Current active connections in TCP listener',
|
|
66
70
|
calculate: () => {
|
|
67
71
|
return {
|
|
68
|
-
[this.addr]: this.
|
|
72
|
+
[this.addr]: this.sockets.size
|
|
69
73
|
};
|
|
70
74
|
}
|
|
71
75
|
});
|
|
@@ -134,14 +138,16 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
134
138
|
return;
|
|
135
139
|
}
|
|
136
140
|
this.log('new inbound connection %s', maConn.remoteAddr);
|
|
137
|
-
this.
|
|
141
|
+
this.sockets.add(socket);
|
|
142
|
+
this.context.upgrader.upgradeInbound(maConn, {
|
|
143
|
+
signal: this.shutdownController.signal
|
|
144
|
+
})
|
|
138
145
|
.then((conn) => {
|
|
139
146
|
this.log('inbound connection upgraded %s', maConn.remoteAddr);
|
|
140
|
-
this.connections.add(maConn);
|
|
141
147
|
socket.once('close', () => {
|
|
142
|
-
this.
|
|
148
|
+
this.sockets.delete(socket);
|
|
143
149
|
if (this.context.closeServerOnMaxConnections != null &&
|
|
144
|
-
this.
|
|
150
|
+
this.sockets.size < this.context.closeServerOnMaxConnections.listenBelow) {
|
|
145
151
|
// The most likely case of error is if the port taken by this
|
|
146
152
|
// application is bound by another process during the time the
|
|
147
153
|
// server if closed. In that case there's not much we can do.
|
|
@@ -158,16 +164,15 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
158
164
|
this.context.handler(conn);
|
|
159
165
|
}
|
|
160
166
|
if (this.context.closeServerOnMaxConnections != null &&
|
|
161
|
-
this.
|
|
162
|
-
this.pause(
|
|
163
|
-
this.log.error('error attempting to close server once connection count over limit', e);
|
|
164
|
-
});
|
|
167
|
+
this.sockets.size >= this.context.closeServerOnMaxConnections.closeAbove) {
|
|
168
|
+
this.pause();
|
|
165
169
|
}
|
|
166
170
|
this.safeDispatchEvent('connection', { detail: conn });
|
|
167
171
|
})
|
|
168
172
|
.catch(async (err) => {
|
|
169
173
|
this.log.error('inbound connection upgrade failed', err);
|
|
170
174
|
this.metrics?.errors.increment({ [`${this.addr} inbound_upgrade`]: true });
|
|
175
|
+
this.sockets.delete(socket);
|
|
171
176
|
maConn.abort(err);
|
|
172
177
|
});
|
|
173
178
|
}
|
|
@@ -223,13 +228,23 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
223
228
|
}
|
|
224
229
|
}
|
|
225
230
|
async close() {
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
});
|
|
231
|
+
const events = [];
|
|
232
|
+
if (this.server.listening) {
|
|
233
|
+
events.push(pEvent(this.server, 'close'));
|
|
234
|
+
}
|
|
231
235
|
// shut down the server socket, permanently
|
|
232
|
-
|
|
236
|
+
this.pause(true);
|
|
237
|
+
// stop any in-progress connection upgrades
|
|
238
|
+
this.shutdownController.abort();
|
|
239
|
+
// synchronously close any open connections - should be done after closing
|
|
240
|
+
// the server socket in case new sockets are opened during the shutdown
|
|
241
|
+
this.sockets.forEach(socket => {
|
|
242
|
+
if (socket.readable) {
|
|
243
|
+
events.push(pEvent(socket, 'close'));
|
|
244
|
+
socket.destroy();
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
await Promise.all(events);
|
|
233
248
|
}
|
|
234
249
|
/**
|
|
235
250
|
* Can resume a stopped or start an inert server
|
|
@@ -248,7 +263,7 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
248
263
|
this.status = { ...this.status, code: TCPListenerStatusCode.ACTIVE };
|
|
249
264
|
this.log('listening on %s', this.server.address());
|
|
250
265
|
}
|
|
251
|
-
|
|
266
|
+
pause(permanent = false) {
|
|
252
267
|
if (!this.server.listening && this.status.code === TCPListenerStatusCode.PAUSED && permanent) {
|
|
253
268
|
this.status = { code: TCPListenerStatusCode.INACTIVE };
|
|
254
269
|
return;
|
|
@@ -271,15 +286,11 @@ export class TCPListener extends TypedEventEmitter {
|
|
|
271
286
|
// We need to set this status before closing server, so other procedures are aware
|
|
272
287
|
// during the time the server is closing
|
|
273
288
|
this.status = permanent ? { code: TCPListenerStatusCode.INACTIVE } : { ...this.status, code: TCPListenerStatusCode.PAUSED };
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
resolve();
|
|
281
|
-
});
|
|
282
|
-
});
|
|
289
|
+
// stop accepting incoming connections - existing connections are maintained
|
|
290
|
+
// - any callback passed here would be invoked after existing connections
|
|
291
|
+
// close, we want to maintain them so no callback is passed otherwise his
|
|
292
|
+
// method will never return
|
|
293
|
+
this.server.close();
|
|
283
294
|
}
|
|
284
295
|
}
|
|
285
296
|
//# sourceMappingURL=listener.js.map
|
package/dist/src/listener.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"listener.js","sourceRoot":"","sources":["../../src/listener.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAA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
|
"name": "@libp2p/tcp",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.10",
|
|
4
4
|
"description": "A TCP transport for libp2p",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp#readme",
|
|
@@ -61,18 +61,19 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@libp2p/interface": "^2.1.3",
|
|
64
|
-
"@libp2p/utils": "^6.1.
|
|
64
|
+
"@libp2p/utils": "^6.1.2",
|
|
65
65
|
"@multiformats/mafmt": "^12.1.6",
|
|
66
66
|
"@multiformats/multiaddr": "^12.2.3",
|
|
67
67
|
"@types/sinon": "^17.0.3",
|
|
68
68
|
"p-defer": "^4.0.1",
|
|
69
|
+
"p-event": "^6.0.1",
|
|
69
70
|
"progress-events": "^1.0.0",
|
|
70
71
|
"race-event": "^1.3.0",
|
|
71
72
|
"stream-to-it": "^1.0.1"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
|
-
"@libp2p/interface-compliance-tests": "^6.1.
|
|
75
|
-
"@libp2p/logger": "^5.1.
|
|
75
|
+
"@libp2p/interface-compliance-tests": "^6.1.7",
|
|
76
|
+
"@libp2p/logger": "^5.1.2",
|
|
76
77
|
"aegir": "^44.0.1",
|
|
77
78
|
"it-all": "^3.0.6",
|
|
78
79
|
"it-pipe": "^3.0.1",
|
package/src/listener.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import net from 'net'
|
|
2
|
-
import {
|
|
2
|
+
import { AlreadyStartedError, InvalidParametersError, NotStartedError, TypedEventEmitter, setMaxListeners } from '@libp2p/interface'
|
|
3
|
+
import { pEvent } from 'p-event'
|
|
3
4
|
import { CODE_P2P } from './constants.js'
|
|
4
5
|
import { toMultiaddrConnection } from './socket-to-conn.js'
|
|
5
6
|
import {
|
|
@@ -67,12 +68,13 @@ type Status = { code: TCPListenerStatusCode.INACTIVE } | {
|
|
|
67
68
|
|
|
68
69
|
export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Listener {
|
|
69
70
|
private readonly server: net.Server
|
|
70
|
-
/** Keep track of open
|
|
71
|
-
private readonly
|
|
71
|
+
/** Keep track of open sockets to destroy in case of timeout */
|
|
72
|
+
private readonly sockets = new Set<net.Socket>()
|
|
72
73
|
private status: Status = { code: TCPListenerStatusCode.INACTIVE }
|
|
73
74
|
private metrics?: TCPListenerMetrics
|
|
74
75
|
private addr: string
|
|
75
76
|
private readonly log: Logger
|
|
77
|
+
private readonly shutdownController: AbortController
|
|
76
78
|
|
|
77
79
|
constructor (private readonly context: Context) {
|
|
78
80
|
super()
|
|
@@ -80,6 +82,9 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
80
82
|
context.keepAlive = context.keepAlive ?? true
|
|
81
83
|
context.noDelay = context.noDelay ?? true
|
|
82
84
|
|
|
85
|
+
this.shutdownController = new AbortController()
|
|
86
|
+
setMaxListeners(Infinity, this.shutdownController.signal)
|
|
87
|
+
|
|
83
88
|
this.log = context.logger.forComponent('libp2p:tcp:listener')
|
|
84
89
|
this.addr = 'unknown'
|
|
85
90
|
this.server = net.createServer(context, this.onSocket.bind(this))
|
|
@@ -119,7 +124,7 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
119
124
|
help: 'Current active connections in TCP listener',
|
|
120
125
|
calculate: () => {
|
|
121
126
|
return {
|
|
122
|
-
[this.addr]: this.
|
|
127
|
+
[this.addr]: this.sockets.size
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
130
|
})
|
|
@@ -195,18 +200,20 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
195
200
|
}
|
|
196
201
|
|
|
197
202
|
this.log('new inbound connection %s', maConn.remoteAddr)
|
|
203
|
+
this.sockets.add(socket)
|
|
198
204
|
|
|
199
|
-
this.context.upgrader.upgradeInbound(maConn
|
|
205
|
+
this.context.upgrader.upgradeInbound(maConn, {
|
|
206
|
+
signal: this.shutdownController.signal
|
|
207
|
+
})
|
|
200
208
|
.then((conn) => {
|
|
201
209
|
this.log('inbound connection upgraded %s', maConn.remoteAddr)
|
|
202
|
-
this.connections.add(maConn)
|
|
203
210
|
|
|
204
211
|
socket.once('close', () => {
|
|
205
|
-
this.
|
|
212
|
+
this.sockets.delete(socket)
|
|
206
213
|
|
|
207
214
|
if (
|
|
208
215
|
this.context.closeServerOnMaxConnections != null &&
|
|
209
|
-
this.
|
|
216
|
+
this.sockets.size < this.context.closeServerOnMaxConnections.listenBelow
|
|
210
217
|
) {
|
|
211
218
|
// The most likely case of error is if the port taken by this
|
|
212
219
|
// application is bound by another process during the time the
|
|
@@ -227,11 +234,9 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
227
234
|
|
|
228
235
|
if (
|
|
229
236
|
this.context.closeServerOnMaxConnections != null &&
|
|
230
|
-
this.
|
|
237
|
+
this.sockets.size >= this.context.closeServerOnMaxConnections.closeAbove
|
|
231
238
|
) {
|
|
232
|
-
this.pause(
|
|
233
|
-
this.log.error('error attempting to close server once connection count over limit', e)
|
|
234
|
-
})
|
|
239
|
+
this.pause()
|
|
235
240
|
}
|
|
236
241
|
|
|
237
242
|
this.safeDispatchEvent('connection', { detail: conn })
|
|
@@ -239,6 +244,7 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
239
244
|
.catch(async err => {
|
|
240
245
|
this.log.error('inbound connection upgrade failed', err)
|
|
241
246
|
this.metrics?.errors.increment({ [`${this.addr} inbound_upgrade`]: true })
|
|
247
|
+
this.sockets.delete(socket)
|
|
242
248
|
maConn.abort(err)
|
|
243
249
|
})
|
|
244
250
|
}
|
|
@@ -300,15 +306,28 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
300
306
|
}
|
|
301
307
|
|
|
302
308
|
async close (): Promise<void> {
|
|
303
|
-
const
|
|
309
|
+
const events: Array<Promise<void>> = []
|
|
304
310
|
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
})
|
|
311
|
+
if (this.server.listening) {
|
|
312
|
+
events.push(pEvent(this.server, 'close'))
|
|
313
|
+
}
|
|
309
314
|
|
|
310
315
|
// shut down the server socket, permanently
|
|
311
|
-
|
|
316
|
+
this.pause(true)
|
|
317
|
+
|
|
318
|
+
// stop any in-progress connection upgrades
|
|
319
|
+
this.shutdownController.abort()
|
|
320
|
+
|
|
321
|
+
// synchronously close any open connections - should be done after closing
|
|
322
|
+
// the server socket in case new sockets are opened during the shutdown
|
|
323
|
+
this.sockets.forEach(socket => {
|
|
324
|
+
if (socket.readable) {
|
|
325
|
+
events.push(pEvent(socket, 'close'))
|
|
326
|
+
socket.destroy()
|
|
327
|
+
}
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
await Promise.all(events)
|
|
312
331
|
}
|
|
313
332
|
|
|
314
333
|
/**
|
|
@@ -332,7 +351,7 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
332
351
|
this.log('listening on %s', this.server.address())
|
|
333
352
|
}
|
|
334
353
|
|
|
335
|
-
private
|
|
354
|
+
private pause (permanent: boolean = false): void {
|
|
336
355
|
if (!this.server.listening && this.status.code === TCPListenerStatusCode.PAUSED && permanent) {
|
|
337
356
|
this.status = { code: TCPListenerStatusCode.INACTIVE }
|
|
338
357
|
return
|
|
@@ -361,15 +380,10 @@ export class TCPListener extends TypedEventEmitter<ListenerEvents> implements Li
|
|
|
361
380
|
// during the time the server is closing
|
|
362
381
|
this.status = permanent ? { code: TCPListenerStatusCode.INACTIVE } : { ...this.status, code: TCPListenerStatusCode.PAUSED }
|
|
363
382
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
resolve()
|
|
372
|
-
})
|
|
373
|
-
})
|
|
383
|
+
// stop accepting incoming connections - existing connections are maintained
|
|
384
|
+
// - any callback passed here would be invoked after existing connections
|
|
385
|
+
// close, we want to maintain them so no callback is passed otherwise his
|
|
386
|
+
// method will never return
|
|
387
|
+
this.server.close()
|
|
374
388
|
}
|
|
375
389
|
}
|