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

Commit

Permalink
feat: add peerId param to bitswap.wantlist
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored and alanshaw committed Jun 18, 2018
1 parent df4e677 commit 9f81bcb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
17 changes: 13 additions & 4 deletions SPEC/BITSWAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* [bitswap.unwant](#bitswapunwant)
* [bitswap.stat](#bitswapstat)

#### `unwant`
#### `bitswap.unwant`

> Removes a given block from your wantlist
Expand All @@ -21,11 +21,20 @@

### `bitswap.wantlist`

(not spec'ed yet)
> Returns the wantlist, optionally limited by peerID
#### `bitswap.unwant`
#### `Go` **WIP**

#### `JavaScript` - ipfs.bitswap.wantlist([peerId])

```JavaScript
ipfs.bitswap.wantlist((err, list) => console.log(list))

//[ { Wantlist object }, ... ]

ipfs.bitswap.wantlist(peerId, (err, list) => console.log(list))

(not spec'ed yet)
//[ { Wantlist object }, ... ]

#### `bitswap.stat`

Expand Down
35 changes: 20 additions & 15 deletions js/src/bitswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = (common) => {
let ipfsA
let ipfsB
let withGo
let ipfsBId
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'

before(function (done) {
Expand All @@ -29,18 +30,18 @@ module.exports = (common) => {
ipfsA = node
withGo = node.peerId.agentVersion.startsWith('go-ipfs')
cb()
//ipfsA.block.get(key)
//.then(() => {})
//.catch(() => {})
//cb()
}),
(cb) => spawn.spawnNodeWithId(factory, (err, node) => {
expect(err).to.not.exist()
ipfsB = node
ipfsBId = node.peerId
ipfsB.block.get(new CID(key))
.then(() => {})
.catch(() => {})
ipfsA.swarm.connect(node.peerId.addresses[0], cb)
ipfsA.swarm.connect(ipfsBId.addresses[0], (err) => {
expect(err).to.not.exist()
setTimeout(cb, 350)
})
})
], done)
})
Expand All @@ -49,15 +50,15 @@ module.exports = (common) => {
after((done) => common.teardown(done))

it('.stat', (done) => {
ipfsA.bitswap.stat((err, stats) => {
ipfsB.bitswap.stat((err, stats) => {
expect(err).to.not.exist()
statsTests.expectIsBitswap(err, stats)
done()
})
})

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

it('.wantlist peerid', (done) => {
ipfsA.bitswap.wantlist(ipfsBId, (err, list) => {
ipfsA.bitswap.wantlist(ipfsBId.id, (err, list) => {
expect(err).to.not.exist()
expect(list.Keys[0]['/']).to.equal(key)
done()
Expand All @@ -77,9 +78,9 @@ module.exports = (common) => {
if (withGo) {
this.skip()
}
ipfsA.bitswap.unwant(key, (err) => {
ipfsB.bitswap.unwant(key, (err) => {
expect(err).to.not.exist();
ipfsA.bitswap.wantlist((err, list) => {
ipfsB.bitswap.wantlist((err, list) => {
expect(err).to.not.exist();
expect(list.Keys).to.be.empty()
done()
Expand Down Expand Up @@ -115,7 +116,7 @@ module.exports = (common) => {
})
})

it('.stat gives error while offline', () => {
it('.stat gives error while offline', (done) => {
ipfs.bitswap.stat((err, stats) => {
expect(err).to.exist()
//When run against core we get our expected error, when run
Expand All @@ -124,10 +125,11 @@ module.exports = (common) => {
expect(err).to.match(/online mode/)
}
expect(stats).to.not.exist()
done()
})
})

it('.wantlist gives error if offline', () => {
it('.wantlist gives error if offline', (done) => {
ipfs.bitswap.wantlist((err, list) => {
expect(err).to.exist()
//When run against core we get our expected error, when run
Expand All @@ -136,18 +138,21 @@ module.exports = (common) => {
expect(err).to.match(/online mode/)
}
expect(list).to.not.exist()
done()
})
})

it('.unwant gives error if offline', () => {
expect(() => ipfs.bitswap.unwant(key, (err) => {
it('.unwant gives error if offline', (done) => {
const key = 'QmUBdnXXPyoDFXj3Hj39dNJ5VkN3QFRskXxcGaYFBB8CNR'
ipfs.bitswap.unwant(key, (err) => {
expect(err).to.exist()
//When run against core we get our expected error, when run
//as part of the http tests we get a connection refused
if (err.code !== 'ECONNREFUSED') {
expect(err).to.match(/online mode/)
}
}))
done()
})
})
})
}

0 comments on commit 9f81bcb

Please sign in to comment.