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

Commit 642deaf

Browse files
committed
chore: convert internals to promises
Tests aren't working yet
1 parent 838acf3 commit 642deaf

Some content is hidden

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

106 files changed

+1643
-2120
lines changed

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

+20-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",
@@ -94,18 +94,18 @@
9494
"hashlru": "^2.3.0",
9595
"human-to-milliseconds": "^2.0.0",
9696
"interface-datastore": "~0.7.0",
97-
"ipfs-bitswap": "~0.25.1",
97+
"ipfs-bitswap": "ipfs/js-ipfs-bitswap#feat/async-await",
9898
"ipfs-block": "~0.8.1",
9999
"ipfs-block-service": "~0.16.0",
100-
"ipfs-http-client": "^35.1.0",
100+
"ipfs-http-client": "ipfs/js-ipfs-http-client#update-ipld-dag-pb",
101101
"ipfs-http-response": "~0.3.1",
102102
"ipfs-mfs": "^0.13.0",
103103
"ipfs-multipart": "^0.2.0",
104-
"ipfs-repo": "~0.27.0",
104+
"ipfs-repo": "^0.28.0",
105105
"ipfs-unixfs": "~0.1.16",
106106
"ipfs-unixfs-exporter": "^0.38.0",
107107
"ipfs-unixfs-importer": "^0.40.0",
108-
"ipfs-utils": "~0.2.0",
108+
"ipfs-utils": "^0.3.0",
109109
"ipld": "~0.25.0",
110110
"ipld-bitcoin": "~0.3.0",
111111
"ipld-dag-cbor": "~0.15.0",
@@ -114,7 +114,7 @@
114114
"ipld-git": "~0.5.0",
115115
"ipld-raw": "^4.0.0",
116116
"ipld-zcash": "~0.3.0",
117-
"ipns": "~0.6.0",
117+
"ipns": "ipfs/js-ipns#downgrade-peer-id",
118118
"is-domain-name": "^1.0.1",
119119
"is-ipfs": "~0.6.1",
120120
"is-pull-stream": "~0.0.0",
@@ -124,41 +124,43 @@
124124
"it-to-stream": "^0.1.1",
125125
"just-safe-set": "^2.1.0",
126126
"kind-of": "^6.0.2",
127-
"ky": "~0.13.0",
127+
"ky": "^0.14.0",
128128
"ky-universal": "~0.3.0",
129129
"libp2p": "~0.26.1",
130-
"libp2p-bootstrap": "~0.10.2",
131-
"libp2p-crypto": "~0.17.0",
130+
"libp2p-bootstrap": "~0.9.3",
131+
"libp2p-crypto": "~0.16.1",
132132
"libp2p-delegated-content-routing": "^0.3.1",
133133
"libp2p-delegated-peer-routing": "^0.3.1",
134134
"libp2p-floodsub": "^0.18.0",
135135
"libp2p-gossipsub": "~0.0.5",
136136
"libp2p-kad-dht": "~0.16.0",
137-
"libp2p-keychain": "~0.5.0",
137+
"libp2p-keychain": "libp2p/js-libp2p-keychain#downgrade-peer-id",
138138
"libp2p-mdns": "~0.12.0",
139139
"libp2p-record": "~0.7.0",
140140
"libp2p-secio": "~0.11.0",
141-
"libp2p-tcp": "~0.13.1",
141+
"libp2p-tcp": "^0.13.0",
142142
"libp2p-webrtc-star": "~0.16.0",
143143
"libp2p-websocket-star-multi": "~0.4.3",
144144
"libp2p-websockets": "~0.12.3",
145145
"lodash": "^4.17.15",
146+
"lodash.flatten": "^4.4.0",
146147
"mafmt": "^6.0.10",
147148
"merge-options": "^1.0.1",
148149
"mime-types": "^2.1.21",
149150
"mkdirp": "~0.5.1",
150151
"mortice": "^2.0.0",
151-
"multiaddr": "^6.1.0",
152+
"multiaddr": "^6.1.1",
152153
"multiaddr-to-uri": "^5.0.0",
153154
"multibase": "~0.6.0",
154155
"multicodec": "~0.5.5",
155156
"multihashes": "~0.4.14",
156-
"multihashing-async": "~0.7.0",
157+
"multihashing-async": "^0.8.0",
157158
"node-fetch": "^2.3.0",
159+
"p-iteration": "^1.1.8",
158160
"p-queue": "^6.1.0",
159-
"peer-book": "~0.9.0",
160-
"peer-id": "~0.13.2",
161-
"peer-info": "~0.16.0",
161+
"peer-book": "^0.9.1",
162+
"peer-id": "^0.12.2",
163+
"peer-info": "~0.15.1",
162164
"progress": "^2.0.1",
163165
"promise-nodeify": "^3.0.1",
164166
"promisify-es6": "^1.0.3",
@@ -200,9 +202,9 @@
200202
"execa": "^2.0.4",
201203
"form-data": "^2.5.1",
202204
"hat": "0.0.3",
203-
"interface-ipfs-core": "^0.113.0",
205+
"interface-ipfs-core": "^0.114.0",
204206
"ipfs-interop": "~0.1.0",
205-
"ipfsd-ctl": "~0.46.0",
207+
"ipfsd-ctl": "^0.47.1",
206208
"libp2p-websocket-star": "~0.10.2",
207209
"ncp": "^2.0.0",
208210
"p-event": "^4.1.0",

