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

Commit 40268fc

Browse files
authored
Merge branch 'master' into feat/ping
2 parents 49aaccc + 7362652 commit 40268fc

File tree

7 files changed

+85
-67
lines changed

7 files changed

+85
-67
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ You can check the development status at the [Waffle Board](https://waffle.io/ipf
4343
**Please read this:** DHT (automatic content discovery) and Circuit Relay (pierce through NATs and dial between any node in the network) are two fundamental pieces that are not finalized yet. There are multiple applications that can be built without these two services but nevertheless they are fundamental to get that magic IPFS experience. If you want to track progress or contribute, please follow:
4444

4545
- DHT: https://github.com/ipfs/js-ipfs/pull/856
46-
- Relay: https://github.com/ipfs/js-ipfs/pull/1063
46+
- Relay: https://github.com/ipfs/js-ipfs/pull/1063
4747

4848
[**`Weekly Dev Calls`**](https://github.com/ipfs/js-ipfs/issues/1179)
4949

@@ -413,8 +413,8 @@ The core API is grouped into several areas:
413413
- [dht (not implemented, yet!)](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/)
414414
415415
- [pubsub](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md)
416-
- [`ipfs.pubsub.subscribe(topic, options, handler, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubsubscribe)
417-
- [`ipfs.pubsub.unsubscribe(topic, handler)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubunsubscribe)
416+
- [`ipfs.pubsub.subscribe(topic, handler, options, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubsubscribe)
417+
- [`ipfs.pubsub.unsubscribe(topic, handler, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubunsubscribe)
418418
- [`ipfs.pubsub.publish(topic, data, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubpublish)
419419
- [`ipfs.pubsub.ls(topic, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubls)
420420
- [`ipfs.pubsub.peers(topic, callback)`](https://github.com/ipfs/interface-ipfs-core/tree/master/SPEC/PUBSUB.md#pubsubpeers)

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373
"expose-loader": "^0.7.5",
7474
"form-data": "^2.3.2",
7575
"hat": "0.0.3",
76-
"interface-ipfs-core": "~0.64.3",
77-
"ipfsd-ctl": "~0.33.2",
76+
"interface-ipfs-core": "~0.65.5",
77+
"ipfsd-ctl": "~0.34.0",
7878
"lodash": "^4.17.10",
7979
"mocha": "^5.1.1",
8080
"ncp": "^2.0.0",
@@ -105,30 +105,30 @@
105105
"hapi-set-header": "^1.0.2",
106106
"hoek": "^5.0.3",
107107
"human-to-milliseconds": "^1.0.0",
108-
"ipfs-api": "^20.2.1",
108+
"ipfs-api": "^21.0.0",
109109
"ipfs-bitswap": "~0.20.0",
110110
"ipfs-block": "~0.7.1",
111111
"ipfs-block-service": "~0.14.0",
112112
"ipfs-multipart": "~0.1.0",
113113
"ipfs-repo": "0.20.0",
114114
"ipfs-unixfs": "~0.1.14",
115115
"ipfs-unixfs-engine": "~0.29.0",
116-
"ipld": "^0.17.0",
117-
"ipld-dag-cbor": "^0.12.0",
116+
"ipld": "~0.17.0",
117+
"ipld-dag-cbor": "~0.12.0",
118118
"ipld-dag-pb": "~0.14.4",
119-
"is-ipfs": "^0.3.2",
119+
"is-ipfs": "~0.3.2",
120120
"is-pull-stream": "0.0.0",
121121
"is-stream": "^1.1.0",
122122
"joi": "^13.2.0",
123123
"joi-browser": "^13.0.1",
124124
"joi-multiaddr": "^2.0.0",
125-
"libp2p": "^0.20.4",
126-
"libp2p-circuit": "^0.2.0",
125+
"libp2p": "~0.20.4",
126+
"libp2p-circuit": "~0.2.0",
127127
"libp2p-floodsub": "~0.15.0",
128128
"libp2p-kad-dht": "~0.10.0",
129129
"libp2p-keychain": "~0.3.1",
130130
"libp2p-mdns": "~0.11.0",
131-
"libp2p-mplex": "^0.7.0",
131+
"libp2p-mplex": "~0.7.0",
132132
"libp2p-railing": "~0.8.1",
133133
"libp2p-secio": "~0.10.0",
134134
"libp2p-tcp": "~0.12.0",
@@ -144,7 +144,7 @@
144144
"mime-types": "^2.1.18",
145145
"mkdirp": "~0.5.1",
146146
"multiaddr": "^5.0.0",
147-
"multibase": "^0.4.0",
147+
"multibase": "~0.4.0",
148148
"multihashes": "~0.4.13",
149149
"once": "^1.4.0",
150150
"path-exists": "^3.0.0",

src/cli/bin.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
const yargs = require('yargs')
66
const updateNotifier = require('update-notifier')
77
const readPkgUp = require('read-pkg-up')
8+
const fs = require('fs')
9+
const path = require('path')
810
const utils = require('./utils')
911
const print = utils.print
1012

@@ -16,6 +18,10 @@ updateNotifier({
1618

1719
const args = process.argv.slice(2)
1820

21+
// Determine if the first argument is a sub-system command
22+
const commandNames = fs.readdirSync(path.join(__dirname, 'commands'))
23+
const isCommand = commandNames.includes(`${args[0]}.js`)
24+
1925
const cli = yargs
2026
.option('silent', {
2127
desc: 'Write no output',
@@ -28,7 +34,14 @@ const cli = yargs
2834
type: 'string',
2935
default: ''
3036
})
31-
.commandDir('commands')
37+
.commandDir('commands', {
38+
// Only include the commands for the sub-system we're using, or include all
39+
// if no sub-system command has been passed.
40+
include (path, filename) {
41+
if (!isCommand) return true
42+
return `${args[0]}.js` === filename
43+
}
44+
})
3245
.epilog(utils.ipfsPathHelp)
3346
.demandCommand(1)
3447
.fail((msg, err, yargs) => {
@@ -43,16 +56,19 @@ const cli = yargs
4356
yargs.showHelp()
4457
})
4558

46-
// NOTE: This creates an alias of
47-
// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`.
48-
// This will stay until https://github.com/ipfs/specs/issues/98 is resolved.
49-
const addCmd = require('./commands/files/add')
50-
const catCmd = require('./commands/files/cat')
51-
const getCmd = require('./commands/files/get')
52-
const aliases = [addCmd, catCmd, getCmd]
53-
aliases.forEach((alias) => {
54-
cli.command(alias.command, alias.describe, alias.builder, alias.handler)
55-
})
59+
// If not a sub-system command then load the top level aliases
60+
if (!isCommand) {
61+
// NOTE: This creates an alias of
62+
// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`.
63+
// This will stay until https://github.com/ipfs/specs/issues/98 is resolved.
64+
const addCmd = require('./commands/files/add')
65+
const catCmd = require('./commands/files/cat')
66+
const getCmd = require('./commands/files/get')
67+
const aliases = [addCmd, catCmd, getCmd]
68+
aliases.forEach((alias) => {
69+
cli.command(alias.command, alias.describe, alias.builder, alias.handler)
70+
})
71+
}
5672

5773
// Need to skip to avoid locking as these commands
5874
// don't require a daemon

src/cli/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
const fs = require('fs')
44
const os = require('os')
5-
const APIctl = require('ipfs-api')
65
const multiaddr = require('multiaddr')
7-
const IPFS = require('../core')
86
const path = require('path')
97
const debug = require('debug')
108
const log = debug('cli')
@@ -35,6 +33,8 @@ function getAPICtl (apiAddr) {
3533
const apiPath = path.join(exports.getRepoPath(), 'api')
3634
apiAddr = multiaddr(fs.readFileSync(apiPath).toString()).toString()
3735
}
36+
// Required inline to reduce startup time
37+
const APIctl = require('ipfs-api')
3838
return APIctl(apiAddr)
3939
}
4040

@@ -43,6 +43,8 @@ exports.getIPFS = (argv, callback) => {
4343
return callback(null, getAPICtl(argv.api), (cb) => cb())
4444
}
4545

46+
// Required inline to reduce startup time
47+
const IPFS = require('../core')
4648
const node = new IPFS({
4749
repo: exports.getRepoPath(),
4850
init: false,

src/core/components/pubsub.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const setImmediate = require('async/setImmediate')
45

56
module.exports = function pubsub (self) {
67
return {
7-
subscribe: (topic, options, handler, callback) => {
8+
subscribe: (topic, handler, options, callback) => {
89
if (typeof options === 'function') {
9-
callback = handler
10-
handler = options
10+
callback = options
1111
options = {}
1212
}
1313

@@ -20,13 +20,19 @@ module.exports = function pubsub (self) {
2020
resolve()
2121
})
2222
})
23-
} else {
24-
self._libp2pNode.pubsub.subscribe(topic, options, handler, callback)
2523
}
24+
25+
self._libp2pNode.pubsub.subscribe(topic, options, handler, callback)
2626
},
2727

28-
unsubscribe: (topic, handler) => {
28+
unsubscribe: (topic, handler, callback) => {
2929
self._libp2pNode.pubsub.unsubscribe(topic, handler)
30+
31+
if (!callback) {
32+
return Promise.resolve()
33+
}
34+
35+
setImmediate(() => callback())
3036
},
3137

3238
publish: promisify((topic, data, callback) => {

src/http/api/resources/pubsub.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ exports.subscribe = {
3333
res.write('{}\n')
3434

3535
const unsubscribe = () => {
36-
ipfs.pubsub.unsubscribe(topic, handler)
37-
res.end()
36+
ipfs.pubsub.unsubscribe(topic, handler, () => res.end())
3837
}
3938

4039
request.once('disconnect', unsubscribe)
4140
request.once('finish', unsubscribe)
4241

43-
ipfs.pubsub.subscribe(topic, {
44-
discover: discover
45-
}, handler, (err) => {
42+
ipfs.pubsub.subscribe(topic, handler, { discover: discover }, (err) => {
4643
if (err) {
4744
return reply(err)
4845
}

test/cli/daemon.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const expect = require('chai').expect
55
const clean = require('../utils/clean')
66
const ipfsCmd = require('../utils/ipfs-exec')
77
const isWindows = require('../utils/platforms').isWindows
8-
const pull = require('pull-stream')
9-
const toPull = require('stream-to-pull-stream')
108
const os = require('os')
119
const path = require('path')
1210
const hat = require('hat')
@@ -37,31 +35,20 @@ function testSignal (ipfs, sig) {
3735
}).then(() => {
3836
const proc = ipfs('daemon')
3937
return new Promise((resolve, reject) => {
40-
pull(
41-
toPull(proc.stdout),
42-
pull.collect((err, res) => {
43-
expect(err).to.not.exist()
44-
const data = res.toString()
45-
if (data.includes(`Daemon is ready`)) {
46-
if (proc.kill(sig)) {
47-
resolve()
48-
} else {
49-
reject(new Error(`Unable to ${sig} process`))
50-
}
38+
proc.stdout.on('data', (data) => {
39+
if (data.toString().includes(`Daemon is ready`)) {
40+
if (proc.kill(sig)) {
41+
resolve()
42+
} else {
43+
reject(new Error(`Unable to ${sig} process`))
5144
}
52-
})
53-
)
54-
55-
pull(
56-
toPull(proc.stderr),
57-
pull.collect((err, res) => {
58-
expect(err).to.not.exist()
59-
const data = res.toString()
60-
if (data.length > 0) {
61-
reject(new Error(data))
62-
}
63-
})
64-
)
45+
}
46+
})
47+
proc.stderr.on('data', (data) => {
48+
if (data.toString().length > 0) {
49+
reject(new Error(data))
50+
}
51+
})
6552
})
6653
})
6754
}
@@ -79,6 +66,8 @@ describe('daemon', () => {
7966

8067
skipOnWindows('do not crash if Addresses.Swarm is empty', function (done) {
8168
this.timeout(100 * 1000)
69+
// These tests are flaky, but retrying 3 times seems to make it work 99% of the time
70+
this.retries(3)
8271

8372
ipfs('init').then(() => {
8473
return ipfs('config', 'Addresses', JSON.stringify({
@@ -87,10 +76,18 @@ describe('daemon', () => {
8776
Gateway: '/ip4/127.0.0.1/tcp/0'
8877
}), '--json')
8978
}).then(() => {
90-
return ipfs('daemon')
91-
}).then((res) => {
92-
expect(res).to.have.string('Daemon is ready')
93-
done()
79+
const res = ipfs('daemon')
80+
const timeout = setTimeout(() => {
81+
done(new Error('Daemon did not get ready in time'))
82+
}, 1000 * 120)
83+
res.stdout.on('data', (data) => {
84+
const line = data.toString()
85+
if (line.includes('Daemon is ready')) {
86+
clearTimeout(timeout)
87+
res.kill()
88+
done()
89+
}
90+
})
9491
}).catch(err => done(err))
9592
})
9693

0 commit comments

Comments
 (0)