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

Commit 115948d

Browse files
authored
chore: upgrade repo to streaming api (#3041)
The latest interface-datastore contains added streaming apis which will let us use fewer resources when importing large datasets. This PR upgrades ipfs-repo and all datastore-* deps. Also bitswap.
1 parent 80c6fdf commit 115948d

File tree

9 files changed

+88
-14
lines changed

9 files changed

+88
-14
lines changed

examples/custom-ipfs-repo/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
},
1010
"license": "MIT",
1111
"dependencies": {
12-
"datastore-fs": "^0.9.1",
12+
"datastore-fs": "^1.1.0",
1313
"ipfs": "^0.44.0",
14-
"ipfs-repo": "^2.0.1",
14+
"ipfs-repo": "^3.0.0",
1515
"it-all": "^1.0.1"
1616
},
1717
"devDependencies": {

packages/interface-ipfs-core/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
],
3232
"license": "MIT",
3333
"dependencies": {
34+
"abort-controller": "^3.0.0",
3435
"buffer": "^5.6.0",
3536
"chai": "^4.2.0",
3637
"chai-as-promised": "^7.1.1",

packages/interface-ipfs-core/src/bitswap/utils.js

+22
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,26 @@ async function waitForWantlistKey (ipfs, key, opts = {}) {
2121
throw new Error(`Timed out waiting for ${key} in wantlist`)
2222
}
2323

24+
async function waitForWantlistKeyToBeRemoved (ipfs, key, opts = {}) {
25+
opts.timeout = opts.timeout || 10000
26+
opts.interval = opts.interval || 100
27+
28+
const end = Date.now() + opts.timeout
29+
30+
while (Date.now() < end) {
31+
const list = await ipfs.bitswap.wantlist(opts.peerId)
32+
33+
if (list.some(cid => cid.toString() === key)) {
34+
await delay(opts.interval)
35+
36+
continue
37+
}
38+
39+
return
40+
}
41+
42+
throw new Error(`Timed out waiting for ${key} to be removed from wantlist`)
43+
}
44+
2445
module.exports.waitForWantlistKey = waitForWantlistKey
46+
module.exports.waitForWantlistKeyToBeRemoved = waitForWantlistKeyToBeRemoved

packages/interface-ipfs-core/src/bitswap/wantlist.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
'use strict'
33

44
const { getDescribe, getIt, expect } = require('../utils/mocha')
5-
const { waitForWantlistKey } = require('./utils')
5+
const { waitForWantlistKey, waitForWantlistKeyToBeRemoved } = require('./utils')
66
const { isWebWorker } = require('ipfs-utils/src/env')
77
const testTimeout = require('../utils/test-timeout')
8+
const AbortController = require('abort-controller')
9+
const CID = require('cids')
10+
const delay = require('delay')
811

912
/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
1013
/**
@@ -57,5 +60,52 @@ module.exports = (common, options) => {
5760

5861
return expect(node.api.bitswap.stat()).to.eventually.be.rejected()
5962
})
63+
64+
it('should remove blocks from the wantlist when requests are cancelled', async () => {
65+
const controller = new AbortController()
66+
const cid = new CID('QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KaGa')
67+
68+
const getPromise = ipfsA.dag.get(cid, {
69+
signal: controller.signal
70+
})
71+
72+
await waitForWantlistKey(ipfsA, cid.toString())
73+
74+
controller.abort()
75+
76+
await expect(getPromise).to.eventually.be.rejectedWith(/aborted/)
77+
78+
await waitForWantlistKeyToBeRemoved(ipfsA, cid.toString())
79+
})
80+
81+
it('should keep blocks in the wantlist when only one request is cancelled', async () => {
82+
const controller = new AbortController()
83+
const otherController = new AbortController()
84+
const cid = new CID('QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1Kaaa')
85+
86+
const getPromise = ipfsA.dag.get(cid, {
87+
signal: controller.signal
88+
})
89+
const otherGetPromise = ipfsA.dag.get(cid, {
90+
signal: otherController.signal
91+
})
92+
93+
await waitForWantlistKey(ipfsA, cid.toString())
94+
95+
controller.abort()
96+
97+
await expect(getPromise).to.eventually.be.rejectedWith(/aborted/)
98+
99+
await delay(1000)
100+
101+
// cid should still be in the wantlist
102+
await waitForWantlistKey(ipfsA, cid.toString())
103+
104+
otherController.abort()
105+
106+
await expect(otherGetPromise).to.eventually.be.rejectedWith(/aborted/)
107+
108+
await waitForWantlistKeyToBeRemoved(ipfsA, cid.toString())
109+
})
60110
})
61111
}

packages/ipfs/.aegir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let sigServerB
1515
let ipfsdServer
1616

1717
module.exports = {
18-
bundlesize: { maxSize: '601kB' },
18+
bundlesize: { maxSize: '446kB' },
1919
karma: {
2020
files: [{
2121
pattern: 'node_modules/interface-ipfs-core/test/fixtures/**/*',

packages/ipfs/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
"cids": "^0.8.0",
8181
"class-is": "^1.1.0",
8282
"dag-cbor-links": "^1.3.3",
83-
"datastore-core": "^1.0.0",
84-
"datastore-level": "^1.0.0",
85-
"datastore-pubsub": "^0.3.1",
83+
"datastore-core": "^1.1.0",
84+
"datastore-level": "^1.1.0",
85+
"datastore-pubsub": "^0.3.2",
8686
"debug": "^4.1.0",
8787
"dlv": "^1.1.3",
8888
"err-code": "^2.0.0",
@@ -92,13 +92,13 @@
9292
"hamt-sharding": "^1.0.0",
9393
"hapi-pino": "^6.1.0",
9494
"hashlru": "^2.3.0",
95-
"interface-datastore": "^0.8.3",
96-
"ipfs-bitswap": "^0.27.2",
97-
"ipfs-block-service": "^0.16.0",
95+
"interface-datastore": "^1.0.2",
96+
"ipfs-bitswap": "^1.0.0",
97+
"ipfs-block-service": "^0.17.1",
9898
"ipfs-core-utils": "^0.2.3",
9999
"ipfs-http-client": "^44.1.0",
100100
"ipfs-http-response": "^0.5.0",
101-
"ipfs-repo": "^2.0.1",
101+
"ipfs-repo": "^3.0.0",
102102
"ipfs-unixfs": "^1.0.2",
103103
"ipfs-unixfs-exporter": "^2.0.1",
104104
"ipfs-unixfs-importer": "^2.0.1",

packages/ipfs/src/core/components/block/get.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ module.exports = ({ blockService, preload }) => {
1212
preload(cid)
1313
}
1414

15-
return blockService.get(cid)
15+
return blockService.get(cid, options)
1616
})
1717
}

packages/ipfs/src/core/components/dag/get.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = ({ ipld, preload }) => {
1212
}
1313

1414
if (path == null || path === '/') {
15-
const value = await ipld.get(cid)
15+
const value = await ipld.get(cid, options)
1616

1717
return {
1818
value,

packages/ipfs/src/core/components/dag/put.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ module.exports = ({ ipld, pin, gcLock, preload }) => {
4848
try {
4949
const cid = await ipld.put(dagNode, options.format, {
5050
hashAlg: options.hashAlg,
51-
cidVersion: options.version
51+
cidVersion: options.version,
52+
signal: options.signal
5253
})
5354

5455
if (options.pin) {

0 commit comments

Comments
 (0)