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

Commit 97334ee

Browse files
committed
feat: add peerId param to bitswap.wantlist
1 parent d1da60d commit 97334ee

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

SPEC/BITSWAP.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* [bitswap.unwant](#bitswapunwant)
55
* [bitswap.stat](#bitswapstat)
66

7-
#### `unwant`
7+
#### `bitswap.unwant`
88

99
> Removes a given block from your wantlist
1010
@@ -21,11 +21,20 @@
2121

2222
### `bitswap.wantlist`
2323

24-
(not spec'ed yet)
24+
> Returns the wantlist, optionally limited by peerID
2525
26-
#### `bitswap.unwant`
26+
#### `Go` **WIP**
27+
28+
#### `JavaScript` - ipfs.bitswap.wantlist([peerId])
29+
30+
```JavaScript
31+
ipfs.bitswap.wantlist((err, list) => console.log(list))
32+
33+
//[ { Wantlist object }, ... ]
34+
35+
ipfs.bitswap.wantlist(peerId, (err, list) => console.log(list))
2736

28-
(not spec'ed yet)
37+
//[ { Wantlist object }, ... ]
2938

3039
#### `bitswap.stat`
3140

js/src/bitswap.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = (common) => {
1414
let ipfsA
1515
let ipfsB
1616
let withGo
17+
let ipfsBId
1718
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
1819

1920
before(function (done) {
@@ -37,10 +38,14 @@ module.exports = (common) => {
3738
(cb) => spawn.spawnNodeWithId(factory, (err, node) => {
3839
expect(err).to.not.exist()
3940
ipfsB = node
40-
ipfsB.block.get(new CID(key))
41-
.then(() => {})
42-
.catch(() => {})
43-
ipfsA.swarm.connect(node.peerId.addresses[0], cb)
41+
ipfsBId = node.peerId
42+
ipfsA.swarm.connect(ipfsBId.addresses[0], (err) => {
43+
expect(err).to.not.exist()
44+
ipfsB.block.get(new CID(key))
45+
.then(() => {})
46+
.catch(() => {})
47+
setTimeout(cb, 1000)
48+
})
4449
})
4550
], done)
4651
})
@@ -49,15 +54,15 @@ module.exports = (common) => {
4954
after((done) => common.teardown(done))
5055

5156
it('.stat', (done) => {
52-
ipfsA.bitswap.stat((err, stats) => {
57+
ipfsB.bitswap.stat((err, stats) => {
5358
expect(err).to.not.exist()
5459
statsTests.expectIsBitswap(err, stats)
5560
done()
5661
})
5762
})
5863

5964
it('.wantlist', (done) => {
60-
ipfsA.bitswap.wantlist((err, list) => {
65+
ipfsB.bitswap.wantlist((err, list) => {
6166
expect(err).to.not.exist()
6267
expect(list.Keys).to.have.length(1);
6368
expect(list.Keys[0]['/']).to.equal(key)
@@ -66,7 +71,7 @@ module.exports = (common) => {
6671
})
6772

6873
it('.wantlist peerid', (done) => {
69-
ipfsA.bitswap.wantlist(ipfsBId, (err, list) => {
74+
ipfsA.bitswap.wantlist(ipfsBId.id, (err, list) => {
7075
expect(err).to.not.exist()
7176
expect(list.Keys[0]['/']).to.equal(key)
7277
done()

0 commit comments

Comments
 (0)