src/cli/commands/daemon.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ module.exports = {
8080
print('Daemon is ready')
8181

8282
const cleanup = async () => {
83-
print(`Received interrupt signal, shutting down...`)
83+
print('Received interrupt signal, shutting down...')
8484
await daemon.stop()
8585
process.exit(0)
8686
}

src/cli/commands/file/ls.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
argv.resolve((async () => {
1212
const path = argv.key
1313
// `ipfs file ls` is deprecated. See https://ipfs.io/docs/commands/#ipfs-file-ls
14-
argv.print(`This functionality is deprecated, and will be removed in future versions. If possible, please use 'ipfs ls' instead.`)
14+
argv.print('This functionality is deprecated, and will be removed in future versions. If possible, please use \'ipfs ls\' instead.')
1515

1616
const ipfs = await argv.getIpfs()
1717
let links = await ipfs.ls(path)

src/cli/commands/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = {
5757
})
5858
} catch (err) {
5959
if (err.code === 'EACCES') {
60-
err.message = `EACCES: permission denied, stat $IPFS_PATH/version`
60+
err.message = 'EACCES: permission denied, stat $IPFS_PATH/version'
6161
}
6262
throw err
6363
}

src/cli/commands/version.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ module.exports = {
1717
commit: {
1818
type: 'boolean',
1919
default: false,
20-
describe: `Include the version's commit hash`
20+
describe: 'Include the version\'s commit hash'
2121
},
2222
repo: {
2323
type: 'boolean',
2424
default: false,
25-
describe: `Print only the repo's version number`
25+
describe: 'Print only the repo\'s version number'
2626
},
2727
all: {
2828
type: 'boolean',

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

+45-57
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,74 @@
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+
}
32+
33+
return true
34+
}
4235

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-
})
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 })
5244
}
45+
}
5346

54-
cb()
55-
},
56-
(cb) => {
57-
// No problem, we don't have to start the node
58-
if (!doStart) {
59-
return cb()
47+
if (doInit) {
48+
const defaultInitOptions = {
49+
bits: 2048,
50+
pass: self._options.pass
6051
}
6152

62-
self.start((err) => {
63-
if (err) return cb(Object.assign(err, { emitted: true }))
64-
cb()
65-
})
53+
const initOptions = Object.assign(defaultInitOptions, typeof options.init === 'object' ? options.init : {})
54+
55+
await self.init(initOptions)
6656
}
67-
], (err) => {
68-
if (err) {
69-
if (!err.emitted) {
70-
self.emit('error', err)
71-
}
72-
return
57+
58+
if (doStart) {
59+
await self.start()
7360
}
61+
7462
self.log('booted')
7563
self.emit('ready')
76-
})
64+
} catch (err) {
65+
if (!err.emitted) {
66+
self.emit('error', err)
67+
}
68+
}
7769
}
7870

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

0 commit comments

Comments
 (0)