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

Commit f55e32d

Browse files
committed
WIP: commit what i currently have
1 parent 22ee531 commit f55e32d

File tree

47 files changed

+1213
-873
lines changed

Some content is hidden

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

47 files changed

+1213
-873
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,5 +250,8 @@
250250
"Jade Meskill <[email protected]>",
251251
"Jacob Karlsson <[email protected]>",
252252
"noah the goodra <[email protected]>"
253-
]
253+
],
254+
"dependencies": {
255+
"@mapbox/node-pre-gyp": "^1.0.0"
256+
}
254257
}

packages/interface-ipfs-core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
"delay": "^4.4.0",
4040
"dirty-chai": "^2.0.1",
4141
"err-code": "^2.0.3",
42-
"ipfs-unixfs": "^2.0.3",
43-
"ipfs-unixfs-importer": "^5.0.0",
42+
"ipfs-unixfs": "https://gitpkg.now.sh/ipfs/js-ipfs-unixfs/packages/ipfs-unixfs?js-dag-pb",
43+
"ipfs-unixfs-importer": "https://gitpkg.now.sh/ipfs/js-ipfs-unixfs/packages/ipfs-unixfs-importer?js-dag-pb",
4444
"ipfs-utils": "^6.0.1",
4545
"ipld-block": "^0.11.0",
4646
"ipld-dag-cbor": "^0.17.0",

