fix: add started state on node and check it on connectToNode

This commit is contained in:
Derrick Hammer 2023-09-01 21:07:28 -04:00
parent 8cc499c320
commit deebe15c6f
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 14 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import KeyPairEd25519 from "#ed25519.js";
import { AbstractLevel } from "abstract-level"; import { AbstractLevel } from "abstract-level";
import { P2PService } from "#service/p2p.js"; import { P2PService } from "#service/p2p.js";
import { RegistryService } from "#service/registry.js"; import { RegistryService } from "#service/registry.js";
import { hash } from "@noble/hashes/_assert";
const DEFAULT_LOGGER = { const DEFAULT_LOGGER = {
info(s: any) { info(s: any) {
console.info(s); console.info(s);
@ -33,6 +34,12 @@ export class S5Node {
this._nodeConfig = config; this._nodeConfig = config;
} }
private _started = false;
get started(): boolean {
return this._started;
}
private _config?: S5Config; private _config?: S5Config;
get config() { get config() {
@ -61,6 +68,8 @@ export class S5Node {
p2p: this._nodeConfig.p2p, p2p: this._nodeConfig.p2p,
}; };
this._started = true;
const p2p = new P2PService(this); const p2p = new P2PService(this);
const registry = new RegistryService(this); const registry = new RegistryService(this);
@ -70,6 +79,7 @@ export class S5Node {
} }
public async stop() { public async stop() {
this._started = false;
await this.services.p2p.stop(); await this.services.p2p.stop();
} }

View File

@ -289,6 +289,10 @@ export class P2PService extends EventEmitter {
} }
async connectToNode(connectionUris: URL[], retried = false): Promise<void> { async connectToNode(connectionUris: URL[], retried = false): Promise<void> {
if (!this.node.started) {
return;
}
const unsupported = new URL("http://0.0.0.0"); const unsupported = new URL("http://0.0.0.0");
unsupported.protocol = "unsupported"; unsupported.protocol = "unsupported";