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

Commit 9f81bcb

Browse files
wraithgaralanshaw
authored andcommitted
feat: add peerId param to bitswap.wantlist
1 parent df4e677 commit 9f81bcb

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

SPEC/BITSWAP.md

+13-4
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

+20-15
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) {
@@ -29,18 +30,18 @@ module.exports = (common) => {
2930
ipfsA = node
3031
withGo = node.peerId.agentVersion.startsWith('go-ipfs')
3132
cb()
32-
//ipfsA.block.get(key)
33-
//.then(() => {})
34-
//.catch(() => {})
35-
//cb()
3633
}),
3734
(cb) => spawn.spawnNodeWithId(factory, (err, node) => {
3835
expect(err).to.not.exist()
3936
ipfsB = node
37+
ipfsBId = node.peerId
4038
ipfsB.block.get(new CID(key))
4139
.then(() => {})
4240
.catch(() => {})
43-
ipfsA.swarm.connect(node.peerId.addresses[0], cb)
41+
ipfsA.swarm.connect(ipfsBId.addresses[0], (err) => {
42+
expect(err).to.not.exist()
43+
setTimeout(cb, 350)
44+
})
4445
})
4546
], done)
4647
})
@@ -49,15 +50,15 @@ module.exports = (common) => {
4950
after((done) => common.teardown(done))
5051

5152
it('.stat', (done) => {
52-
ipfsA.bitswap.stat((err, stats) => {
53+
ipfsB.bitswap.stat((err, stats) => {
5354
expect(err).to.not.exist()
5455
statsTests.expectIsBitswap(err, stats)
5556
done()
5657
})
5758
})
5859

5960
it('.wantlist', (done) => {
60-
ipfsA.bitswap.wantlist((err, list) => {
61+
ipfsB.bitswap.wantlist((err, list) => {
6162
expect(err).to.not.exist()
6263
expect(list.Keys).to.have.length(1);
6364
expect(list.Keys[0]['/']).to.equal(key)
@@ -66,7 +67,7 @@ module.exports = (common) => {
6667
})
6768

6869
it('.wantlist peerid', (done) => {
69-
ipfsA.bitswap.wantlist(ipfsBId, (err, list) => {
70+
ipfsA.bitswap.wantlist(ipfsBId.id, (err, list) => {
7071
expect(err).to.not.exist()
7172
expect(list.Keys[0]['/']).to.equal(key)
7273
done()
@@ -77,9 +78,9 @@ module.exports = (common) => {
7778
if (withGo) {
7879
this.skip()
7980
}
80-
ipfsA.bitswap.unwant(key, (err) => {
81+
ipfsB.bitswap.unwant(key, (err) => {
8182
expect(err).to.not.exist();
82-
ipfsA.bitswap.wantlist((err, list) => {
83+
ipfsB.bitswap.wantlist((err, list) => {
8384
expect(err).to.not.exist();
8485
expect(list.Keys).to.be.empty()
8586
done()
@@ -115,7 +116,7 @@ module.exports = (common) => {
115116
})
116117
})
117118

118-
it('.stat gives error while offline', () => {
119+
it('.stat gives error while offline', (done) => {
119120
ipfs.bitswap.stat((err, stats) => {
120121
expect(err).to.exist()
121122
//When run against core we get our expected error, when run
@@ -124,10 +125,11 @@ module.exports = (common) => {
124125
expect(err).to.match(/online mode/)
125126
}
126127
expect(stats).to.not.exist()
128+
done()
127129
})
128130
})
129131

130-
it('.wantlist gives error if offline', () => {
132+
it('.wantlist gives error if offline', (done) => {
131133
ipfs.bitswap.wantlist((err, list) => {
132134
expect(err).to.exist()
133135
//When run against core we get our expected error, when run
@@ -136,18 +138,21 @@ module.exports = (common) => {
136138
expect(err).to.match(/online mode/)
137139
}
138140
expect(list).to.not.exist()
141+
done()
139142
})
140143
})
141144

142-
it('.unwant gives error if offline', () => {
143-
expect(() => ipfs.bitswap.unwant(key, (err) => {
145+
it('.unwant gives error if offline', (done) => {
146+
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
147+
ipfs.bitswap.unwant(key, (err) => {
144148
expect(err).to.exist()
145149
//When run against core we get our expected error, when run
146150
//as part of the http tests we get a connection refused
147151
if (err.code !== 'ECONNREFUSED') {
148152
expect(err).to.match(/online mode/)
149153
}
150-
}))
154+
done()
155+
})
151156
})
152157
})
153158
}

0 commit comments

Comments
 (0)