libp2p 1.0.0-bcf18265e → 1.0.1-53224004f

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
@@ -58,7 +58,7 @@
58
58
  `),r),r.log.trace('handle: responded with "%s" for "%s"',i,i),{stream:n.unwrap(),protocol:i};if(i==="ls"){let s=new ze(...e.map(o=>En.single(Q(`${o}
59
59
  `))),Q(`
60
60
  `));r.log.trace('handle: respond with "%s" for %s',e,i),await _n(n,s,r),r.log.trace('handle: responded with "%s" for %s',e,i);continue}r.log('handle: respond with "na" for "%s"',i),await _n(n,Q(`na
61
- `),r),r.log('handle: responded with "na" for "%s"',i)}}var Ev=500,ql=class{id;remoteAddr;remotePeer;direction;timeline;multiplexer;encryption;status;transient;log;tags;_newStream;_close;_abort;_getStreams;constructor(e){let{remoteAddr:r,remotePeer:n,newStream:i,close:s,abort:o,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.log=e.logger.forComponent(`libp2p:connection:${this.direction}:${this.id}`),this.remoteAddr.getPeerId()==null&&(this.remoteAddr=this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`)),this._newStream=i,this._close=s,this._abort=o,this._getStreams=a,this.tags=[]}[Symbol.toStringTag]="Connection";[m0]=!0;get streams(){return this._getStreams()}async newStream(e,r){if(this.status==="closing")throw new S("the connection is being closed","ERR_CONNECTION_BEING_CLOSED");if(this.status==="closed")throw new S("the connection is closed","ERR_CONNECTION_CLOSED");if(Array.isArray(e)||(e=[e]),this.transient&&r?.runOnTransientConnection!==!0)throw new S("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")){if(this.log("closing connection to %a",this.remoteAddr),this.status="closing",e.signal==null){let r=AbortSignal.timeout(Ev);pt(1/0,r),e={...e,signal:r}}try{this.log.trace("closing all streams"),await Promise.all(this.streams.map(async r=>r.close(e))),this.log.trace("closing underlying transport"),await this._close(e),this.log.trace("updating timeline with close time"),this.status="closed",this.timeline.close=Date.now()}catch(r){this.log.error("error encountered during graceful close of connection to %a",this.remoteAddr,r),this.abort(r)}}}abort(e){this.log.error("aborting connection to %a due to error",this.remoteAddr,e),this.status="closing",this.streams.forEach(r=>{r.abort(e)}),this.log.error("all streams aborted",this.streams.length),this._abort(e),this.timeline.close=Date.now(),this.status="closed"}};function zm(t){return new ql(t)}var _v=3e4;function Sv(t,e){try{let{options:r}=e.getHandler(t);return r.maxInboundStreams}catch(r){if(r.code!==F.ERR_NO_HANDLER_FOR_PROTOCOL)throw r}return Nl}function Av(t,e,r={}){try{let{options:n}=e.getHandler(t);if(n.maxOutboundStreams!=null)return n.maxOutboundStreams}catch(n){if(n.code!==F.ERR_NO_HANDLER_FOR_PROTOCOL)throw n}return r.maxOutboundStreams??kl}function Hm(t,e,r){let n=0;return r.streams.forEach(i=>{i.direction===e&&i.protocol===t&&n++}),n}var fa=class{components;connectionEncryption;muxers;inboundUpgradeTimeout;events;log;constructor(e,r){this.components=e,this.connectionEncryption=new Map,this.log=e.logger.forComponent("libp2p:upgrader"),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 S(`The multiaddr connection is blocked by gater.${n}`,F.ERR_CONNECTION_INTERCEPTED)}async upgradeInbound(e,r){if(!await this.components.connectionManager.acceptIncomingConnection(e))throw new S("connection denied",F.ERR_CONNECTION_DENIED);let i,s,o,a,c,u=AbortSignal.timeout(this.inboundUpgradeTimeout),l=()=>{e.abort(new S("inbound upgrade timeout",Ss))};u.addEventListener("abort",l,{once:!0}),pt(1/0,u);try{if(await this.components.connectionGater.denyInboundConnection?.(e)===!0)throw new S("The multiaddr connection is blocked by gater.acceptConnection",F.ERR_CONNECTION_INTERCEPTED);this.components.metrics?.trackMultiaddrConnection(e),this.log("starting the inbound connection upgrade");let f=e;if(r?.skipProtection!==!0){let h=this.components.connectionProtector;h!=null&&(this.log("protecting the inbound connection"),f=await h.protect(e))}try{if(i=f,r?.skipEncryption!==!0){({conn:i,remotePeer:s,protocol:c}=await this._encryptInbound(f));let h={...f,...i};await this.shouldBlockConnection(s,h,"denyInboundEncryptedConnection")}else{let h=e.remoteAddr.getPeerId();if(h==null)throw new S("inbound connection that skipped encryption must have a peer id",F.ERR_INVALID_MULTIADDR);let p=ce(h);c="native",s=p}if(o=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,o=h.stream}}catch(h){throw this.log.error("Failed to upgrade inbound connection",h),h}return await this.shouldBlockConnection(s,e,"denyInboundUpgradedConnection"),this.log("successfully upgraded inbound connection"),this._createConnection({cryptoProtocol:c,direction:"inbound",maConn:e,upgradedConn:o,muxerFactory:a,remotePeer:s,transient:r?.transient})}finally{u.removeEventListener("abort",l),this.components.connectionManager.afterUpgradeInbound()}}async upgradeOutbound(e,r){let n=e.remoteAddr.getPeerId(),i;n!=null&&(i=ce(n),await this.shouldBlockConnection(i,e,"denyOutboundConnection"));let s,o,a,c,u;this.components.metrics?.trackMultiaddrConnection(e),this.log("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(s=l,r?.skipEncryption!==!0){({conn:s,remotePeer:o,protocol:c}=await this._encryptOutbound(l,i));let f={...l,...s};await this.shouldBlockConnection(o,f,"denyOutboundEncryptedConnection")}else{if(i==null)throw new S("Encryption was skipped but no peer id was passed",F.ERR_INVALID_PEER);c="native",o=i}if(a=s,r?.muxerFactory!=null)u=r.muxerFactory;else if(this.muxers.size>0){let f=await this._multiplexOutbound({...l,...s},this.muxers);u=f.muxerFactory,a=f.stream}}catch(f){throw this.log.error("Failed to upgrade outbound connection",f),await e.close(f),f}return await this.shouldBlockConnection(o,e,"denyOutboundUpgradedConnection"),this.log("Successfully upgraded outbound connection"),this._createConnection({cryptoProtocol:c,direction:"outbound",maConn:e,upgradedConn:a,muxerFactory:u,remotePeer:o,transient:r?.transient})}_createConnection(e){let{cryptoProtocol:r,direction:n,maConn:i,upgradedConn:s,remotePeer:o,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 is(d,m,{log:d.log,yieldBytes:!1});if(f==null)return;f.log("incoming stream opened on %s",g);let x=Sv(g,this.components.registrar);if(Hm(g,"inbound",f)===x){let I=new S(`Too many inbound protocol streams for protocol "${g}" - limit ${x}`,F.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS);throw d.abort(I),I}d.source=y.source,d.sink=y.sink,d.protocol=g,y.closeWrite!=null&&(d.closeWrite=y.closeWrite),y.closeRead!=null&&(d.closeRead=y.closeRead),y.close!=null&&(d.close=y.close),await this.components.peerStore.merge(o,{protocols:[g]}),this.components.metrics?.trackProtocolStream(d,f),this._onStream({connection:f,stream:d,protocol:g})}).catch(async m=>{this.log.error("error handling incoming stream id %s",d.id,m.message,m.code,m.stack),d.timeline.close==null&&await d.close()})}}),l=async(d,m={})=>{if(u==null)throw new S("Stream is not multiplexed",F.ERR_MUXER_UNAVAILABLE);f.log("starting new stream for protocols %s",d);let y=await u.newStream();f.log.trace("started new stream %s for protocols %s",y.id,d);try{if(m.signal==null){this.log("No abort signal was passed while trying to negotiate protocols %s falling back to default timeout",d);let v=AbortSignal.timeout(_v);pt(1/0,v),m={...m,signal:v}}y.log.trace("selecting protocol from protocols %s",d);let{stream:g,protocol:x}=await ns(y,d,{...m,log:y.log,yieldBytes:!0});y.log("selected protocol %s",x);let b=Av(x,this.components.registrar,m);if(Hm(x,"outbound",f)>=b){let v=new S(`Too many outbound protocol streams for protocol "${x}" - limit ${b}`,F.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS);throw y.abort(v),v}return await this.components.peerStore.merge(o,{protocols:[x]}),y.source=g.source,y.sink=g.sink,y.protocol=x,g.closeWrite!=null&&(y.closeWrite=g.closeWrite),g.closeRead!=null&&(y.closeRead=g.closeRead),g.close!=null&&(y.close=g.close),this.components.metrics?.trackProtocolStream(y,f),y}catch(g){throw f.log.error("could not create new stream for protocols %s",d,g),y.timeline.close==null&&y.abort(g),g.code!=null?g:new S(String(g),F.ERR_UNSUPPORTED_PROTOCOL)}},Promise.all([u.sink(s.source),s.sink(u.source)]).catch(d=>{this.log.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){this.log.error(m)}finally{this.events.safeDispatchEvent("connection:close",{detail:f})}})().catch(m=>{this.log.error(m)}),Reflect.set(...d))}),i.timeline.upgraded=Date.now();let p=()=>{throw new S("connection is not multiplexed",F.ERR_CONNECTION_NOT_MULTIPLEXED)};return f=zm({remoteAddr:i.remoteAddr,remotePeer:o,status:"open",direction:n,timeline:i.timeline,multiplexer:u?.protocol,encryption:r,transient:c,logger:this.components.logger,newStream:l??p,getStreams:()=>u!=null?u.streams:[],close:async d=>{u!=null&&(this.log.trace("close muxer"),await u.close(d)),this.log.trace("close maconn"),await i.close(d),this.log.trace("closed maconn")},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:s,options:o}=this.components.registrar.getHandler(i);if(r.transient&&o.runOnTransientConnection!==!0)throw new S("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");s({connection:r,stream:n})}async _encryptInbound(e){let r=Array.from(this.connectionEncryption.keys());this.log("handling inbound crypto protocol selection",r);try{let{stream:n,protocol:i}=await is(e,r,{log:e.log}),s=this.connectionEncryption.get(i);if(s==null)throw new Error(`no crypto module found for ${i}`);return this.log("encrypting inbound connection using",i),{...await s.secureInbound(this.components.peerId,n),protocol:i}}catch(n){throw new S(String(n),F.ERR_ENCRYPTION_FAILED)}}async _encryptOutbound(e,r){let n=Array.from(this.connectionEncryption.keys());this.log("selecting outbound crypto protocol",n);try{e.log.trace("selecting encrypter from %s",n);let{stream:i,protocol:s}=await ns(e,n,{log:e.log,yieldBytes:!0}),o=this.connectionEncryption.get(s);if(o==null)throw new Error(`no crypto module found for ${s}`);return e.log("encrypting outbound connection to %p using %p",r),{...await o.secureOutbound(this.components.peerId,i,r),protocol:s}}catch(i){throw new S(String(i),F.ERR_ENCRYPTION_FAILED)}}async _multiplexOutbound(e,r){let n=Array.from(r.keys());this.log("outbound selecting muxer %s",n);try{e.log.trace("selecting stream muxer from %s",n);let{stream:i,protocol:s}=await ns(e,n,{log:e.log,yieldBytes:!0});e.log("selected %s as muxer protocol",s);let o=r.get(s);return{stream:i,muxerFactory:o}}catch(i){throw e.log.error("error multiplexing outbound stream",i),new S(String(i),F.ERR_MUXER_UNAVAILABLE)}}async _multiplexInbound(e,r){let n=Array.from(r.keys());this.log("inbound handling muxers %s",n);try{let{stream:i,protocol:s}=await is(e,n,{log:e.log}),o=r.get(s);return{stream:i,muxerFactory:o}}catch(i){throw this.log.error("error multiplexing inbound stream",i),new S(String(i),F.ERR_MUXER_UNAVAILABLE)}}};var Gm="1.0.0-bcf18265e",Wm="libp2p";var Vl=class extends wi{peerId;peerStore;contentRouting;peerRouting;metrics;services;logger;components;#e;log;constructor(e){super();let r=new wi,n=r.dispatchEvent.bind(r);r.dispatchEvent=a=>{let c=n(a),u=this.dispatchEvent(new Ka(a.type,{detail:a.detail}));return c||u},pt(1/0,r),this.#e=!1,this.peerId=e.peerId,this.logger=e.logger??Qs(),this.log=this.logger.forComponent("libp2p"),this.services={};let i=this.components=Jd({peerId:e.peerId,nodeInfo:e.nodeInfo??{name:Wm,version:Gm},logger:this.logger,events:r,datastore:e.datastore??new So,connectionGater:up(e.connectionGater)});this.peerStore=this.configureComponent("peerStore",new Eo(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",a=>{if(a.detail.previous==null){let c={id:a.detail.peer.id,multiaddrs:a.detail.peer.addresses.map(u=>u.multiaddr)};i.events.safeDispatchEvent("peer:discovery",{detail:c})}}),e.connectionProtector!=null&&this.configureComponent("connectionProtector",e.connectionProtector(i)),this.components.upgrader=new fa(this.components,{connectionEncryption:(e.connectionEncryption??[]).map((a,c)=>this.configureComponent(`connection-encryption-${c}`,a(this.components))),muxers:(e.streamMuxers??[]).map((a,c)=>this.configureComponent(`stream-muxers-${c}`,a(this.components))),inboundUpgradeTimeout:e.connectionManager.inboundUpgradeTimeout}),this.configureComponent("transportManager",new ia(this.components,e.transportManager)),this.configureComponent("connectionManager",new Xo(this.components,e.connectionManager)),this.configureComponent("registrar",new na(this.components)),this.configureComponent("addressManager",new Ao(this.components,e.addresses));let s=(e.peerRouters??[]).map((a,c)=>this.configureComponent(`peer-router-${c}`,a(this.components)));this.peerRouting=this.components.peerRouting=this.configureComponent("peerRouting",new ra(this.components,{routers:s}));let o=(e.contentRouters??[]).map((a,c)=>this.configureComponent(`content-router-${c}`,a(this.components)));if(this.contentRouting=this.components.contentRouting=this.configureComponent("contentRouting",new ta(this.components,{routers:o})),(e.peerDiscovery??[]).forEach((a,c)=>{this.configureComponent(`peer-discovery-${c}`,a(this.components)).addEventListener("peer",l=>{this.#t(l)})}),e.transports.forEach((a,c)=>{this.components.transportManager.add(this.configureComponent(`transport-${c}`,a(this.components)))}),e.services!=null)for(let a of Object.keys(e.services)){let c=e.services[a],u=c(this.components);if(u==null){this.log.error("service factory %s returned null or undefined instance",a);continue}this.services[a]=u,this.configureComponent(a,u),u[ka]!=null&&(this.log("registering service %s for content routing",a),o.push(u[ka])),u[Ua]!=null&&(this.log("registering service %s for peer routing",a),s.push(u[Ua])),u[Oa]!=null&&(this.log("registering service %s for peer discovery",a),u[Oa].addEventListener("peer",l=>{this.#t(l)}))}}configureComponent(e,r){return r==null&&this.log.error("component %s was null or undefined",e),this.components[e]=r,r}async start(){if(!this.#e){this.#e=!0,this.log("libp2p is starting");try{await this.components.beforeStart?.(),await this.components.start(),await this.components.afterStart?.(),this.safeDispatchEvent("start",{detail:this}),this.log("libp2p has started")}catch(e){throw this.log.error("An error occurred starting libp2p",e),await this.stop(),e}}}async stop(){this.#e&&(this.log("libp2p is stopping"),this.#e=!1,await this.components.beforeStop?.(),await this.components.stop(),await this.components.afterStop?.(),this.safeDispatchEvent("stop",{detail:this}),this.log("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 fn;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 S("no protocols were provided to open a stream",F.ERR_INVALID_PROTOCOLS_FOR_STREAM);if(r=Array.isArray(r)?r:[r],r.length===0)throw new S("no protocols were provided to open a stream",F.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={}){Nr(e)&&(e=ce(e.getPeerId()??"")),await this.components.connectionManager.closeConnections(e,r)}async getPublicKey(e,r={}){if(this.log("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=Te([Q("/pk/"),e.multihash.digest]),s=await this.contentRouting.get(i,r);return Mi(s),await this.peerStore.patch(e,{publicKey:s}),s}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()){this.log.error(new Error(F.ERR_DISCOVERED_SELF));return}this.components.peerStore.merge(r.id,{multiaddrs:r.multiaddrs}).catch(n=>{this.log.error(n)})}};async function Ym(t){return t.peerId??=await id(),new Vl(Np(t))}async function Rv(t){let e=await Ym(t);return t.start!==!1&&await e.start(),e}return cy(Cv);})();
61
+ `),r),r.log('handle: responded with "na" for "%s"',i)}}var Ev=500,ql=class{id;remoteAddr;remotePeer;direction;timeline;multiplexer;encryption;status;transient;log;tags;_newStream;_close;_abort;_getStreams;constructor(e){let{remoteAddr:r,remotePeer:n,newStream:i,close:s,abort:o,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.log=e.logger.forComponent(`libp2p:connection:${this.direction}:${this.id}`),this.remoteAddr.getPeerId()==null&&(this.remoteAddr=this.remoteAddr.encapsulate(`/p2p/${this.remotePeer}`)),this._newStream=i,this._close=s,this._abort=o,this._getStreams=a,this.tags=[]}[Symbol.toStringTag]="Connection";[m0]=!0;get streams(){return this._getStreams()}async newStream(e,r){if(this.status==="closing")throw new S("the connection is being closed","ERR_CONNECTION_BEING_CLOSED");if(this.status==="closed")throw new S("the connection is closed","ERR_CONNECTION_CLOSED");if(Array.isArray(e)||(e=[e]),this.transient&&r?.runOnTransientConnection!==!0)throw new S("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")){if(this.log("closing connection to %a",this.remoteAddr),this.status="closing",e.signal==null){let r=AbortSignal.timeout(Ev);pt(1/0,r),e={...e,signal:r}}try{this.log.trace("closing all streams"),await Promise.all(this.streams.map(async r=>r.close(e))),this.log.trace("closing underlying transport"),await this._close(e),this.log.trace("updating timeline with close time"),this.status="closed",this.timeline.close=Date.now()}catch(r){this.log.error("error encountered during graceful close of connection to %a",this.remoteAddr,r),this.abort(r)}}}abort(e){this.log.error("aborting connection to %a due to error",this.remoteAddr,e),this.status="closing",this.streams.forEach(r=>{r.abort(e)}),this.log.error("all streams aborted",this.streams.length),this._abort(e),this.timeline.close=Date.now(),this.status="closed"}};function zm(t){return new ql(t)}var _v=3e4;function Sv(t,e){try{let{options:r}=e.getHandler(t);return r.maxInboundStreams}catch(r){if(r.code!==F.ERR_NO_HANDLER_FOR_PROTOCOL)throw r}return Nl}function Av(t,e,r={}){try{let{options:n}=e.getHandler(t);if(n.maxOutboundStreams!=null)return n.maxOutboundStreams}catch(n){if(n.code!==F.ERR_NO_HANDLER_FOR_PROTOCOL)throw n}return r.maxOutboundStreams??kl}function Hm(t,e,r){let n=0;return r.streams.forEach(i=>{i.direction===e&&i.protocol===t&&n++}),n}var fa=class{components;connectionEncryption;muxers;inboundUpgradeTimeout;events;log;constructor(e,r){this.components=e,this.connectionEncryption=new Map,this.log=e.logger.forComponent("libp2p:upgrader"),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 S(`The multiaddr connection is blocked by gater.${n}`,F.ERR_CONNECTION_INTERCEPTED)}async upgradeInbound(e,r){if(!await this.components.connectionManager.acceptIncomingConnection(e))throw new S("connection denied",F.ERR_CONNECTION_DENIED);let i,s,o,a,c,u=AbortSignal.timeout(this.inboundUpgradeTimeout),l=()=>{e.abort(new S("inbound upgrade timeout",Ss))};u.addEventListener("abort",l,{once:!0}),pt(1/0,u);try{if(await this.components.connectionGater.denyInboundConnection?.(e)===!0)throw new S("The multiaddr connection is blocked by gater.acceptConnection",F.ERR_CONNECTION_INTERCEPTED);this.components.metrics?.trackMultiaddrConnection(e),this.log("starting the inbound connection upgrade");let f=e;if(r?.skipProtection!==!0){let h=this.components.connectionProtector;h!=null&&(this.log("protecting the inbound connection"),f=await h.protect(e))}try{if(i=f,r?.skipEncryption!==!0){({conn:i,remotePeer:s,protocol:c}=await this._encryptInbound(f));let h={...f,...i};await this.shouldBlockConnection(s,h,"denyInboundEncryptedConnection")}else{let h=e.remoteAddr.getPeerId();if(h==null)throw new S("inbound connection that skipped encryption must have a peer id",F.ERR_INVALID_MULTIADDR);let p=ce(h);c="native",s=p}if(o=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,o=h.stream}}catch(h){throw this.log.error("Failed to upgrade inbound connection",h),h}return await this.shouldBlockConnection(s,e,"denyInboundUpgradedConnection"),this.log("successfully upgraded inbound connection"),this._createConnection({cryptoProtocol:c,direction:"inbound",maConn:e,upgradedConn:o,muxerFactory:a,remotePeer:s,transient:r?.transient})}finally{u.removeEventListener("abort",l),this.components.connectionManager.afterUpgradeInbound()}}async upgradeOutbound(e,r){let n=e.remoteAddr.getPeerId(),i;n!=null&&(i=ce(n),await this.shouldBlockConnection(i,e,"denyOutboundConnection"));let s,o,a,c,u;this.components.metrics?.trackMultiaddrConnection(e),this.log("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(s=l,r?.skipEncryption!==!0){({conn:s,remotePeer:o,protocol:c}=await this._encryptOutbound(l,i));let f={...l,...s};await this.shouldBlockConnection(o,f,"denyOutboundEncryptedConnection")}else{if(i==null)throw new S("Encryption was skipped but no peer id was passed",F.ERR_INVALID_PEER);c="native",o=i}if(a=s,r?.muxerFactory!=null)u=r.muxerFactory;else if(this.muxers.size>0){let f=await this._multiplexOutbound({...l,...s},this.muxers);u=f.muxerFactory,a=f.stream}}catch(f){throw this.log.error("Failed to upgrade outbound connection",f),await e.close(f),f}return await this.shouldBlockConnection(o,e,"denyOutboundUpgradedConnection"),this.log("Successfully upgraded outbound connection"),this._createConnection({cryptoProtocol:c,direction:"outbound",maConn:e,upgradedConn:a,muxerFactory:u,remotePeer:o,transient:r?.transient})}_createConnection(e){let{cryptoProtocol:r,direction:n,maConn:i,upgradedConn:s,remotePeer:o,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 is(d,m,{log:d.log,yieldBytes:!1});if(f==null)return;f.log("incoming stream opened on %s",g);let x=Sv(g,this.components.registrar);if(Hm(g,"inbound",f)===x){let I=new S(`Too many inbound protocol streams for protocol "${g}" - limit ${x}`,F.ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS);throw d.abort(I),I}d.source=y.source,d.sink=y.sink,d.protocol=g,y.closeWrite!=null&&(d.closeWrite=y.closeWrite),y.closeRead!=null&&(d.closeRead=y.closeRead),y.close!=null&&(d.close=y.close),await this.components.peerStore.merge(o,{protocols:[g]}),this.components.metrics?.trackProtocolStream(d,f),this._onStream({connection:f,stream:d,protocol:g})}).catch(async m=>{this.log.error("error handling incoming stream id %s",d.id,m.message,m.code,m.stack),d.timeline.close==null&&await d.close()})}}),l=async(d,m={})=>{if(u==null)throw new S("Stream is not multiplexed",F.ERR_MUXER_UNAVAILABLE);f.log("starting new stream for protocols %s",d);let y=await u.newStream();f.log.trace("started new stream %s for protocols %s",y.id,d);try{if(m.signal==null){this.log("No abort signal was passed while trying to negotiate protocols %s falling back to default timeout",d);let v=AbortSignal.timeout(_v);pt(1/0,v),m={...m,signal:v}}y.log.trace("selecting protocol from protocols %s",d);let{stream:g,protocol:x}=await ns(y,d,{...m,log:y.log,yieldBytes:!0});y.log("selected protocol %s",x);let b=Av(x,this.components.registrar,m);if(Hm(x,"outbound",f)>=b){let v=new S(`Too many outbound protocol streams for protocol "${x}" - limit ${b}`,F.ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS);throw y.abort(v),v}return await this.components.peerStore.merge(o,{protocols:[x]}),y.source=g.source,y.sink=g.sink,y.protocol=x,g.closeWrite!=null&&(y.closeWrite=g.closeWrite),g.closeRead!=null&&(y.closeRead=g.closeRead),g.close!=null&&(y.close=g.close),this.components.metrics?.trackProtocolStream(y,f),y}catch(g){throw f.log.error("could not create new stream for protocols %s",d,g),y.timeline.close==null&&y.abort(g),g.code!=null?g:new S(String(g),F.ERR_UNSUPPORTED_PROTOCOL)}},Promise.all([u.sink(s.source),s.sink(u.source)]).catch(d=>{this.log.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){this.log.error(m)}finally{this.events.safeDispatchEvent("connection:close",{detail:f})}})().catch(m=>{this.log.error(m)}),Reflect.set(...d))}),i.timeline.upgraded=Date.now();let p=()=>{throw new S("connection is not multiplexed",F.ERR_CONNECTION_NOT_MULTIPLEXED)};return f=zm({remoteAddr:i.remoteAddr,remotePeer:o,status:"open",direction:n,timeline:i.timeline,multiplexer:u?.protocol,encryption:r,transient:c,logger:this.components.logger,newStream:l??p,getStreams:()=>u!=null?u.streams:[],close:async d=>{u!=null&&(this.log.trace("close muxer"),await u.close(d)),this.log.trace("close maconn"),await i.close(d),this.log.trace("closed maconn")},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:s,options:o}=this.components.registrar.getHandler(i);if(r.transient&&o.runOnTransientConnection!==!0)throw new S("Cannot open protocol stream on transient connection","ERR_TRANSIENT_CONNECTION");s({connection:r,stream:n})}async _encryptInbound(e){let r=Array.from(this.connectionEncryption.keys());this.log("handling inbound crypto protocol selection",r);try{let{stream:n,protocol:i}=await is(e,r,{log:e.log}),s=this.connectionEncryption.get(i);if(s==null)throw new Error(`no crypto module found for ${i}`);return this.log("encrypting inbound connection using",i),{...await s.secureInbound(this.components.peerId,n),protocol:i}}catch(n){throw new S(String(n),F.ERR_ENCRYPTION_FAILED)}}async _encryptOutbound(e,r){let n=Array.from(this.connectionEncryption.keys());this.log("selecting outbound crypto protocol",n);try{e.log.trace("selecting encrypter from %s",n);let{stream:i,protocol:s}=await ns(e,n,{log:e.log,yieldBytes:!0}),o=this.connectionEncryption.get(s);if(o==null)throw new Error(`no crypto module found for ${s}`);return e.log("encrypting outbound connection to %p using %p",r),{...await o.secureOutbound(this.components.peerId,i,r),protocol:s}}catch(i){throw new S(String(i),F.ERR_ENCRYPTION_FAILED)}}async _multiplexOutbound(e,r){let n=Array.from(r.keys());this.log("outbound selecting muxer %s",n);try{e.log.trace("selecting stream muxer from %s",n);let{stream:i,protocol:s}=await ns(e,n,{log:e.log,yieldBytes:!0});e.log("selected %s as muxer protocol",s);let o=r.get(s);return{stream:i,muxerFactory:o}}catch(i){throw e.log.error("error multiplexing outbound stream",i),new S(String(i),F.ERR_MUXER_UNAVAILABLE)}}async _multiplexInbound(e,r){let n=Array.from(r.keys());this.log("inbound handling muxers %s",n);try{let{stream:i,protocol:s}=await is(e,n,{log:e.log}),o=r.get(s);return{stream:i,muxerFactory:o}}catch(i){throw this.log.error("error multiplexing inbound stream",i),new S(String(i),F.ERR_MUXER_UNAVAILABLE)}}};var Gm="1.0.1-53224004f",Wm="libp2p";var Vl=class extends wi{peerId;peerStore;contentRouting;peerRouting;metrics;services;logger;status;components;log;constructor(e){super(),this.status="stopped";let r=new wi,n=r.dispatchEvent.bind(r);r.dispatchEvent=a=>{let c=n(a),u=this.dispatchEvent(new Ka(a.type,{detail:a.detail}));return c||u},pt(1/0,r),this.peerId=e.peerId,this.logger=e.logger??Qs(),this.log=this.logger.forComponent("libp2p"),this.services={};let i=this.components=Jd({peerId:e.peerId,nodeInfo:e.nodeInfo??{name:Wm,version:Gm},logger:this.logger,events:r,datastore:e.datastore??new So,connectionGater:up(e.connectionGater)});this.peerStore=this.configureComponent("peerStore",new Eo(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",a=>{if(a.detail.previous==null){let c={id:a.detail.peer.id,multiaddrs:a.detail.peer.addresses.map(u=>u.multiaddr)};i.events.safeDispatchEvent("peer:discovery",{detail:c})}}),e.connectionProtector!=null&&this.configureComponent("connectionProtector",e.connectionProtector(i)),this.components.upgrader=new fa(this.components,{connectionEncryption:(e.connectionEncryption??[]).map((a,c)=>this.configureComponent(`connection-encryption-${c}`,a(this.components))),muxers:(e.streamMuxers??[]).map((a,c)=>this.configureComponent(`stream-muxers-${c}`,a(this.components))),inboundUpgradeTimeout:e.connectionManager.inboundUpgradeTimeout}),this.configureComponent("transportManager",new ia(this.components,e.transportManager)),this.configureComponent("connectionManager",new Xo(this.components,e.connectionManager)),this.configureComponent("registrar",new na(this.components)),this.configureComponent("addressManager",new Ao(this.components,e.addresses));let s=(e.peerRouters??[]).map((a,c)=>this.configureComponent(`peer-router-${c}`,a(this.components)));this.peerRouting=this.components.peerRouting=this.configureComponent("peerRouting",new ra(this.components,{routers:s}));let o=(e.contentRouters??[]).map((a,c)=>this.configureComponent(`content-router-${c}`,a(this.components)));if(this.contentRouting=this.components.contentRouting=this.configureComponent("contentRouting",new ta(this.components,{routers:o})),(e.peerDiscovery??[]).forEach((a,c)=>{this.configureComponent(`peer-discovery-${c}`,a(this.components)).addEventListener("peer",l=>{this.#e(l)})}),e.transports.forEach((a,c)=>{this.components.transportManager.add(this.configureComponent(`transport-${c}`,a(this.components)))}),e.services!=null)for(let a of Object.keys(e.services)){let c=e.services[a],u=c(this.components);if(u==null){this.log.error("service factory %s returned null or undefined instance",a);continue}this.services[a]=u,this.configureComponent(a,u),u[ka]!=null&&(this.log("registering service %s for content routing",a),o.push(u[ka])),u[Ua]!=null&&(this.log("registering service %s for peer routing",a),s.push(u[Ua])),u[Oa]!=null&&(this.log("registering service %s for peer discovery",a),u[Oa].addEventListener("peer",l=>{this.#e(l)}))}}configureComponent(e,r){return r==null&&this.log.error("component %s was null or undefined",e),this.components[e]=r,r}async start(){if(this.status==="stopped"){this.status="starting",this.log("libp2p is starting");try{await this.components.beforeStart?.(),await this.components.start(),await this.components.afterStart?.(),this.status="started",this.safeDispatchEvent("start",{detail:this}),this.log("libp2p has started")}catch(e){throw this.log.error("An error occurred starting libp2p",e),await this.stop(),e}}}async stop(){this.status==="started"&&(this.log("libp2p is stopping"),this.status="stopping",await this.components.beforeStop?.(),await this.components.stop(),await this.components.afterStop?.(),this.status="stopped",this.safeDispatchEvent("stop",{detail:this}),this.log("libp2p has stopped"))}getConnections(e){return this.components.connectionManager.getConnections(e)}getDialQueue(){return this.components.connectionManager.getDialQueue()}getPeers(){let e=new fn;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 S("no protocols were provided to open a stream",F.ERR_INVALID_PROTOCOLS_FOR_STREAM);if(r=Array.isArray(r)?r:[r],r.length===0)throw new S("no protocols were provided to open a stream",F.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={}){Nr(e)&&(e=ce(e.getPeerId()??"")),await this.components.connectionManager.closeConnections(e,r)}async getPublicKey(e,r={}){if(this.log("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=Te([Q("/pk/"),e.multihash.digest]),s=await this.contentRouting.get(i,r);return Mi(s),await this.peerStore.patch(e,{publicKey:s}),s}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)}#e(e){let{detail:r}=e;if(r.id.toString()===this.peerId.toString()){this.log.error(new Error(F.ERR_DISCOVERED_SELF));return}this.components.peerStore.merge(r.id,{multiaddrs:r.multiaddrs}).catch(n=>{this.log.error(n)})}};async function Ym(t){return t.peerId??=await id(),new Vl(Np(t))}async function Rv(t){let e=await Ym(t);return t.start!==!1&&await e.start(),e}return cy(Cv);})();
62
62
  /*! Bundled license information:
63
63
 
64
64
  @noble/hashes/esm/utils.js:
@@ -2,7 +2,7 @@ import { TypedEventEmitter } from '@libp2p/interface';
2
2
  import { type Multiaddr } from '@multiformats/multiaddr';
3
3
  import type { Components } from './components.js';
4
4
  import type { Libp2p, Libp2pInit, Libp2pOptions } from './index.js';
5
- import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerStore, Topology } from '@libp2p/interface';
5
+ import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerStore, Topology, Libp2pStatus } from '@libp2p/interface';
6
6
  import type { StreamHandler, StreamHandlerOptions } from '@libp2p/interface-internal';
7
7
  export declare class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends TypedEventEmitter<Libp2pEvents> implements Libp2p<T> {
8
8
  #private;
@@ -13,6 +13,7 @@ export declare class Libp2pNode<T extends ServiceMap = Record<string, unknown>>
13
13
  metrics?: Metrics;
14
14
  services: T;
15
15
  logger: ComponentLogger;
16
+ status: Libp2pStatus;
16
17
  components: Components;
17
18
  private readonly log;
18
19
  constructor(init: Libp2pInit<T>);
@@ -25,7 +26,6 @@ export declare class Libp2pNode<T extends ServiceMap = Record<string, unknown>>
25
26
  * Stop the libp2p node by closing its listeners and open connections
26
27
  */
27
28
  stop(): Promise<void>;
28
- isStarted(): boolean;
29
29
  getConnections(peerId?: PeerId): Connection[];
30
30
  getDialQueue(): PendingDial[];
31
31
  getPeers(): PeerId[];
@@ -1 +1 @@
1
- {"version":3,"file":"libp2p.d.ts","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,iBAAiB,EAAwE,MAAM,mBAAmB,CAAA;AAM5J,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAgBrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAU,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAY,SAAS,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACxO,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAErF,qBAAa,UAAU,CAAC,CAAC,SAAS,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAE,SAAQ,iBAAiB,CAAC,YAAY,CAAE,YAAW,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E,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;IA8B5E,MAAM,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAY5G,QAAQ,CAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYtD,QAAQ,CAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAItE,UAAU,CAAE,EAAE,EAAE,MAAM,GAAG,IAAI;CAqB9B;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CAAE,CAAC,SAAS,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAG,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAI1I"}
@@ -29,11 +29,12 @@ export class Libp2pNode extends TypedEventEmitter {
29
29
  metrics;
30
30
  services;
31
31
  logger;
32
+ status;
32
33
  components;
33
- #started;
34
34
  log;
35
35
  constructor(init) {
36
36
  super();
37
+ this.status = 'stopped';
37
38
  // event bus - components can listen to this emitter to be notified of system events
38
39
  // and also cause them to be emitted
39
40
  const events = new TypedEventEmitter();
@@ -45,7 +46,6 @@ export class Libp2pNode extends TypedEventEmitter {
45
46
  };
46
47
  // This emitter gets listened to a lot
47
48
  setMaxListeners(Infinity, events);
48
- this.#started = false;
49
49
  this.peerId = init.peerId;
50
50
  this.logger = init.logger ?? defaultLogger();
51
51
  this.log = this.logger.forComponent('libp2p');
@@ -157,15 +157,16 @@ export class Libp2pNode extends TypedEventEmitter {
157
157
  * Starts the libp2p node and all its subsystems
158
158
  */
159
159
  async start() {
160
- if (this.#started) {
160
+ if (this.status !== 'stopped') {
161
161
  return;
162
162
  }
163
- this.#started = true;
163
+ this.status = 'starting';
164
164
  this.log('libp2p is starting');
165
165
  try {
166
166
  await this.components.beforeStart?.();
167
167
  await this.components.start();
168
168
  await this.components.afterStart?.();
169
+ this.status = 'started';
169
170
  this.safeDispatchEvent('start', { detail: this });
170
171
  this.log('libp2p has started');
171
172
  }
@@ -179,20 +180,18 @@ export class Libp2pNode extends TypedEventEmitter {
179
180
  * Stop the libp2p node by closing its listeners and open connections
180
181
  */
181
182
  async stop() {
182
- if (!this.#started) {
183
+ if (this.status !== 'started') {
183
184
  return;
184
185
  }
185
186
  this.log('libp2p is stopping');
186
- this.#started = false;
187
+ this.status = 'stopping';
187
188
  await this.components.beforeStop?.();
188
189
  await this.components.stop();
189
190
  await this.components.afterStop?.();
191
+ this.status = 'stopped';
190
192
  this.safeDispatchEvent('stop', { detail: this });
191
193
  this.log('libp2p has stopped');
192
194
  }
193
- isStarted() {
194
- return this.#started;
195
- }
196
195
  getConnections(peerId) {
197
196
  return this.components.connectionManager.getConnections(peerId);
198
197
  }
@@ -1 +1 @@
1
- {"version":3,"file":"libp2p.js","sourceRoot":"","sources":["../../src/libp2p.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,iBAAiB,EAAE,WAAW,EAAE,eAAe,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC5J,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAkB,MAAM,yBAAyB,CAAA;AAC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E,GAA0B;QAC1C,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;QAE5B,IAAI,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC;YAClD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAA;YACpD,OAAM;QACR,CAAC;QAED,KAAK,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE;YAC5C,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC;aACC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;IAC1C,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAmD,OAAyB;IAChH,OAAO,CAAC,MAAM,KAAK,MAAM,mBAAmB,EAAE,CAAA;IAE9C,OAAO,IAAI,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAA;AAChD,CAAC"}
@@ -1,3 +1,3 @@
1
- export declare const version = "1.0.0-bcf18265e";
1
+ export declare const version = "1.0.1-53224004f";
2
2
  export declare const name = "libp2p";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1,3 +1,3 @@
1
- export const version = '1.0.0-bcf18265e';
1
+ export const version = '1.0.1-53224004f';
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": "1.0.0-bcf18265e",
3
+ "version": "1.0.1-53224004f",
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/main/packages/libp2p#readme",
@@ -64,16 +64,16 @@
64
64
  "test:interop": "aegir test -t node -f dist/test/interop.js"
65
65
  },
66
66
  "dependencies": {
67
- "@libp2p/crypto": "3.0.0-bcf18265e",
68
- "@libp2p/interface": "1.0.0-bcf18265e",
69
- "@libp2p/interface-internal": "0.1.10-bcf18265e",
70
- "@libp2p/logger": "4.0.0-bcf18265e",
71
- "@libp2p/multistream-select": "4.0.7-bcf18265e",
72
- "@libp2p/peer-collections": "4.0.9-bcf18265e",
73
- "@libp2p/peer-id": "4.0.0-bcf18265e",
74
- "@libp2p/peer-id-factory": "3.0.9-bcf18265e",
75
- "@libp2p/peer-store": "9.0.10-bcf18265e",
76
- "@libp2p/utils": "5.0.0-bcf18265e",
67
+ "@libp2p/crypto": "3.0.1-53224004f",
68
+ "@libp2p/interface": "1.0.1-53224004f",
69
+ "@libp2p/interface-internal": "0.1.11-53224004f",
70
+ "@libp2p/logger": "4.0.1-53224004f",
71
+ "@libp2p/multistream-select": "4.0.8-53224004f",
72
+ "@libp2p/peer-collections": "4.0.10-53224004f",
73
+ "@libp2p/peer-id": "4.0.1-53224004f",
74
+ "@libp2p/peer-id-factory": "3.0.10-53224004f",
75
+ "@libp2p/peer-store": "9.0.11-53224004f",
76
+ "@libp2p/utils": "5.0.1-53224004f",
77
77
  "@multiformats/mafmt": "^12.1.6",
78
78
  "@multiformats/multiaddr": "^12.1.10",
79
79
  "@multiformats/multiaddr-matcher": "^1.1.0",
@@ -102,20 +102,20 @@
102
102
  "@chainsafe/libp2p-gossipsub": "^10.0.0",
103
103
  "@chainsafe/libp2p-noise": "^14.0.0",
104
104
  "@chainsafe/libp2p-yamux": "^6.0.1",
105
- "@libp2p/bootstrap": "10.0.0-bcf18265e",
106
- "@libp2p/circuit-relay-v2": "1.0.0-bcf18265e",
105
+ "@libp2p/bootstrap": "10.0.1-53224004f",
106
+ "@libp2p/circuit-relay-v2": "1.0.1-53224004f",
107
107
  "@libp2p/daemon-client": "^8.0.0",
108
108
  "@libp2p/daemon-server": "^7.0.0",
109
- "@libp2p/floodsub": "8.0.14-bcf18265e",
110
- "@libp2p/identify": "1.0.0-bcf18265e",
111
- "@libp2p/interface-compliance-tests": "5.0.0-bcf18265e",
109
+ "@libp2p/floodsub": "8.0.15-53224004f",
110
+ "@libp2p/identify": "1.0.1-53224004f",
111
+ "@libp2p/interface-compliance-tests": "5.0.1-53224004f",
112
112
  "@libp2p/interop": "^10.0.0",
113
- "@libp2p/kad-dht": "11.0.0-bcf18265e",
114
- "@libp2p/mdns": "10.0.0-bcf18265e",
115
- "@libp2p/mplex": "10.0.0-bcf18265e",
116
- "@libp2p/plaintext": "1.0.0-bcf18265e",
117
- "@libp2p/tcp": "9.0.0-bcf18265e",
118
- "@libp2p/websockets": "8.0.0-bcf18265e",
113
+ "@libp2p/kad-dht": "11.0.1-53224004f",
114
+ "@libp2p/mdns": "10.0.1-53224004f",
115
+ "@libp2p/mplex": "10.0.1-53224004f",
116
+ "@libp2p/plaintext": "1.0.1-53224004f",
117
+ "@libp2p/tcp": "9.0.1-53224004f",
118
+ "@libp2p/websockets": "8.0.1-53224004f",
119
119
  "aegir": "^41.0.2",
120
120
  "execa": "^8.0.1",
121
121
  "go-libp2p": "^1.1.1",
package/src/libp2p.ts CHANGED
@@ -23,7 +23,7 @@ import { DefaultUpgrader } from './upgrader.js'
23
23
  import * as pkg from './version.js'
24
24
  import type { Components } from './components.js'
25
25
  import type { Libp2p, Libp2pInit, Libp2pOptions } from './index.js'
26
- import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology } from '@libp2p/interface'
26
+ import type { PeerRouting, ContentRouting, Libp2pEvents, PendingDial, ServiceMap, AbortOptions, ComponentLogger, Logger, Connection, NewStreamOptions, Stream, Metrics, PeerId, PeerInfo, PeerStore, Topology, Libp2pStatus } from '@libp2p/interface'
27
27
  import type { StreamHandler, StreamHandlerOptions } from '@libp2p/interface-internal'
28
28
 
29
29
  export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends TypedEventEmitter<Libp2pEvents> implements Libp2p<T> {
@@ -34,14 +34,16 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
34
34
  public metrics?: Metrics
35
35
  public services: T
36
36
  public logger: ComponentLogger
37
+ public status: Libp2pStatus
37
38
 
38
39
  public components: Components
39
- #started: boolean
40
40
  private readonly log: Logger
41
41
 
42
42
  constructor (init: Libp2pInit<T>) {
43
43
  super()
44
44
 
45
+ this.status = 'stopped'
46
+
45
47
  // event bus - components can listen to this emitter to be notified of system events
46
48
  // and also cause them to be emitted
47
49
  const events = new TypedEventEmitter<Libp2pEvents>()
@@ -58,7 +60,6 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
58
60
  // This emitter gets listened to a lot
59
61
  setMaxListeners(Infinity, events)
60
62
 
61
- this.#started = false
62
63
  this.peerId = init.peerId
63
64
  this.logger = init.logger ?? defaultLogger()
64
65
  this.log = this.logger.forComponent('libp2p')
@@ -196,11 +197,11 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
196
197
  * Starts the libp2p node and all its subsystems
197
198
  */
198
199
  async start (): Promise<void> {
199
- if (this.#started) {
200
+ if (this.status !== 'stopped') {
200
201
  return
201
202
  }
202
203
 
203
- this.#started = true
204
+ this.status = 'starting'
204
205
 
205
206
  this.log('libp2p is starting')
206
207
 
@@ -209,6 +210,7 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
209
210
  await this.components.start()
210
211
  await this.components.afterStart?.()
211
212
 
213
+ this.status = 'started'
212
214
  this.safeDispatchEvent('start', { detail: this })
213
215
  this.log('libp2p has started')
214
216
  } catch (err: any) {
@@ -222,26 +224,23 @@ export class Libp2pNode<T extends ServiceMap = Record<string, unknown>> extends
222
224
  * Stop the libp2p node by closing its listeners and open connections
223
225
  */
224
226
  async stop (): Promise<void> {
225
- if (!this.#started) {
227
+ if (this.status !== 'started') {
226
228
  return
227
229
  }
228
230
 
229
231
  this.log('libp2p is stopping')
230
232
 
231
- this.#started = false
233
+ this.status = 'stopping'
232
234
 
233
235
  await this.components.beforeStop?.()
234
236
  await this.components.stop()
235
237
  await this.components.afterStop?.()
236
238
 
239
+ this.status = 'stopped'
237
240
  this.safeDispatchEvent('stop', { detail: this })
238
241
  this.log('libp2p has stopped')
239
242
  }
240
243
 
241
- isStarted (): boolean {
242
- return this.#started
243
- }
244
-
245
244
  getConnections (peerId?: PeerId): Connection[] {
246
245
  return this.components.connectionManager.getConnections(peerId)
247
246
  }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const version = '1.0.0-bcf18265e'
1
+ export const version = '1.0.1-53224004f'
2
2
  export const name = 'libp2p'