feat: check connection on client peer start

Signed-off-by: Suraneti Rodsuwan <suraneti.rod@gmail.com>
This commit is contained in:
Suraneti Rodsuwan 2024-05-31 13:37:56 +07:00
parent 5c346f6566
commit 16c07f4363
No known key found for this signature in database
GPG Key ID: A35F4E12CA18C77F

View File

@ -25,6 +25,7 @@ import { IMarineHost } from "../marine/interfaces.js";
import { relayOptionToMultiaddr } from "../util/libp2pUtils.js"; import { relayOptionToMultiaddr } from "../util/libp2pUtils.js";
import { logger } from "../util/logger.js"; import { logger } from "../util/logger.js";
import { checkConnection } from './checkConnection.js'
import { import {
ClientConfig, ClientConfig,
IFluenceClient, IFluenceClient,
@ -128,7 +129,14 @@ export class ClientPeer extends FluencePeer implements IFluenceClient {
log.trace("connecting to Fluence network"); log.trace("connecting to Fluence network");
this.changeConnectionState("connecting"); this.changeConnectionState("connecting");
await super.start(); await super.start();
// TODO: check connection (`checkConnection` function) here
const connected = await checkConnection(this);
if (!connected) {
this.changeConnectionState("disconnected");
log.trace("Disconnected");
throw new Error(`Failed to establish a connection with ClientPeer ID '${this.getPeerId()}'`);
}
this.changeConnectionState("connected"); this.changeConnectionState("connected");
log.trace("connected"); log.trace("connected");
} }