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

Commit 1eb664f

Browse files
authored
Merge pull request #625 from ipfs/feat/awesome-dag-pb
feat/awesome dag-pb
2 parents 2027b96 + 20e3d2e commit 1eb664f

35 files changed

+458
-273
lines changed

.aegir.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ module.exports = {
99
included: false
1010
}]
1111
}
12-
}
12+
}
13+

examples/bundle-browserify/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var IPFS = require('ipfs')
55
// Create the IPFS node instance
66
// for simplicity, we create a new repo everytime the node
77
// is created, because you can't init already existing repos
8-
const repoPath = '' + Math.random()
8+
const repoPath = String(Math.random())
99
const node = new IPFS(repoPath)
1010
const concat = require('concat-stream')
1111

examples/bundle-webpack/src/App.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class App extends React.Component {
2626

2727
// for simplicity, we create a new repo everytime the node
2828
// is created, because you can't init already existing repos
29-
const repoPath = '' + Math.random()
29+
const repoPath = String(Math.random())
3030
node = new IPFS(repoPath)
3131

3232
node.init({ emptyRepo: true, bits: 2048 }, function (err) {

examples/bundle-webpack/webpack.config.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use strict'
2+
13
var path = require('path')
24
var webpack = require('webpack')
35

package.json

+12-11
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@
5454
"buffer-loader": "0.0.1",
5555
"chai": "^3.5.0",
5656
"detect-node": "^2.0.3",
57+
"eslint-plugin-react": "^6.7.1",
5758
"execa": "^0.5.0",
5859
"expose-loader": "^0.7.1",
5960
"form-data": "^2.1.2",
6061
"fs-pull-blob-store": "^0.4.1",
6162
"gulp": "^3.9.1",
62-
"interface-ipfs-core": "^0.18.4",
63+
"interface-ipfs-core": "^0.22.0",
6364
"left-pad": "^1.1.3",
64-
"lodash": "^4.17.1",
65+
"lodash": "^4.17.2",
6566
"ncp": "^2.0.0",
6667
"nexpect": "^0.5.0",
6768
"pre-commit": "^1.1.3",
@@ -70,7 +71,7 @@
7071
"transform-loader": "^0.2.3"
7172
},
7273
"dependencies": {
73-
"async": "^2.1.2",
74+
"async": "^2.1.4",
7475
"bl": "^1.1.2",
7576
"boom": "^4.2.0",
7677
"debug": "^2.3.3",
@@ -79,17 +80,17 @@
7980
"hapi": "^15.2.0",
8081
"hapi-set-header": "^1.0.2",
8182
"idb-pull-blob-store": "^0.5.1",
82-
"ipfs-api": "^11.1.0",
83+
"ipfs-api": "^12.0.0",
8384
"ipfs-bitswap": "^0.8.1",
8485
"ipfs-block": "^0.5.0",
8586
"ipfs-block-service": "^0.7.0",
8687
"ipfs-multipart": "^0.1.0",
8788
"ipfs-repo": "^0.11.1",
8889
"ipfs-unixfs": "^0.1.5",
89-
"ipfs-unixfs-engine": "^0.13.0",
90-
"ipld-resolver": "^0.2.0",
90+
"ipfs-unixfs-engine": "^0.14.0",
91+
"ipld-resolver": "^0.3.0",
9192
"isstream": "^0.1.2",
92-
"joi": "^9.2.0",
93+
"joi": "^10.0.1",
9394
"libp2p-ipfs": "^0.15.0",
9495
"libp2p-ipfs-browser": "^0.16.0",
9596
"lodash.flatmap": "^4.5.0",
@@ -99,12 +100,12 @@
99100
"lodash.sortby": "^4.7.0",
100101
"lodash.values": "^4.3.0",
101102
"mafmt": "^2.1.2",
102-
"multiaddr": "^2.0.3",
103+
"multiaddr": "^2.1.1",
103104
"multihashes": "^0.2.2",
104105
"path-exists": "^3.0.0",
105106
"peer-book": "^0.3.0",
106107
"peer-id": "^0.8.0",
107-
"peer-info": "^0.8.0",
108+
"peer-info": "^0.8.1",
108109
"promisify-es6": "^1.0.2",
109110
"pull-file": "^1.0.0",
110111
"pull-paramap": "^1.2.1",
@@ -114,7 +115,7 @@
114115
"pull-stream-to-stream": "^1.3.3",
115116
"pull-zip": "^2.0.1",
116117
"read-pkg-up": "^2.0.0",
117-
"readable-stream": "^1.1.14",
118+
"readable-stream": "1.1.14",
118119
"stream-to-pull-stream": "^1.7.2",
119120
"tar-stream": "^1.5.2",
120121
"temp": "^0.8.3",
@@ -147,4 +148,4 @@
147148
"nginnever <[email protected]>",
148149
"npmcdn-to-unpkg-bot <[email protected]>"
149150
]
150-
}
151+
}

