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

Commit 51febd3

Browse files
author
Alan Shaw
committed
fix: review feedback
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent 9d8233e commit 51febd3

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"ipfs-bitswap": "~0.25.1",
9797
"ipfs-block": "~0.8.1",
9898
"ipfs-block-service": "~0.15.2",
99-
"ipfs-http-client": "^33.0.1",
99+
"ipfs-http-client": "^33.1.1",
100100
"ipfs-http-response": "~0.3.1",
101101
"ipfs-mfs": "~0.12.0",
102102
"ipfs-multipart": "~0.1.1",
@@ -150,7 +150,6 @@
150150
"multihashes": "~0.4.14",
151151
"multihashing-async": "~0.6.0",
152152
"node-fetch": "^2.3.0",
153-
"p-event": "^4.1.0",
154153
"peer-book": "~0.9.0",
155154
"peer-id": "~0.12.3",
156155
"peer-info": "~0.15.0",
@@ -198,6 +197,7 @@
198197
"ipfsd-ctl": "^0.43.0",
199198
"libp2p-websocket-star": "~0.10.2",
200199
"ncp": "^2.0.0",
200+
"p-event": "^4.1.0",
201201
"qs": "^6.5.2",
202202
"rimraf": "^2.6.2",
203203
"sinon": "^7.4.0",

src/core/components/files-regular/add-pull-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function pinFile (file, self, opts, cb) {
116116
const isRootDir = !file.path.includes('/')
117117
const shouldPin = pin && isRootDir && !opts.onlyHash && !opts.hashAlg
118118
if (shouldPin) {
119-
// Note: we take a GC lock wherever we call addPullStream(), so tell
119+
// Note: addPullStream() has already taken a GC lock, so tell
120120
// pin.add() not to take a (second) GC lock
121121
return self.pin.add(file.hash, { preload: false, lock: false }, err => cb(err, file))
122122
} else {

src/core/components/pin/gc.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ const CID = require('cids')
55
const base32 = require('base32.js')
66
const parallel = require('async/parallel')
77
const mapLimit = require('async/mapLimit')
8-
const { Key } = require('interface-datastore')
98
const expErr = require('explain-error')
109
const { cidToString } = require('../../../utils/cid')
1110
const log = require('debug')('ipfs:gc')
11+
// TODO: Use exported key from root when upgraded to ipfs-mfs@>=13
12+
// https://github.com/ipfs/js-ipfs-mfs/pull/58
13+
const { MFS_ROOT_KEY } = require('ipfs-mfs/src/core/utils/constants')
1214

1315
// Limit on the number of parallel block remove operations
1416
const BLOCK_RM_CONCURRENCY = 256
15-
const MFS_ROOT_DS_KEY = new Key('/local/filesroot')
1617

1718
// Perform mark and sweep garbage collection
1819
module.exports = function gc (self) {
@@ -72,7 +73,7 @@ function createMarkedSet (ipfs, callback) {
7273
}),
7374

7475
// The MFS root and all its descendants
75-
(cb) => ipfs._repo.root.get(MFS_ROOT_DS_KEY, (err, mh) => {
76+
(cb) => ipfs._repo.root.get(MFS_ROOT_KEY, (err, mh) => {
7677
if (err) {
7778
if (err.code === 'ERR_NOT_FOUND') {
7879
log(`No blocks in MFS`)
@@ -147,6 +148,8 @@ function deleteUnmarkedBlocks (ipfs, markedSet, blockKeys, callback) {
147148
})
148149
}
149150

151+
// TODO: Use exported utility when upgrade to ipfs-repo@>=0.27.1
152+
// https://github.com/ipfs/js-ipfs-repo/pull/206
150153
function dsKeyToCid (key) {
151154
// Block key is of the form /<base32 encoded string>
152155
const decoder = new base32.Decoder()

src/core/components/pin/pin-manager.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ const { Key } = require('interface-datastore')
1313
const errCode = require('err-code')
1414
const multicodec = require('multicodec')
1515
const debug = require('debug')
16+
const { cidToString } = require('../../../utils/cid')
1617

1718
const createPinSet = require('./pin-set')
1819

1920
// arbitrary limit to the number of concurrent dag operations
2021
const concurrencyLimit = 300
2122
const PIN_DS_KEY = new Key('/local/pins')
2223

23-
function toB58String (hash) {
24-
return new CID(hash).toBaseEncodedString()
25-
}
26-
2724
function invalidPinTypeErr (type) {
2825
const errMsg = `Invalid type '${type}', must be one of {direct, indirect, recursive, all}`
2926
return errCode(new Error(errMsg), 'ERR_INVALID_PIN_TYPE')
@@ -192,8 +189,8 @@ class PinManager {
192189
if (err) { return callback(err) }
193190
const [rKeys, dKeys] = keys
194191

195-
this.directPins = new Set(dKeys.map(toB58String))
196-
this.recursivePins = new Set(rKeys.map(toB58String))
192+
this.directPins = new Set(dKeys.map(k => cidToString(k)))
193+
this.recursivePins = new Set(rKeys.map(k => cidToString(k)))
197194

198195
this.log('Loaded pins from the datastore')
199196
return callback(null)
@@ -202,7 +199,7 @@ class PinManager {
202199
}
203200

204201
isPinnedWithType (multihash, type, callback) {
205-
const key = toB58String(multihash)
202+
const key = cidToString(multihash)
206203
const { recursive, direct, all } = PinTypes
207204

208205
// recursive

src/utils/mutex.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const assert = require('assert')
44
const mortice = require('mortice')
5-
const setImmediate = require('async/setImmediate')
65
const noop = () => {}
76

87
// Wrap mortice to present a callback interface
@@ -33,8 +32,8 @@ class Mutex {
3332
* @returns {void}
3433
*/
3534
_lock (type, lockedFn, cb = noop) {
36-
assert(typeof lockedFn === 'function', `first argument to CBLock.${type}() must be a function`)
37-
assert(typeof cb === 'function', `second argument to CBLock.${type}() must be a callback function`)
35+
assert(typeof lockedFn === 'function', `first argument to Mutex.${type}() must be a function`)
36+
assert(typeof cb === 'function', `second argument to Mutex.${type}() must be a callback function`)
3837

3938
const lockId = this.lockId++
4039
this.log(`[${lockId}] ${type} requested`)
@@ -55,10 +54,7 @@ class Mutex {
5554
const lock = this.mutex[type](locked)
5655

5756
// When the locked piece of code is complete, the Promise resolves
58-
return lock.then(
59-
(res) => setImmediate(() => cb(null, res)),
60-
(err) => setImmediate(() => cb(err))
61-
)
57+
return lock.then(res => cb(null, res), cb)
6258
}
6359
}
6460

0 commit comments

Comments
 (0)