libp2p 0.46.7-13f5b48e → 0.46.7-24a5edae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -45,7 +45,7 @@
45
45
  (?:${Ve}:){1}(?:(?::${Ve}){0,4}:${Gt}|(?::${Ve}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
46
46
  (?::(?:(?::${Ve}){0,5}:${Gt}|(?::${Ve}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
47
47
  )(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
48
- `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),qv=new RegExp(`(?:^${Gt}$)|(?:^${oa}$)`),Vv=new RegExp(`^${Gt}$`),$v=new RegExp(`^${oa}$`),Rl=t=>t&&t.exact?qv:new RegExp(`(?:${Xr(t)}${Gt}${Xr(t)})|(?:${Xr(t)}${oa}${Xr(t)})`,"g");Rl.v4=t=>t&&t.exact?Vv:new RegExp(`${Xr(t)}${Gt}${Xr(t)}`,"g");Rl.v6=t=>t&&t.exact?$v:new RegExp(`${Xr(t)}${oa}${Xr(t)}`,"g");var Km=Rl;var zm=te(Vm(),1),{isValid:Hv,parse:zv}=zm.default,Gv=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Yv=Gv.map(t=>new Hm.Netmask(t));function Wv(t){for(let e of Yv)if(e.contains(t))return!0;return!1}function $m(t){return/^::$/.test(t)||/^::1$/.test(t)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}var Gm=t=>{if(Hv(t)){let e=zv(t);if(e.kind()==="ipv4")return Wv(e.toNormalizedString());if(e.kind()==="ipv6")return $m(t)}else if(wi(t)&&Km.v6().test(t))return $m(t)};var aa=Gm;function Ym(t={}){return{denyDialPeer:async()=>!1,denyDialMultiaddr:async e=>{let r=e.stringTuples();return r[0][0]===4||r[0][0]===41?!!aa(`${r[0][1]}`):!1},denyInboundConnection:async()=>!1,denyOutboundConnection:async()=>!1,denyInboundEncryptedConnection:async()=>!1,denyOutboundEncryptedConnection:async()=>!1,denyInboundUpgradedConnection:async()=>!1,denyOutboundUpgradedConnection:async()=>!1,filterMultiaddrForPeer:async()=>!0,...t}}var eL=Symbol.for("@libp2p/transport");var Zr;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(Zr||(Zr={}));function Cl(t){try{let{address:e}=t.nodeAddress();return!!aa(e)}catch{return!0}}function Ii(t,e){let r=Cl(t.multiaddr),n=Cl(e.multiaddr);return r&&!n?1:!r&&n||t.isCertified&&!e.isCertified?-1:!t.isCertified&&e.isCertified?1:0}var Bl=te(Tu(),1),Ll=te(Xm(),1);var Zm=globalThis.fetch,jm=globalThis.Headers,aL=globalThis.Request,cL=globalThis.Response;function ca(t,e,r){return`${t}?name=${e}&type=${r}`}async function Jm(t,e){return await(await Zm(t,{headers:new jm({accept:"application/dns-json"}),signal:e})).json()}function kn(t,e){return`${e}_${t}`}var Tl=Object.assign((0,Bl.default)("dns-over-http-resolver"),{error:(0,Bl.default)("dns-over-http-resolver:error")}),Pl=class{constructor(e={}){this._cache=new Ll.default({max:e?.maxCache??100}),this._TXTcache=new Ll.default({max:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??Jm,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>e.abort())}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let r=e.length-1;r>0;r--){let n=Math.floor(Math.random()*r),i=e[r];e[r]=e[n],e[n]=i}return e}setServers(e){this._servers=e}async resolve(e,r="A"){switch(r){case"A":return await this.resolve4(e);case"AAAA":return await this.resolve6(e);case"TXT":return await this.resolveTxt(e);default:throw new Error(`${r} is not supported`)}}async resolve4(e){let r="A",n=this._cache.get(kn(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ca(o,e,r),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(kn(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Tl.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}async resolve6(e){let r="AAAA",n=this._cache.get(kn(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ca(o,e,r),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(kn(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Tl.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}async resolveTxt(e){let r="TXT",n=this._TXTcache.get(kn(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ca(o,e,r),s.signal),c=a.Answer.map(l=>[l.data.replace(/['"]+/g,"")]),u=Math.min(...a.Answer.map(l=>l.TTL));return this._TXTcache.set(kn(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Tl.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},ey=Pl;var ty=ey;var{code:Jv}=be("dnsaddr");async function Ri(t,e={}){let r=new ty;e.signal!=null&&e.signal.addEventListener("abort",()=>{r.cancel()});let n=t.getPeerId(),[,i]=t.stringTuples().find(([a])=>a===Jv)??[];if(i==null)throw new Error("No hostname found in multiaddr");let s=(await r.resolveTxt(`_dnsaddr.${i}`)).flat().map(a=>a.split("=")[1]).filter(Boolean);return n!=null&&(s=s.filter(a=>a.includes(n))),s}var sr;(function(t){t.NOT_STARTED_YET="The libp2p node is not started yet",t.DHT_DISABLED="DHT is not available",t.PUBSUB_DISABLED="PubSub is not available",t.CONN_ENCRYPTION_REQUIRED="At least one connection encryption module is required",t.ERR_TRANSPORTS_REQUIRED="At least one transport module is required",t.ERR_PROTECTOR_REQUIRED="Private network is enforced, but no protector was provided",t.NOT_FOUND="Not found"})(sr||(sr={}));var K;(function(t){t.DHT_DISABLED="ERR_DHT_DISABLED",t.ERR_PUBSUB_DISABLED="ERR_PUBSUB_DISABLED",t.PUBSUB_NOT_STARTED="ERR_PUBSUB_NOT_STARTED",t.DHT_NOT_STARTED="ERR_DHT_NOT_STARTED",t.CONN_ENCRYPTION_REQUIRED="ERR_CONN_ENCRYPTION_REQUIRED",t.ERR_TRANSPORTS_REQUIRED="ERR_TRANSPORTS_REQUIRED",t.ERR_PROTECTOR_REQUIRED="ERR_PROTECTOR_REQUIRED",t.ERR_PEER_DIAL_INTERCEPTED="ERR_PEER_DIAL_INTERCEPTED",t.ERR_CONNECTION_INTERCEPTED="ERR_CONNECTION_INTERCEPTED",t.ERR_INVALID_PROTOCOLS_FOR_STREAM="ERR_INVALID_PROTOCOLS_FOR_STREAM",t.ERR_CONNECTION_ENDED="ERR_CONNECTION_ENDED",t.ERR_CONNECTION_FAILED="ERR_CONNECTION_FAILED",t.ERR_NODE_NOT_STARTED="ERR_NODE_NOT_STARTED",t.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",t.ERR_TOO_MANY_ADDRESSES="ERR_TOO_MANY_ADDRESSES",t.ERR_NO_VALID_ADDRESSES="ERR_NO_VALID_ADDRESSES",t.ERR_RELAYED_DIAL="ERR_RELAYED_DIAL",t.ERR_DIALED_SELF="ERR_DIALED_SELF",t.ERR_DISCOVERED_SELF="ERR_DISCOVERED_SELF",t.ERR_DUPLICATE_TRANSPORT="ERR_DUPLICATE_TRANSPORT",t.ERR_ENCRYPTION_FAILED="ERR_ENCRYPTION_FAILED",t.ERR_HOP_REQUEST_FAILED="ERR_HOP_REQUEST_FAILED",t.ERR_INVALID_KEY="ERR_INVALID_KEY",t.ERR_INVALID_MESSAGE="ERR_INVALID_MESSAGE",t.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",t.ERR_INVALID_PEER="ERR_INVALID_PEER",t.ERR_MUXER_UNAVAILABLE="ERR_MUXER_UNAVAILABLE",t.ERR_NOT_FOUND="ERR_NOT_FOUND",t.ERR_TIMEOUT="ERR_TIMEOUT",t.ERR_TRANSPORT_UNAVAILABLE="ERR_TRANSPORT_UNAVAILABLE",t.ERR_TRANSPORT_DIAL_FAILED="ERR_TRANSPORT_DIAL_FAILED",t.ERR_UNSUPPORTED_PROTOCOL="ERR_UNSUPPORTED_PROTOCOL",t.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED="ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED",t.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",t.ERR_SIGNATURE_NOT_VALID="ERR_SIGNATURE_NOT_VALID",t.ERR_FIND_SELF="ERR_FIND_SELF",t.ERR_NO_ROUTERS_AVAILABLE="ERR_NO_ROUTERS_AVAILABLE",t.ERR_CONNECTION_NOT_MULTIPLEXED="ERR_CONNECTION_NOT_MULTIPLEXED",t.ERR_NO_DIAL_TOKENS="ERR_NO_DIAL_TOKENS",t.ERR_KEYCHAIN_REQUIRED="ERR_KEYCHAIN_REQUIRED",t.ERR_INVALID_CMS="ERR_INVALID_CMS",t.ERR_MISSING_KEYS="ERR_MISSING_KEYS",t.ERR_NO_KEY="ERR_NO_KEY",t.ERR_INVALID_KEY_NAME="ERR_INVALID_KEY_NAME",t.ERR_INVALID_KEY_TYPE="ERR_INVALID_KEY_TYPE",t.ERR_KEY_ALREADY_EXISTS="ERR_KEY_ALREADY_EXISTS",t.ERR_INVALID_KEY_SIZE="ERR_INVALID_KEY_SIZE",t.ERR_KEY_NOT_FOUND="ERR_KEY_NOT_FOUND",t.ERR_OLD_KEY_NAME_INVALID="ERR_OLD_KEY_NAME_INVALID",t.ERR_NEW_KEY_NAME_INVALID="ERR_NEW_KEY_NAME_INVALID",t.ERR_PASSWORD_REQUIRED="ERR_PASSWORD_REQUIRED",t.ERR_PEM_REQUIRED="ERR_PEM_REQUIRED",t.ERR_CANNOT_READ_KEY="ERR_CANNOT_READ_KEY",t.ERR_MISSING_PRIVATE_KEY="ERR_MISSING_PRIVATE_KEY",t.ERR_MISSING_PUBLIC_KEY="ERR_MISSING_PUBLIC_KEY",t.ERR_INVALID_OLD_PASS_TYPE="ERR_INVALID_OLD_PASS_TYPE",t.ERR_INVALID_NEW_PASS_TYPE="ERR_INVALID_NEW_PASS_TYPE",t.ERR_INVALID_PASS_LENGTH="ERR_INVALID_PASS_LENGTH",t.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",t.ERR_WRONG_PING_ACK="ERR_WRONG_PING_ACK",t.ERR_INVALID_RECORD="ERR_INVALID_RECORD",t.ERR_ALREADY_SUCCEEDED="ERR_ALREADY_SUCCEEDED",t.ERR_NO_HANDLER_FOR_PROTOCOL="ERR_NO_HANDLER_FOR_PROTOCOL",t.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS",t.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",t.ERR_CONNECTION_DENIED="ERR_CONNECTION_DENIED",t.ERR_TRANSFER_LIMIT_EXCEEDED="ERR_TRANSFER_LIMIT_EXCEEDED"})(K||(K={}));var e_={addresses:{listen:[],announce:[],noAnnounce:[],announceFilter:t=>t},connectionManager:{resolvers:{dnsaddr:Ri},addressSorter:Ii},transportManager:{faultTolerance:Zr.FATAL_ALL}};function ry(t){let e=$r(e_,t);if(e.transports==null||e.transports.length<1)throw new b(sr.ERR_TRANSPORTS_REQUIRED,K.ERR_TRANSPORTS_REQUIRED);if(e.connectionProtector===null&&globalThis.process?.env?.LIBP2P_FORCE_PNET!=null)throw new b(sr.ERR_PROTECTOR_REQUIRED,K.ERR_PROTECTOR_REQUIRED);return e}var ny="keep-alive";var tg=te(Zy(),1);var O_=ie("libp2p:get-peer");function la(t){if(Bs(t))return{peerId:t,multiaddrs:[]};Array.isArray(t)||(t=[t]);let e;if(t.length>0){let r=t[0].getPeerId();e=r==null?void 0:de(r),t.forEach(n=>{if(!Ln(n))throw O_.error("multiaddr %s was invalid",n),new b("Invalid Multiaddr",K.ERR_INVALID_MULTIADDR);let i=n.getPeerId();if(i==null){if(e!=null)throw new b("Multiaddrs must all have the same peer id or have no peer id",K.ERR_INVALID_PARAMETERS)}else{let o=de(i);if(e==null||!e.equals(o))throw new b("Multiaddrs must all have the same peer id or have no peer id",K.ERR_INVALID_PARAMETERS)}})}return{peerId:e,multiaddrs:t}}function M_(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Wl=class{#e=[];enqueue(e,r){let n=r?.peerId,i=r?.priority??0;if(n==null)throw new b("missing peer id",K.ERR_INVALID_PARAMETERS);let o={priority:i,peerId:n,run:e};if(this.size>0&&this.#e[this.size-1].priority>=i){this.#e.push(o);return}let s=M_(this.#e,o,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,o)}dequeue(){return this.#e.shift()?.run}filter(e){if(e.peerId!=null){let r=e.peerId;return this.#e.filter(n=>r.equals(n.peerId)).map(n=>n.run)}return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}},fa=class extends Yr{constructor(e={}){super({...e,queueClass:Wl})}hasJob(e){return this.sizeBy({peerId:e})>0}};var ha="last-dial-failure";var da=10,pa=5,ma=100,ya=10;var st=ie("libp2p:connection-manager:auto-dial"),Pi={minConnections:pa,maxQueueLength:100,autoDialConcurrency:ya,autoDialPriority:0,autoDialInterval:5e3,autoDialPeerRetryThreshold:6e4},ga=class{connectionManager;peerStore;queue;minConnections;autoDialPriority;autoDialIntervalMs;autoDialMaxQueueLength;autoDialPeerRetryThresholdMs;autoDialInterval;started;running;constructor(e,r){this.connectionManager=e.connectionManager,this.peerStore=e.peerStore,this.minConnections=r.minConnections??Pi.minConnections,this.autoDialPriority=r.autoDialPriority??Pi.autoDialPriority,this.autoDialIntervalMs=r.autoDialInterval??Pi.autoDialInterval,this.autoDialMaxQueueLength=r.maxQueueLength??Pi.maxQueueLength,this.autoDialPeerRetryThresholdMs=r.autoDialPeerRetryThreshold??Pi.autoDialPeerRetryThreshold,this.started=!1,this.running=!1,this.queue=new fa({concurrency:r.autoDialConcurrency??Pi.autoDialConcurrency}),this.queue.addListener("error",n=>{st.error("error during auto-dial",n)}),e.events.addEventListener("connection:close",()=>{this.autoDial().catch(n=>{st.error(n)})})}isStarted(){return this.started}start(){this.autoDialInterval=setTimeout(()=>{this.autoDial().catch(e=>{st.error("error while autodialing",e)})},this.autoDialIntervalMs),this.started=!0}afterStart(){this.autoDial().catch(e=>{st.error("error while autodialing",e)})}stop(){this.queue.clear(),clearTimeout(this.autoDialInterval),this.started=!1,this.running=!1}async autoDial(){if(!this.started)return;let e=this.connectionManager.getConnectionsMap(),r=e.size;if(r>=this.minConnections){this.minConnections>0&&st.trace("have enough connections %d/%d",r,this.minConnections);return}if(this.queue.size>this.autoDialMaxQueueLength){st("not enough connections %d/%d but auto dial queue is full",r,this.minConnections);return}if(this.running){st("not enough connections %d/%d - but skipping autodial as it is already running",r,this.minConnections);return}this.running=!0,st("not enough connections %d/%d - will dial peers to increase the number of connections",r,this.minConnections);let n=new Bn(this.connectionManager.getDialQueue().map(u=>u.peerId).filter(Boolean)),i=await this.peerStore.all({filters:[u=>u.addresses.length===0?(st.trace("not autodialing %p because they have no addresses"),!1):e.has(u.id)?(st.trace("not autodialing %p because they are already connected"),!1):n.has(u.id)?(st.trace("not autodialing %p because they are already being dialed"),!1):this.queue.hasJob(u.id)?(st.trace("not autodialing %p because they are already being autodialed"),!1):!0]}),o=i.sort(()=>Math.random()>.5?1:-1),s=new $t;for(let u of o)s.has(u.id)||s.set(u.id,[...u.tags.values()].reduce((l,f)=>l+f.value,0));let c=o.sort((u,l)=>{let f=s.get(u.id)??0,h=s.get(l.id)??0;return f>h?-1:f<h?1:0}).filter(u=>{let l=u.metadata.get(ha);if(l==null)return!0;let f=parseInt(Z(l));return isNaN(f)?!0:Date.now()-f>this.autoDialPeerRetryThresholdMs});st("selected %d/%d peers to dial",c.length,i.length);for(let u of c)this.queue.add(async()=>{let l=this.connectionManager.getConnectionsMap().size;if(l>=this.minConnections){st("got enough connections now %d/%d",l,this.minConnections),this.queue.clear();return}st("connecting to a peerStore stored peer %p",u.id),await this.connectionManager.openConnection(u.id,{priority:this.autoDialPriority})},{peerId:u.id}).catch(l=>{st.error("could not connect to peerStore stored peer",l)});this.running=!1,this.started&&(this.autoDialInterval=setTimeout(()=>{this.autoDial().catch(u=>{st.error("error while autodialing",u)})},this.autoDialIntervalMs))}};var Di=ie("libp2p:connection-manager:connection-pruner"),jy={maxConnections:ma,allow:[]},xa=class{maxConnections;connectionManager;peerStore;allow;events;constructor(e,r={}){this.maxConnections=r.maxConnections??jy.maxConnections,this.allow=r.allow??jy.allow,this.connectionManager=e.connectionManager,this.peerStore=e.peerStore,this.events=e.events,e.events.addEventListener("connection:open",()=>{this.maybePruneConnections().catch(n=>{Di.error(n)})})}async maybePruneConnections(){let e=this.connectionManager.getConnections(),r=e.length,n=Math.max(r-this.maxConnections,0);if(Di("checking max connections limit %d/%d",r,this.maxConnections),r<=this.maxConnections)return;Di("max connections limit exceeded %d/%d, pruning %d connection(s)",r,this.maxConnections,n);let i=new $t;for(let a of e){let c=a.remotePeer;if(!i.has(c)){i.set(c,0);try{let u=await this.peerStore.get(c);i.set(c,[...u.tags.values()].reduce((l,f)=>l+f.value,0))}catch(u){u.code!=="ERR_NOT_FOUND"&&Di.error("error loading peer tags",u)}}}let o=e.sort((a,c)=>{let u=i.get(a.remotePeer)??0,l=i.get(c.remotePeer)??0;if(u>l)return 1;if(u<l)return-1;let f=a.timeline.open,h=c.timeline.open;return f<h?1:f>h?-1:0}),s=[];for(let a of o)if(Di("too many connections open - closing a connection to %p",a.remotePeer),this.allow.some(u=>a.remoteAddr.toString().startsWith(u.toString()))||s.push(a),s.length===n)break;await Promise.all(s.map(async a=>{try{await a.close()}catch(c){Di.error(c)}})),this.events.safeDispatchEvent("connection:prune",{detail:s})}};var Jl=te($n(),1);function Ea(t){let e=new globalThis.AbortController;function r(){e.abort();for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let i=e.signal;return i.clear=n,i}function Jr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Zl=te($n(),1);var Jy=ie("libp2p:connection-manager:utils");async function jl(t,e){if(!t.protoNames().includes("dnsaddr"))return[t];let n=await K_(t,e),s=(await Promise.all(n.map(async a=>jl(a,e)))).flat().reduce((a,c)=>(a.find(u=>u.equals(c))==null&&a.push(c),a),[]);return Jy("resolved %s to",t,s.map(a=>a.toString())),s}async function K_(t,e){try{return t=ze(t.toString()),await t.resolve(e)}catch(r){return Jy.error(`multiaddr ${t.toString()} could not be resolved`,r),[]}}function eg(...t){let e=[];for(let n of t)if(n!=null){try{(0,Zl.setMaxListeners)?.(1/0,n)}catch{}e.push(n)}let r=Ea(e);try{(0,Zl.setMaxListeners)?.(1/0,r)}catch{}return r}var at=ie("libp2p:connection-manager:dial-queue"),So={addressSorter:Ii,maxParallelDials:da,maxPeerAddrsToDial:25,maxParallelDialsPerPeer:10,dialTimeout:3e4,resolvers:{dnsaddr:Ri}},wa=class{pendingDials;queue;peerId;peerStore;connectionGater;transportManager;addressSorter;maxPeerAddrsToDial;maxParallelDialsPerPeer;dialTimeout;inProgressDialCount;pendingDialCount;shutDownController;constructor(e,r={}){this.addressSorter=r.addressSorter??So.addressSorter,this.maxPeerAddrsToDial=r.maxPeerAddrsToDial??So.maxPeerAddrsToDial,this.maxParallelDialsPerPeer=r.maxParallelDialsPerPeer??So.maxParallelDialsPerPeer,this.dialTimeout=r.dialTimeout??So.dialTimeout,this.peerId=e.peerId,this.peerStore=e.peerStore,this.connectionGater=e.connectionGater,this.transportManager=e.transportManager,this.shutDownController=new AbortController;try{(0,Jl.setMaxListeners)?.(1/0,this.shutDownController.signal)}catch{}this.pendingDialCount=e.metrics?.registerMetric("libp2p_dialler_pending_dials"),this.inProgressDialCount=e.metrics?.registerMetric("libp2p_dialler_in_progress_dials"),this.pendingDials=[];for(let[n,i]of Object.entries(r.resolvers??{}))Ju.set(n,i);this.queue=new Yr({concurrency:r.maxParallelDials??So.maxParallelDials}),this.queue.on("add",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("active",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("completed",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("error",n=>{at.error("error in dial queue",n),this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("empty",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("idle",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)})}stop(){this.shutDownController.abort()}async dial(e,r={}){let{peerId:n,multiaddrs:i}=la(e),o=i.map(l=>({multiaddr:l,isCertified:!1})),s=this.createDialAbortControllers(r.signal),a;try{a=await this.calculateMultiaddrs(n,o,{...r,signal:s})}catch(l){throw s.clear(),l}let c=this.pendingDials.find(l=>!!(l.peerId!=null&&n!=null&&l.peerId.equals(n)||a.map(({multiaddr:f})=>f.toString()).join()===l.multiaddrs.map(f=>f.toString()).join()));if(c!=null)return at("joining existing dial target for %p",n),s.clear(),c.promise;at("creating dial target for",a.map(({multiaddr:l})=>l.toString()));let u={id:V_(),status:"queued",peerId:n,multiaddrs:a.map(({multiaddr:l})=>l)};return u.promise=this.performDial(u,{...r,signal:s}).finally(()=>{this.pendingDials=this.pendingDials.filter(l=>l.id!==u.id),s.clear()}).catch(async l=>{if(at.error("dial failed to %s",u.multiaddrs.map(f=>f.toString()).join(", "),l),n!=null)try{await this.peerStore.patch(n,{metadata:{[ha]:G(Date.now().toString())}})}catch(f){at.error("could not update last dial failure key for %p",n,f)}throw s.aborted?new b(l.message,K.ERR_TIMEOUT):l}),this.pendingDials.push(u),u.promise}createDialAbortControllers(e){let r=Ea([AbortSignal.timeout(this.dialTimeout),this.shutDownController.signal,e]);try{(0,Jl.setMaxListeners)?.(1/0,r)}catch{}return r}async calculateMultiaddrs(e,r=[],n={}){if(e!=null){if(this.peerId.equals(e))throw new b("Tried to dial self",K.ERR_DIALED_SELF);if(await this.connectionGater.denyDialPeer?.(e)===!0)throw new b("The dial request is blocked by gater.allowDialPeer",K.ERR_PEER_DIAL_INTERCEPTED);if(r.length===0){at("loading multiaddrs for %p",e);try{let l=await this.peerStore.get(e);r.push(...l.addresses),at("loaded multiaddrs for %p",e,r.map(({multiaddr:f})=>f.toString()))}catch(l){if(l.code!==K.ERR_NOT_FOUND)throw l}}}let i=(await Promise.all(r.map(async l=>{let f=await jl(l.multiaddr,n);return f.length===1&&f[0].equals(l.multiaddr)?l:f.map(h=>({multiaddr:h,isCertified:!1}))}))).flat(),o=i.filter(l=>{if(this.transportManager.transportForMultiaddr(l.multiaddr)==null)return!1;let f=l.multiaddr.getPeerId();return e!=null&&f!=null?e.equals(f):!0}),s=new Map;for(let l of o){let f=l.multiaddr.toString(),h=s.get(f);if(h!=null){h.isCertified=h.isCertified||l.isCertified||!1;continue}s.set(f,l)}let a=[...s.values()];if((a.length===0||a.length>this.maxPeerAddrsToDial)&&(at("addresses for %p before filtering",e??"unknown peer",i.map(({multiaddr:l})=>l.toString())),at("addresses for %p after filtering",e??"unknown peer",a.map(({multiaddr:l})=>l.toString()))),a.length===0)throw new b("The dial request has no valid addresses",K.ERR_NO_VALID_ADDRESSES);if(a.length>this.maxPeerAddrsToDial)throw new b("dial with more addresses than allowed",K.ERR_TOO_MANY_ADDRESSES);if(e!=null){let l=`/p2p/${e.toString()}`;a=a.map(f=>{let h=f.multiaddr.getPeerId();return f.multiaddr.protos().pop()?.path===!0?f:h!==e.toString()?{multiaddr:f.multiaddr.encapsulate(l),isCertified:f.isCertified}:f})}let c=[];for(let l of a)this.connectionGater.denyDialMultiaddr!=null&&await this.connectionGater.denyDialMultiaddr(l.multiaddr)||c.push(l);let u=c.sort(this.addressSorter);if(u.length===0)throw new b("The connection gater denied all addresses in the dial request",K.ERR_NO_VALID_ADDRESSES);return u}async performDial(e,r={}){let n=e.multiaddrs.map(()=>new AbortController);try{let i=new Yr({concurrency:this.maxParallelDialsPerPeer});i.on("error",s=>{at.error("error dialling",s)});let o=await Promise.any(e.multiaddrs.map(async(s,a)=>{let c=n[a];if(c==null)throw new b("dialAction did not come with an AbortController",K.ERR_INVALID_PARAMETERS);let u=eg(c.signal,r.signal);u.addEventListener("abort",()=>{at("dial to %a aborted",s)});let l=Jr();return await i.add(async()=>{if(u.aborted){at("dial to %a was aborted before reaching the head of the peer dial queue",s),l.reject(new Wn);return}await this.queue.add(async()=>{try{if(u.aborted){at("dial to %a was aborted before reaching the head of the dial queue",s),l.reject(new Wn);return}e.status="active";let f=await this.transportManager.dial(s,{...r,signal:u});if(c.signal.aborted){at("multiple dials succeeded, closing superfluous connection"),f.close().catch(h=>{at.error("error closing superfluous connection",h)}),l.reject(new Wn);return}n[a]=void 0,n.forEach(h=>{h!==void 0&&h.abort()}),at("dial to %a succeeded",s),l.resolve(f)}catch(f){at.error("error during dial of %a",s,f),l.reject(f)}},{...r,signal:u}).catch(f=>{l.reject(f)})},{signal:u}).catch(f=>{l.reject(f)}).finally(()=>{u.clear()}),l.promise}));if(o==null)throw new b("successful dial led to empty object returned from peer dial queue",K.ERR_TRANSPORT_DIAL_FAILED);return e.status="success",o}catch(i){throw e.status="error",e.multiaddrs.length===1&&i.name==="AggregateError"?i.errors[0]:i}}};function V_(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var It=ie("libp2p:connection-manager"),z_=50,On={minConnections:pa,maxConnections:ma,inboundConnectionThreshold:5,maxIncomingPendingConnections:10,autoDialConcurrency:ya,autoDialPriority:0,autoDialMaxQueueLength:100},ba=class{started;connections;allow;deny;maxIncomingPendingConnections;incomingPendingConnections;maxConnections;dialQueue;autoDial;connectionPruner;inboundConnectionRateLimiter;peerStore;metrics;events;constructor(e,r={}){this.maxConnections=r.maxConnections??On.maxConnections;let n=r.minConnections??On.minConnections;if(this.maxConnections<n)throw new b("Connection Manager maxConnections must be greater than minConnections",K.ERR_INVALID_PARAMETERS);this.connections=new $t,this.started=!1,this.peerStore=e.peerStore,this.metrics=e.metrics,this.events=e.events,this.onConnect=this.onConnect.bind(this),this.onDisconnect=this.onDisconnect.bind(this),this.events.addEventListener("connection:open",this.onConnect),this.events.addEventListener("connection:close",this.onDisconnect),this.allow=(r.allow??[]).map(i=>ze(i)),this.deny=(r.deny??[]).map(i=>ze(i)),this.incomingPendingConnections=0,this.maxIncomingPendingConnections=r.maxIncomingPendingConnections??On.maxIncomingPendingConnections,this.inboundConnectionRateLimiter=new tg.RateLimiterMemory({points:r.inboundConnectionThreshold??On.inboundConnectionThreshold,duration:1}),this.autoDial=new ga({connectionManager:this,peerStore:e.peerStore,events:e.events},{minConnections:n,autoDialConcurrency:r.autoDialConcurrency??On.autoDialConcurrency,autoDialPriority:r.autoDialPriority??On.autoDialPriority,maxQueueLength:r.autoDialMaxQueueLength??On.autoDialMaxQueueLength}),this.connectionPruner=new xa({connectionManager:this,peerStore:e.peerStore,events:e.events},{maxConnections:this.maxConnections,allow:this.allow}),this.dialQueue=new wa({peerId:e.peerId,metrics:e.metrics,peerStore:e.peerStore,transportManager:e.transportManager,connectionGater:e.connectionGater},{addressSorter:r.addressSorter??Ii,maxParallelDials:r.maxParallelDials??da,maxPeerAddrsToDial:r.maxPeerAddrsToDial??25,dialTimeout:r.dialTimeout??3e4,resolvers:r.resolvers??{dnsaddr:Ri}})}isStarted(){return this.started}async start(){this.metrics?.registerMetricGroup("libp2p_connection_manager_connections",{calculate:()=>{let e={inbound:0,outbound:0};for(let r of this.connections.values())for(let n of r)n.direction==="inbound"?e.inbound++:e.outbound++;return e}}),this.metrics?.registerMetricGroup("libp2p_protocol_streams_total",{label:"protocol",calculate:()=>{let e={};for(let r of this.connections.values())for(let n of r)for(let i of n.streams){let o=`${i.direction} ${i.protocol??"unnegotiated"}`;e[o]=(e[o]??0)+1}return e}}),this.metrics?.registerMetricGroup("libp2p_connection_manager_protocol_streams_per_connection_90th_percentile",{label:"protocol",calculate:()=>{let e={};for(let n of this.connections.values())for(let i of n){let o={};for(let s of i.streams){let a=`${s.direction} ${s.protocol??"unnegotiated"}`;o[a]=(o[a]??0)+1}for(let[s,a]of Object.entries(o))e[s]=e[s]??[],e[s].push(a)}let r={};for(let[n,i]of Object.entries(e)){i=i.sort((s,a)=>s-a);let o=Math.floor(i.length*.9);r[n]=i[o]}return r}}),this.autoDial.start(),this.started=!0,It("started")}async afterStart(){Promise.resolve().then(async()=>{let e=await this.peerStore.all({filters:[r=>r.tags.has(ny)]});await Promise.all(e.map(async r=>{await this.openConnection(r.id).catch(n=>{It.error(n)})}))}).catch(e=>{It.error(e)}),this.autoDial.afterStart()}async stop(){this.dialQueue.stop(),this.autoDial.stop();let e=[];for(let r of this.connections.values())for(let n of r)e.push((async()=>{try{await n.close()}catch(i){It.error(i)}})());It("closing %d connections",e.length),await Promise.all(e),this.connections.clear(),It("stopped")}onConnect(e){this._onConnect(e).catch(r=>{It.error(r)})}async _onConnect(e){let{detail:r}=e;if(!this.started){await r.close();return}let n=r.remotePeer,i=this.connections.get(n),o=!1;i!=null?i.push(r):(o=!0,this.connections.set(n,[r])),n.publicKey!=null&&n.type==="RSA"&&await this.peerStore.patch(n,{publicKey:n.publicKey}),o&&this.events.safeDispatchEvent("peer:connect",{detail:r.remotePeer})}onDisconnect(e){let{detail:r}=e;if(!this.started)return;let n=r.remotePeer,i=this.connections.get(n);i!=null&&i.length>1?(i=i.filter(o=>o.id!==r.id),this.connections.set(n,i)):i!=null&&(this.connections.delete(n),this.events.safeDispatchEvent("peer:disconnect",{detail:r.remotePeer}))}getConnections(e){if(e!=null)return this.connections.get(e)??[];let r=[];for(let n of this.connections.values())r=r.concat(n);return r}getConnectionsMap(){return this.connections}async openConnection(e,r={}){if(!this.isStarted())throw new b("Not started",K.ERR_NODE_NOT_STARTED);r.signal?.throwIfAborted();let{peerId:n}=la(e);if(n!=null&&r.force!==!0){It("dial %p",n);let a=this.getConnections(n);if(a.length>0)return It("had an existing connection to %p",n),a[0]}let i=await this.dialQueue.dial(e,{...r,priority:r.priority??z_}),o=this.connections.get(i.remotePeer);o==null&&(o=[],this.connections.set(i.remotePeer,o));let s=!1;for(let a of o)a.id===i.id&&(s=!0);return s||o.push(i),i}async closeConnections(e,r={}){let n=this.connections.get(e)??[];await Promise.all(n.map(async i=>{try{await i.close(r)}catch(o){i.abort(o)}}))}async acceptIncomingConnection(e){if(this.deny.some(i=>e.remoteAddr.toString().startsWith(i.toString())))return It("connection from %a refused - connection remote address was in deny list",e.remoteAddr),!1;if(this.allow.some(i=>e.remoteAddr.toString().startsWith(i.toString())))return this.incomingPendingConnections++,!0;if(this.incomingPendingConnections===this.maxIncomingPendingConnections)return It("connection from %a refused - incomingPendingConnections exceeded by host",e.remoteAddr),!1;if(e.remoteAddr.isThinWaistAddress()){let i=e.remoteAddr.nodeAddress().address;try{await this.inboundConnectionRateLimiter.consume(i,1)}catch{return It("connection from %a refused - inboundConnectionThreshold exceeded by host %s",e.remoteAddr,i),!1}}return this.getConnections().length<this.maxConnections?(this.incomingPendingConnections++,!0):(It("connection from %a refused - maxConnections exceeded",e.remoteAddr),!1)}afterUpgradeInbound(){this.incomingPendingConnections--}getDialQueue(){return this.dialQueue.pendingDials}};var va=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ni=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new va(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new va(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var rf=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Mn(t={}){return G_(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function G_(t,e){e=e??{};let r=e.onEnd,n=new Ni,i,o,s,a=Jr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,g)=>{o=x=>{o=null,n.push(x);try{y(t(n))}catch(w){g(w)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Jr()})}},u=y=>o!=null?o(y):(n.push(y),i),l=y=>(n=new Ni,o!=null?o({error:y}):(n.push({error:y}),i)),f=y=>{if(s)return i;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},h=y=>s?i:(s=!0,y!=null?l(y):u({done:!0})),p=()=>(n=new Ni,h(),{done:!0}),d=y=>(h(y),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:p,throw:d,push:f,end:h,get readableLength(){return n.size},onEmpty:async y=>{let g=y?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let x,w;g!=null&&(x=new Promise((C,_)=>{w=()=>{_(new rf)},g.addEventListener("abort",w)}));try{await Promise.race([a.promise,x])}finally{w!=null&&g!=null&&g?.removeEventListener("abort",w)}}},r==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(y){return m.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return m.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(y){return m.end(y),r!=null&&(r(y),r=void 0),i},get readableLength(){return m.readableLength}},i}function Y_(t){return t[Symbol.asyncIterator]!=null}function W_(...t){let e=[];for(let r of t)Y_(r)||e.push(r);return e.length===t.length?function*(){for(let r of e)yield*r}():async function*(){let r=Mn({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(t.map(async n=>{for await(let i of n)r.push(i)})),r.end()}catch(n){r.end(n)}}),yield*r}()}var en=W_;function Un(t,...e){if(t==null)throw new Error("Empty pipeline");if(nf(t)){let n=t;t=()=>n.source}else if(ng(t)||rg(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&nf(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)nf(r[n])&&(r[n]=X_(r[n]));return Q_(...r)}var Q_=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},rg=t=>t?.[Symbol.asyncIterator]!=null,ng=t=>t?.[Symbol.iterator]!=null,nf=t=>t==null?!1:t.sink!=null&&t.source!=null,X_=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=Mn({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,o=t.source;if(rg(o))i=async function*(){yield*o,n.end()};else if(ng(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return en(n,i())}return t.source};function Z_(t){return t[Symbol.asyncIterator]!=null}function j_(t,e){if(Z_(t))return async function*(){for await(let a of t)yield e(a)}();let r=ta(t),{value:n,done:i}=r.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of r)yield e(a)}();let s=e;return function*(){yield o;for(let a of r)yield s(a)}()}var ig=j_;async function*Io(t,e){yield*ig(t,async r=>(await e.merge(r.id,{multiaddrs:r.multiaddrs}),r))}function _a(t){let e=new Set;return zt(t,r=>e.has(r.id.toString())?!1:(e.add(r.id.toString()),!0))}async function*Aa(t,e=1){let r=0;for await(let n of t)r++,yield n;if(r<e)throw new b(`more peers required, seen: ${r} min: ${e}`,"NOT_FOUND")}var Sa=class{routers;started;components;constructor(e,r){this.routers=r.routers??[],this.started=!1,this.components=e}isStarted(){return this.started}async start(){this.started=!0}async stop(){this.started=!1}async*findProviders(e,r={}){if(this.routers.length===0)throw new b("No content routers available",K.ERR_NO_ROUTERS_AVAILABLE);yield*Un(en(...this.routers.map(n=>n.findProviders(e,r))),n=>Io(n,this.components.peerStore),n=>_a(n),n=>Aa(n))}async provide(e,r={}){if(this.routers.length===0)throw new b("No content routers available",K.ERR_NO_ROUTERS_AVAILABLE);await Promise.all(this.routers.map(async n=>{await n.provide(e,r)}))}async put(e,r,n){if(!this.isStarted())throw new b(sr.NOT_STARTED_YET,K.DHT_NOT_STARTED);await Promise.all(this.routers.map(async i=>{await i.put(e,r,n)}))}async get(e,r){if(!this.isStarted())throw new b(sr.NOT_STARTED_YET,K.DHT_NOT_STARTED);return Promise.any(this.routers.map(async n=>n.get(e,r)))}};function J_(t){return t[Symbol.asyncIterator]!=null}function eA(t){if(J_(t))return(async()=>{for await(let e of t)return e})();for(let e of t)return e}var Ia=eA;var tA=ie("libp2p:peer-routing"),Ra=class{components;routers;constructor(e,r){this.components=e,this.routers=r.routers??[]}async findPeer(e,r){if(this.routers.length===0)throw new b("No peer routers available",K.ERR_NO_ROUTERS_AVAILABLE);if(e.toString()===this.components.peerId.toString())throw new b("Should not try to find self",K.ERR_FIND_SELF);let n=await Un(en(...this.routers.map(i=>async function*(){try{yield await i.findPeer(e,r)}catch(o){tA.error(o)}}())),i=>zt(i,Boolean),i=>Io(i,this.components.peerStore),async i=>Ia(i));if(n!=null)return n;throw new b(sr.NOT_FOUND,K.ERR_NOT_FOUND)}async*getClosestPeers(e,r){if(this.routers.length===0)throw new b("No peer routers available",K.ERR_NO_ROUTERS_AVAILABLE);yield*Un(en(...this.routers.map(n=>n.getClosestPeers(e,r))),n=>Io(n,this.components.peerStore),n=>_a(n),n=>Aa(n))}};var of=ie("libp2p:registrar"),sf=32,af=64,Ca=class{topologies;handlers;components;constructor(e){this.topologies=new Map,this.handlers=new Map,this.components=e,this._onDisconnect=this._onDisconnect.bind(this),this._onPeerUpdate=this._onPeerUpdate.bind(this),this._onConnect=this._onConnect.bind(this),this.components.events.addEventListener("peer:disconnect",this._onDisconnect),this.components.events.addEventListener("peer:connect",this._onConnect),this.components.events.addEventListener("peer:update",this._onPeerUpdate)}getProtocols(){return Array.from(new Set([...this.handlers.keys()])).sort()}getHandler(e){let r=this.handlers.get(e);if(r==null)throw new b(`No handler registered for protocol ${e}`,K.ERR_NO_HANDLER_FOR_PROTOCOL);return r}getTopologies(e){let r=this.topologies.get(e);return r==null?[]:[...r.values()]}async handle(e,r,n){if(this.handlers.has(e))throw new b(`Handler already registered for protocol ${e}`,K.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED);let i=$r.bind({ignoreUndefined:!0})({maxInboundStreams:sf,maxOutboundStreams:af},n);this.handlers.set(e,{handler:r,options:i}),await this.components.peerStore.merge(this.components.peerId,{protocols:[e]})}async unhandle(e){let r=Array.isArray(e)?e:[e];r.forEach(n=>{this.handlers.delete(n)}),await this.components.peerStore.patch(this.components.peerId,{protocols:r})}async register(e,r){if(r==null)throw new b("invalid topology",K.ERR_INVALID_PARAMETERS);let n=`${(Math.random()*1e9).toString(36)}${Date.now()}`,i=this.topologies.get(e);return i==null&&(i=new Map,this.topologies.set(e,i)),i.set(n,r),n}unregister(e){for(let[r,n]of this.topologies.entries())n.has(e)&&(n.delete(e),n.size===0&&this.topologies.delete(r))}_onDisconnect(e){let r=e.detail;this.components.peerStore.get(r).then(n=>{for(let i of n.protocols){let o=this.topologies.get(i);if(o!=null)for(let s of o.values())s.onDisconnect?.(r)}}).catch(n=>{n.code!==K.ERR_NOT_FOUND&&of.error("could not inform topologies of disconnecting peer %p",r,n)})}_onConnect(e){let r=e.detail;this.components.peerStore.get(r).then(n=>{let i=this.components.connectionManager.getConnections(n.id)[0];if(i==null){of("peer %p connected but the connection manager did not have a connection",n);return}for(let o of n.protocols){let s=this.topologies.get(o);if(s!=null)for(let a of s.values())a.onConnect?.(r,i)}}).catch(n=>{n.code!==K.ERR_NOT_FOUND&&of.error("could not inform topologies of connecting peer %p",r,n)})}_onPeerUpdate(e){let{peer:r,previous:n}=e.detail,i=(n?.protocols??[]).filter(s=>!r.protocols.includes(s)),o=r.protocols.filter(s=>!(n?.protocols??[]).includes(s));for(let s of i){let a=this.topologies.get(s);if(a!=null)for(let c of a.values())c.onDisconnect?.(r.id)}for(let s of o){let a=this.topologies.get(s);if(a!=null)for(let c of a.values()){let u=this.components.connectionManager.getConnections(r.id)[0];u!=null&&c.onConnect?.(r.id,u)}}}};var cf=class extends Map{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function og(t){let{name:e,metrics:r}=t,n;return r!=null?n=new cf({name:e,metrics:r}):n=new Map,n}var Fn=ie("libp2p:transports"),Ta=class{components;transports;listeners;faultTolerance;started;constructor(e,r={}){this.components=e,this.started=!1,this.transports=new Map,this.listeners=og({name:"libp2p_transport_manager_listeners",metrics:this.components.metrics}),this.faultTolerance=r.faultTolerance??Zr.FATAL_ALL}add(e){let r=e[Symbol.toStringTag];if(r==null)throw new b("Transport must have a valid tag",K.ERR_INVALID_KEY);if(this.transports.has(r))throw new b(`There is already a transport with the tag ${r}`,K.ERR_DUPLICATE_TRANSPORT);Fn("adding transport %s",r),this.transports.set(r,e),this.listeners.has(r)||this.listeners.set(r,[])}isStarted(){return this.started}start(){this.started=!0}async afterStart(){let e=this.components.addressManager.getListenAddrs();await this.listen(e)}async stop(){let e=[];for(let[r,n]of this.listeners)for(Fn("closing listeners for %s",r);n.length>0;){let i=n.pop();i!=null&&e.push(i.close())}await Promise.all(e),Fn("all listeners closed");for(let r of this.listeners.keys())this.listeners.set(r,[]);this.started=!1}async dial(e,r){let n=this.transportForMultiaddr(e);if(n==null)throw new b(`No transport available for address ${String(e)}`,K.ERR_TRANSPORT_UNAVAILABLE);try{return await n.dial(e,{...r,upgrader:this.components.upgrader})}catch(i){throw i.code==null&&(i.code=K.ERR_TRANSPORT_DIAL_FAILED),i}}getAddrs(){let e=[];for(let r of this.listeners.values())for(let n of r)e=[...e,...n.getAddrs()];return e}getTransports(){return Array.of(...this.transports.values())}getListeners(){return Array.of(...this.listeners.values()).flat()}transportForMultiaddr(e){for(let r of this.transports.values())if(r.filter([e]).length>0)return r}async listen(e){if(!this.isStarted())throw new b("Not started",K.ERR_NODE_NOT_STARTED);if(e==null||e.length===0){Fn("no addresses were provided for listening, this node is dial only");return}let r=[];for(let[n,i]of this.transports.entries()){let o=i.filter(e),s=[];for(let u of o){Fn("creating listener for %s on %a",n,u);let l=i.createListener({upgrader:this.components.upgrader}),f=this.listeners.get(n)??[];f==null&&(f=[],this.listeners.set(n,f)),f.push(l),l.addEventListener("listening",()=>{this.components.events.safeDispatchEvent("transport:listening",{detail:l})}),l.addEventListener("close",()=>{let h=f.findIndex(p=>p===l);f.splice(h,1),this.components.events.safeDispatchEvent("transport:close",{detail:l})}),s.push(l.listen(u))}if(s.length===0){r.push(n);continue}if((await Promise.allSettled(s)).find(u=>u.status==="fulfilled")==null&&this.faultTolerance!==Zr.NO_FATAL)throw new b(`Transport (${n}) could not listen on any available address`,K.ERR_NO_VALID_ADDRESSES)}if(r.length===this.transports.size){let n=`no valid addresses were provided for transports [${r.join(", ")}]`;if(this.faultTolerance===Zr.FATAL_ALL)throw new b(n,K.ERR_NO_VALID_ADDRESSES);Fn(`libp2p in dial mode only: ${n}`)}}async remove(e){Fn("removing %s",e);for(let r of this.listeners.get(e)??[])await r.close();this.transports.delete(e),this.listeners.delete(e)}async removeAll(){let e=[];for(let r of this.transports.keys())e.push(this.remove(r));await Promise.all(e)}};var hf=te($n(),1);var Rr="/multistream/1.0.0";function uf(t){let e=async function*(){let r=yield,n=new Ze;for await(let i of t){if(r==null){n.append(i),r=yield n,n=new Ze;continue}for(n.append(i);n.length>=r;){let o=n.sublist(0,r);if(n.consume(r),r=yield o,r==null){n.length>0&&(r=yield n,n=new Ze);break}}}if(r!=null)throw Object.assign(new Error(`stream ended before ${r} bytes became available`),{code:"ERR_UNDER_READ",buffer:n})}();return e.next(),e}function Ba(t){let e=Mn(),r=uf(t.source),n=Jr(),i,o=t.sink(async function*(){yield*e,yield*await n.promise}());return o.catch(a=>{i=a}),{reader:r,writer:e,stream:{sink:async a=>{if(i!=null){await Promise.reject(i);return}n.resolve(a),await o},source:r},rest:()=>e.end(),write:e.push,read:async()=>{let a=await r.next();if(a.value!=null)return a.value}}}var Ro=class extends Error{constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function sg(t){if(t!=null){if(typeof t[Symbol.iterator]=="function")return t[Symbol.iterator]();if(typeof t[Symbol.asyncIterator]=="function")return t[Symbol.asyncIterator]();if(typeof t.next=="function")return t}throw new Error("argument is not an iterator or iterable")}function La(t,e,r){let n=r??{},i=sg(t);async function*o(){let s,a=()=>{s?.()};for(e.addEventListener("abort",a);;){let c;try{if(e.aborted){let{abortMessage:l,abortCode:f}=n;throw new Ro(l,f)}let u=new Promise((l,f)=>{s=()=>{let{abortMessage:h,abortCode:p}=n;f(new Ro(h,p))}});c=await Promise.race([u,i.next()]),s=null}catch(u){e.removeEventListener("abort",a);let l=u.type==="aborted"&&e.aborted;if(l&&n.onAbort!=null&&n.onAbort(t),typeof i.return=="function")try{let f=i.return();f instanceof Promise&&f.catch(h=>{n.onReturnError!=null&&n.onReturnError(h)})}catch(f){n.onReturnError!=null&&n.onReturnError(f)}if(l&&n.returnOnAbort===!0)return;throw u}if(c.done===!0)break;yield c.value}e.removeEventListener("abort",a)}return o()}function rA(t,e,r){return n=>t(La(n,e,r))}function ag(t,e,r){return{sink:rA(t.sink,e,{...r,onAbort:void 0}),source:La(t.source,e,r)}}function Pa(t){return t[Symbol.asyncIterator]!=null}var Da=t=>{let e=yt(t),r=Ot(e);return Lt(t,r),Da.bytes=e,r};Da.bytes=0;function Na(t,e){e=e??{};let r=e.lengthEncoder??Da;function*n(i){let o=r(i.byteLength);o instanceof Uint8Array?yield o:yield*o,i instanceof Uint8Array?yield i:yield*i}return Pa(t)?async function*(){for await(let i of t)yield*n(i)}():function*(){for(let i of t)yield*n(i)}()}Na.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Da;return new Ze(r(t.byteLength),t)};var ki=te(Al(),1);var nA=8,iA=1024*1024*4,Kn;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(Kn||(Kn={}));var lf=t=>{let e=Sr(t);return lf.bytes=yt(e),e};lf.bytes=0;function Co(t,e){let r=new Ze,n=Kn.LENGTH,i=-1,o=e?.lengthDecoder??lf,s=e?.maxLengthLength??nA,a=e?.maxDataLength??iA;function*c(){for(;r.byteLength>0;){if(n===Kn.LENGTH)try{if(i=o(r),i<0)throw(0,ki.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>a)throw(0,ki.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=o.bytes;r.consume(u),e?.onLength!=null&&e.onLength(i),n=Kn.DATA}catch(u){if(u instanceof RangeError){if(r.byteLength>s)throw(0,ki.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===Kn.DATA){if(r.byteLength<i)break;let u=r.sublist(0,i);r.consume(i),e?.onData!=null&&e.onData(u),yield u,n=Kn.LENGTH}}}return Pa(t)?async function*(){for await(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw(0,ki.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw(0,ki.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Co.fromReader=(t,e)=>{let r=1,n=async function*(){for(;;)try{let{done:o,value:s}=await t.next(r);if(o===!0)return;s!=null&&(yield s)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{r=1}}();return Co(n,{...e??{},onLength:o=>{r=o}})};var aA=ie("libp2p:mss"),cg=G(`
48
+ `.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),qv=new RegExp(`(?:^${Gt}$)|(?:^${oa}$)`),Vv=new RegExp(`^${Gt}$`),$v=new RegExp(`^${oa}$`),Rl=t=>t&&t.exact?qv:new RegExp(`(?:${Xr(t)}${Gt}${Xr(t)})|(?:${Xr(t)}${oa}${Xr(t)})`,"g");Rl.v4=t=>t&&t.exact?Vv:new RegExp(`${Xr(t)}${Gt}${Xr(t)}`,"g");Rl.v6=t=>t&&t.exact?$v:new RegExp(`${Xr(t)}${oa}${Xr(t)}`,"g");var Km=Rl;var zm=te(Vm(),1),{isValid:Hv,parse:zv}=zm.default,Gv=["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.0.0/29","192.0.0.8/32","192.0.0.9/32","192.0.0.10/32","192.0.0.170/32","192.0.0.171/32","192.0.2.0/24","192.31.196.0/24","192.52.193.0/24","192.88.99.0/24","192.168.0.0/16","192.175.48.0/24","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","240.0.0.0/4","255.255.255.255/32"],Yv=Gv.map(t=>new Hm.Netmask(t));function Wv(t){for(let e of Yv)if(e.contains(t))return!0;return!1}function $m(t){return/^::$/.test(t)||/^::1$/.test(t)||/^::f{4}:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^::f{4}:0.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^64:ff9b::([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/.test(t)||/^100::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001::([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:2[0-9a-fA-F]:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2001:db8:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^2002:([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4}):?([0-9a-fA-F]{0,4})$/.test(t)||/^f[c-d]([0-9a-fA-F]{2,2}):/i.test(t)||/^fe[8-9a-bA-B][0-9a-fA-F]:/i.test(t)||/^ff([0-9a-fA-F]{2,2}):/i.test(t)}var Gm=t=>{if(Hv(t)){let e=zv(t);if(e.kind()==="ipv4")return Wv(e.toNormalizedString());if(e.kind()==="ipv6")return $m(t)}else if(wi(t)&&Km.v6().test(t))return $m(t)};var aa=Gm;function Ym(t={}){return{denyDialPeer:async()=>!1,denyDialMultiaddr:async e=>{let r=e.stringTuples();return r[0][0]===4||r[0][0]===41?!!aa(`${r[0][1]}`):!1},denyInboundConnection:async()=>!1,denyOutboundConnection:async()=>!1,denyInboundEncryptedConnection:async()=>!1,denyOutboundEncryptedConnection:async()=>!1,denyInboundUpgradedConnection:async()=>!1,denyOutboundUpgradedConnection:async()=>!1,filterMultiaddrForPeer:async()=>!0,...t}}var eL=Symbol.for("@libp2p/transport");var Zr;(function(t){t[t.FATAL_ALL=0]="FATAL_ALL",t[t.NO_FATAL=1]="NO_FATAL"})(Zr||(Zr={}));function Cl(t){try{let{address:e}=t.nodeAddress();return!!aa(e)}catch{return!0}}function Ii(t,e){let r=Cl(t.multiaddr),n=Cl(e.multiaddr);return r&&!n?1:!r&&n||t.isCertified&&!e.isCertified?-1:!t.isCertified&&e.isCertified?1:0}var Bl=te(Tu(),1),Ll=te(Xm(),1);var Zm=globalThis.fetch,jm=globalThis.Headers,aL=globalThis.Request,cL=globalThis.Response;function ca(t,e,r){return`${t}?name=${e}&type=${r}`}async function Jm(t,e){return await(await Zm(t,{headers:new jm({accept:"application/dns-json"}),signal:e})).json()}function kn(t,e){return`${e}_${t}`}var Tl=Object.assign((0,Bl.default)("dns-over-http-resolver"),{error:(0,Bl.default)("dns-over-http-resolver:error")}),Pl=class{constructor(e={}){this._cache=new Ll.default({max:e?.maxCache??100}),this._TXTcache=new Ll.default({max:e?.maxCache??100}),this._servers=["https://cloudflare-dns.com/dns-query","https://dns.google/resolve"],this._request=e.request??Jm,this._abortControllers=[]}cancel(){this._abortControllers.forEach(e=>e.abort())}getServers(){return this._servers}_getShuffledServers(){let e=[...this._servers];for(let r=e.length-1;r>0;r--){let n=Math.floor(Math.random()*r),i=e[r];e[r]=e[n],e[n]=i}return e}setServers(e){this._servers=e}async resolve(e,r="A"){switch(r){case"A":return await this.resolve4(e);case"AAAA":return await this.resolve6(e);case"TXT":return await this.resolveTxt(e);default:throw new Error(`${r} is not supported`)}}async resolve4(e){let r="A",n=this._cache.get(kn(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ca(o,e,r),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(kn(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Tl.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryA ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}async resolve6(e){let r="AAAA",n=this._cache.get(kn(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ca(o,e,r),s.signal),c=a.Answer.map(l=>l.data),u=Math.min(...a.Answer.map(l=>l.TTL));return this._cache.set(kn(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Tl.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryAaaa ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}async resolveTxt(e){let r="TXT",n=this._TXTcache.get(kn(e,r));if(n!=null)return n;let i=!1;for(let o of this._getShuffledServers()){let s=new AbortController;this._abortControllers.push(s);try{let a=await this._request(ca(o,e,r),s.signal),c=a.Answer.map(l=>[l.data.replace(/['"]+/g,"")]),u=Math.min(...a.Answer.map(l=>l.TTL));return this._TXTcache.set(kn(e,r),c,{ttl:u}),c}catch{s.signal.aborted&&(i=!0),Tl.error(`${o} could not resolve ${e} record ${r}`)}finally{this._abortControllers=this._abortControllers.filter(a=>a!==s)}}throw i?Object.assign(new Error("queryTxt ECANCELLED"),{code:"ECANCELLED"}):new Error(`Could not resolve ${e} record ${r}`)}clearCache(){this._cache.clear(),this._TXTcache.clear()}},ey=Pl;var ty=ey;var{code:Jv}=be("dnsaddr");async function Ri(t,e={}){let r=new ty;e.signal!=null&&e.signal.addEventListener("abort",()=>{r.cancel()});let n=t.getPeerId(),[,i]=t.stringTuples().find(([a])=>a===Jv)??[];if(i==null)throw new Error("No hostname found in multiaddr");let s=(await r.resolveTxt(`_dnsaddr.${i}`)).flat().map(a=>a.split("=")[1]).filter(Boolean);return n!=null&&(s=s.filter(a=>a.includes(n))),s}var sr;(function(t){t.NOT_STARTED_YET="The libp2p node is not started yet",t.DHT_DISABLED="DHT is not available",t.PUBSUB_DISABLED="PubSub is not available",t.CONN_ENCRYPTION_REQUIRED="At least one connection encryption module is required",t.ERR_TRANSPORTS_REQUIRED="At least one transport module is required",t.ERR_PROTECTOR_REQUIRED="Private network is enforced, but no protector was provided",t.NOT_FOUND="Not found"})(sr||(sr={}));var K;(function(t){t.DHT_DISABLED="ERR_DHT_DISABLED",t.ERR_PUBSUB_DISABLED="ERR_PUBSUB_DISABLED",t.PUBSUB_NOT_STARTED="ERR_PUBSUB_NOT_STARTED",t.DHT_NOT_STARTED="ERR_DHT_NOT_STARTED",t.CONN_ENCRYPTION_REQUIRED="ERR_CONN_ENCRYPTION_REQUIRED",t.ERR_TRANSPORTS_REQUIRED="ERR_TRANSPORTS_REQUIRED",t.ERR_PROTECTOR_REQUIRED="ERR_PROTECTOR_REQUIRED",t.ERR_PEER_DIAL_INTERCEPTED="ERR_PEER_DIAL_INTERCEPTED",t.ERR_CONNECTION_INTERCEPTED="ERR_CONNECTION_INTERCEPTED",t.ERR_INVALID_PROTOCOLS_FOR_STREAM="ERR_INVALID_PROTOCOLS_FOR_STREAM",t.ERR_CONNECTION_ENDED="ERR_CONNECTION_ENDED",t.ERR_CONNECTION_FAILED="ERR_CONNECTION_FAILED",t.ERR_NODE_NOT_STARTED="ERR_NODE_NOT_STARTED",t.ERR_ALREADY_ABORTED="ERR_ALREADY_ABORTED",t.ERR_TOO_MANY_ADDRESSES="ERR_TOO_MANY_ADDRESSES",t.ERR_NO_VALID_ADDRESSES="ERR_NO_VALID_ADDRESSES",t.ERR_RELAYED_DIAL="ERR_RELAYED_DIAL",t.ERR_DIALED_SELF="ERR_DIALED_SELF",t.ERR_DISCOVERED_SELF="ERR_DISCOVERED_SELF",t.ERR_DUPLICATE_TRANSPORT="ERR_DUPLICATE_TRANSPORT",t.ERR_ENCRYPTION_FAILED="ERR_ENCRYPTION_FAILED",t.ERR_HOP_REQUEST_FAILED="ERR_HOP_REQUEST_FAILED",t.ERR_INVALID_KEY="ERR_INVALID_KEY",t.ERR_INVALID_MESSAGE="ERR_INVALID_MESSAGE",t.ERR_INVALID_PARAMETERS="ERR_INVALID_PARAMETERS",t.ERR_INVALID_PEER="ERR_INVALID_PEER",t.ERR_MUXER_UNAVAILABLE="ERR_MUXER_UNAVAILABLE",t.ERR_NOT_FOUND="ERR_NOT_FOUND",t.ERR_TIMEOUT="ERR_TIMEOUT",t.ERR_TRANSPORT_UNAVAILABLE="ERR_TRANSPORT_UNAVAILABLE",t.ERR_TRANSPORT_DIAL_FAILED="ERR_TRANSPORT_DIAL_FAILED",t.ERR_UNSUPPORTED_PROTOCOL="ERR_UNSUPPORTED_PROTOCOL",t.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED="ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED",t.ERR_INVALID_MULTIADDR="ERR_INVALID_MULTIADDR",t.ERR_SIGNATURE_NOT_VALID="ERR_SIGNATURE_NOT_VALID",t.ERR_FIND_SELF="ERR_FIND_SELF",t.ERR_NO_ROUTERS_AVAILABLE="ERR_NO_ROUTERS_AVAILABLE",t.ERR_CONNECTION_NOT_MULTIPLEXED="ERR_CONNECTION_NOT_MULTIPLEXED",t.ERR_NO_DIAL_TOKENS="ERR_NO_DIAL_TOKENS",t.ERR_KEYCHAIN_REQUIRED="ERR_KEYCHAIN_REQUIRED",t.ERR_INVALID_CMS="ERR_INVALID_CMS",t.ERR_MISSING_KEYS="ERR_MISSING_KEYS",t.ERR_NO_KEY="ERR_NO_KEY",t.ERR_INVALID_KEY_NAME="ERR_INVALID_KEY_NAME",t.ERR_INVALID_KEY_TYPE="ERR_INVALID_KEY_TYPE",t.ERR_KEY_ALREADY_EXISTS="ERR_KEY_ALREADY_EXISTS",t.ERR_INVALID_KEY_SIZE="ERR_INVALID_KEY_SIZE",t.ERR_KEY_NOT_FOUND="ERR_KEY_NOT_FOUND",t.ERR_OLD_KEY_NAME_INVALID="ERR_OLD_KEY_NAME_INVALID",t.ERR_NEW_KEY_NAME_INVALID="ERR_NEW_KEY_NAME_INVALID",t.ERR_PASSWORD_REQUIRED="ERR_PASSWORD_REQUIRED",t.ERR_PEM_REQUIRED="ERR_PEM_REQUIRED",t.ERR_CANNOT_READ_KEY="ERR_CANNOT_READ_KEY",t.ERR_MISSING_PRIVATE_KEY="ERR_MISSING_PRIVATE_KEY",t.ERR_MISSING_PUBLIC_KEY="ERR_MISSING_PUBLIC_KEY",t.ERR_INVALID_OLD_PASS_TYPE="ERR_INVALID_OLD_PASS_TYPE",t.ERR_INVALID_NEW_PASS_TYPE="ERR_INVALID_NEW_PASS_TYPE",t.ERR_INVALID_PASS_LENGTH="ERR_INVALID_PASS_LENGTH",t.ERR_NOT_IMPLEMENTED="ERR_NOT_IMPLEMENTED",t.ERR_WRONG_PING_ACK="ERR_WRONG_PING_ACK",t.ERR_INVALID_RECORD="ERR_INVALID_RECORD",t.ERR_ALREADY_SUCCEEDED="ERR_ALREADY_SUCCEEDED",t.ERR_NO_HANDLER_FOR_PROTOCOL="ERR_NO_HANDLER_FOR_PROTOCOL",t.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS",t.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS="ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS",t.ERR_CONNECTION_DENIED="ERR_CONNECTION_DENIED",t.ERR_TRANSFER_LIMIT_EXCEEDED="ERR_TRANSFER_LIMIT_EXCEEDED"})(K||(K={}));var e_={addresses:{listen:[],announce:[],noAnnounce:[],announceFilter:t=>t},connectionManager:{resolvers:{dnsaddr:Ri},addressSorter:Ii},transportManager:{faultTolerance:Zr.FATAL_ALL}};function ry(t){let e=$r(e_,t);if(e.transports==null||e.transports.length<1)throw new b(sr.ERR_TRANSPORTS_REQUIRED,K.ERR_TRANSPORTS_REQUIRED);if(e.connectionProtector===null&&globalThis.process?.env?.LIBP2P_FORCE_PNET!=null)throw new b(sr.ERR_PROTECTOR_REQUIRED,K.ERR_PROTECTOR_REQUIRED);return e}var ny="keep-alive";var tg=te(Zy(),1);var O_=ie("libp2p:get-peer");function la(t){if(Bs(t))return{peerId:t,multiaddrs:[]};Array.isArray(t)||(t=[t]);let e;if(t.length>0){let r=t[0].getPeerId();e=r==null?void 0:de(r),t.forEach(n=>{if(!Ln(n))throw O_.error("multiaddr %s was invalid",n),new b("Invalid Multiaddr",K.ERR_INVALID_MULTIADDR);let i=n.getPeerId();if(i==null){if(e!=null)throw new b("Multiaddrs must all have the same peer id or have no peer id",K.ERR_INVALID_PARAMETERS)}else{let o=de(i);if(e==null||!e.equals(o))throw new b("Multiaddrs must all have the same peer id or have no peer id",K.ERR_INVALID_PARAMETERS)}})}return{peerId:e,multiaddrs:t}}function M_(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Wl=class{#e=[];enqueue(e,r){let n=r?.peerId,i=r?.priority??0;if(n==null)throw new b("missing peer id",K.ERR_INVALID_PARAMETERS);let o={priority:i,peerId:n,run:e};if(this.size>0&&this.#e[this.size-1].priority>=i){this.#e.push(o);return}let s=M_(this.#e,o,(a,c)=>c.priority-a.priority);this.#e.splice(s,0,o)}dequeue(){return this.#e.shift()?.run}filter(e){if(e.peerId!=null){let r=e.peerId;return this.#e.filter(n=>r.equals(n.peerId)).map(n=>n.run)}return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}},fa=class extends Yr{constructor(e={}){super({...e,queueClass:Wl})}hasJob(e){return this.sizeBy({peerId:e})>0}};var ha="last-dial-failure";var da=10,pa=5,ma=100,ya=10;var st=ie("libp2p:connection-manager:auto-dial"),Pi={minConnections:pa,maxQueueLength:100,autoDialConcurrency:ya,autoDialPriority:0,autoDialInterval:5e3,autoDialPeerRetryThreshold:6e4},ga=class{connectionManager;peerStore;queue;minConnections;autoDialPriority;autoDialIntervalMs;autoDialMaxQueueLength;autoDialPeerRetryThresholdMs;autoDialInterval;started;running;constructor(e,r){this.connectionManager=e.connectionManager,this.peerStore=e.peerStore,this.minConnections=r.minConnections??Pi.minConnections,this.autoDialPriority=r.autoDialPriority??Pi.autoDialPriority,this.autoDialIntervalMs=r.autoDialInterval??Pi.autoDialInterval,this.autoDialMaxQueueLength=r.maxQueueLength??Pi.maxQueueLength,this.autoDialPeerRetryThresholdMs=r.autoDialPeerRetryThreshold??Pi.autoDialPeerRetryThreshold,this.started=!1,this.running=!1,this.queue=new fa({concurrency:r.autoDialConcurrency??Pi.autoDialConcurrency}),this.queue.addListener("error",n=>{st.error("error during auto-dial",n)}),e.events.addEventListener("connection:close",()=>{this.autoDial().catch(n=>{st.error(n)})})}isStarted(){return this.started}start(){this.autoDialInterval=setTimeout(()=>{this.autoDial().catch(e=>{st.error("error while autodialing",e)})},this.autoDialIntervalMs),this.started=!0}afterStart(){this.autoDial().catch(e=>{st.error("error while autodialing",e)})}stop(){this.queue.clear(),clearTimeout(this.autoDialInterval),this.started=!1,this.running=!1}async autoDial(){if(!this.started)return;let e=this.connectionManager.getConnectionsMap(),r=e.size;if(r>=this.minConnections){this.minConnections>0&&st.trace("have enough connections %d/%d",r,this.minConnections);return}if(this.queue.size>this.autoDialMaxQueueLength){st("not enough connections %d/%d but auto dial queue is full",r,this.minConnections);return}if(this.running){st("not enough connections %d/%d - but skipping autodial as it is already running",r,this.minConnections);return}this.running=!0,st("not enough connections %d/%d - will dial peers to increase the number of connections",r,this.minConnections);let n=new Bn(this.connectionManager.getDialQueue().map(u=>u.peerId).filter(Boolean)),i=await this.peerStore.all({filters:[u=>u.addresses.length===0?(st.trace("not autodialing %p because they have no addresses"),!1):e.has(u.id)?(st.trace("not autodialing %p because they are already connected"),!1):n.has(u.id)?(st.trace("not autodialing %p because they are already being dialed"),!1):this.queue.hasJob(u.id)?(st.trace("not autodialing %p because they are already being autodialed"),!1):!0]}),o=i.sort(()=>Math.random()>.5?1:-1),s=new $t;for(let u of o)s.has(u.id)||s.set(u.id,[...u.tags.values()].reduce((l,f)=>l+f.value,0));let c=o.sort((u,l)=>{let f=s.get(u.id)??0,h=s.get(l.id)??0;return f>h?-1:f<h?1:0}).filter(u=>{let l=u.metadata.get(ha);if(l==null)return!0;let f=parseInt(Z(l));return isNaN(f)?!0:Date.now()-f>this.autoDialPeerRetryThresholdMs});st("selected %d/%d peers to dial",c.length,i.length);for(let u of c)this.queue.add(async()=>{let l=this.connectionManager.getConnectionsMap().size;if(l>=this.minConnections){st("got enough connections now %d/%d",l,this.minConnections),this.queue.clear();return}st("connecting to a peerStore stored peer %p",u.id),await this.connectionManager.openConnection(u.id,{priority:this.autoDialPriority})},{peerId:u.id}).catch(l=>{st.error("could not connect to peerStore stored peer",l)});this.running=!1,this.started&&(this.autoDialInterval=setTimeout(()=>{this.autoDial().catch(u=>{st.error("error while autodialing",u)})},this.autoDialIntervalMs))}};var Di=ie("libp2p:connection-manager:connection-pruner"),jy={maxConnections:ma,allow:[]},xa=class{maxConnections;connectionManager;peerStore;allow;events;constructor(e,r={}){this.maxConnections=r.maxConnections??jy.maxConnections,this.allow=r.allow??jy.allow,this.connectionManager=e.connectionManager,this.peerStore=e.peerStore,this.events=e.events,e.events.addEventListener("connection:open",()=>{this.maybePruneConnections().catch(n=>{Di.error(n)})})}async maybePruneConnections(){let e=this.connectionManager.getConnections(),r=e.length,n=Math.max(r-this.maxConnections,0);if(Di("checking max connections limit %d/%d",r,this.maxConnections),r<=this.maxConnections)return;Di("max connections limit exceeded %d/%d, pruning %d connection(s)",r,this.maxConnections,n);let i=new $t;for(let a of e){let c=a.remotePeer;if(!i.has(c)){i.set(c,0);try{let u=await this.peerStore.get(c);i.set(c,[...u.tags.values()].reduce((l,f)=>l+f.value,0))}catch(u){u.code!=="ERR_NOT_FOUND"&&Di.error("error loading peer tags",u)}}}let o=e.sort((a,c)=>{let u=i.get(a.remotePeer)??0,l=i.get(c.remotePeer)??0;if(u>l)return 1;if(u<l)return-1;let f=a.timeline.open,h=c.timeline.open;return f<h?1:f>h?-1:0}),s=[];for(let a of o)if(Di("too many connections open - closing a connection to %p",a.remotePeer),this.allow.some(u=>a.remoteAddr.toString().startsWith(u.toString()))||s.push(a),s.length===n)break;await Promise.all(s.map(async a=>{try{await a.close()}catch(c){Di.error(c)}})),this.events.safeDispatchEvent("connection:prune",{detail:s})}};var Jl=te($n(),1);function Ea(t){let e=new globalThis.AbortController;function r(){e.abort();for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}for(let o of t){if(o?.aborted===!0){r();break}o?.addEventListener!=null&&o.addEventListener("abort",r)}function n(){for(let o of t)o?.removeEventListener!=null&&o.removeEventListener("abort",r)}let i=e.signal;return i.clear=n,i}function Jr(){let t={};return t.promise=new Promise((e,r)=>{t.resolve=e,t.reject=r}),t}var Zl=te($n(),1);var Jy=ie("libp2p:connection-manager:utils");async function jl(t,e){if(!t.protoNames().includes("dnsaddr"))return[t];let n=await K_(t,e),s=(await Promise.all(n.map(async a=>jl(a,e)))).flat().reduce((a,c)=>(a.find(u=>u.equals(c))==null&&a.push(c),a),[]);return Jy("resolved %s to",t,s.map(a=>a.toString())),s}async function K_(t,e){try{return t=ze(t.toString()),await t.resolve(e)}catch(r){return Jy.error(`multiaddr ${t.toString()} could not be resolved`,r),[]}}function eg(...t){let e=[];for(let n of t)if(n!=null){try{(0,Zl.setMaxListeners)?.(1/0,n)}catch{}e.push(n)}let r=Ea(e);try{(0,Zl.setMaxListeners)?.(1/0,r)}catch{}return r}var at=ie("libp2p:connection-manager:dial-queue"),So={addressSorter:Ii,maxParallelDials:da,maxPeerAddrsToDial:25,maxParallelDialsPerPeer:10,dialTimeout:3e4,resolvers:{dnsaddr:Ri}},wa=class{pendingDials;queue;peerId;peerStore;connectionGater;transportManager;addressSorter;maxPeerAddrsToDial;maxParallelDialsPerPeer;dialTimeout;inProgressDialCount;pendingDialCount;shutDownController;constructor(e,r={}){this.addressSorter=r.addressSorter??So.addressSorter,this.maxPeerAddrsToDial=r.maxPeerAddrsToDial??So.maxPeerAddrsToDial,this.maxParallelDialsPerPeer=r.maxParallelDialsPerPeer??So.maxParallelDialsPerPeer,this.dialTimeout=r.dialTimeout??So.dialTimeout,this.peerId=e.peerId,this.peerStore=e.peerStore,this.connectionGater=e.connectionGater,this.transportManager=e.transportManager,this.shutDownController=new AbortController;try{(0,Jl.setMaxListeners)?.(1/0,this.shutDownController.signal)}catch{}this.pendingDialCount=e.metrics?.registerMetric("libp2p_dialler_pending_dials"),this.inProgressDialCount=e.metrics?.registerMetric("libp2p_dialler_in_progress_dials"),this.pendingDials=[];for(let[n,i]of Object.entries(r.resolvers??{}))Ju.set(n,i);this.queue=new Yr({concurrency:r.maxParallelDials??So.maxParallelDials}),this.queue.on("add",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("active",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("completed",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("error",n=>{at.error("error in dial queue",n),this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("empty",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)}),this.queue.on("idle",()=>{this.pendingDialCount?.update(this.queue.size),this.inProgressDialCount?.update(this.queue.pending)})}stop(){this.shutDownController.abort()}async dial(e,r={}){let{peerId:n,multiaddrs:i}=la(e),o=i.map(l=>({multiaddr:l,isCertified:!1})),s=this.createDialAbortControllers(r.signal),a;try{a=await this.calculateMultiaddrs(n,o,{...r,signal:s})}catch(l){throw s.clear(),l}let c=this.pendingDials.find(l=>!!(l.peerId!=null&&n!=null&&l.peerId.equals(n)||a.map(({multiaddr:f})=>f.toString()).join()===l.multiaddrs.map(f=>f.toString()).join()));if(c!=null)return at("joining existing dial target for %p",n),s.clear(),c.promise;at("creating dial target for",a.map(({multiaddr:l})=>l.toString()));let u={id:V_(),status:"queued",peerId:n,multiaddrs:a.map(({multiaddr:l})=>l)};return u.promise=this.performDial(u,{...r,signal:s}).finally(()=>{this.pendingDials=this.pendingDials.filter(l=>l.id!==u.id),s.clear()}).catch(async l=>{if(at.error("dial failed to %s",u.multiaddrs.map(f=>f.toString()).join(", "),l),n!=null)try{await this.peerStore.patch(n,{metadata:{[ha]:G(Date.now().toString())}})}catch(f){at.error("could not update last dial failure key for %p",n,f)}throw s.aborted?new b(l.message,K.ERR_TIMEOUT):l}),this.pendingDials.push(u),u.promise}createDialAbortControllers(e){let r=Ea([AbortSignal.timeout(this.dialTimeout),this.shutDownController.signal,e]);try{(0,Jl.setMaxListeners)?.(1/0,r)}catch{}return r}async calculateMultiaddrs(e,r=[],n={}){if(e!=null){if(this.peerId.equals(e))throw new b("Tried to dial self",K.ERR_DIALED_SELF);if(await this.connectionGater.denyDialPeer?.(e)===!0)throw new b("The dial request is blocked by gater.allowDialPeer",K.ERR_PEER_DIAL_INTERCEPTED);if(r.length===0){at("loading multiaddrs for %p",e);try{let l=await this.peerStore.get(e);r.push(...l.addresses),at("loaded multiaddrs for %p",e,r.map(({multiaddr:f})=>f.toString()))}catch(l){if(l.code!==K.ERR_NOT_FOUND)throw l}}}let i=(await Promise.all(r.map(async l=>{let f=await jl(l.multiaddr,n);return f.length===1&&f[0].equals(l.multiaddr)?l:f.map(h=>({multiaddr:h,isCertified:!1}))}))).flat(),o=i.filter(l=>{if(this.transportManager.transportForMultiaddr(l.multiaddr)==null)return!1;let f=l.multiaddr.getPeerId();return e!=null&&f!=null?e.equals(f):!0}),s=new Map;for(let l of o){let f=l.multiaddr.toString(),h=s.get(f);if(h!=null){h.isCertified=h.isCertified||l.isCertified||!1;continue}s.set(f,l)}let a=[...s.values()];if((a.length===0||a.length>this.maxPeerAddrsToDial)&&(at("addresses for %p before filtering",e??"unknown peer",i.map(({multiaddr:l})=>l.toString())),at("addresses for %p after filtering",e??"unknown peer",a.map(({multiaddr:l})=>l.toString()))),a.length===0)throw new b("The dial request has no valid addresses",K.ERR_NO_VALID_ADDRESSES);if(a.length>this.maxPeerAddrsToDial)throw new b("dial with more addresses than allowed",K.ERR_TOO_MANY_ADDRESSES);if(e!=null){let l=`/p2p/${e.toString()}`;a=a.map(f=>{let h=f.multiaddr.getPeerId();return f.multiaddr.protos().pop()?.path===!0?f:h!==e.toString()?{multiaddr:f.multiaddr.encapsulate(l),isCertified:f.isCertified}:f})}let c=[];for(let l of a)this.connectionGater.denyDialMultiaddr!=null&&await this.connectionGater.denyDialMultiaddr(l.multiaddr)||c.push(l);let u=c.sort(this.addressSorter);if(u.length===0)throw new b("The connection gater denied all addresses in the dial request",K.ERR_NO_VALID_ADDRESSES);return u}async performDial(e,r={}){let n=e.multiaddrs.map(()=>new AbortController);try{let i=new Yr({concurrency:this.maxParallelDialsPerPeer});i.on("error",s=>{at.error("error dialling",s)});let o=await Promise.any(e.multiaddrs.map(async(s,a)=>{let c=n[a];if(c==null)throw new b("dialAction did not come with an AbortController",K.ERR_INVALID_PARAMETERS);let u=eg(c.signal,r.signal);u.addEventListener("abort",()=>{at("dial to %a aborted",s)});let l=Jr();return await i.add(async()=>{if(u.aborted){at("dial to %a was aborted before reaching the head of the peer dial queue",s),l.reject(new Wn);return}await this.queue.add(async()=>{try{if(u.aborted){at("dial to %a was aborted before reaching the head of the dial queue",s),l.reject(new Wn);return}e.status="active";let f=await this.transportManager.dial(s,{...r,signal:u});if(c.signal.aborted){at("multiple dials succeeded, closing superfluous connection"),f.close().catch(h=>{at.error("error closing superfluous connection",h)}),l.reject(new Wn);return}n[a]=void 0,n.forEach(h=>{h!==void 0&&h.abort()}),at("dial to %a succeeded",s),l.resolve(f)}catch(f){at.error("error during dial of %a",s,f),l.reject(f)}},{...r,signal:u}).catch(f=>{l.reject(f)})},{signal:u}).catch(f=>{l.reject(f)}).finally(()=>{u.clear()}),l.promise}));if(o==null)throw new b("successful dial led to empty object returned from peer dial queue",K.ERR_TRANSPORT_DIAL_FAILED);return e.status="success",o}catch(i){throw e.status="error",e.multiaddrs.length===1&&i.name==="AggregateError"?i.errors[0]:i}}};function V_(){return`${parseInt(String(Math.random()*1e9),10).toString()}${Date.now()}`}var It=ie("libp2p:connection-manager"),z_=50,On={minConnections:pa,maxConnections:ma,inboundConnectionThreshold:5,maxIncomingPendingConnections:10,autoDialConcurrency:ya,autoDialPriority:0,autoDialMaxQueueLength:100},ba=class{started;connections;allow;deny;maxIncomingPendingConnections;incomingPendingConnections;maxConnections;dialQueue;autoDial;connectionPruner;inboundConnectionRateLimiter;peerStore;metrics;events;constructor(e,r={}){this.maxConnections=r.maxConnections??On.maxConnections;let n=r.minConnections??On.minConnections;if(this.maxConnections<n)throw new b("Connection Manager maxConnections must be greater than minConnections",K.ERR_INVALID_PARAMETERS);this.connections=new $t,this.started=!1,this.peerStore=e.peerStore,this.metrics=e.metrics,this.events=e.events,this.onConnect=this.onConnect.bind(this),this.onDisconnect=this.onDisconnect.bind(this),this.events.addEventListener("connection:open",this.onConnect),this.events.addEventListener("connection:close",this.onDisconnect),this.allow=(r.allow??[]).map(i=>ze(i)),this.deny=(r.deny??[]).map(i=>ze(i)),this.incomingPendingConnections=0,this.maxIncomingPendingConnections=r.maxIncomingPendingConnections??On.maxIncomingPendingConnections,this.inboundConnectionRateLimiter=new tg.RateLimiterMemory({points:r.inboundConnectionThreshold??On.inboundConnectionThreshold,duration:1}),this.autoDial=new ga({connectionManager:this,peerStore:e.peerStore,events:e.events},{minConnections:n,autoDialConcurrency:r.autoDialConcurrency??On.autoDialConcurrency,autoDialPriority:r.autoDialPriority??On.autoDialPriority,maxQueueLength:r.autoDialMaxQueueLength??On.autoDialMaxQueueLength}),this.connectionPruner=new xa({connectionManager:this,peerStore:e.peerStore,events:e.events},{maxConnections:this.maxConnections,allow:this.allow}),this.dialQueue=new wa({peerId:e.peerId,metrics:e.metrics,peerStore:e.peerStore,transportManager:e.transportManager,connectionGater:e.connectionGater},{addressSorter:r.addressSorter??Ii,maxParallelDials:r.maxParallelDials??da,maxPeerAddrsToDial:r.maxPeerAddrsToDial??25,dialTimeout:r.dialTimeout??3e4,resolvers:r.resolvers??{dnsaddr:Ri}})}isStarted(){return this.started}async start(){this.metrics?.registerMetricGroup("libp2p_connection_manager_connections",{calculate:()=>{let e={inbound:0,outbound:0};for(let r of this.connections.values())for(let n of r)n.direction==="inbound"?e.inbound++:e.outbound++;return e}}),this.metrics?.registerMetricGroup("libp2p_protocol_streams_total",{label:"protocol",calculate:()=>{let e={};for(let r of this.connections.values())for(let n of r)for(let i of n.streams){let o=`${i.direction} ${i.protocol??"unnegotiated"}`;e[o]=(e[o]??0)+1}return e}}),this.metrics?.registerMetricGroup("libp2p_connection_manager_protocol_streams_per_connection_90th_percentile",{label:"protocol",calculate:()=>{let e={};for(let n of this.connections.values())for(let i of n){let o={};for(let s of i.streams){let a=`${s.direction} ${s.protocol??"unnegotiated"}`;o[a]=(o[a]??0)+1}for(let[s,a]of Object.entries(o))e[s]=e[s]??[],e[s].push(a)}let r={};for(let[n,i]of Object.entries(e)){i=i.sort((s,a)=>s-a);let o=Math.floor(i.length*.9);r[n]=i[o]}return r}}),this.autoDial.start(),this.started=!0,It("started")}async afterStart(){Promise.resolve().then(async()=>{let e=await this.peerStore.all({filters:[r=>r.tags.has(ny)]});await Promise.all(e.map(async r=>{await this.openConnection(r.id).catch(n=>{It.error(n)})}))}).catch(e=>{It.error(e)}),this.autoDial.afterStart()}async stop(){this.dialQueue.stop(),this.autoDial.stop();let e=[];for(let r of this.connections.values())for(let n of r)e.push((async()=>{try{await n.close()}catch(i){It.error(i)}})());It("closing %d connections",e.length),await Promise.all(e),this.connections.clear(),It("stopped")}onConnect(e){this._onConnect(e).catch(r=>{It.error(r)})}async _onConnect(e){let{detail:r}=e;if(!this.started){await r.close();return}let n=r.remotePeer,i=this.connections.get(n),o=!1;i!=null?i.push(r):(o=!0,this.connections.set(n,[r])),n.publicKey!=null&&n.type==="RSA"&&await this.peerStore.patch(n,{publicKey:n.publicKey}),o&&this.events.safeDispatchEvent("peer:connect",{detail:r.remotePeer})}onDisconnect(e){let{detail:r}=e;if(!this.started)return;let n=r.remotePeer,i=this.connections.get(n);i!=null&&i.length>1?(i=i.filter(o=>o.id!==r.id),this.connections.set(n,i)):i!=null&&(this.connections.delete(n),this.events.safeDispatchEvent("peer:disconnect",{detail:r.remotePeer}))}getConnections(e){if(e!=null)return this.connections.get(e)??[];let r=[];for(let n of this.connections.values())r=r.concat(n);return r}getConnectionsMap(){return this.connections}async openConnection(e,r={}){if(!this.isStarted())throw new b("Not started",K.ERR_NODE_NOT_STARTED);r.signal?.throwIfAborted();let{peerId:n}=la(e);if(n!=null&&r.force!==!0){It("dial %p",n);let a=this.getConnections(n);if(a.length>0)return It("had an existing connection to %p",n),a[0]}let i=await this.dialQueue.dial(e,{...r,priority:r.priority??z_}),o=this.connections.get(i.remotePeer);o==null&&(o=[],this.connections.set(i.remotePeer,o));let s=!1;for(let a of o)a.id===i.id&&(s=!0);return s||o.push(i),i}async closeConnections(e,r={}){let n=this.connections.get(e)??[];await Promise.all(n.map(async i=>{try{await i.close(r)}catch(o){i.abort(o)}}))}async acceptIncomingConnection(e){if(this.deny.some(i=>e.remoteAddr.toString().startsWith(i.toString())))return It("connection from %a refused - connection remote address was in deny list",e.remoteAddr),!1;if(this.allow.some(i=>e.remoteAddr.toString().startsWith(i.toString())))return this.incomingPendingConnections++,!0;if(this.incomingPendingConnections===this.maxIncomingPendingConnections)return It("connection from %a refused - incomingPendingConnections exceeded by host",e.remoteAddr),!1;if(e.remoteAddr.isThinWaistAddress()){let i=e.remoteAddr.nodeAddress().address;try{await this.inboundConnectionRateLimiter.consume(i,1)}catch{return It("connection from %a refused - inboundConnectionThreshold exceeded by host %s",e.remoteAddr,i),!1}}return this.getConnections().length<this.maxConnections?(this.incomingPendingConnections++,!0):(It("connection from %a refused - maxConnections exceeded",e.remoteAddr),!1)}afterUpgradeInbound(){this.incomingPendingConnections--}getDialQueue(){return this.dialQueue.pendingDials}};var va=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Ni=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new va(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let r=this.head;this.head=r.next=new va(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let r=this.tail.next;this.tail.next=null,this.tail=r,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var rf=class extends Error{type;code;constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function Mn(t={}){return G_(r=>{let n=r.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},t)}function G_(t,e){e=e??{};let r=e.onEnd,n=new Ni,i,o,s,a=Jr(),c=async()=>{try{return n.isEmpty()?s?{done:!0}:await new Promise((y,g)=>{o=x=>{o=null,n.push(x);try{y(t(n))}catch(w){g(w)}return i}}):t(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=Jr()})}},u=y=>o!=null?o(y):(n.push(y),i),l=y=>(n=new Ni,o!=null?o({error:y}):(n.push({error:y}),i)),f=y=>{if(s)return i;if(e?.objectMode!==!0&&y?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return u({done:!1,value:y})},h=y=>s?i:(s=!0,y!=null?l(y):u({done:!0})),p=()=>(n=new Ni,h(),{done:!0}),d=y=>(h(y),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:p,throw:d,push:f,end:h,get readableLength(){return n.size},onEmpty:async y=>{let g=y?.signal;if(g?.throwIfAborted(),n.isEmpty())return;let x,w;g!=null&&(x=new Promise((C,_)=>{w=()=>{_(new rf)},g.addEventListener("abort",w)}));try{await Promise.race([a.promise,x])}finally{w!=null&&g!=null&&g?.removeEventListener("abort",w)}}},r==null)return i;let m=i;return i={[Symbol.asyncIterator](){return this},next(){return m.next()},throw(y){return m.throw(y),r!=null&&(r(y),r=void 0),{done:!0}},return(){return m.return(),r!=null&&(r(),r=void 0),{done:!0}},push:f,end(y){return m.end(y),r!=null&&(r(y),r=void 0),i},get readableLength(){return m.readableLength}},i}function Y_(t){return t[Symbol.asyncIterator]!=null}function W_(...t){let e=[];for(let r of t)Y_(r)||e.push(r);return e.length===t.length?function*(){for(let r of e)yield*r}():async function*(){let r=Mn({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(t.map(async n=>{for await(let i of n)r.push(i)})),r.end()}catch(n){r.end(n)}}),yield*r}()}var en=W_;function Un(t,...e){if(t==null)throw new Error("Empty pipeline");if(nf(t)){let n=t;t=()=>n.source}else if(ng(t)||rg(t)){let n=t;t=()=>n}let r=[t,...e];if(r.length>1&&nf(r[r.length-1])&&(r[r.length-1]=r[r.length-1].sink),r.length>2)for(let n=1;n<r.length-1;n++)nf(r[n])&&(r[n]=X_(r[n]));return Q_(...r)}var Q_=(...t)=>{let e;for(;t.length>0;)e=t.shift()(e);return e},rg=t=>t?.[Symbol.asyncIterator]!=null,ng=t=>t?.[Symbol.iterator]!=null,nf=t=>t==null?!1:t.sink!=null&&t.source!=null,X_=t=>e=>{let r=t.sink(e);if(r?.then!=null){let n=Mn({objectMode:!0});r.then(()=>{n.end()},s=>{n.end(s)});let i,o=t.source;if(rg(o))i=async function*(){yield*o,n.end()};else if(ng(o))i=function*(){yield*o,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return en(n,i())}return t.source};function Z_(t){return t[Symbol.asyncIterator]!=null}function j_(t,e){if(Z_(t))return async function*(){for await(let a of t)yield e(a)}();let r=ta(t),{value:n,done:i}=r.next();if(i===!0)return function*(){}();let o=e(n);if(typeof o.then=="function")return async function*(){yield await o;for await(let a of r)yield e(a)}();let s=e;return function*(){yield o;for(let a of r)yield s(a)}()}var ig=j_;async function*Io(t,e){yield*ig(t,async r=>(await e.merge(r.id,{multiaddrs:r.multiaddrs}),r))}function _a(t){let e=new Set;return zt(t,r=>e.has(r.id.toString())?!1:(e.add(r.id.toString()),!0))}async function*Aa(t,e=1){let r=0;for await(let n of t)r++,yield n;if(r<e)throw new b(`more peers required, seen: ${r} min: ${e}`,"NOT_FOUND")}var Sa=class{routers;started;components;constructor(e,r){this.routers=r.routers??[],this.started=!1,this.components=e}isStarted(){return this.started}async start(){this.started=!0}async stop(){this.started=!1}async*findProviders(e,r={}){if(this.routers.length===0)throw new b("No content routers available",K.ERR_NO_ROUTERS_AVAILABLE);yield*Un(en(...this.routers.map(n=>n.findProviders(e,r))),n=>Io(n,this.components.peerStore),n=>_a(n),n=>Aa(n))}async provide(e,r={}){if(this.routers.length===0)throw new b("No content routers available",K.ERR_NO_ROUTERS_AVAILABLE);await Promise.all(this.routers.map(async n=>{await n.provide(e,r)}))}async put(e,r,n){if(!this.isStarted())throw new b(sr.NOT_STARTED_YET,K.DHT_NOT_STARTED);await Promise.all(this.routers.map(async i=>{await i.put(e,r,n)}))}async get(e,r){if(!this.isStarted())throw new b(sr.NOT_STARTED_YET,K.DHT_NOT_STARTED);return Promise.any(this.routers.map(async n=>n.get(e,r)))}};function J_(t){return t[Symbol.asyncIterator]!=null}function eA(t){if(J_(t))return(async()=>{for await(let e of t)return e})();for(let e of t)return e}var Ia=eA;var tA=ie("libp2p:peer-routing"),Ra=class{components;routers;constructor(e,r){this.components=e,this.routers=r.routers??[]}async findPeer(e,r){if(this.routers.length===0)throw new b("No peer routers available",K.ERR_NO_ROUTERS_AVAILABLE);if(e.toString()===this.components.peerId.toString())throw new b("Should not try to find self",K.ERR_FIND_SELF);let n=await Un(en(...this.routers.map(i=>async function*(){try{yield await i.findPeer(e,r)}catch(o){tA.error(o)}}())),i=>zt(i,Boolean),i=>Io(i,this.components.peerStore),async i=>Ia(i));if(n!=null)return n;throw new b(sr.NOT_FOUND,K.ERR_NOT_FOUND)}async*getClosestPeers(e,r){if(this.routers.length===0)throw new b("No peer routers available",K.ERR_NO_ROUTERS_AVAILABLE);yield*Un(en(...this.routers.map(n=>n.getClosestPeers(e,r))),n=>Io(n,this.components.peerStore),n=>_a(n),n=>Aa(n))}};var of=ie("libp2p:registrar"),sf=32,af=64,Ca=class{topologies;handlers;components;constructor(e){this.topologies=new Map,this.handlers=new Map,this.components=e,this._onDisconnect=this._onDisconnect.bind(this),this._onPeerUpdate=this._onPeerUpdate.bind(this),this._onConnect=this._onConnect.bind(this),this.components.events.addEventListener("peer:disconnect",this._onDisconnect),this.components.events.addEventListener("peer:connect",this._onConnect),this.components.events.addEventListener("peer:update",this._onPeerUpdate)}getProtocols(){return Array.from(new Set([...this.handlers.keys()])).sort()}getHandler(e){let r=this.handlers.get(e);if(r==null)throw new b(`No handler registered for protocol ${e}`,K.ERR_NO_HANDLER_FOR_PROTOCOL);return r}getTopologies(e){let r=this.topologies.get(e);return r==null?[]:[...r.values()]}async handle(e,r,n){if(this.handlers.has(e))throw new b(`Handler already registered for protocol ${e}`,K.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED);let i=$r.bind({ignoreUndefined:!0})({maxInboundStreams:sf,maxOutboundStreams:af},n);this.handlers.set(e,{handler:r,options:i}),await this.components.peerStore.merge(this.components.peerId,{protocols:[e]})}async unhandle(e){(Array.isArray(e)?e:[e]).forEach(n=>{this.handlers.delete(n)}),await this.components.peerStore.patch(this.components.peerId,{protocols:this.getProtocols()})}async register(e,r){if(r==null)throw new b("invalid topology",K.ERR_INVALID_PARAMETERS);let n=`${(Math.random()*1e9).toString(36)}${Date.now()}`,i=this.topologies.get(e);return i==null&&(i=new Map,this.topologies.set(e,i)),i.set(n,r),n}unregister(e){for(let[r,n]of this.topologies.entries())n.has(e)&&(n.delete(e),n.size===0&&this.topologies.delete(r))}_onDisconnect(e){let r=e.detail;this.components.peerStore.get(r).then(n=>{for(let i of n.protocols){let o=this.topologies.get(i);if(o!=null)for(let s of o.values())s.onDisconnect?.(r)}}).catch(n=>{n.code!==K.ERR_NOT_FOUND&&of.error("could not inform topologies of disconnecting peer %p",r,n)})}_onConnect(e){let r=e.detail;this.components.peerStore.get(r).then(n=>{let i=this.components.connectionManager.getConnections(n.id)[0];if(i==null){of("peer %p connected but the connection manager did not have a connection",n);return}for(let o of n.protocols){let s=this.topologies.get(o);if(s!=null)for(let a of s.values())a.onConnect?.(r,i)}}).catch(n=>{n.code!==K.ERR_NOT_FOUND&&of.error("could not inform topologies of connecting peer %p",r,n)})}_onPeerUpdate(e){let{peer:r,previous:n}=e.detail,i=(n?.protocols??[]).filter(s=>!r.protocols.includes(s)),o=r.protocols.filter(s=>!(n?.protocols??[]).includes(s));for(let s of i){let a=this.topologies.get(s);if(a!=null)for(let c of a.values())c.onDisconnect?.(r.id)}for(let s of o){let a=this.topologies.get(s);if(a!=null)for(let c of a.values()){let u=this.components.connectionManager.getConnections(r.id)[0];u!=null&&c.onConnect?.(r.id,u)}}}};var cf=class extends Map{metric;constructor(e){super();let{name:r,metrics:n}=e;this.metric=n.registerMetric(r),this.updateComponentMetric()}set(e,r){return super.set(e,r),this.updateComponentMetric(),this}delete(e){let r=super.delete(e);return this.updateComponentMetric(),r}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function og(t){let{name:e,metrics:r}=t,n;return r!=null?n=new cf({name:e,metrics:r}):n=new Map,n}var Fn=ie("libp2p:transports"),Ta=class{components;transports;listeners;faultTolerance;started;constructor(e,r={}){this.components=e,this.started=!1,this.transports=new Map,this.listeners=og({name:"libp2p_transport_manager_listeners",metrics:this.components.metrics}),this.faultTolerance=r.faultTolerance??Zr.FATAL_ALL}add(e){let r=e[Symbol.toStringTag];if(r==null)throw new b("Transport must have a valid tag",K.ERR_INVALID_KEY);if(this.transports.has(r))throw new b(`There is already a transport with the tag ${r}`,K.ERR_DUPLICATE_TRANSPORT);Fn("adding transport %s",r),this.transports.set(r,e),this.listeners.has(r)||this.listeners.set(r,[])}isStarted(){return this.started}start(){this.started=!0}async afterStart(){let e=this.components.addressManager.getListenAddrs();await this.listen(e)}async stop(){let e=[];for(let[r,n]of this.listeners)for(Fn("closing listeners for %s",r);n.length>0;){let i=n.pop();i!=null&&e.push(i.close())}await Promise.all(e),Fn("all listeners closed");for(let r of this.listeners.keys())this.listeners.set(r,[]);this.started=!1}async dial(e,r){let n=this.transportForMultiaddr(e);if(n==null)throw new b(`No transport available for address ${String(e)}`,K.ERR_TRANSPORT_UNAVAILABLE);try{return await n.dial(e,{...r,upgrader:this.components.upgrader})}catch(i){throw i.code==null&&(i.code=K.ERR_TRANSPORT_DIAL_FAILED),i}}getAddrs(){let e=[];for(let r of this.listeners.values())for(let n of r)e=[...e,...n.getAddrs()];return e}getTransports(){return Array.of(...this.transports.values())}getListeners(){return Array.of(...this.listeners.values()).flat()}transportForMultiaddr(e){for(let r of this.transports.values())if(r.filter([e]).length>0)return r}async listen(e){if(!this.isStarted())throw new b("Not started",K.ERR_NODE_NOT_STARTED);if(e==null||e.length===0){Fn("no addresses were provided for listening, this node is dial only");return}let r=[];for(let[n,i]of this.transports.entries()){let o=i.filter(e),s=[];for(let u of o){Fn("creating listener for %s on %a",n,u);let l=i.createListener({upgrader:this.components.upgrader}),f=this.listeners.get(n)??[];f==null&&(f=[],this.listeners.set(n,f)),f.push(l),l.addEventListener("listening",()=>{this.components.events.safeDispatchEvent("transport:listening",{detail:l})}),l.addEventListener("close",()=>{let h=f.findIndex(p=>p===l);f.splice(h,1),this.components.events.safeDispatchEvent("transport:close",{detail:l})}),s.push(l.listen(u))}if(s.length===0){r.push(n);continue}if((await Promise.allSettled(s)).find(u=>u.status==="fulfilled")==null&&this.faultTolerance!==Zr.NO_FATAL)throw new b(`Transport (${n}) could not listen on any available address`,K.ERR_NO_VALID_ADDRESSES)}if(r.length===this.transports.size){let n=`no valid addresses were provided for transports [${r.join(", ")}]`;if(this.faultTolerance===Zr.FATAL_ALL)throw new b(n,K.ERR_NO_VALID_ADDRESSES);Fn(`libp2p in dial mode only: ${n}`)}}async remove(e){Fn("removing %s",e);for(let r of this.listeners.get(e)??[])await r.close();this.transports.delete(e),this.listeners.delete(e)}async removeAll(){let e=[];for(let r of this.transports.keys())e.push(this.remove(r));await Promise.all(e)}};var hf=te($n(),1);var Rr="/multistream/1.0.0";function uf(t){let e=async function*(){let r=yield,n=new Ze;for await(let i of t){if(r==null){n.append(i),r=yield n,n=new Ze;continue}for(n.append(i);n.length>=r;){let o=n.sublist(0,r);if(n.consume(r),r=yield o,r==null){n.length>0&&(r=yield n,n=new Ze);break}}}if(r!=null)throw Object.assign(new Error(`stream ended before ${r} bytes became available`),{code:"ERR_UNDER_READ",buffer:n})}();return e.next(),e}function Ba(t){let e=Mn(),r=uf(t.source),n=Jr(),i,o=t.sink(async function*(){yield*e,yield*await n.promise}());return o.catch(a=>{i=a}),{reader:r,writer:e,stream:{sink:async a=>{if(i!=null){await Promise.reject(i);return}n.resolve(a),await o},source:r},rest:()=>e.end(),write:e.push,read:async()=>{let a=await r.next();if(a.value!=null)return a.value}}}var Ro=class extends Error{constructor(e,r){super(e??"The operation was aborted"),this.type="aborted",this.code=r??"ABORT_ERR"}};function sg(t){if(t!=null){if(typeof t[Symbol.iterator]=="function")return t[Symbol.iterator]();if(typeof t[Symbol.asyncIterator]=="function")return t[Symbol.asyncIterator]();if(typeof t.next=="function")return t}throw new Error("argument is not an iterator or iterable")}function La(t,e,r){let n=r??{},i=sg(t);async function*o(){let s,a=()=>{s?.()};for(e.addEventListener("abort",a);;){let c;try{if(e.aborted){let{abortMessage:l,abortCode:f}=n;throw new Ro(l,f)}let u=new Promise((l,f)=>{s=()=>{let{abortMessage:h,abortCode:p}=n;f(new Ro(h,p))}});c=await Promise.race([u,i.next()]),s=null}catch(u){e.removeEventListener("abort",a);let l=u.type==="aborted"&&e.aborted;if(l&&n.onAbort!=null&&n.onAbort(t),typeof i.return=="function")try{let f=i.return();f instanceof Promise&&f.catch(h=>{n.onReturnError!=null&&n.onReturnError(h)})}catch(f){n.onReturnError!=null&&n.onReturnError(f)}if(l&&n.returnOnAbort===!0)return;throw u}if(c.done===!0)break;yield c.value}e.removeEventListener("abort",a)}return o()}function rA(t,e,r){return n=>t(La(n,e,r))}function ag(t,e,r){return{sink:rA(t.sink,e,{...r,onAbort:void 0}),source:La(t.source,e,r)}}function Pa(t){return t[Symbol.asyncIterator]!=null}var Da=t=>{let e=yt(t),r=Ot(e);return Lt(t,r),Da.bytes=e,r};Da.bytes=0;function Na(t,e){e=e??{};let r=e.lengthEncoder??Da;function*n(i){let o=r(i.byteLength);o instanceof Uint8Array?yield o:yield*o,i instanceof Uint8Array?yield i:yield*i}return Pa(t)?async function*(){for await(let i of t)yield*n(i)}():function*(){for(let i of t)yield*n(i)}()}Na.single=(t,e)=>{e=e??{};let r=e.lengthEncoder??Da;return new Ze(r(t.byteLength),t)};var ki=te(Al(),1);var nA=8,iA=1024*1024*4,Kn;(function(t){t[t.LENGTH=0]="LENGTH",t[t.DATA=1]="DATA"})(Kn||(Kn={}));var lf=t=>{let e=Sr(t);return lf.bytes=yt(e),e};lf.bytes=0;function Co(t,e){let r=new Ze,n=Kn.LENGTH,i=-1,o=e?.lengthDecoder??lf,s=e?.maxLengthLength??nA,a=e?.maxDataLength??iA;function*c(){for(;r.byteLength>0;){if(n===Kn.LENGTH)try{if(i=o(r),i<0)throw(0,ki.default)(new Error("invalid message length"),"ERR_INVALID_MSG_LENGTH");if(i>a)throw(0,ki.default)(new Error("message length too long"),"ERR_MSG_DATA_TOO_LONG");let u=o.bytes;r.consume(u),e?.onLength!=null&&e.onLength(i),n=Kn.DATA}catch(u){if(u instanceof RangeError){if(r.byteLength>s)throw(0,ki.default)(new Error("message length length too long"),"ERR_MSG_LENGTH_TOO_LONG");break}throw u}if(n===Kn.DATA){if(r.byteLength<i)break;let u=r.sublist(0,i);r.consume(i),e?.onData!=null&&e.onData(u),yield u,n=Kn.LENGTH}}}return Pa(t)?async function*(){for await(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw(0,ki.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}():function*(){for(let u of t)r.append(u),yield*c();if(r.byteLength>0)throw(0,ki.default)(new Error("unexpected end of input"),"ERR_UNEXPECTED_EOF")}()}Co.fromReader=(t,e)=>{let r=1,n=async function*(){for(;;)try{let{done:o,value:s}=await t.next(r);if(o===!0)return;s!=null&&(yield s)}catch(o){if(o.code==="ERR_UNDER_READ")return{done:!0,value:null};throw o}finally{r=1}}();return Co(n,{...e??{},onLength:o=>{r=o}})};var aA=ie("libp2p:mss"),cg=G(`
49
49
  `);function To(t){let e=new Ze(t,cg);return Na.single(e)}function qn(t,e,r={}){let n=To(e);r.writeBytes===!0?t.push(n.subarray()):t.push(n)}function ug(t,e,r={}){let n=new Ze;for(let i of e)n.append(To(i));r.writeBytes===!0?t.push(n.subarray()):t.push(n)}async function cA(t,e){let r=1,n={[Symbol.asyncIterator]:()=>n,next:async()=>t.next(r)},i=n;e?.signal!=null&&(i=La(n,e.signal));let o=a=>{r=a},s=await Un(i,a=>Co(a,{onLength:o,maxDataLength:1024}),async a=>Ia(a));if(s==null||s.length===0)throw new b("no buffer returned","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");if(s.get(s.byteLength-1)!==cg[0])throw aA.error("Invalid mss message - missing newline - %s",s.subarray()),new b("missing newline","ERR_INVALID_MULTISTREAM_SELECT_MESSAGE");return s.sublist(0,-1)}async function Oi(t,e){let r=await cA(t,e);return Z(r.subarray())}var Bo=ie("libp2p:mss:select");async function Lo(t,e,r={}){e=Array.isArray(e)?[...e]:[e];let{reader:n,writer:i,rest:o,stream:s}=Ba(t),a=e.shift();if(a==null)throw new Error("At least one protocol must be specified");Bo.trace('select: write ["%s", "%s"]',Rr,a);let c=G(Rr),u=G(a);ug(i,[c,u],r);let l=await Oi(n,r);if(Bo.trace('select: read "%s"',l),l===Rr&&(l=await Oi(n,r),Bo.trace('select: read "%s"',l)),l===a)return o(),{stream:s,protocol:a};for(let f of e){Bo.trace('select: write "%s"',f),qn(i,G(f),r);let h=await Oi(n,r);if(Bo.trace('select: read "%s" for "%s"',h,f),h===f)return o(),{stream:s,protocol:f}}throw o(),new b("protocol selection failed","ERR_UNSUPPORTED_PROTOCOL")}var Po=ie("libp2p:mss:handle");async function Do(t,e,r){e=Array.isArray(e)?e:[e];let{writer:n,reader:i,rest:o,stream:s}=Ba(t);for(;;){let a=await Oi(i,r);if(Po.trace('read "%s"',a),a===Rr){Po.trace('respond with "%s" for "%s"',Rr,a),qn(n,G(Rr),r);continue}if(e.includes(a))return qn(n,G(a),r),Po.trace('respond with "%s" for "%s"',a,a),o(),{stream:s,protocol:a};if(a==="ls"){qn(n,new Ze(...e.map(c=>To(G(c)))),r),Po.trace('respond with "%s" for %s',e,a);continue}qn(n,G("na"),r),Po('respond with "na" for "%s"',a)}}var hg=te($n(),1);var fg=Symbol.for("@libp2p/connection");var ka=ie("libp2p:connection"),lA=500,ff=class{id;remoteAddr;remotePeer;direction;timeline;multiplexer;encryption;status;transient;tags;_newStream;_close;_abort;_getStreams;constructor(e){let{remoteAddr:r,remotePeer:n,newStream:i,close:o,abort:s,getStreams:a}=e;this.id=`${parseInt(String(Math.random()*1e9)).toString(36)}${Date.now()}`,this.remoteAddr=r,this.remotePeer=n,this.direction=e.direction,this.status="open",this.timeline=e.timeline,this.multiplexer=e.multiplexer,this.encryption=e.encryption,this.transient=e.transient??!1,this._newStream=i,this._close=o,this._abort=s,this._getStreams=a,this.tags=[]}[Symbol.toStringTag]="Connection";[fg]=!0;get streams(){return this._getStreams()}async newStream(e,r){if(this.status==="closing")throw new b("the connection is being closed","ERR_CONNECTION_BEING_CLOSED");if(this.status==="closed")throw new b("the connection is closed","ERR_CONNECTION_CLOSED");if(Array.isArray(e)||(e=[e]),this.transient&&r?.runOnTransientConnection!==!0)throw new b("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");let n=await this._newStream(e,r);return n.direction="outbound",n}async close(e={}){if(!(this.status==="closed"||this.status==="closing")){ka("closing connection to %a",this.remoteAddr),this.status="closing",e.signal=e?.signal??AbortSignal.timeout(lA);try{(0,hg.setMaxListeners)?.(1/0,e.signal)}catch{}try{await Promise.all(this.streams.map(async r=>r.close(e))),await this._close(e),this.timeline.close=Date.now(),this.status="closed"}catch(r){ka.error("error encountered during graceful close of connection to %a",this.remoteAddr,r),this.abort(r)}}}abort(e){ka.error("aborting connection to %a due to error",this.remoteAddr,e),this.status="closing",this.streams.forEach(r=>{r.abort(e)}),ka.error("all streams aborted",this.streams.length),this._abort(e),this.timeline.close=Date.now(),this.status="closed"}};function dg(t){return new ff(t)}var Be=ie("libp2p:upgrader");function hA(t,e){try{let{options:r}=e.getHandler(t);return r.maxInboundStreams}catch(r){if(r.code!==K.ERR_NO_HANDLER_FOR_PROTOCOL)throw r}return sf}function dA(t,e,r={}){try{let{options:n}=e.getHandler(t);if(n.maxOutboundStreams!=null)return n.maxOutboundStreams}catch(n){if(n.code!==K.ERR_NO_HANDLER_FOR_PROTOCOL)throw n}return r.maxOutboundStreams??af}function pg(t,e,r){let n=0;return r.streams.forEach(i=>{i.direction===e&&i.protocol===t&&n++}),n}var Oa=class{components;connectionEncryption;muxers;inboundUpgradeTimeout;events;constructor(e,r){this.components=e,this.connectionEncryption=new Map,r.connectionEncryption.forEach(n=>{this.connectionEncryption.set(n.protocol,n)}),this.muxers=new Map,r.muxers.forEach(n=>{this.muxers.set(n.protocol,n)}),this.inboundUpgradeTimeout=r.inboundUpgradeTimeout??3e4,this.events=e.events}async shouldBlockConnection(e,r,n){let i=this.components.connectionGater[n];if(i!==void 0&&await i(e,r))throw new b(`The multiaddr connection is blocked by gater.${n}`,K.ERR_CONNECTION_INTERCEPTED)}async upgradeInbound(e,r){if(!await this.components.connectionManager.acceptIncomingConnection(e))throw new b("connection denied",K.ERR_CONNECTION_DENIED);let i,o,s,a,c,u=AbortSignal.timeout(this.inboundUpgradeTimeout);try{(0,hf.setMaxListeners)?.(1/0,u)}catch{}try{let l=ag(e,u);if(e.source=l.source,e.sink=l.sink,await this.components.connectionGater.denyInboundConnection?.(e)===!0)throw new b("The multiaddr connection is blocked by gater.acceptConnection",K.ERR_CONNECTION_INTERCEPTED);this.components.metrics?.trackMultiaddrConnection(e),Be("starting the inbound connection upgrade");let f=e;if(r?.skipProtection!==!0){let h=this.components.connectionProtector;h!=null&&(Be("protecting the inbound connection"),f=await h.protect(e))}try{if(i=f,r?.skipEncryption!==!0){({conn:i,remotePeer:o,protocol:c}=await this._encryptInbound(f));let h={...f,...i};await this.shouldBlockConnection(o,h,"denyInboundEncryptedConnection")}else{let h=e.remoteAddr.getPeerId();if(h==null)throw new b("inbound connection that skipped encryption must have a peer id",K.ERR_INVALID_MULTIADDR);let p=de(h);c="native",o=p}if(s=i,r?.muxerFactory!=null)a=r.muxerFactory;else if(this.muxers.size>0){let h=await this._multiplexInbound({...f,...i},this.muxers);a=h.muxerFactory,s=h.stream}}catch(h){throw Be.error("Failed to upgrade inbound connection",h),h}return await this.shouldBlockConnection(o,e,"denyInboundUpgradedConnection"),Be("Successfully upgraded inbound connection"),this._createConnection({cryptoProtocol:c,direction:"inbound",maConn:e,upgradedConn:s,muxerFactory:a,remotePeer:o,transient:r?.transient})}finally{this.components.connectionManager.afterUpgradeInbound()}}async upgradeOutbound(e,r){let n=e.remoteAddr.getPeerId(),i;n!=null&&(i=de(n),await this.shouldBlockConnection(i,e,"denyOutboundConnection"));let o,s,a,c,u;this.components.metrics?.trackMultiaddrConnection(e),Be("Starting the outbound connection upgrade");let l=e;if(r?.skipProtection!==!0){let f=this.components.connectionProtector;f!=null&&(l=await f.protect(e))}try{if(o=l,r?.skipEncryption!==!0){({conn:o,remotePeer:s,protocol:c}=await this._encryptOutbound(l,i));let f={...l,...o};await this.shouldBlockConnection(s,f,"denyOutboundEncryptedConnection")}else{if(i==null)throw new b("Encryption was skipped but no peer id was passed",K.ERR_INVALID_PEER);c="native",s=i}if(a=o,r?.muxerFactory!=null)u=r.muxerFactory;else if(this.muxers.size>0){let f=await this._multiplexOutbound({...l,...o},this.muxers);u=f.muxerFactory,a=f.stream}}catch(f){throw Be.error("Failed to upgrade outbound connection",f),await e.close(f),f}return await this.shouldBlockConnection(s,e,"denyOutboundUpgradedConnection"),Be("Successfully upgraded outbound connection"),this._createConnection({cryptoProtocol:c,direction:"outbound",maConn:e,upgradedConn:a,muxerFactory:u,remotePeer:s,transient:r?.transient})}_createConnection(e){let{cryptoProtocol:r,direction:n,maConn:i,upgradedConn:o,remotePeer:s,muxerFactory:a,transient:c}=e,u,l,f;a!=null&&(u=a.createStreamMuxer({direction:n,onIncomingStream:d=>{f!=null&&Promise.resolve().then(async()=>{let m=this.components.registrar.getProtocols(),{stream:y,protocol:g}=await Do(d,m);if(Be("%s: incoming stream opened on %s",n,g),f==null)return;let x=hA(g,this.components.registrar);if(pg(g,"inbound",f)===x){let C=new b(`Too many inbound protocol streams for protocol "${g}" - limit ${x}`,K.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS);throw d.abort(C),C}d.source=y.source,d.sink=y.sink,d.protocol=g,await this.components.peerStore.merge(s,{protocols:[g]}),this.components.metrics?.trackProtocolStream(d,f),this._onStream({connection:f,stream:d,protocol:g})}).catch(async m=>{Be.error(m),d.timeline.close==null&&await d.close()})}}),l=async(d,m={})=>{if(u==null)throw new b("Stream is not multiplexed",K.ERR_MUXER_UNAVAILABLE);Be("%s: starting new stream on %s",n,d);let y=await u.newStream();try{if(m.signal==null){Be("No abort signal was passed while trying to negotiate protocols %s falling back to default timeout",d),m.signal=AbortSignal.timeout(3e4);try{(0,hf.setMaxListeners)?.(1/0,m.signal)}catch{}}let{stream:g,protocol:x}=await Lo(y,d,m),w=dA(x,this.components.registrar,m);if(pg(x,"outbound",f)>=w){let _=new b(`Too many outbound protocol streams for protocol "${x}" - limit ${w}`,K.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS);throw y.abort(_),_}return await this.components.peerStore.merge(s,{protocols:[x]}),y.source=g.source,y.sink=g.sink,y.protocol=x,this.components.metrics?.trackProtocolStream(y,f),y}catch(g){throw Be.error("could not create new stream",g),y.timeline.close==null&&y.abort(g),g.code!=null?g:new b(String(g),K.ERR_UNSUPPORTED_PROTOCOL)}},Promise.all([u.sink(o.source),o.sink(u.source)]).catch(d=>{Be.error(d)}));let h=i.timeline;i.timeline=new Proxy(h,{set:(...d)=>(f!=null&&d[1]==="close"&&d[2]!=null&&h.close==null&&(async()=>{try{f.status==="open"&&await f.close()}catch(m){Be.error(m)}finally{this.events.safeDispatchEvent("connection:close",{detail:f})}})().catch(m=>{Be.error(m)}),Reflect.set(...d))}),i.timeline.upgraded=Date.now();let p=()=>{throw new b("connection is not multiplexed",K.ERR_CONNECTION_NOT_MULTIPLEXED)};return f=dg({remoteAddr:i.remoteAddr,remotePeer:s,status:"open",direction:n,timeline:i.timeline,multiplexer:u?.protocol,encryption:r,transient:c,newStream:l??p,getStreams:()=>u!=null?u.streams:[],close:async d=>{await i.close(d),u!=null&&await u.close(d)},abort:d=>{i.abort(d),u?.abort(d)}}),this.events.safeDispatchEvent("connection:open",{detail:f}),f}_onStream(e){let{connection:r,stream:n,protocol:i}=e,{handler:o,options:s}=this.components.registrar.getHandler(i);if(r.transient&&s.runOnTransientConnection!==!0)throw new b("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");o({connection:r,stream:n})}async _encryptInbound(e){let r=Array.from(this.connectionEncryption.keys());Be("handling inbound crypto protocol selection",r);try{let{stream:n,protocol:i}=await Do(e,r,{writeBytes:!0}),o=this.connectionEncryption.get(i);if(o==null)throw new Error(`no crypto module found for ${i}`);return Be("encrypting inbound connection..."),{...await o.secureInbound(this.components.peerId,n),protocol:i}}catch(n){throw new b(String(n),K.ERR_ENCRYPTION_FAILED)}}async _encryptOutbound(e,r){let n=Array.from(this.connectionEncryption.keys());Be("selecting outbound crypto protocol",n);try{let{stream:i,protocol:o}=await Lo(e,n,{writeBytes:!0}),s=this.connectionEncryption.get(o);if(s==null)throw new Error(`no crypto module found for ${o}`);return Be("encrypting outbound connection to %p",r),{...await s.secureOutbound(this.components.peerId,i,r),protocol:o}}catch(i){throw new b(String(i),K.ERR_ENCRYPTION_FAILED)}}async _multiplexOutbound(e,r){let n=Array.from(r.keys());Be("outbound selecting muxer %s",n);try{let{stream:i,protocol:o}=await Lo(e,n,{writeBytes:!0});Be("%s selected as muxer protocol",o);let s=r.get(o);return{stream:i,muxerFactory:s}}catch(i){throw Be.error("error multiplexing outbound stream",i),new b(String(i),K.ERR_MUXER_UNAVAILABLE)}}async _multiplexInbound(e,r){let n=Array.from(r.keys());Be("inbound handling muxers %s",n);try{let{stream:i,protocol:o}=await Do(e,n,{writeBytes:!0}),s=r.get(o);return{stream:i,muxerFactory:s}}catch(i){throw Be.error("error multiplexing inbound stream",i),new b(String(i),K.ERR_MUXER_UNAVAILABLE)}}};var gt=ie("libp2p"),df=class extends co{peerId;peerStore;contentRouting;peerRouting;keychain;metrics;services;components;#e;constructor(e){super();let r=new co,n=r.dispatchEvent.bind(r);r.dispatchEvent=c=>{let u=n(c),l=this.dispatchEvent(new Su(c.type,{detail:c.detail}));return u||l};try{(0,mg.setMaxListeners)?.(1/0,r)}catch{}this.#e=!1,this.peerId=e.peerId,this.services={};let i=this.components=Mm({peerId:e.peerId,events:r,datastore:e.datastore??new na,connectionGater:Ym(e.connectionGater)});this.peerStore=this.configureComponent("peerStore",new ea(i,{addressFilter:this.components.connectionGater.filterMultiaddrForPeer,...e.peerStore})),e.metrics!=null&&(this.metrics=this.configureComponent("metrics",e.metrics(this.components))),i.events.addEventListener("peer:update",c=>{if(c.detail.previous==null){let u={id:c.detail.peer.id,multiaddrs:c.detail.peer.addresses.map(l=>l.multiaddr),protocols:c.detail.peer.protocols};this.safeDispatchEvent("peer:discovery",{detail:u})}}),e.connectionProtector!=null&&this.configureComponent("connectionProtector",e.connectionProtector(i)),this.components.upgrader=new Oa(this.components,{connectionEncryption:(e.connectionEncryption??[]).map((c,u)=>this.configureComponent(`connection-encryption-${u}`,c(this.components))),muxers:(e.streamMuxers??[]).map((c,u)=>this.configureComponent(`stream-muxers-${u}`,c(this.components))),inboundUpgradeTimeout:e.connectionManager.inboundUpgradeTimeout}),this.configureComponent("transportManager",new Ta(this.components,e.transportManager)),this.configureComponent("connectionManager",new ba(this.components,e.connectionManager)),this.configureComponent("registrar",new Ca(this.components)),this.configureComponent("addressManager",new ia(this.components,e.addresses));let o=Tn.generateOptions();this.keychain=this.configureComponent("keyChain",new Tn(this.components,{...o,...e.keychain}));let s=(e.peerRouters??[]).map((c,u)=>this.configureComponent(`peer-router-${u}`,c(this.components)));this.peerRouting=this.components.peerRouting=this.configureComponent("peerRouting",new Ra(this.components,{routers:s}));let a=(e.contentRouters??[]).map((c,u)=>this.configureComponent(`content-router-${u}`,c(this.components)));if(this.contentRouting=this.components.contentRouting=this.configureComponent("contentRouting",new Sa(this.components,{routers:a})),(e.peerDiscovery??[]).forEach((c,u)=>{this.configureComponent(`peer-discovery-${u}`,c(this.components)).addEventListener("peer",f=>{this.#t(f)})}),e.transports.forEach((c,u)=>{this.components.transportManager.add(this.configureComponent(`transport-${u}`,c(this.components)))}),e.services!=null)for(let c of Object.keys(e.services)){let u=e.services[c],l=u(this.components);if(l==null){gt.error("service factory %s returned null or undefined instance",c);continue}this.services[c]=l,this.configureComponent(c,l),l[_u]!=null&&(gt("registering service %s for content routing",c),a.push(l[_u])),l[Ru]!=null&&(gt("registering service %s for peer routing",c),s.push(l[Ru])),l[Iu]!=null&&(gt("registering service %s for peer discovery",c),l[Iu].addEventListener("peer",f=>{this.#t(f)}))}}configureComponent(e,r){return r==null&&gt.error("component %s was null or undefined",e),this.components[e]=r,r}async start(){if(this.#e)return;this.#e=!0,gt("libp2p is starting"),(await this.keychain.listKeys()).find(r=>r.name==="self")==null&&(gt("importing self key into keychain"),await this.keychain.importPeer("self",this.components.peerId));try{await this.components.beforeStart?.(),await this.components.start(),await this.components.afterStart?.(),this.safeDispatchEvent("start",{detail:this}),gt("libp2p has started")}catch(r){throw gt.error("An error occurred starting libp2p",r),await this.stop(),r}}async stop(){this.#e&&(gt("libp2p is stopping"),this.#e=!1,await this.components.beforeStop?.(),await this.components.stop(),await this.components.afterStop?.(),this.safeDispatchEvent("stop",{detail:this}),gt("libp2p has stopped"))}isStarted(){return this.#e}getConnections(e){return this.components.connectionManager.getConnections(e)}getDialQueue(){return this.components.connectionManager.getDialQueue()}getPeers(){let e=new Bn;for(let r of this.components.connectionManager.getConnections())e.add(r.remotePeer);return Array.from(e)}async dial(e,r={}){return this.components.connectionManager.openConnection(e,r)}async dialProtocol(e,r,n={}){if(r==null)throw new b("no protocols were provided to open a stream",K.ERR_INVALID_PROTOCOLS_FOR_STREAM);if(r=Array.isArray(r)?r:[r],r.length===0)throw new b("no protocols were provided to open a stream",K.ERR_INVALID_PROTOCOLS_FOR_STREAM);return(await this.dial(e,n)).newStream(r,n)}getMultiaddrs(){return this.components.addressManager.getAddresses()}getProtocols(){return this.components.registrar.getProtocols()}async hangUp(e,r={}){Ln(e)&&(e=de(e.getPeerId()??"")),await this.components.connectionManager.closeConnections(e,r)}async getPublicKey(e,r={}){if(gt("getPublicKey %p",e),e.publicKey!=null)return e.publicKey;let n=await this.peerStore.get(e);if(n.id.publicKey!=null)return n.id.publicKey;let i=Ue([G("/pk/"),e.multihash.digest]),o=await this.contentRouting.get(i,r);return so(o),await this.peerStore.patch(e,{publicKey:o}),o}async handle(e,r,n){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async i=>{await this.components.registrar.handle(i,r,n)}))}async unhandle(e){Array.isArray(e)||(e=[e]),await Promise.all(e.map(async r=>{await this.components.registrar.unhandle(r)}))}async register(e,r){return this.components.registrar.register(e,r)}unregister(e){this.components.registrar.unregister(e)}#t(e){let{detail:r}=e;if(r.id.toString()===this.peerId.toString()){gt.error(new Error(K.ERR_DISCOVERED_SELF));return}this.components.peerStore.merge(r.id,{multiaddrs:r.multiaddrs,protocols:r.protocols}).catch(n=>{gt.error(n)})}};async function yg(t){if(t.peerId==null){let e=t.datastore;if(e!=null)try{let r=new Tn({datastore:e},$r(Tn.generateOptions(),t.keychain));t.peerId=await r.exportPeerId("self")}catch(r){if(r.code!=="ERR_NOT_FOUND")throw r}}return t.peerId==null&&(t.peerId=await Fp()),new df(ry(t))}async function pA(t){let e=await yg(t);return t.start!==!1&&await e.start(),e}return Bg(mA);})();
50
50
  /*! Bundled license information:
51
51
 
@@ -75,7 +75,7 @@ export class DefaultRegistrar {
75
75
  });
76
76
  // Update self protocols in the peer store
77
77
  await this.components.peerStore.patch(this.components.peerId, {
78
- protocols: protocolList
78
+ protocols: this.getProtocols()
79
79
  });
80
80
  }
81
81
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,MAAM,eAAe,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AASnC,MAAM,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAEtC,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,CAAA;AAC7C,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAA;AAS9C;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACV,UAAU,CAAoC;IAC9C,QAAQ,CAAkC;IAC1C,UAAU,CAAqB;IAEhD,YAAa,UAA+B;QAC1C,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAE5B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClD,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,C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IAAI,CAAC,UAAU,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;gBAE/E,IAAI,UAAU,IAAI,IAAI,EAAE;oBACtB,SAAQ;iBACT;gBACD,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;aAC1C;SACF;IACH,CAAC;CACF"}
@@ -1,3 +1,3 @@
1
- export declare const version = "0.46.7-13f5b48e";
1
+ export declare const version = "0.46.7-24a5edae";
2
2
  export declare const name = "libp2p";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1,3 +1,3 @@
1
- export const version = '0.46.7-13f5b48e';
1
+ export const version = '0.46.7-24a5edae';
2
2
  export const name = 'libp2p';
3
3
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libp2p",
3
- "version": "0.46.7-13f5b48e",
3
+ "version": "0.46.7-24a5edae",
4
4
  "description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/libp2p#readme",
@@ -120,18 +120,18 @@
120
120
  },
121
121
  "dependencies": {
122
122
  "@achingbrain/nat-port-mapper": "^1.0.9",
123
- "@libp2p/crypto": "2.0.3-13f5b48e",
124
- "@libp2p/interface": "0.1.2-13f5b48e",
125
- "@libp2p/interface-internal": "0.1.4-13f5b48e",
126
- "@libp2p/keychain": "3.0.3-13f5b48e",
127
- "@libp2p/logger": "3.0.2-13f5b48e",
128
- "@libp2p/multistream-select": "4.0.2-13f5b48e",
129
- "@libp2p/peer-collections": "4.0.3-13f5b48e",
130
- "@libp2p/peer-id": "3.0.2-13f5b48e",
131
- "@libp2p/peer-id-factory": "3.0.3-13f5b48e",
132
- "@libp2p/peer-record": "6.0.3-13f5b48e",
133
- "@libp2p/peer-store": "9.0.3-13f5b48e",
134
- "@libp2p/utils": "4.0.2-13f5b48e",
123
+ "@libp2p/crypto": "2.0.3-24a5edae",
124
+ "@libp2p/interface": "0.1.2-24a5edae",
125
+ "@libp2p/interface-internal": "0.1.4-24a5edae",
126
+ "@libp2p/keychain": "3.0.3-24a5edae",
127
+ "@libp2p/logger": "3.0.2-24a5edae",
128
+ "@libp2p/multistream-select": "4.0.2-24a5edae",
129
+ "@libp2p/peer-collections": "4.0.3-24a5edae",
130
+ "@libp2p/peer-id": "3.0.2-24a5edae",
131
+ "@libp2p/peer-id-factory": "3.0.3-24a5edae",
132
+ "@libp2p/peer-record": "6.0.3-24a5edae",
133
+ "@libp2p/peer-store": "9.0.3-24a5edae",
134
+ "@libp2p/utils": "4.0.2-24a5edae",
135
135
  "@multiformats/mafmt": "^12.1.2",
136
136
  "@multiformats/multiaddr": "^12.1.5",
137
137
  "@multiformats/multiaddr-matcher": "^1.0.0",
@@ -157,7 +157,7 @@
157
157
  "multiformats": "^12.0.1",
158
158
  "p-defer": "^4.0.0",
159
159
  "p-queue": "^7.3.4",
160
- "p-retry": "^5.0.0",
160
+ "p-retry": "^6.0.0",
161
161
  "private-ip": "^3.0.0",
162
162
  "protons-runtime": "^5.0.0",
163
163
  "rate-limiter-flexible": "^3.0.0",
@@ -170,17 +170,17 @@
170
170
  "@chainsafe/libp2p-gossipsub": "^10.0.0",
171
171
  "@chainsafe/libp2p-noise": "^13.0.0",
172
172
  "@chainsafe/libp2p-yamux": "^5.0.0",
173
- "@libp2p/bootstrap": "9.0.5-13f5b48e",
173
+ "@libp2p/bootstrap": "9.0.5-24a5edae",
174
174
  "@libp2p/daemon-client": "^7.0.0",
175
175
  "@libp2p/daemon-server": "^6.0.0",
176
- "@libp2p/floodsub": "8.0.6-13f5b48e",
177
- "@libp2p/interface-compliance-tests": "4.0.5-13f5b48e",
176
+ "@libp2p/floodsub": "8.0.6-24a5edae",
177
+ "@libp2p/interface-compliance-tests": "4.0.5-24a5edae",
178
178
  "@libp2p/interop": "^9.0.0",
179
- "@libp2p/kad-dht": "10.0.5-13f5b48e",
180
- "@libp2p/mdns": "9.0.5-13f5b48e",
181
- "@libp2p/mplex": "9.0.5-13f5b48e",
182
- "@libp2p/tcp": "8.0.5-13f5b48e",
183
- "@libp2p/websockets": "7.0.5-13f5b48e",
179
+ "@libp2p/kad-dht": "10.0.5-24a5edae",
180
+ "@libp2p/mdns": "9.0.5-24a5edae",
181
+ "@libp2p/mplex": "9.0.5-24a5edae",
182
+ "@libp2p/tcp": "8.0.5-24a5edae",
183
+ "@libp2p/websockets": "7.0.5-24a5edae",
184
184
  "@types/xsalsa20": "^1.1.0",
185
185
  "aegir": "^40.0.8",
186
186
  "execa": "^8.0.1",
package/src/registrar.ts CHANGED
@@ -109,7 +109,7 @@ export class DefaultRegistrar implements Registrar {
109
109
 
110
110
  // Update self protocols in the peer store
111
111
  await this.components.peerStore.patch(this.components.peerId, {
112
- protocols: protocolList
112
+ protocols: this.getProtocols()
113
113
  })
114
114
  }
115
115
 
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const version = '0.46.7-13f5b48e'
1
+ export const version = '0.46.7-24a5edae'
2
2
  export const name = 'libp2p'