From 16c07f4363098ed7d34c752c7a62e28a68acca6e Mon Sep 17 00:00:00 2001 From: Suraneti Rodsuwan Date: Fri, 31 May 2024 13:37:56 +0700 Subject: [PATCH] feat: check connection on client peer start Signed-off-by: Suraneti Rodsuwan --- packages/core/js-client/src/clientPeer/ClientPeer.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/js-client/src/clientPeer/ClientPeer.ts b/packages/core/js-client/src/clientPeer/ClientPeer.ts index 4e5b345e..1888942b 100644 --- a/packages/core/js-client/src/clientPeer/ClientPeer.ts +++ b/packages/core/js-client/src/clientPeer/ClientPeer.ts @@ -25,6 +25,7 @@ import { IMarineHost } from "../marine/interfaces.js"; import { relayOptionToMultiaddr } from "../util/libp2pUtils.js"; import { logger } from "../util/logger.js"; +import { checkConnection } from './checkConnection.js' import { ClientConfig, IFluenceClient, @@ -128,7 +129,14 @@ export class ClientPeer extends FluencePeer implements IFluenceClient { log.trace("connecting to Fluence network"); this.changeConnectionState("connecting"); 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"); log.trace("connected"); }