Compare commits
6 Commits
v1.1.0
...
feature/ip
| Author | SHA1 | Date | |
|---|---|---|---|
|
ef1ae5add7
|
|||
|
9c34e4c913
|
|||
|
ba5f67861f
|
|||
| ba7c98b564 | |||
| 3f03368e25 | |||
| a3d21ebb30 |
62
index.js
62
index.js
@@ -3,9 +3,24 @@
|
|||||||
const Kredits = require('kredits-contracts');
|
const Kredits = require('kredits-contracts');
|
||||||
const IpfsPinner = require('./lib/ipfs-pinner');
|
const IpfsPinner = require('./lib/ipfs-pinner');
|
||||||
const debug = require('debug')('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')
|
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')
|
.boolean('monitor')
|
||||||
.describe({
|
.describe({
|
||||||
network: 'Ethereum network to connect to',
|
network: 'Ethereum network to connect to',
|
||||||
@@ -14,7 +29,8 @@ const argv = require('yargs')
|
|||||||
host: 'IPFS API host',
|
host: 'IPFS API host',
|
||||||
port: 'IPFS API port',
|
port: 'IPFS API port',
|
||||||
protocol: 'IPFS API protocol',
|
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.')
|
.example('$0 --network rinkeby --host localhost', 'Pins all existing IPFS documents to the IPFS API running on localhost and monitors for new events.')
|
||||||
.argv;
|
.argv;
|
||||||
@@ -27,15 +43,6 @@ const ipfsConfig = {
|
|||||||
|
|
||||||
console.log(`Using IPFS:`, 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 () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const kredits = await Kredits.for(
|
const kredits = await Kredits.for(
|
||||||
@@ -49,18 +56,33 @@ async function swarmConnect (ipfsApi, address) {
|
|||||||
|
|
||||||
await ipfsApi.id();
|
await ipfsApi.id();
|
||||||
|
|
||||||
// TODO discover address dynamically from somewhere
|
// debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
|
||||||
await swarmConnect(ipfsApi, '/ip4/46.4.18.160/tcp/4001/ipfs/QmZ4Lpzhz8bafbTYvEMMCmrbrMM4JfyHDR23WbCSAd9bo7');
|
// await ipfsApi.swarm.connect(argv.bootstrapNode);
|
||||||
|
|
||||||
const ipfsPinner = new IpfsPinner(kredits);
|
let peers;
|
||||||
|
|
||||||
ipfsPinner.pinAll().then(pins => {
|
try {
|
||||||
console.log(`Pinned ${pins.length} existing documents`);
|
peers = await ipfsApi.config.get('Peering.Peers');
|
||||||
});
|
} catch(e) { /* No peers configured */ }
|
||||||
|
|
||||||
ipfsPinner.monitor(pin => {
|
if (peers) {
|
||||||
console.log('Pinned a new document:', pin[0]["hash"]);
|
// 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}`);
|
console.log(`Subscribed to DAO: ${kredits.Kernel.contract.address}`);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@67p/kredits-ipfs-pinner",
|
"name": "@67p/kredits-ipfs-pinner",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kosmos/kredits-ipfs-pinner",
|
"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",
|
"description": "Pins IPFS data of a Kredits organization on an IPFS node",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user