From deebe15c6fcb514a58a5dbaec04d61dca8f99c14 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 1 Sep 2023 21:07:28 -0400 Subject: [PATCH] fix: add started state on node and check it on connectToNode --- src/node.ts | 10 ++++++++++ src/service/p2p.ts | 4 ++++ 2 files changed, 14 insertions(+) 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";