6 Commits

Author SHA1 Message Date
ef1ae5add7 Use DNS multiaddr
Makes it much easier to identify the node you're connecting to
2020-10-26 09:16:00 +01:00
9c34e4c913 WIP Use new IPFS peering config
Currently crashes go-ipfs 0.6 for some reason.
2020-10-25 10:59:59 +01:00
ba5f67861f Change IPFS bootstrap node 2020-10-23 12:08:36 +02:00
ba7c98b564 1.2.0 2019-08-18 12:40:27 +02:00
3f03368e25 Merge branch 'refactor/bootstrap_node' of kosmos/kredits-ipfs-pinner into master 2019-08-18 09:03:51 +00:00
a3d21ebb30 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.
2019-08-14 10:12:07 +02:00
3 changed files with 44 additions and 22 deletions

View File

@@ -3,9 +3,24 @@
const Kredits = require('kredits-contracts');
const IpfsPinner = require('./lib/ipfs-pinner');
const debug = require('debug')('ipfs-pinner');
const { inspect } = require('util');
// TODO make configurable
const peerId = "QmbqZCZ2RzVr4r1UEdFak6ra76kHxtGmfV9r3e1Ev6Tj5D";
const peerAddrs = [ "/dns4/barnard.kosmos.org/tcp/4001" ];
const bootstrapNode = `${peerAddrs[0]}/ipfs/${peerId}`;
const peerConfig = { "ID": peerId, "Addrs": [ peerAddrs ] };
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: bootstrapNode
})
.boolean('monitor')
.describe({
network: 'Ethereum network to connect to',
@@ -14,7 +29,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 +43,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,18 +56,33 @@ 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);
let peers;
ipfsPinner.pinAll().then(pins => {
console.log(`Pinned ${pins.length} existing documents`);
});
try {
peers = await ipfsApi.config.get('Peering.Peers');
} catch(e) { /* No peers configured */ }
ipfsPinner.monitor(pin => {
console.log('Pinned a new document:', pin[0]["hash"]);
});
if (peers) {
// TODO check for kosmos peer
debug('IPFS peers configured:');
debug(inspect(peers.map(p => p.ID)));
} else {
debug(`Configuring persistent IPFS peer: ${peerId}`);
await ipfsApi.config.set('Peering', { "Peers": [ peerConfig ]});
}
// const ipfsPinner = new IpfsPinner(kredits);
// ipfsPinner.pinAll().then(pins => {
// console.log(`Pinned ${pins.length} existing documents`);
// });
//
// ipfsPinner.monitor(pin => {
// console.log('Pinned a new document:', pin[0]["hash"]);
// });
console.log(`Subscribed to DAO: ${kredits.Kernel.contract.address}`);
} catch(e) {

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{
"name": "@67p/kredits-ipfs-pinner",
"version": "1.1.0",
"version": "1.2.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@kosmos/kredits-ipfs-pinner",
"version": "1.1.0",
"version": "1.2.0",
"description": "Pins IPFS data of a Kredits organization on an IPFS node",
"main": "index.js",
"scripts": {