Browse Source

Refactor bootstrap node connect, add CLI argument

Removes the superfluous wrapper function (as the API already returns a
Promise). Also adds a command line argument so you can choose a
different bootstrap node.
tags/v1.2.0
raucao 1 year ago
parent
commit
a3d21ebb30
Signed by: raucao <sebastian@kip.pe> GPG Key ID: BE4634D632D39B67
1 changed files with 13 additions and 13 deletions
  1. +13
    -13
      index.js

+ 13
- 13
index.js View File

@@ -5,7 +5,15 @@ const IpfsPinner = require('./lib/ipfs-pinner');
const debug = require('debug')('ipfs-pinner');

const argv = require('yargs')
.default({ network: 'rinkeby', apm: 'open.aragonpm.eth', host: 'localhost', port: '5001', protocol: 'http', monitor: true })
.default({
network: 'rinkeby',
apm: 'open.aragonpm.eth',
host: 'localhost',
port: '5001',
protocol: 'http',
monitor: true,
bootstrapNode: '/ip4/46.4.18.160/tcp/4001/ipfs/QmZ4Lpzhz8bafbTYvEMMCmrbrMM4JfyHDR23WbCSAd9bo7'
})
.boolean('monitor')
.describe({
network: 'Ethereum network to connect to',
@@ -14,7 +22,8 @@ const argv = require('yargs')
host: 'IPFS API host',
port: 'IPFS API port',
protocol: 'IPFS API protocol',
monitor: 'Monitor contract events for new IPFS documents'
monitor: 'Monitor contract events for new IPFS documents',
bootstrapNode: 'IPFS node address to connect to before fetching documents'
})
.example('$0 --network rinkeby --host localhost', 'Pins all existing IPFS documents to the IPFS API running on localhost and monitors for new events.')
.argv;
@@ -27,15 +36,6 @@ const ipfsConfig = {

console.log(`Using IPFS:`, ipfsConfig);

async function swarmConnect (ipfsApi, address) {
return new Promise((resolve, reject) => {
debug(`Connecting to known IPFS node: ${address}`);
ipfsApi.swarm.connect(address, err => {
return err ? reject(err) : resolve();
})
});
}

(async () => {
try {
const kredits = await Kredits.for(
@@ -49,8 +49,8 @@ async function swarmConnect (ipfsApi, address) {

await ipfsApi.id();

// TODO discover address dynamically from somewhere
await swarmConnect(ipfsApi, '/ip4/46.4.18.160/tcp/4001/ipfs/QmZ4Lpzhz8bafbTYvEMMCmrbrMM4JfyHDR23WbCSAd9bo7');
debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
await ipfsApi.swarm.connect(argv.bootstrapNode);

const ipfsPinner = new IpfsPinner(kredits);



Loading…
Cancel
Save