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

Commit

Permalink
feat(breaking change): experimental config options
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Feb 1, 2017
1 parent c205736 commit 6441898
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 86 deletions.
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
18 changes: 18 additions & 0 deletions src/core/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
exports.goOnline = require('./go-online')
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: 48 additions & 63 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,53 @@ const PeerBook = require('peer-book')

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')

exports = module.exports = IPFS

function IPFS (repoInstance) {
if (!(this instanceof IPFS)) {
throw new Error('Must be instantiated with new')
const components = require('./components')

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

configOpts.EXPERIMENTAL = configOpts.EXPERIMENTAL || {}

// 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

// 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)
}

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

// 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 Core exposed components

// 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)

// 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)
}

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
7 changes: 6 additions & 1 deletion test/utils/temp-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ function setAddresses (repo, num, callback) {

function createTempNode (num, callback) {
const repo = createTempRepo()
const ipfs = new IPFS(repo)
const ipfs = new IPFS({
repo: repo,
EXPERIMENTAL: {
pubsub: true
}
})

num = leftPad(num, 3, 0)

Expand Down

0 comments on commit 6441898

Please sign in to comment.