packages/ipfs-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
"scripts": {
2222
"lint": "aegir lint",
23-
"prepare": "aegir build --no-bundle",
23+
"prepare": "aegir build --no-bundle --no-types",
2424
"test": "npm run test:node",
2525
"test:node": "aegir test -t node",
2626
"coverage": "nyc --reporter=text --reporter=lcov npm run test:node",

packages/ipfs-client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"scripts": {
3333
"test": "aegir test",
3434
"lint": "aegir lint",
35-
"prepare": "aegir build --no-bundle",
35+
"prepare": "aegir build --no-bundle --no-types",
3636
"prepublishOnly": "aegir build",
3737
"coverage": "npx nyc -r html npm run test:node -- --bail",
3838
"clean": "rimraf ./dist",

packages/ipfs-core-utils/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
"test:electron-renderer": "aegir test -t electron-renderer",
3131
"test:node": "aegir test -t node",
3232
"lint": "aegir lint",
33-
"prepare": "aegir build --no-bundle",
33+
"prepare": "aegir build --no-bundle --no-types",
3434
"clean": "rimraf ./dist",
3535
"dep-check": "aegir dep-check -i rimraf -i ipfs-core-types"
3636
},
3737
"license": "MIT",
3838
"dependencies": {
39+
"multiformats": "^4.0.0",
3940
"any-signal": "^2.1.2",
4041
"blob-to-it": "^1.0.1",
4142
"browser-readablestream-to-it": "^1.0.1",
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict'
2+
3+
const legacyCID = require('cids')
4+
// @ts-ignore
5+
const CID = require('multiformats/cid')
6+
7+
/**
8+
* Makes sure that an object only contains js-cid style CIDs.
9+
*
10+
* It traverses the object recursively and changes all instances of a CID from
11+
* a js-multiforamts style CID to a js-cid style CID (js-cid style CIDs stay
12+
* as they are). You can also pass in a CID directly.
13+
*
14+
* Once js-cid is no longer used in the code base, this utility function will
15+
* no longer be needed.
16+
*
17+
* @param {any} obj - The object to do the transformation on
18+
*/
19+
const asLegacyCid = (obj) => {
20+
if (legacyCID.isCID(obj)) {
21+
return obj
22+
}
23+
24+
// NOTE vmx 2021-02-22: I have no idea why TypeScript doesn't pick this up
25+
// correctly => ignore it for now, deal with it later.
26+
// @ts-ignore
27+
const newCID = CID.asCID(obj)
28+
if (newCID) {
29+
const { version, code, multihash: { bytes } } = newCID
30+
const { buffer, byteOffset, byteLength } = bytes
31+
const multihash = Buffer.from(buffer, byteOffset, byteLength)
32+
return new legacyCID(version, code, multihash)
33+
}
34+
35+
if (obj && typeof obj === 'object') {
36+
for (const [key, value] of Object.entries(obj)) {
37+
obj[key] = asLegacyCid(value)
38+
}
39+
}
40+
41+
return obj
42+
}
43+
44+
module.exports = asLegacyCid

packages/ipfs-core/package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"scripts": {
4141
"lint": "aegir lint",
42-
"prepare": "aegir build --no-bundle",
42+
"prepare": "aegir build --no-bundle --no-types",
4343
"prepublishOnly": "aegir build",
4444
"test": "aegir test",
4545
"test:node": "aegir test -t node",
@@ -53,6 +53,7 @@
5353
"dep-check": "aegir dep-check -i interface-ipfs-core -i ipfs-core-types -i abort-controller"
5454
},
5555
"dependencies": {
56+
"@ipld/dag-pb": "0.0.1",
5657
"abort-controller": "^3.0.0",
5758
"array-shuffle": "^2.0.0",
5859
"bignumber.js": "^9.0.0",
@@ -73,9 +74,9 @@
7374
"ipfs-core-types": "^0.3.0",
7475
"ipfs-core-utils": "^0.7.1",
7576
"ipfs-repo": "^8.0.0",
76-
"ipfs-unixfs": "^2.0.3",
77-
"ipfs-unixfs-exporter": "^3.0.4",
78-
"ipfs-unixfs-importer": "^5.0.0",
77+
"ipfs-unixfs": "https://gitpkg.now.sh/ipfs/js-ipfs-unixfs/packages/ipfs-unixfs?js-dag-pb",
78+
"ipfs-unixfs-exporter": "https://gitpkg.now.sh/ipfs/js-ipfs-unixfs/packages/ipfs-unixfs-exporter?js-dag-pb",
79+
"ipfs-unixfs-importer": "https://gitpkg.now.sh/ipfs/js-ipfs-unixfs/packages/ipfs-unixfs-importer?js-dag-pb",
7980
"ipfs-utils": "^6.0.1",
8081
"ipld": "^0.28.0",
8182
"ipld-block": "^0.11.0",
@@ -109,6 +110,7 @@
109110
"multiaddr-to-uri": "^6.0.0",
110111
"multibase": "^4.0.0",
111112
"multicodec": "^3.0.1",
113+
"multiformats": "^4.0.0",
112114
"multihashing-async": "^2.0.1",
113115
"native-abort-controller": "^1.0.3",
114116
"p-queue": "^6.6.1",

packages/ipfs-core/src/components/add-all/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { parseChunkerString } = require('./utils')
66
const { pipe } = require('it-pipe')
77
const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
88
const mergeOptions = require('merge-options').bind({ ignoreUndefined: true })
9+
const asLegacyCid = require('ipfs-core-utils/src/as-legacy-cid')
910

1011
/**
1112
* @typedef {Object} Context
@@ -97,7 +98,9 @@ module.exports = ({ block, gcLock, preload, pin, options }) => {
9798
// do not keep file totals around forever
9899
delete totals[added.path]
99100

100-
yield added
101+
const legacyAdded = added
102+
legacyAdded.cid = asLegacyCid(added.cid)
103+
yield legacyAdded
101104
}
102105
} finally {
103106
releaseLock()

packages/ipfs-core/src/components/add.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const last = require('it-last')
4+
const asLegacyCid = require('ipfs-core-utils/src/as-legacy-cid')
45

56
/**
67
* @typedef {Object} Context
@@ -27,7 +28,10 @@ module.exports = ({ addAll }) => {
2728
throw Error('Failed to add a file, if you see this please report a bug')
2829
}
2930

30-
return result
31+
let legacyResult = result
32+
legacyResult.cid = asLegacyCid(result.cid)
33+
34+
return legacyResult
3135
}
3236

3337
return add

packages/ipfs-core/src/components/cat.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ const withTimeoutOption = require('ipfs-core-utils/src/with-timeout-option')
66

77
/**
88
* @typedef {Object} Context
9-
* @property {import('.').IPLD} ipld
9+
* @property {import('.').BlockService} blockService
1010
* @property {import('.').Preload} preload
1111
*
1212
* @param {Context} context
1313
*/
14-
module.exports = function ({ ipld, preload }) {
14+
module.exports = function ({ blockService, preload }) {
1515
/**
1616
* Returns content of the file addressed by a valid IPFS Path or CID.
1717
*
@@ -27,7 +27,7 @@ module.exports = function ({ ipld, preload }) {
2727
preload(pathComponents[0])
2828
}
2929

30-
const file = await exporter(ipfsPath, ipld, options)
30+
const file = await exporter(ipfsPath, blockService, options)
3131

3232
// File may not have unixfs prop if small & imported with rawLeaves true
3333
if (file.unixfs && file.unixfs.type.includes('dir')) {

packages/ipfs-core/src/components/files/chmod.js

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ const toTrail = require('./utils/to-trail')
99
const addLink = require('./utils/add-link')
1010
const updateTree = require('./utils/update-tree')
1111
const updateMfsRoot = require('./utils/update-mfs-root')
12-
const { DAGNode } = require('ipld-dag-pb')
12+
const dagPb = require('@ipld/dag-pb')
13+
// @ts-ignore
14+
const { sha256 } = require('multiformats/hashes/sha2')
15+
const Block = require('multiformats/block')
16+
// @ts-ignore
17+
const IpldBlock = require('ipld-block')
18+
const CID = require('cids')
1319
const mc = require('multicodec')
1420
const mh = require('multihashing-async').multihash
1521
const { pipe } = require('it-pipe')
@@ -193,10 +199,14 @@ module.exports = (context) => {
193199
// but do not reimport files, only manipulate dag-pb nodes
194200
const root = await pipe(
195201
async function * () {
196-
for await (const entry of exporter.recursive(cid, context.ipld)) {
197-
let node = await context.ipld.get(entry.cid)
202+
for await (const entry of exporter.recursive(cid, context.blockService)) {
203+
const block = await context.blockService(entry.cid)
204+
let node = dagPb.decode(block.data)
198205
entry.unixfs.mode = calculateMode(mode, entry.unixfs)
199-
node = new DAGNode(entry.unixfs.marshal(), node.Links)
206+
node = prepare({
207+
Data: entry.unixfs.marshal(),
208+
Links: node.Links
209+
})
200210

201211
yield {
202212
path: entry.path,
@@ -234,20 +244,32 @@ module.exports = (context) => {
234244
return
235245
}
236246

237-
let node = await context.ipld.get(cid)
247+
const block = await context.blockService.get(cid)
248+
let node = dagPb.decode(block.data)
238249
const metadata = UnixFS.unmarshal(node.Data)
239250
metadata.mode = calculateMode(mode, metadata)
240-
node = new DAGNode(metadata.marshal(), node.Links)
251+
node = prepare({
252+
Data: metadata.marshal(),
253+
Links: node.Links
254+
})
255+
241256

242-
const updatedCid = await context.ipld.put(node, mc.DAG_PB, {
243-
cidVersion: cid.version,
244-
hashAlg: mh.names[opts.hashAlg || defaultOptions.hashAlg],
245-
onlyHash: !opts.flush
257+
const updatedBlock = await Block.encode({
258+
value: node,
259+
codec: dagPb,
260+
// TODO vmx 2021-02-22: Add back support for other hashing algorithms
261+
hasher: sha256
246262
})
263+
updatedCid = updatedBlock.cid
264+
if (settings.flush) {
265+
const legacyCid = new CID(updatedBlock.cid.multihash.bytes)
266+
await context.blockService.put(new IpldBlock(updatedBlock.bytes, legacyCid))
267+
}
247268

248269
const trail = await toTrail(context, mfsDirectory)
249270
const parent = trail[trail.length - 1]
250-
const parentNode = await context.ipld.get(parent.cid)
271+
const parentBlock = await context.blockService(parent.cid)
272+
const parentNode = dagPb.decode(parentBlock.data)
251273

252274
const result = await addLink(context, {
253275
parent: parentNode,

packages/ipfs-core/src/components/files/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const wrap = ({
5151

5252
const defaultOptions = {
5353
repoOwner: true,
54-
ipld: null,
5554
repo: null
5655
}
5756

@@ -93,17 +92,15 @@ function createMfs (options) {
9392

9493
/**
9594
* @param {Object} context
96-
* @param {import('..').IPLD} context.ipld
9795
* @param {import('..').Block} context.block
9896
* @param {import('..').BlockService} context.blockService
9997
* @param {import('..').Repo} context.repo
10098
* @param {import('..').Preload} context.preload
10199
* @param {import('..').Options} context.options
102100
* @returns {MFS}
103101
*/
104-
module.exports = ({ ipld, block, blockService, repo, preload, options: constructorOptions }) => {
102+
module.exports = ({ block, blockService, repo, preload, options: constructorOptions }) => {
105103
const methods = createMfs({
106-
ipld,
107104
block,
108105
blocks: blockService,
109106
datastore: repo.root,

packages/ipfs-core/src/components/files/ls.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ module.exports = (context) => {
6464
*/
6565
async function * mfsLs (path, options = {}) {
6666
const mfsPath = await toMfsPath(context, path, options)
67-
const fsDir = await exporter(mfsPath.mfsPath, context.ipld)
67+
const fsDir = await exporter(mfsPath.mfsPath, context.blocks)
6868

6969
// single file/node
7070
if (!fsDir.unixfs || !fsDir.unixfs.type.includes('directory')) {

packages/ipfs-core/src/components/files/mkdir.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = (context) => {
7575
const subPath = `/ipfs/${root}/${subPathComponents.join('/')}`
7676

7777
try {
78-
parent = await exporter(subPath, context.ipld)
78+
parent = await exporter(subPath, context.blockService)
7979
log(`${subPath} existed`)
8080
log(`${subPath} had children ${parent.node.Links.map(link => link.Name)}`)
8181

packages/ipfs-core/src/components/files/read.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module.exports = (context) => {
4040
return {
4141
[Symbol.asyncIterator]: async function * read () {
4242
const mfsPath = await toMfsPath(context, path, options)
43-
const result = await exporter(mfsPath.mfsPath, context.ipld)
43+
const result = await exporter(mfsPath.mfsPath, context.blockService)
4444

4545
if (result.unixfs.type !== 'file') {
4646
throw errCode(new Error(`${path} was not a file`), 'ERR_NOT_FILE')

0 commit comments

Comments
 (0)