13 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
b11dbb9fde 1.1.0 2019-08-13 11:10:09 +02:00
gregkare
bfb51d48bc Merge branch 'feature/connect_to_kosmos_ipfs_node' of kosmos/kredits-ipfs-pinner into master 2019-08-13 09:02:34 +00:00
f2f884a317 Connect to ipfs.kosmos.org node on start
This ensures that the local IPFS node is always connected to a known
Kosmos node before attempting to fetch documents. Vastly improves
performance.

closes #4
2019-08-13 10:07:25 +02:00
2a3c021737 1.0.3 2019-08-04 14:52:06 +02:00
c4c95d9b38 Move package to "kosmos" org 2019-08-04 14:51:38 +02:00
2d08cc929f Merge branch 'bugfix/broken_executable' of kosmos/kredits-ipfs-pinner into master 2019-08-04 12:51:03 +00:00
5d36ca05a5 Fix executable not working
Need to tell the system it's dealing with a node script. This fixes both
the installed `kredits-ipfs-pinner` command as well as npx (which is
also running that command).
2019-08-04 14:47:57 +02:00
4 changed files with 54 additions and 16 deletions

View File

@@ -9,11 +9,11 @@ config flags, in case it is not running on localhost with default ports.)
### With NPX magic ### With NPX magic
npx @67p/kredits-ipfs-pinner npx @kosmos/kredits-ipfs-pinner
### Global install ### Global install
npm install -g @67p/kredits-ipfs-pinner npm install -g @kosmos/kredits-ipfs-pinner
kredits-ipfs-pinner kredits-ipfs-pinner
### From repo ### From repo

View File

@@ -1,9 +1,26 @@
const debug = require('debug')('ipfs-pinner'); #!/usr/bin/env node
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 { 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',
@@ -12,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;
@@ -34,17 +52,37 @@ console.log(`Using IPFS:`, ipfsConfig);
// check the connection to the IPFS client // check the connection to the IPFS client
// TODO redesign IPFS wrapper API and do not use an internal attribute // TODO redesign IPFS wrapper API and do not use an internal attribute
await kredits.ipfs._ipfsAPI.id(); const ipfsApi = kredits.ipfs._ipfsAPI;
const ipfsPinner = new IpfsPinner(kredits); await ipfsApi.id();
ipfsPinner.pinAll().then(pins => { // debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
console.log(`Pinned ${pins.length} existing documents`); // await ipfsApi.swarm.connect(argv.bootstrapNode);
});
ipfsPinner.monitor(pin => { let peers;
console.log('Pinned a new document:', pin[0]["hash"]);
}); try {
peers = await ipfsApi.config.get('Peering.Peers');
} catch(e) { /* No peers configured */ }
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}`); console.log(`Subscribed to DAO: ${kredits.Kernel.contract.address}`);
} catch(e) { } catch(e) {

2
package-lock.json generated
View File

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

View File

@@ -1,6 +1,6 @@
{ {
"name": "@67p/kredits-ipfs-pinner", "name": "@kosmos/kredits-ipfs-pinner",
"version": "1.0.2", "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": {