Prevent bootstrap node connects on the same IPFS node

This commit is contained in:
Râu Cao 2022-11-02 20:50:54 +01:00
parent 45c0aed4a5
commit 2401d8dff2
Signed by: raucao
GPG Key ID: 15E65F399D084BA9
1 changed files with 10 additions and 3 deletions

View File

@ -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