Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

feat(breaking change): experimental config options #749

Merged
merged 3 commits into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,12 @@ The HTTP-API exposed by the js-ipfs daemon follows the [`http-api-spec`](https:/
const repo = <IPFS Repo instance or repo path>

// Create the IPFS node instance
const node = new IPFS(repo)
const node = new IPFS({
repo: repo,
EXPERIMENTAL: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to upcase this? I think experimental is enough. What would be good is to print something to the console when this is enabled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like making things very OBVIOUS :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUT DO YOU REALLY NEED TO SCREAM AT ME?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add your log :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added your log :)

pubsub: false
}
})

// We need to init our repo, in this case the repo was empty
// We are picking 2048 bits for the RSA key that will be our PeerId
Expand Down
7 changes: 6 additions & 1 deletion examples/basics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const IPFS = require('../../src/core')
/*
* Create a new IPFS instance, using default repo (fs) on default path (~/.ipfs)
*/
const node = new IPFS(path.join(os.tmpDir() + '/' + new Date().toString()))
const node = new IPFS({
repo: path.join(os.tmpDir() + '/' + new Date().toString()),
EXPERIMENTAL: {
pubsub: false
}
})

const fileToAdd = {
path: 'hello.txt',
Expand Down
7 changes: 6 additions & 1 deletion examples/bundle-browserify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ var IPFS = require('../../../src/core') // replace this by line below
// for simplicity, we create a new repo everytime the node
// is created, because you can't init already existing repos
const repoPath = String(Math.random())
const node = new IPFS(repoPath)
const node = new IPFS({
repo: repoPath,
EXPERIMENTAL: {
pubsub: false
}
})
const concat = require('concat-stream')

node.init({ emptyRepo: true, bits: 2048 }, function (err) {
Expand Down
7 changes: 6 additions & 1 deletion examples/bundle-webpack/src/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class App extends React.Component {
// for simplicity, we create a new repo everytime the node
// is created, because you can't init already existing repos
const repoPath = String(Math.random())
node = new IPFS(repoPath)
node = new IPFS({
repo: repoPath,
EXPERIMENTAL: {
pubsub: false
}
})

node.init({ emptyRepo: true, bits: 2048 }, function (err) {
if (err) {
Expand Down
13 changes: 8 additions & 5 deletions src/cli/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const IpfsRepo = require('ipfs-repo')
const Ipfs = require('../../core')
const Repo = require('ipfs-repo')
const IPFS = require('../../core')
const Store = require('fs-pull-blob-store')
const utils = require('../utils')

Expand Down Expand Up @@ -35,18 +35,21 @@ module.exports = {
const log = utils.createLogger(true)
log(`initializing ipfs node at ${path}`)

const repo = new IpfsRepo(path, {
const repo = new Repo(path, {
stores: Store
})

const ipfs = new Ipfs(repo)
const ipfs = new IPFS({
repo: repo,
EXPERIMENTAL: {}
})

ipfs.init({
bits: argv.bits,
force: argv.force,
emptyRepo: argv.emptyRepo,
log
}, function (err) {
}, (err) => {
if (err) {
console.error(err.toString())
process.exit(1)
Expand Down
9 changes: 6 additions & 3 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ function getAPICtl () {

exports.getIPFS = (callback) => {
if (!isDaemonOn()) {
const ipfs = new IPFS(exports.getRepoPath())
ipfs.load(() => {
callback(null, ipfs)
const ipfs = new IPFS({
repo: exports.getRepoPath(),
EXPERIMENTAL: {
pubsub: true
}
})
ipfs.load(() => callback(null, ipfs))
return
}

Expand Down
11 changes: 9 additions & 2 deletions src/core/components/go-offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ module.exports = (self) => {
return (callback) => {
self._blockService.goOffline()
self._bitswap.stop()
self._pubsub.stop((err) => {

if (self._configOpts.EXPERIMENTAL.pubsub) {
self._pubsub.stop(next)
} else {
next()
}

function next (err) {
if (err) {
return callback(err)
}
self.libp2p.stop(callback)
})
}
}
}
10 changes: 7 additions & 3 deletions src/core/components/go-online.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ module.exports = (self) => {
self._blockService.goOnline(self._bitswap)
cb()
},
(cb) => self._pubsub.start(cb) // ,
// For all of the protocols to handshake with each other
// (cb) => setTimeout(cb, 1000) // Still not decided if we want this
(cb) => {
if (self._configOpts.EXPERIMENTAL.pubsub) {
self._pubsub.start(cb)
} else {
cb()
}
}
], callback)
})
}
Expand Down
20 changes: 20 additions & 0 deletions src/core/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

exports.goOnline = require('./go-online')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not duplicate exports everywhere

module.exports = {
  goOnline: require('./go-online'),
  ...
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that way we have to worry about those commas, the way it is right now doesn't

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what commas you mean

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it is inside an object, for every add/delete, we get the 'no dangling comma situation'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a lot of mixed and unclean diffs, not sure this makes any diff ;)

exports.goOffline = require('./go-offline')
exports.isOnline = require('./is-online')
exports.load = require('./load')
exports.version = require('./version')
exports.id = require('./id')
exports.repo = require('./repo')
exports.init = require('./init')
exports.bootstrap = require('./bootstrap')
exports.config = require('./config')
exports.block = require('./block')
exports.object = require('./object')
exports.libp2p = require('./libp2p')
exports.swarm = require('./swarm')
exports.ping = require('./ping')
exports.files = require('./files')
exports.bitswap = require('./bitswap')
exports.pubsub = require('./pubsub')
111 changes: 53 additions & 58 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,66 @@
const BlockService = require('ipfs-block-service')
const IPLDResolver = require('ipld-resolver')
const PeerBook = require('peer-book')
const debug = require('debug')

const defaultRepo = require('./default-repo')

const goOnline = require('./components/go-online')
const goOffline = require('./components/go-offline')
const isOnline = require('./components/is-online')
const load = require('./components/load')
const version = require('./components/version')
const id = require('./components/id')
const repo = require('./components/repo')
const init = require('./components/init')
const bootstrap = require('./components/bootstrap')
const config = require('./components/config')
const block = require('./components/block')
const object = require('./components/object')
const libp2p = require('./components/libp2p')
const swarm = require('./components/swarm')
const ping = require('./components/ping')
const files = require('./components/files')
const bitswap = require('./components/bitswap')
const pubsub = require('./components/pubsub')
const components = require('./components')

exports = module.exports = IPFS
class IPFS {
constructor (configOpts) {
let repoInstance
if (typeof configOpts.repo === 'string' || configOpts.repo === undefined) {
repoInstance = defaultRepo(configOpts.repo)
} else {
repoInstance = configOpts.repo
}
delete configOpts.repo

function IPFS (repoInstance) {
if (!(this instanceof IPFS)) {
throw new Error('Must be instantiated with new')
}

if (typeof repoInstance === 'string' ||
repoInstance === undefined) {
repoInstance = defaultRepo(repoInstance)
}
configOpts.EXPERIMENTAL = configOpts.EXPERIMENTAL || {}

// IPFS Core Internals
this._repo = repoInstance
this._peerInfoBook = new PeerBook()
this._peerInfo = null
this._libp2pNode = null
this._bitswap = null
this._blockService = new BlockService(this._repo)
this._ipldResolver = new IPLDResolver(this._blockService)
this._pubsub = null
// IPFS utils
this.types = {}
this.log = debug('jsipfs')
this.log.err = debug('jsipfs:err')

// IPFS Core exposed components
// IPFS Core Internals
this._configOpts = configOpts
this._repo = repoInstance
this._peerInfoBook = new PeerBook()
this._peerInfo = undefined
this._libp2pNode = undefined
this._bitswap = undefined
this._blockService = new BlockService(this._repo)
this._ipldResolver = new IPLDResolver(this._blockService)
this._pubsub = undefined

// for booting up a node
this.goOnline = goOnline(this)
this.goOffline = goOffline(this)
this.isOnline = isOnline(this)
this.load = load(this)
this.init = init(this)
// IPFS Core exposed components
// - for booting up a node
this.goOnline = components.goOnline(this)
this.goOffline = components.goOffline(this)
this.isOnline = components.isOnline(this)
this.load = components.load(this)
this.init = components.init(this)
// - interface-ipfs-core defined API
this.version = components.version(this)
this.id = components.id(this)
this.repo = components.repo(this)
this.bootstrap = components.bootstrap(this)
this.config = components.config(this)
this.block = components.block(this)
this.object = components.object(this)
this.libp2p = components.libp2p(this)
this.swarm = components.swarm(this)
this.files = components.files(this)
this.bitswap = components.bitswap(this)
this.ping = components.ping(this)
this.pubsub = components.pubsub(this)

// interface-ipfs-core defined API
this.version = version(this)
this.id = id(this)
this.repo = repo(this)
this.bootstrap = bootstrap(this)
this.config = config(this)
this.block = block(this)
this.object = object(this)
this.libp2p = libp2p(this)
this.swarm = swarm(this)
this.files = files(this)
this.bitswap = bitswap(this)
this.ping = ping(this)
this.pubsub = pubsub(this)
if (configOpts.EXPERIMENTAL.pubsub) {
this.log('EXPERIMENTAL pubsub is enabled')
}
}
}

module.exports = IPFS
8 changes: 7 additions & 1 deletion src/http-api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ exports = module.exports = function HttpApi (repo) {
repo = new IPFSRepo(repo, {stores: Store})
}

this.ipfs = new IPFS(repo)
this.ipfs = new IPFS({
repo: repo,
EXPERIMENTAL: {
pubsub: true
}
})

const repoPath = this.ipfs.repo.path()

try {
Expand Down
4 changes: 1 addition & 3 deletions test/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ describe('cli', () => {
})
})

after(() => {
clean(repoTests)
})
after(() => clean(repoTests))

describe('--all', () => {
const tests = fs.readdirSync(__dirname)
Expand Down
7 changes: 6 additions & 1 deletion test/core/bitswap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ describe('bitswap', () => {

beforeEach((done) => {
const repo = createTempRepo()
inProcNode = new IPFS(repo)
inProcNode = new IPFS({
repo: repo,
EXPERIMENTAL: {
pubsub: true
}
})
series([
(cb) => inProcNode.init({ bits: 2048 }, cb),
(cb) => {
Expand Down
7 changes: 6 additions & 1 deletion test/core/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ describe('bootstrap', () => {

before((done) => {
const repo = createTempRepo()
ipfs = new IPFS(repo)
ipfs = new IPFS({
repo: repo,
EXPERIMENTAL: {
pubsub: true
}
})
series([
(cb) => ipfs.init({ bits: 1024 }, cb),
(cb) => ipfs.load(cb)
Expand Down
7 changes: 6 additions & 1 deletion test/core/init.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ describe('init', () => {

beforeEach(() => {
repo = createTempRepo()
ipfs = new IPFS(repo)
ipfs = new IPFS({
repo: repo,
EXPERIMENTAL: {
pubsub: true
}
})
})

afterEach((done) => repo.teardown(done))
Expand Down
8 changes: 7 additions & 1 deletion test/utils/factory-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ function Factory () {
const repo = createTempRepo(repoPath)

// create the IPFS node
const ipfs = new IPFS(repo)
const ipfs = new IPFS({
repo: repo,
EXPERIMENTAL: {
pubsub: true
}
})

ipfs.init({ emptyRepo: true, bits: 1024 }, (err) => {
if (err) {
return callback(err)
Expand Down
8 changes: 7 additions & 1 deletion test/utils/factory-http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ function Factory () {
}

// create the IPFS node
const ipfs = new IPFS(repo)
const ipfs = new IPFS({
repo: repo,
EXPERIMENTAL: {
pubsub: true
}
})

ipfs.init({
emptyRepo: true,
bits: 1024
Expand Down
Loading