diff --git a/ot-node.js b/ot-node.js index 2660f544ad..5e89a6b99f 100644 --- a/ot-node.js +++ b/ot-node.js @@ -69,6 +69,7 @@ class OTNode { await this.initializeCommandExecutor(); await this.initializeRouters(); + await this.startNetworkModule(); this.logger.info('Node is up and running!'); } @@ -254,6 +255,11 @@ class OTNode { } } + async startNetworkModule() { + const networkModuleManager = this.container.resolve('networkModuleManager'); + await networkModuleManager.start(); + } + async executePrivateAssetsMetadataMigration() { if ( process.env.NODE_ENV === NODE_ENVIRONMENTS.DEVELOPMENT || diff --git a/src/modules/network/implementation/libp2p-service.js b/src/modules/network/implementation/libp2p-service.js index 1b99a1c873..1d3885debe 100644 --- a/src/modules/network/implementation/libp2p-service.js +++ b/src/modules/network/implementation/libp2p-service.js @@ -101,13 +101,16 @@ class Libp2pService { */ this.sessions = {}; this.node = await libp2p.create(initializationObject); - await this.node.start(); const port = parseInt(this.node.multiaddrs.toString().split('/')[4], 10); const peerId = this.node.peerId.toB58String(); this.config.id = peerId; this.logger.info(`Network ID is ${peerId}, connection port is ${port}`); } + async start() { + this.node.start(); + } + async onPeerConnected(listener) { this.node.connectionManager.on('peer:connect', listener); } diff --git a/src/modules/network/network-module-manager.js b/src/modules/network/network-module-manager.js index 758ca4244a..698c7f5697 100644 --- a/src/modules/network/network-module-manager.js +++ b/src/modules/network/network-module-manager.js @@ -5,6 +5,12 @@ class NetworkModuleManager extends BaseModuleManager { return 'network'; } + async start() { + if (this.initialized) { + return this.getImplementation().module.start(); + } + } + async onPeerConnected(listener) { if (this.initialized) { return this.getImplementation().module.onPeerConnected(listener);