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

Commit 76a0f0e

Browse files
committed
feat: add peerId param to bitswap.wantlist
1 parent 8c6181c commit 76a0f0e

File tree

2 files changed

+50
-21
lines changed

2 files changed

+50
-21
lines changed

SPEC/BITSWAP.md

Lines changed: 1 addition & 5 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
@@ -23,10 +23,6 @@
2323

2424
(not spec'ed yet)
2525

26-
#### `bitswap.unwant`
27-
28-
(not spec'ed yet)
29-
3026
#### `bitswap.stat`
3127

3228
> Adds an IPFS object to the pinset and also stores it to the IPFS repo. pinset is the set of hashes currently pinned (not gc'able).

js/src/bitswap.js

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
const chai = require('chai')
44
const dirtyChai = require('dirty-chai')
5+
const series = require('async/series')
56
const expect = chai.expect
67
const statsTests = require('./utils/stats')
78
chai.use(dirtyChai)
89
const CID = require('cids')
910

1011
module.exports = (common) => {
1112
describe('.bitswap online', () => {
12-
let ipfs
13+
let ipfsA
14+
let ipfsB
15+
let ipfsBId
1316
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
1417

1518
before(function (done) {
@@ -19,38 +22,68 @@ module.exports = (common) => {
1922

2023
common.setup((err, factory) => {
2124
expect(err).to.not.exist()
22-
factory.spawnNode((err, node) => {
23-
expect(err).to.not.exist()
24-
ipfs = node
25-
ipfs.block.get(new CID(key))
26-
.then(() => {})
27-
.catch(() => {})
28-
setTimeout(done, 250)
29-
})
25+
series([
26+
(cb) => factory.spawnNode((err, node) => {
27+
expect(err).to.not.exist()
28+
ipfsA = node
29+
cb()
30+
}),
31+
(cb) => factory.spawnNode((err, node) => {
32+
expect(err).to.not.exist()
33+
ipfsB = node
34+
cb()
35+
}),
36+
(cb) => {
37+
ipfsB.id((err, id) => {
38+
expect(err).to.not.exist()
39+
const ipfsBAddr = id.addresses[0]
40+
ipfsBId = id.id
41+
ipfsA.swarm.connect(ipfsBAddr, cb)
42+
})
43+
},
44+
(cb) => {
45+
//Ask for a block so we can check that it shows up in our peer's wantlist
46+
ipfsB.block.get(new CID(key))
47+
.then(() => {})
48+
.catch(() => {})
49+
//Wait a short amount of time for the block to show up in our peer's wantlist
50+
setTimeout(cb, 500)
51+
}
52+
], done)
3053
})
3154
})
3255

3356
after((done) => common.teardown(done))
3457

3558
it('.stat', (done) => {
3659

37-
ipfs.bitswap.stat((err, stats) => {
60+
ipfsA.bitswap.stat((err, stats) => {
61+
expect(err).to.not.exist()
3862
statsTests.expectIsBitswap(err, stats)
3963
done()
4064
})
4165
})
4266

4367
it('.wantlist', (done) => {
44-
ipfs.bitswap.wantlist((err, list) => {
68+
ipfsB.bitswap.wantlist((err, list) => {
69+
expect(err).to.not.exist()
70+
expect(list[0].cid.toBaseEncodedString()).to.equal(key)
71+
done()
72+
})
73+
})
74+
75+
it('.wantlist peerid', (done) => {
76+
ipfsA.bitswap.wantlist(ipfsBId, (err, list) => {
4577
expect(err).to.not.exist()
4678
expect(list[0].cid.toBaseEncodedString()).to.equal(key)
4779
done()
4880
})
4981
})
5082

5183
it('.unwant', (done) => {
52-
ipfs.bitswap.unwant(new CID(key), (err) => {
53-
ipfs.bitswap.wantlist((err, list) => {
84+
ipfsA.bitswap.unwant(new CID(key), (err) => {
85+
ipfsA.bitswap.wantlist((err, list) => {
86+
expect(err).to.not.exist()
5487
expect(list).to.be.empty()
5588
done()
5689
})
@@ -87,21 +120,21 @@ module.exports = (common) => {
87120

88121
it('.stat gives error while offline', () => {
89122
ipfs.bitswap.stat((err, stats) => {
90-
expect(err).to.exist()
123+
expect(err).to.match(/online mode/)
91124
expect(stats).to.not.exist()
92125
})
93126
})
94127

95128
it('.wantlist gives error if offline', () => {
96129
ipfs.bitswap.wantlist((err, list) => {
97-
expect(err).to.exist()
130+
expect(err).to.match(/online mode/)
98131
expect(list).to.not.exist()
99132
})
100133
})
101134

102135
it('.unwant gives error if offline', () => {
103136
expect(() => ipfs.bitswap.unwant(new CID(key), (err) => {
104-
expect(err).to.exist()
137+
expect(err).to.match(/online mode/)
105138
}))
106139
})
107140
})

0 commit comments

Comments
 (0)