diff --git a/src/node.ts b/src/node.ts index 0419b68..bed4541 100644 --- a/src/node.ts +++ b/src/node.ts @@ -8,6 +8,7 @@ import KeyPairEd25519 from "#ed25519.js"; import { AbstractLevel } from "abstract-level"; import { P2PService } from "#service/p2p.js"; import { RegistryService } from "#service/registry.js"; +import { hash } from "@noble/hashes/_assert"; const DEFAULT_LOGGER = { info(s: any) { console.info(s); @@ -33,6 +34,12 @@ export class S5Node { this._nodeConfig = config; } + private _started = false; + + get started(): boolean { + return this._started; + } + private _config?: S5Config; get config() { @@ -61,6 +68,8 @@ export class S5Node { p2p: this._nodeConfig.p2p, }; + this._started = true; + const p2p = new P2PService(this); const registry = new RegistryService(this); @@ -70,6 +79,7 @@ export class S5Node { } public async stop() { + this._started = false; await this.services.p2p.stop(); } diff --git a/src/service/p2p.ts b/src/service/p2p.ts index 4c716e4..1a4ac84 100644 --- a/src/service/p2p.ts +++ b/src/service/p2p.ts @@ -289,6 +289,10 @@ export class P2PService extends EventEmitter { } async connectToNode(connectionUris: URL[], retried = false): Promise { + if (!this.node.started) { + return; + } + const unsupported = new URL("http://0.0.0.0"); unsupported.protocol = "unsupported";