Created
March 11, 2017 21:45
-
-
Save thisconnect/c317cbf680e4e83be1cef05135ceeab8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const init = require('./init.js') | |
// WebRTC-Star Signal Server for js-ipfs | |
// SignalServer: null, | |
init({ | |
repo: process.env.IPFS_PATH || './ipfs', | |
Addresses: { | |
API: '/ip4/127.0.0.1/tcp/5001', | |
Swarm: ['/ip4/0.0.0.0/tcp/4001'], | |
Gateway: '/ip4/0.0.0.0/tcp/8080' | |
}, | |
EXPERIMENTAL: { | |
pubsub: false | |
} | |
}) | |
.then(daemon => { | |
return daemon.api.add(Buffer.from('juihui 3.14')) | |
.then(console.log) | |
// .then(api => api.config.get()) | |
// .then(data => console.log(data.toString())) | |
// .then(api => api.id()) | |
// .then(id => console.log('my id is: ', id)) | |
.then(() => daemon.api.log.tail()) | |
.then(stream => stream.on('data', chunk => { | |
if (['dhtSentMessage'].includes(chunk.event)) { | |
console.log(chunk) | |
} | |
if (['handleAddProvider', 'handleGetProviders'].includes(chunk.event)) { | |
console.log(chunk) | |
} | |
if (chunk.key) { | |
console.log(chunk) | |
} | |
if (chunk.message) { | |
console.log(chunk) | |
} | |
})) | |
}) | |
.catch(err => console.error(err)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ipfsd = require('ipfsd-ctl') | |
module.exports = (options => { | |
return new Promise((resolve, reject) => { | |
ipfsd.local(options.repo, (err, daemon) => { | |
if (err) { | |
return reject(err) | |
} | |
console.log(`using IPFS repo at '${daemon.path}'`) | |
resolve(daemon) | |
}) | |
}) | |
.then(daemon => { | |
return new Promise((resolve, reject) => { | |
daemon.init({ | |
// emptyRepo: true, | |
// bits: 2048 | |
directory: options.repo | |
}, (err) => { | |
if (err && !err.message.includes('ipfs configuration file already exists!')){ | |
return reject(err) | |
} | |
resolve(daemon) | |
}) | |
}) | |
}) | |
.then(daemon => { | |
console.log('starting IPFS daemon') | |
return new Promise((resolve, reject) => { | |
daemon.startDaemon([/*'--enable-pubsub-experiment'*/], (err, api) => { | |
if (err) { | |
return reject(err) | |
} | |
console.log(`IPFS daemon started at ${api.apiHost} port ${api.apiPort}`) | |
// console.log('daemon', Object.keys(daemon).join()) | |
// console.log('api', Object.keys(api).join()) | |
// resolve(api) | |
resolve(daemon) | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment