|
3 | 3 | const BlockService = require('ipfs-block-service')
|
4 | 4 | const IPLDResolver = require('ipld-resolver')
|
5 | 5 | const PeerBook = require('peer-book')
|
| 6 | +const debug = require('debug') |
6 | 7 |
|
7 | 8 | const defaultRepo = require('./default-repo')
|
8 | 9 |
|
9 |
| -const goOnline = require('./components/go-online') |
10 |
| -const goOffline = require('./components/go-offline') |
11 |
| -const isOnline = require('./components/is-online') |
12 |
| -const load = require('./components/load') |
13 |
| -const version = require('./components/version') |
14 |
| -const id = require('./components/id') |
15 |
| -const repo = require('./components/repo') |
16 |
| -const init = require('./components/init') |
17 |
| -const bootstrap = require('./components/bootstrap') |
18 |
| -const config = require('./components/config') |
19 |
| -const block = require('./components/block') |
20 |
| -const object = require('./components/object') |
21 |
| -const libp2p = require('./components/libp2p') |
22 |
| -const swarm = require('./components/swarm') |
23 |
| -const ping = require('./components/ping') |
24 |
| -const files = require('./components/files') |
25 |
| -const bitswap = require('./components/bitswap') |
26 |
| -const pubsub = require('./components/pubsub') |
| 10 | +const components = require('./components') |
27 | 11 |
|
28 |
| -exports = module.exports = IPFS |
| 12 | +class IPFS { |
| 13 | + constructor (configOpts) { |
| 14 | + let repoInstance |
| 15 | + if (typeof configOpts.repo === 'string' || configOpts.repo === undefined) { |
| 16 | + repoInstance = defaultRepo(configOpts.repo) |
| 17 | + } else { |
| 18 | + repoInstance = configOpts.repo |
| 19 | + } |
| 20 | + delete configOpts.repo |
29 | 21 |
|
30 |
| -function IPFS (repoInstance) { |
31 |
| - if (!(this instanceof IPFS)) { |
32 |
| - throw new Error('Must be instantiated with new') |
33 |
| - } |
34 |
| - |
35 |
| - if (typeof repoInstance === 'string' || |
36 |
| - repoInstance === undefined) { |
37 |
| - repoInstance = defaultRepo(repoInstance) |
38 |
| - } |
| 22 | + configOpts.EXPERIMENTAL = configOpts.EXPERIMENTAL || {} |
39 | 23 |
|
40 |
| - // IPFS Core Internals |
41 |
| - this._repo = repoInstance |
42 |
| - this._peerInfoBook = new PeerBook() |
43 |
| - this._peerInfo = null |
44 |
| - this._libp2pNode = null |
45 |
| - this._bitswap = null |
46 |
| - this._blockService = new BlockService(this._repo) |
47 |
| - this._ipldResolver = new IPLDResolver(this._blockService) |
48 |
| - this._pubsub = null |
| 24 | + // IPFS utils |
| 25 | + this.types = {} |
| 26 | + this.log = debug('jsipfs') |
| 27 | + this.log.err = debug('jsipfs:err') |
49 | 28 |
|
50 |
| - // IPFS Core exposed components |
| 29 | + // IPFS Core Internals |
| 30 | + this._configOpts = configOpts |
| 31 | + this._repo = repoInstance |
| 32 | + this._peerInfoBook = new PeerBook() |
| 33 | + this._peerInfo = undefined |
| 34 | + this._libp2pNode = undefined |
| 35 | + this._bitswap = undefined |
| 36 | + this._blockService = new BlockService(this._repo) |
| 37 | + this._ipldResolver = new IPLDResolver(this._blockService) |
| 38 | + this._pubsub = undefined |
51 | 39 |
|
52 |
| - // for booting up a node |
53 |
| - this.goOnline = goOnline(this) |
54 |
| - this.goOffline = goOffline(this) |
55 |
| - this.isOnline = isOnline(this) |
56 |
| - this.load = load(this) |
57 |
| - this.init = init(this) |
| 40 | + // IPFS Core exposed components |
| 41 | + // - for booting up a node |
| 42 | + this.goOnline = components.goOnline(this) |
| 43 | + this.goOffline = components.goOffline(this) |
| 44 | + this.isOnline = components.isOnline(this) |
| 45 | + this.load = components.load(this) |
| 46 | + this.init = components.init(this) |
| 47 | + // - interface-ipfs-core defined API |
| 48 | + this.version = components.version(this) |
| 49 | + this.id = components.id(this) |
| 50 | + this.repo = components.repo(this) |
| 51 | + this.bootstrap = components.bootstrap(this) |
| 52 | + this.config = components.config(this) |
| 53 | + this.block = components.block(this) |
| 54 | + this.object = components.object(this) |
| 55 | + this.libp2p = components.libp2p(this) |
| 56 | + this.swarm = components.swarm(this) |
| 57 | + this.files = components.files(this) |
| 58 | + this.bitswap = components.bitswap(this) |
| 59 | + this.ping = components.ping(this) |
| 60 | + this.pubsub = components.pubsub(this) |
58 | 61 |
|
59 |
| - // interface-ipfs-core defined API |
60 |
| - this.version = version(this) |
61 |
| - this.id = id(this) |
62 |
| - this.repo = repo(this) |
63 |
| - this.bootstrap = bootstrap(this) |
64 |
| - this.config = config(this) |
65 |
| - this.block = block(this) |
66 |
| - this.object = object(this) |
67 |
| - this.libp2p = libp2p(this) |
68 |
| - this.swarm = swarm(this) |
69 |
| - this.files = files(this) |
70 |
| - this.bitswap = bitswap(this) |
71 |
| - this.ping = ping(this) |
72 |
| - this.pubsub = pubsub(this) |
| 62 | + if (configOpts.EXPERIMENTAL.pubsub) { |
| 63 | + this.log('EXPERIMENTAL pubsub is enabled') |
| 64 | + } |
| 65 | + } |
73 | 66 | }
|
| 67 | + |
| 68 | +module.exports = IPFS |
0 commit comments