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

Commit 706ada2

Browse files
authored
Merge pull request #797 from ipfs/feat/datastore
feat: Awesome datastore
2 parents 7107d4f + 68d92b6 commit 706ada2

File tree

131 files changed

+984
-1200
lines changed

Some content is hidden

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

131 files changed

+984
-1200
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ node_modules
3333

3434
lib
3535
dist
36+
test/test-data/go-ipfs-repo/LOCK
37+
test/test-data/go-ipfs-repo/LOG
38+
test/test-data/go-ipfs-repo/LOG.old

examples/dag/eth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ createNode((err, ipfs) => {
3030
const cid = new CID(1, 'eth-block', multihash)
3131
// console.log(cid.toBaseEncodedString())
3232

33-
ipfs.block.put(new Block(data), cid, cb)
33+
ipfs.block.put(new Block(data, cid), cb)
3434
})
3535
}, (err) => {
3636
if (err) {

gulpfile.js

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const gulp = require('gulp')
44
const parallel = require('async/parallel')
55
const series = require('async/series')
66
const createTempRepo = require('./test/utils/create-repo-node.js')
7-
const IPFS = require('./src/core')
87
const HTTPAPI = require('./src/http-api')
98
const leftPad = require('left-pad')
109

@@ -16,38 +15,26 @@ let nodes = []
1615
function spawnDaemon (num, callback) {
1716
num = leftPad(num, 3, 0)
1817

19-
const node = new IPFS({
20-
repo: createTempRepo(),
21-
init: {
22-
bits: 1024
18+
const config = {
19+
Addresses: {
20+
Swarm: [
21+
`/ip4/127.0.0.1/tcp/10${num}`,
22+
`/ip4/127.0.0.1/tcp/20${num}/ws`
23+
],
24+
API: `/ip4/127.0.0.1/tcp/31${num}`,
25+
Gateway: `/ip4/127.0.0.1/tcp/32${num}`
2326
},
24-
start: false,
25-
EXPERIMENTAL: {
26-
pubsub: true
27-
},
28-
config: {
29-
Addresses: {
30-
Swarm: [
31-
`/ip4/127.0.0.1/tcp/10${num}`,
32-
`/ip4/127.0.0.1/tcp/20${num}/ws`
33-
],
34-
API: `/ip4/127.0.0.1/tcp/31${num}`,
35-
Gateway: `/ip4/127.0.0.1/tcp/32${num}`
36-
},
37-
Bootstrap: [],
38-
Discovery: {
39-
MDNS: {
40-
Enabled: false
41-
}
27+
Bootstrap: [],
28+
Discovery: {
29+
MDNS: {
30+
Enabled: false
4231
}
4332
}
44-
})
33+
}
4534

46-
node.on('init', () => {
47-
const daemon = new HTTPAPI(node.repo.path())
48-
nodes.push(daemon)
49-
setTimeout(() => daemon.start(callback), 400)
50-
})
35+
const daemon = new HTTPAPI(createTempRepo(), config)
36+
nodes.push(daemon)
37+
daemon.start(true, callback)
5138
}
5239

5340
gulp.task('libnode:start', (done) => {

package.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,19 @@
6363
},
6464
"homepage": "https://github.com/ipfs/js-ipfs#readme",
6565
"devDependencies": {
66-
"aegir": "^11.0.0",
66+
"aegir": "^11.0.1",
6767
"buffer-loader": "0.0.1",
6868
"chai": "^3.5.0",
69-
"delay": "^1.3.1",
69+
"delay": "^2.0.0",
7070
"detect-node": "^2.0.3",
7171
"dir-compare": "^1.3.0",
7272
"dirty-chai": "^1.2.2",
73-
"eslint-plugin-react": "^6.10.0",
74-
"execa": "^0.6.1",
73+
"eslint-plugin-react": "^6.10.3",
74+
"execa": "^0.6.3",
7575
"expose-loader": "^0.7.3",
7676
"form-data": "^2.1.2",
7777
"gulp": "^3.9.1",
78-
"interface-ipfs-core": "~0.25.0",
78+
"interface-ipfs-core": "~0.26.0",
7979
"ipfsd-ctl": "~0.20.0",
8080
"left-pad": "^1.1.3",
8181
"lodash": "^4.17.4",
@@ -93,36 +93,35 @@
9393
"dependencies": {
9494
"async": "^2.1.5",
9595
"bl": "^1.2.0",
96-
"boom": "^4.2.0",
96+
"boom": "^4.3.0",
9797
"cids": "^0.4.2",
9898
"debug": "^2.6.3",
99-
"fs-pull-blob-store": "~0.4.1",
99+
"fsm-event": "^2.1.0",
100100
"glob": "^7.1.1",
101101
"hapi": "^16.1.0",
102102
"hapi-set-header": "^1.0.2",
103103
"hoek": "^4.1.0",
104-
"idb-pull-blob-store": "~0.5.1",
105-
"ipfs-api": "^12.1.7",
106-
"ipfs-bitswap": "~0.9.5",
107-
"ipfs-block": "~0.5.5",
108-
"ipfs-block-service": "~0.8.3",
104+
"ipfs-api": "^13.0.0",
105+
"ipfs-bitswap": "~0.10.0",
106+
"ipfs-block": "~0.6.0",
107+
"ipfs-block-service": "~0.9.0",
109108
"ipfs-multipart": "~0.1.0",
110-
"ipfs-repo": "~0.11.3",
109+
"ipfs-repo": "~0.13.0",
111110
"ipfs-unixfs": "~0.1.11",
112-
"ipfs-unixfs-engine": "~0.17.0",
113-
"ipld-resolver": "~0.10.1",
111+
"ipfs-unixfs-engine": "~0.18.0",
112+
"ipld-resolver": "~0.11.0",
114113
"isstream": "^0.1.2",
115-
"joi": "^10.2.2",
116-
"libp2p-floodsub": "~0.7.4",
117-
"libp2p-ipfs-browser": "~0.20.0",
118-
"libp2p-ipfs-nodejs": "~0.20.0",
114+
"joi": "^10.3.0",
115+
"libp2p-floodsub": "~0.7.5",
116+
"libp2p-ipfs-browser": "~0.20.1",
117+
"libp2p-ipfs-nodejs": "~0.20.1",
119118
"lodash.flatmap": "^4.5.0",
120119
"lodash.get": "^4.4.2",
121120
"lodash.has": "^4.5.2",
122121
"lodash.set": "^4.3.2",
123122
"lodash.sortby": "^4.7.0",
124123
"lodash.values": "^4.3.0",
125-
"mafmt": "^2.1.6",
124+
"mafmt": "^2.1.7",
126125
"mkdirp": "^0.5.1",
127126
"multiaddr": "^2.2.2",
128127
"multihashes": "~0.4.4",
@@ -141,12 +140,13 @@
141140
"pull-zip": "^2.0.1",
142141
"read-pkg-up": "^2.0.0",
143142
"readable-stream": "1.1.14",
143+
"safe-buffer": "^5.0.1",
144144
"stream-to-pull-stream": "^1.7.2",
145145
"tar-stream": "^1.5.2",
146146
"temp": "^0.8.3",
147147
"through2": "^2.0.3",
148148
"update-notifier": "^2.1.0",
149-
"yargs": "^6.6.0"
149+
"yargs": "7.0.2"
150150
},
151151
"contributors": [
152152
"Andrew de Andrade <andrew@deandrade.com.br>",

src/cli/bin.js

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const yargs = require('yargs')
66
const updateNotifier = require('update-notifier')
77
const readPkgUp = require('read-pkg-up')
8+
const utils = require('./utils')
89

910
const pkg = readPkgUp.sync({cwd: __dirname}).pkg
1011
updateNotifier({
@@ -14,7 +15,7 @@ updateNotifier({
1415

1516
const cli = yargs
1617
.commandDir('commands')
17-
.demand(1)
18+
.demandCommand(1)
1819

1920
// NOTE: This creates an alias of
2021
// `jsipfs files {add, get, cat}` to `jsipfs {add, get, cat}`.
@@ -27,9 +28,35 @@ aliases.forEach((alias) => {
2728
cli.command(alias.command, alias.describe, alias.builder, alias.handler)
2829
})
2930

30-
// finalize cli setup
31-
cli // eslint-disable-line
32-
.help()
33-
.strict()
34-
.completion()
35-
.argv
31+
const args = process.argv.slice(2)
32+
33+
// Need to skip to avoid locking as these commands
34+
// don't require a daemon
35+
if (args[0] === 'daemon' || args[0] === 'init') {
36+
return cli
37+
.help()
38+
.strict(false)
39+
.completion()
40+
.parse(args)
41+
}
42+
43+
utils.getIPFS((err, ipfs, cleanup) => {
44+
if (err) {
45+
throw err
46+
}
47+
48+
// finalize cli setup
49+
cli // eslint-disable-line
50+
.help()
51+
.strict(false)
52+
.completion()
53+
.parse(args, {
54+
ipfs: ipfs
55+
}, (err, argv, output) => {
56+
cleanup(() => {
57+
if (err) {
58+
throw err
59+
}
60+
})
61+
})
62+
})

src/cli/commands/bitswap/stat.js

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

3-
const utils = require('../../utils')
43
const CID = require('cids')
54

65
module.exports = {
@@ -10,34 +9,28 @@ module.exports = {
109

1110
builder: {},
1211

13-
handler () {
14-
utils.getIPFS((err, ipfs) => {
12+
handler (argv) {
13+
argv.ipfs.bitswap.stat((err, stats) => {
1514
if (err) {
1615
throw err
1716
}
1817

19-
ipfs.bitswap.stat((err, stats) => {
20-
if (err) {
21-
throw err
22-
}
23-
24-
stats.Wantlist = stats.Wantlist || []
25-
stats.Wantlist = stats.Wantlist.map((entry) => {
26-
const buf = new Buffer(entry.cid.hash.data)
27-
const cid = new CID(entry.cid.version, entry.cid.codec, buf)
28-
return cid.toBaseEncodedString()
29-
})
30-
stats.Peers = stats.Peers || []
18+
stats.Wantlist = stats.Wantlist || []
19+
stats.Wantlist = stats.Wantlist.map((entry) => {
20+
const buf = new Buffer(entry.cid.hash.data)
21+
const cid = new CID(entry.cid.version, entry.cid.codec, buf)
22+
return cid.toBaseEncodedString()
23+
})
24+
stats.Peers = stats.Peers || []
3125

32-
console.log(`bitswap status
26+
console.log(`bitswap status
3327
blocks received: ${stats.BlocksReceived}
3428
dup blocks received: ${stats.DupBlksReceived}
3529
dup data received: ${stats.DupDataReceived}B
3630
wantlist [${stats.Wantlist.length} keys]
3731
${stats.Wantlist.join('\n ')}
3832
partners [${stats.Peers.length}]
3933
${stats.Peers.join('\n ')}`)
40-
})
4134
})
4235
}
4336
}

src/cli/commands/bitswap/unwant.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
'use strict'
22

3-
const utils = require('../../utils')
4-
53
module.exports = {
64
command: 'unwant <key>',
75

86
describe: 'Remove a given block from your wantlist.',
97

108
handler (argv) {
11-
utils.getIPFS((err, ipfs) => {
12-
if (err) {
13-
throw err
14-
}
15-
16-
throw new Error('Not implemented yet')
17-
})
9+
throw new Error('Not implemented yet')
1810
}
1911
}

src/cli/commands/bitswap/wantlist.js

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

3-
const utils = require('../../utils')
4-
53
module.exports = {
64
command: 'wantlist',
75

@@ -17,18 +15,12 @@ module.exports = {
1715

1816
handler (argv) {
1917
// TODO: handle argv.peer
20-
utils.getIPFS((err, ipfs) => {
18+
argv.ipfs.bitswap.wantlist((err, res) => {
2119
if (err) {
2220
throw err
2321
}
24-
25-
ipfs.bitswap.wantlist((err, res) => {
26-
if (err) {
27-
throw err
28-
}
29-
res.Keys.forEach((cidStr) => {
30-
console.log(cidStr)
31-
})
22+
res.Keys.forEach((cidStr) => {
23+
console.log(cidStr)
3224
})
3325
})
3426
}

src/cli/commands/block/get.js

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

3-
const utils = require('../../utils')
43
const CID = require('cids')
5-
const debug = require('debug')
6-
const log = debug('cli:block')
7-
log.error = debug('cli:block:error')
84

95
module.exports = {
106
command: 'get <key>',
@@ -14,21 +10,15 @@ module.exports = {
1410
builder: {},
1511

1612
handler (argv) {
17-
utils.getIPFS((err, ipfs) => {
13+
const cid = new CID(argv.key)
14+
15+
argv.ipfs.block.get(cid, (err, block) => {
1816
if (err) {
1917
throw err
2018
}
2119

22-
const cid = new CID(argv.key)
23-
24-
ipfs.block.get(cid, (err, block) => {
25-
if (err) {
26-
throw err
27-
}
28-
29-
process.stdout.write(block.data)
30-
process.stdout.write('\n')
31-
})
20+
process.stdout.write(block.data)
21+
process.stdout.write('\n')
3222
})
3323
}
3424
}

0 commit comments

Comments
 (0)