src/cli/commands/object/get.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,29 @@ module.exports = {
1616
handler (argv) {
1717
waterfall([
1818
(cb) => utils.getIPFS(cb),
19-
(ipfs, cb) => ipfs.object.get(argv.key, {enc: 'base58'}, cb),
20-
(node, cb) => node.toJSON(cb)
21-
], (err, nodeJson) => {
19+
(ipfs, cb) => ipfs.object.get(argv.key, {enc: 'base58'}, cb)
20+
], (err, node) => {
2221
if (err) {
2322
throw err
2423
}
24+
const nodeJSON = node.toJSON()
2525

26-
nodeJson.Data = nodeJson.Data ? nodeJson.Data.toString() : ''
27-
console.log(JSON.stringify(nodeJson))
26+
nodeJSON.data = nodeJSON.data ? nodeJSON.data.toString() : ''
27+
28+
const answer = {
29+
Data: nodeJSON.data,
30+
Hash: nodeJSON.multihash,
31+
Size: nodeJSON.size,
32+
Links: nodeJSON.links.map((l) => {
33+
return {
34+
Name: l.name,
35+
Size: l.size,
36+
Hash: l.multihash
37+
}
38+
})
39+
}
40+
41+
console.log(JSON.stringify(answer))
2842
})
2943
}
3044
}

src/cli/commands/object/links.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ module.exports = {
2525

2626
links.forEach((link) => {
2727
link = link.toJSON()
28-
console.log(link.Hash, link.Size, link.Name)
28+
29+
console.log(
30+
link.multihash,
31+
link.size,
32+
link.name
33+
)
2934
})
3035
})
3136
})

src/cli/commands/object/new.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ module.exports = {
1616
handler (argv) {
1717
waterfall([
1818
(cb) => utils.getIPFS(cb),
19-
(ipfs, cb) => ipfs.object.new(cb),
20-
(node, cb) => node.toJSON(cb)
19+
(ipfs, cb) => ipfs.object.new(cb)
2120
], (err, node) => {
2221
if (err) {
2322
throw err
2423
}
2524

26-
console.log(node.Hash)
25+
const nodeJSON = node.toJSON()
26+
27+
console.log(nodeJSON.multihash)
2728
})
2829
}
2930
}

src/cli/commands/object/patch/add-link.js

+37-21
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const debug = require('debug')
55
const log = debug('cli:object')
66
const dagPB = require('ipld-dag-pb')
77
const DAGLink = dagPB.DAGLink
8-
const waterfall = require('async/waterfall')
9-
const parallel = require('async/parallel')
8+
const series = require('async/series')
109
log.error = debug('cli:object:error')
1110

