Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 73a153e

Browse files
wraithgaralanshaw
authored andcommitted
feat: implement bitswap wantlist peer ID param and bitswap unwant (#761)
* fix(bitswap.unwant) Parse CID from arg * feat(bitswap.wantlist) add peer parameter * chore: simplify CID parsing for wantlist and unwant * chore: update interface-ipfs-core dependency * chore: upgrades interface-ipfs-core dependency License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
1 parent 7fb2e07 commit 73a153e

File tree

5 files changed

+64
-74
lines changed

5 files changed

+64
-74
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"eslint-plugin-react": "^7.9.1",
8080
"go-ipfs-dep": "~0.4.15",
8181
"gulp": "^3.9.1",
82-
"interface-ipfs-core": "~0.67.0",
82+
"interface-ipfs-core": "~0.68.1",
8383
"ipfsd-ctl": "~0.37.3",
8484
"pull-stream": "^3.6.8",
8585
"socket.io": "^2.1.1",

Diff for: src/bitswap/unwant.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const CID = require('cids')
45

56
module.exports = (send) => {
6-
return promisify((args, opts, callback) => {
7+
return promisify((cid, opts, callback) => {
78
if (typeof (opts) === 'function') {
89
callback = opts
910
opts = {}
1011
}
12+
13+
try {
14+
cid = new CID(cid)
15+
} catch (err) {
16+
return callback(err)
17+
}
18+
1119
send({
1220
path: 'bitswap/unwant',
13-
args: args,
21+
args: cid.toBaseEncodedString(),
1422
qs: opts
1523
}, callback)
1624
})

Diff for: src/bitswap/wantlist.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
'use strict'
22

33
const promisify = require('promisify-es6')
4+
const CID = require('cids')
45

56
module.exports = (send) => {
6-
return promisify((callback) => {
7+
return promisify((peerId, opts, callback) => {
8+
if (typeof (peerId) === 'function') {
9+
callback = peerId
10+
opts = {}
11+
peerId = null
12+
} else if (typeof (opts) === 'function') {
13+
callback = opts
14+
opts = {}
15+
}
16+
17+
if (peerId) {
18+
try {
19+
opts.peer = new CID(peerId).toBaseEncodedString()
20+
} catch (err) {
21+
return callback(err)
22+
}
23+
}
24+
725
send({
8-
path: 'bitswap/wantlist'
26+
path: 'bitswap/wantlist',
27+
qs: opts
928
}, callback)
1029
})
1130
}

Diff for: test/bitswap.spec.js

-69
This file was deleted.

Diff for: test/interface/bitswap.spec.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-env mocha */
2+
3+
'use strict'
4+
5+
const test = require('interface-ipfs-core')
6+
const parallel = require('async/parallel')
7+
8+
const IPFSApi = require('../../src')
9+
const f = require('../utils/factory')
10+
11+
const nodes = []
12+
const common = {
13+
setup: function (callback) {
14+
callback(null, {
15+
spawnNode: (cb) => {
16+
f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => {
17+
if (err) {
18+
return cb(err)
19+
}
20+
21+
nodes.push(_ipfsd)
22+
cb(null, IPFSApi(_ipfsd.apiAddr))
23+
})
24+
}
25+
})
26+
},
27+
teardown: function (callback) {
28+
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
29+
}
30+
}
31+
32+
test.bitswap(common)

0 commit comments

Comments
 (0)