From 2401d8dff220c35c6c6420c162e672470d33c612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Wed, 2 Nov 2022 20:50:54 +0100 Subject: [PATCH] Prevent bootstrap node connects on the same IPFS node --- index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5e89146..fea4d77 100755 --- a/index.js +++ b/index.js @@ -50,15 +50,22 @@ debug(`IPFS node:`, ipfsConfig); // TODO redesign IPFS wrapper API and do not use an internal attribute const ipfsApi = kredits.ipfs._ipfsAPI; + let connectBootstrapNode = true; - await ipfsApi.id().catch(e => { + await ipfsApi.id().then(res => { + if (res.id === argv.bootstrapNode.split('/')[argv.bootstrapNode.split('/').length-1]) { + connectBootstrapNode = false; + } + }).catch(e => { console.log('Failed to initialize IPFS:'); console.log(e.message); process.exit(1); }); - debug(`Connecting to known IPFS node ${argv.bootstrapNode}`); - await ipfsApi.swarm.connect(argv.bootstrapNode); + if (connectBootstrapNode) { + debug(`Connecting to known IPFS node ${argv.bootstrapNode}`); + await ipfsApi.swarm.connect(argv.bootstrapNode); + } const ipfsPinner = new IpfsPinner(kredits, { progress: argv.progress