1211
module.exports = {
@@ -17,29 +16,46 @@ module.exports = {
1716
builder: {},
1817

1918
handler (argv) {
20-
waterfall([
21-
(cb) => utils.getIPFS(cb),
22-
(ipfs, cb) => waterfall([
23-
(cb) => ipfs.object.get(argv.ref, {enc: 'base58'}, cb),
24-
(linkedObj, cb) => parallel([
25-
(cb) => linkedObj.size(cb),
26-
(cb) => linkedObj.multihash(cb)
27-
], cb)
28-
], (err, stats) => {
29-
if (err) {
30-
return cb(err)
31-
}
32-
33-
const link = new DAGLink(argv.name, stats[0], stats[1])
34-
ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'}, cb)
35-
}),
36-
(node, cb) => node.toJSON(cb)
37-
], (err, node) => {
19+
let ipfs
20+
let nodeA
21+
let nodeB
22+
23+
series([
24+
(cb) => {
25+
utils.getIPFS((err, _ipfs) => {
26+
if (err) {
27+
return cb(err)
28+
}
29+
ipfs = _ipfs
30+
cb()
31+
})
32+
},
33+
(cb) => {
34+
ipfs.object.get(argv.ref, {enc: 'base58'}, (err, node) => {
35+
if (err) {
36+
return cb(err)
37+
}
38+
nodeA = node
39+
cb()
40+
})
41+
},
42+
(cb) => {
43+
const link = new DAGLink(argv.name, nodeA.size, nodeA.multihash)
44+
45+
ipfs.object.patch.addLink(argv.root, link, {enc: 'base58'}, (err, node) => {
46+
if (err) {
47+
return cb(err)
48+
}
49+
nodeB = node
50+
cb()
51+
})
52+
}
53+
], (err) => {
3854
if (err) {
3955
throw err
4056
}
4157

42-
console.log(node.Hash)
58+
console.log(nodeB.toJSON().multihash)
4359
})
4460
}
4561
}

src/cli/commands/object/patch/append-data.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ log.error = debug('cli:object:error')
1111
function appendData (key, data) {
1212
waterfall([
1313
(cb) => utils.getIPFS(cb),
14-
(ipfs, cb) => ipfs.object.patch.appendData(key, data, {enc: 'base58'}, cb),
15-
(node, cb) => node.toJSON(cb)
14+
(ipfs, cb) => ipfs.object.patch.appendData(key, data, {enc: 'base58'}, cb)
1615
], (err, node) => {
1716
if (err) {
1817
throw err
1918
}
19+
const nodeJSON = node.toJSON()
2020

21-
console.log(node.Hash)
21+
console.log(nodeJSON.multihash)
2222
})
2323
}
2424

src/cli/commands/object/patch/rm-link.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,23 @@ module.exports = {
1515
builder: {},
1616

1717
handler (argv) {
18-
const dLink = new DAGLink(argv.link)
18+
// TODO rmLink should support removing by name and/or multihash
19+
// without having to know everything, which in fact it does, however,
20+
// since it expectes a DAGLink type, we have to pass some fake size and
21+
// hash.
22+
const link = new DAGLink(argv.link, 1, 'Qm')
1923

2024
waterfall([
2125
(cb) => utils.getIPFS(cb),
22-
(ipfs, cb) => ipfs.object.patch.rmLink(argv.root, dLink, {enc: 'base58'}, cb),
23-
(node, cb) => node.toJSON(cb)
26+
(ipfs, cb) => ipfs.object.patch.rmLink(argv.root, link, {enc: 'base58'}, cb)
2427
], (err, node) => {
2528
if (err) {
2629
throw err
2730
}
2831

29-
console.log(node.Hash)
32+
const nodeJSON = node.toJSON()
33+
34+
console.log(nodeJSON.multihash)
3035
})
3136
}
3237
}

src/cli/commands/object/patch/set-data.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ log.error = debug('cli:object:error')
1111
function parseAndAddNode (key, data) {
1212
waterfall([
1313
(cb) => utils.getIPFS(cb),
14-
(ipfs, cb) => ipfs.object.patch.setData(key, data, {enc: 'base58'}, cb),
15-
(node, cb) => node.toJSON(cb)
14+
(ipfs, cb) => ipfs.object.patch.setData(key, data, {enc: 'base58'}, cb)
1615
], (err, node) => {
1716
if (err) {
1817
throw err
1918
}
19+
const nodeJSON = node.toJSON()
2020

21-
console.log(node.Hash)
21+
console.log(nodeJSON.multihash)
2222
})
2323
}
2424

src/cli/commands/object/put.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ log.error = debug('cli:object:error')
1111
function putNode (buf, enc) {
1212
waterfall([
1313
(cb) => utils.getIPFS(cb),
14-
(ipfs, cb) => ipfs.object.put(buf, {enc: enc}, cb),
15-
(node, cb) => node.toJSON(cb)
14+
(ipfs, cb) => ipfs.object.put(buf, {enc: enc}, cb)
1615
], (err, node) => {
1716
if (err) {
1817
throw err
1918
}
2019

21-
console.log('added', node.Hash)
20+
const nodeJSON = node.toJSON()
21+
22+
console.log('added', nodeJSON.multihash)
2223
})
2324
}
2425

@@ -36,7 +37,9 @@ module.exports = {
3637

3738
handler (argv) {
3839
if (argv.data) {
39-
return putNode(fs.readFileSync(argv.data), argv.inputenc)
40+
const buf = fs.readFileSync(argv.data)
41+
putNode(buf, argv.inputenc)
42+
return
4043
}
4144

4245
process.stdin.pipe(bl((err, input) => {

src/cli/commands/swarm/peers.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ module.exports = {
2222
throw new Error('This command must be run in online mode. Try running \'ipfs daemon\' first.')
2323
}
2424

25-
ipfs.swarm.peers((err, res) => {
25+
ipfs.swarm.peers((err, result) => {
2626
if (err) {
2727
throw err
2828
}
2929

30-
res.forEach((addr) => {
31-
console.log(addr.toString())
30+
result.forEach((item) => {
31+
console.log(item.addr.toString())
3232
})
3333
})
3434
})

src/core/components/files.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,13 @@ function prepareFile (self, file, callback) {
102102
const bs58mh = multihashes.toB58String(file.multihash)
103103
waterfall([
104104
(cb) => self.object.get(file.multihash, cb),
105-
(node, cb) => node.size((err, size) => {
106-
if (err) {
107-
return cb(err)
108-
}
105+
(node, cb) => {
109106
cb(null, {
110107
path: file.path || bs58mh,
111108
hash: bs58mh,
112-
size: size
109+
size: node.size
113110
})
114-
})
111+
}
115112
], callback)
116113
}
117114

0 commit comments

Comments
 (0)