Skip to content

Commit

Permalink
Merge branch 'v6/bug-fix/delay-start-libp2p' into v6/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroxbt committed Jul 20, 2023
2 parents 28a7ab9 + 01dd59c commit 8a61165
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ot-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class OTNode {

await this.initializeCommandExecutor();
await this.initializeRouters();
await this.startNetworkModule();
this.logger.info('Node is up and running!');
}

Expand Down Expand Up @@ -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 ||
Expand Down
5 changes: 4 additions & 1 deletion src/modules/network/implementation/libp2p-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions src/modules/network/network-module-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8a61165

Please sign in to comment.