diff --git a/index.js b/index.js index d2d6918..d66e956 100755 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const Kredits = require('kredits-contracts'); 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 }) @@ -26,6 +27,15 @@ 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( @@ -35,7 +45,12 @@ console.log(`Using IPFS:`, ipfsConfig); // check the connection to the IPFS client // TODO redesign IPFS wrapper API and do not use an internal attribute - await kredits.ipfs._ipfsAPI.id(); + const ipfsApi = kredits.ipfs._ipfsAPI; + + await ipfsApi.id(); + + // TODO discover address dynamically from somewhere + await swarmConnect(ipfsApi, '/ip4/46.4.18.160/tcp/4001/ipfs/QmZ4Lpzhz8bafbTYvEMMCmrbrMM4JfyHDR23WbCSAd9bo7'); const ipfsPinner = new IpfsPinner(kredits);