Compare commits
1 Commits
feature/ip
...
d8dda84fd6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d8dda84fd6
|
42
index.js
42
index.js
@@ -3,13 +3,6 @@
|
|||||||
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({
|
.default({
|
||||||
@@ -19,7 +12,7 @@ const argv = require('yargs')
|
|||||||
port: '5001',
|
port: '5001',
|
||||||
protocol: 'http',
|
protocol: 'http',
|
||||||
monitor: true,
|
monitor: true,
|
||||||
bootstrapNode: bootstrapNode
|
bootstrapNode: '/dns4/barnard.kosmos.org/tcp/4001/ipfs/QmbqZCZ2RzVr4r1UEdFak6ra76kHxtGmfV9r3e1Ev6Tj5D'
|
||||||
})
|
})
|
||||||
.boolean('monitor')
|
.boolean('monitor')
|
||||||
.describe({
|
.describe({
|
||||||
@@ -56,33 +49,18 @@ console.log(`Using IPFS:`, ipfsConfig);
|
|||||||
|
|
||||||
await ipfsApi.id();
|
await ipfsApi.id();
|
||||||
|
|
||||||
// debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
|
debug(`Connecting to known IPFS node ${argv.bootstrapNode}`);
|
||||||
// await ipfsApi.swarm.connect(argv.bootstrapNode);
|
await ipfsApi.swarm.connect(argv.bootstrapNode);
|
||||||
|
|
||||||
let peers;
|
const ipfsPinner = new IpfsPinner(kredits);
|
||||||
|
|
||||||
try {
|
ipfsPinner.pinAll().then(pins => {
|
||||||
peers = await ipfsApi.config.get('Peering.Peers');
|
console.log(`Pinned ${pins.length} existing documents`);
|
||||||
} catch(e) { /* No peers configured */ }
|
});
|
||||||
|
|
||||||
if (peers) {
|
ipfsPinner.monitor(pin => {
|
||||||
// TODO check for kosmos peer
|
console.log('Pinned a new document:', pin[0]["hash"]);
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user