WIP: Set native IPFS peering config #9
42
index.js
42
index.js
|
@ -3,6 +3,13 @@
|
|||
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({
|
||||
|
@ -12,7 +19,7 @@ const argv = require('yargs')
|
|||
port: '5001',
|
||||
protocol: 'http',
|
||||
monitor: true,
|
||||
bootstrapNode: '/ip4/46.4.18.160/tcp/4001/ipfs/QmZ4Lpzhz8bafbTYvEMMCmrbrMM4JfyHDR23WbCSAd9bo7'
|
||||
bootstrapNode: bootstrapNode
|
||||
})
|
||||
.boolean('monitor')
|
||||
.describe({
|
||||
|
@ -49,18 +56,33 @@ console.log(`Using IPFS:`, ipfsConfig);
|
|||
|
||||
await ipfsApi.id();
|
||||
|
||||
debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
|
||||
await ipfsApi.swarm.connect(argv.bootstrapNode);
|
||||
// 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) {
|
||||
|
|
Loading…
Reference in New Issue