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

Commit 99d7410

Browse files
committed
chore: convert internals to promises
1 parent 74ef556 commit 99d7410

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2052
-2377
lines changed

.aegir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const preloadNode = MockPreloadNode.createNode()
1010
const echoServer = EchoServer.createServer()
1111

1212
module.exports = {
13-
bundlesize: { maxSize: '696kB' },
13+
bundlesize: { maxSize: '683kB' },
1414
webpack: {
1515
resolve: {
1616
mainFields: ['browser', 'main'],

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ env:
2828
# https://travis-ci.community/t/timeout-after-build-finished-and-succeeded/1336
2929
- YARN_GPG=no
3030

31+
addons:
32+
apt:
33+
packages:
34+
# Fixes error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory
35+
# https://github.com/electron/electron/issues/1518
36+
- libgconf-2-4
37+
3138
script: npx nyc -s npx aegir test -t node --timeout 10000 --bail
3239
after_success:
3340
- npx nyc report --reporter=text-lcov > coverage.lcov && npx codecov

examples/traverse-ipld-graphs/create-node.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const IPFS = require('../../src/core')
44
// In your project, replace by the following line and install IPFS as a dep
55
// const IPFS = require('ipfs')
66

7-
function createNode (options = {}) {
7+
function createNode (options) {
8+
options = options || {}
89
options.path = options.path || '/tmp/ipfs' + Math.random()
910
return IPFS.create({ repo: options.path })
1011
}

examples/traverse-ipld-graphs/eth.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const multihashing = require('multihashing-async')
66
const Block = require('ipfs-block')
77
const CID = require('cids')
88
const fs = require('fs').promises
9-
const { promisify } = require('util')
109

1110
async function main () {
1211
const ipfs = await createNode()
@@ -20,7 +19,7 @@ async function main () {
2019

2120
for (const ethBlockPath of ethBlocks) {
2221
const data = await fs.readFile(ethBlockPath)
23-
const multihash = await promisify(multihashing)(data, 'keccak-256')
22+
const multihash = await multihashing(data, 'keccak-256')
2423

2524
const cid = new CID(1, 'eth-block', multihash)
2625
// console.log(cid.toBaseEncodedString())

examples/traverse-ipld-graphs/git.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const multihashing = require('multihashing-async')
66
const Block = require('ipfs-block')
77
const CID = require('cids')
88
const fs = require('fs').promises
9-
const { promisify } = require('util')
109

1110
async function main () {
1211
const ipfs = await createNode()
@@ -28,7 +27,7 @@ async function main () {
2827

2928
await Promise.all(gitObjects.map(async gitObjectsPath => {
3029
const data = await fs.readFile(gitObjectsPath)
31-
const multihash = await promisify(multihashing)(data, 'sha1')
30+
const multihash = await multihashing(data, 'sha1')
3231

3332
const cid = new CID(1, 'git-raw', multihash)
3433
console.log(cid.toString())

package.json

+22-18
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@hapi/ammo": "^3.1.1",
6464
"@hapi/boom": "^7.4.3",
6565
"@hapi/hapi": "^18.3.2",
66-
"@hapi/joi": "^15.0.1",
66+
"@hapi/joi": "^15.0.0",
6767
"array-shuffle": "^1.0.1",
6868
"async": "^2.6.1",
6969
"async-iterator-all": "^1.0.0",
@@ -76,11 +76,13 @@
7676
"bs58": "^4.0.1",
7777
"buffer-peek-stream": "^1.0.1",
7878
"byteman": "^1.3.5",
79+
"callbackify": "^1.1.0",
7980
"cid-tool": "~0.3.0",
8081
"cids": "~0.7.1",
8182
"class-is": "^1.1.0",
83+
"dag-cbor-links": "^1.3.0",
8284
"datastore-core": "~0.7.0",
83-
"datastore-pubsub": "~0.1.1",
85+
"datastore-pubsub": "^0.2.1",
8486
"debug": "^4.1.0",
8587
"dlv": "^1.1.3",
8688
"err-code": "^2.0.0",
@@ -94,14 +96,14 @@
9496
"hashlru": "^2.3.0",
9597
"human-to-milliseconds": "^2.0.0",
9698
"interface-datastore": "~0.7.0",
97-
"ipfs-bitswap": "~0.25.1",
99+
"ipfs-bitswap": "^0.26.0",
98100
"ipfs-block": "~0.8.1",
99101
"ipfs-block-service": "~0.16.0",
100-
"ipfs-http-client": "^37.0.2",
102+
"ipfs-http-client": "^38.0.0",
101103
"ipfs-http-response": "~0.3.1",
102104
"ipfs-mfs": "^0.13.0",
103105
"ipfs-multipart": "^0.2.0",
104-
"ipfs-repo": "~0.27.0",
106+
"ipfs-repo": "^0.28.0",
105107
"ipfs-unixfs": "~0.1.16",
106108
"ipfs-unixfs-exporter": "^0.38.0",
107109
"ipfs-unixfs-importer": "^0.40.0",
@@ -114,7 +116,7 @@
114116
"ipld-git": "~0.5.0",
115117
"ipld-raw": "^4.0.0",
116118
"ipld-zcash": "~0.3.0",
117-
"ipns": "~0.6.0",
119+
"ipns": "^0.6.1",
118120
"is-domain-name": "^1.0.1",
119121
"is-ipfs": "~0.6.1",
120122
"is-pull-stream": "~0.0.0",
@@ -124,41 +126,43 @@
124126
"it-to-stream": "^0.1.1",
125127
"just-safe-set": "^2.1.0",
126128
"kind-of": "^6.0.2",
127-
"ky": "~0.14.0",
129+
"ky": "^0.14.0",
128130
"ky-universal": "~0.3.0",
129-
"libp2p": "~0.26.1",
130-
"libp2p-bootstrap": "~0.10.2",
131-
"libp2p-crypto": "~0.17.0",
131+
"libp2p": "^0.26.2",
132+
"libp2p-bootstrap": "~0.9.3",
133+
"libp2p-crypto": "^0.16.2",
132134
"libp2p-delegated-content-routing": "^0.3.1",
133135
"libp2p-delegated-peer-routing": "^0.3.1",
134136
"libp2p-floodsub": "^0.18.0",
135137
"libp2p-gossipsub": "~0.0.5",
136138
"libp2p-kad-dht": "~0.16.0",
137-
"libp2p-keychain": "~0.5.0",
139+
"libp2p-keychain": "^0.5.1",
138140
"libp2p-mdns": "~0.12.0",
139141
"libp2p-record": "~0.7.0",
140142
"libp2p-secio": "~0.11.0",
141-
"libp2p-tcp": "~0.13.1",
143+
"libp2p-tcp": "^0.13.0",
142144
"libp2p-webrtc-star": "~0.16.0",
143145
"libp2p-websocket-star-multi": "~0.4.3",
144146
"libp2p-websockets": "~0.12.3",
145147
"lodash": "^4.17.15",
148+
"lodash.flatten": "^4.4.0",
146149
"mafmt": "^6.0.10",
147150
"merge-options": "^1.0.1",
148151
"mime-types": "^2.1.21",
149152
"mkdirp": "~0.5.1",
150153
"mortice": "^2.0.0",
151-
"multiaddr": "^6.1.0",
154+
"multiaddr": "^6.1.1",
152155
"multiaddr-to-uri": "^5.0.0",
153156
"multibase": "~0.6.0",
154157
"multicodec": "~0.5.5",
155158
"multihashes": "~0.4.14",
156-
"multihashing-async": "~0.7.0",
159+
"multihashing-async": "^0.8.0",
157160
"node-fetch": "^2.3.0",
161+
"p-iteration": "^1.1.8",
158162
"p-queue": "^6.1.0",
159-
"peer-book": "~0.9.0",
160-
"peer-id": "~0.13.2",
161-
"peer-info": "~0.16.0",
163+
"peer-book": "^0.9.1",
164+
"peer-id": "^0.12.2",
165+
"peer-info": "~0.15.1",
162166
"progress": "^2.0.1",
163167
"promise-nodeify": "^3.0.1",
164168
"promisify-es6": "^1.0.3",
@@ -200,7 +204,7 @@
200204
"execa": "^2.0.4",
201205
"form-data": "^2.5.1",
202206
"hat": "0.0.3",
203-
"interface-ipfs-core": "~0.114.0",
207+
"interface-ipfs-core": "^0.115.0",
204208
"ipfs-interop": "~0.1.0",
205209
"ipfsd-ctl": "^0.47.2",
206210
"libp2p-websocket-star": "~0.10.2",

src/cli/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ exports.getIPFS = (argv, callback) => {
5555

5656
const cleanup = callbackify(async () => {
5757
if (node && node._repo && !node._repo.closed) {
58-
return node._repo.close()
58+
await node._repo.close()
5959
}
6060
})
6161

src/core/boot.js

+44-58
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,72 @@
11
'use strict'
22

3-
const waterfall = require('async/waterfall')
43
const RepoErrors = require('ipfs-repo').errors
54

65
// Boot an IPFS node depending on the options set
7-
module.exports = (self) => {
6+
module.exports = async (self) => {
87
self.log('booting')
98
const options = self._options
109
const doInit = options.init
1110
const doStart = options.start
1211

13-
// Do the actual boot sequence
14-
waterfall([
15-
// Checks if a repo exists, and if so opens it
16-
// Will return callback with a bool indicating the existence
17-
// of the repo
18-
// TODO vmx 2019-08-05: THIS WON'T WORK IN THE BROWSER due to transpiling, this needs a proper fix. This is just a hack to keep things moving
19-
async () => {
20-
// nothing to do
21-
if (!self._repo.closed) {
22-
return true
23-
}
12+
// Checks if a repo exists, and if so opens it
13+
// Will return callback with a bool indicating the existence
14+
// of the repo
15+
async function repoOpened () {
16+
// nothing to do
17+
if (!self._repo.closed) {
18+
return true
19+
}
2420

25-
try {
26-
const res = await self._repo.open()
27-
} catch (err) {
28-
if (isRepoUninitializedError(err)) return false
29-
if (err) throw err
21+
try {
22+
await self._repo.open()
23+
} catch (err) {
24+
if (isRepoUninitializedError(err)) {
25+
return false
3026
}
3127

32-
return true
33-
},
34-
(repoOpened, cb) => {
35-
// Init with existing initialized, opened, repo
36-
if (repoOpened) {
37-
return self.init({ repo: self._repo }, (err) => {
38-
if (err) return cb(Object.assign(err, { emitted: true }))
39-
cb()
40-
})
28+
if (err) {
29+
throw err
4130
}
31+
}
4232

43-
if (doInit) {
44-
const initOptions = Object.assign(
45-
{ bits: 2048, pass: self._options.pass },
46-
typeof options.init === 'object' ? options.init : {}
47-
)
48-
return self.init(initOptions, (err) => {
49-
if (err) return cb(Object.assign(err, { emitted: true }))
50-
cb()
51-
})
52-
}
33+
return true
34+
}
5335

54-
cb()
55-
},
56-
(cb) => {
57-
// No problem, we don't have to start the node
58-
if (!doStart) {
59-
return cb()
36+
// Do the actual boot sequence
37+
try {
38+
// Init with existing initialized, opened, repo
39+
if (await repoOpened()) {
40+
try {
41+
await self.init({ repo: self._repo })
42+
} catch (err) {
43+
throw Object.assign(err, { emitted: true })
44+
}
45+
} else if (doInit) {
46+
const defaultInitOptions = {
47+
bits: 2048,
48+
pass: self._options.pass
6049
}
6150

62-
self.start((err) => {
63-
if (err) return cb(Object.assign(err, { emitted: true }))
64-
cb()
65-
})
51+
const initOptions = Object.assign(defaultInitOptions, typeof options.init === 'object' ? options.init : {})
52+
53+
await self.init(initOptions)
6654
}
67-
], (err) => {
68-
if (err) {
69-
if (!err.emitted) {
70-
self.emit('error', err)
71-
}
72-
return
55+
56+
if (doStart) {
57+
await self.start()
7358
}
59+
7460
self.log('booted')
7561
self.emit('ready')
76-
})
62+
} catch (err) {
63+
if (!err.emitted) {
64+
self.emit('error', err)
65+
}
66+
}
7767
}
7868

7969
function isRepoUninitializedError (err) {
80-
if (!err) {
81-
return false
82-
}
83-
8470
// If the error is that no repo exists,
8571
// which happens when the version file is not found
8672
// we just want to signal that no repo exist, not

0 commit comments

Comments
 (0)