fix: add started state on node and check it on connectToNode
This commit is contained in:
parent
8cc499c320
commit
deebe15c6f
10
src/node.ts
10
src/node.ts
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue