-
Notifications
You must be signed in to change notification settings - Fork 47
Bitswap Complete (1.0.0 + 1.1.0) #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,9 @@ class BitswapMessage { | |
} | ||
} | ||
|
||
addBlock (block) { | ||
this.blocks.set(mh.toB58String(block.key), block) | ||
addBlock (block, hashAlg) { | ||
const key = block.key(hashAlg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is going to be async with the new crypto. so might be better to base it on top of that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be incredibly hard to work on top of a PR of PRs and do PR of PRs. One giant at a time, that is why we have git :) |
||
this.blocks.set(mh.toB58String(key), block) | ||
} | ||
|
||
cancel (key) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,8 @@ function createRepo (id, done) { | |
}) | ||
}) | ||
|
||
const mainBlob = new Store(id) | ||
const blocksBlob = new Store(`${id}/blocks`) | ||
const mainBlob = new Store(id + Math.random()) | ||
const blocksBlob = new Store(`${id}/blocks` + Math.random()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was due to ipfs/js-ipfs#528 (comment) |
||
|
||
dbs.push(id) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ module.exports = (repo) => { | |
|
||
before((done) => { | ||
repo.create('hello', (err, r) => { | ||
if (err) return done(err) | ||
expect(err).to.not.exist | ||
store = r.blockstore | ||
done() | ||
}) | ||
|
@@ -46,7 +46,7 @@ module.exports = (repo) => { | |
}) | ||
|
||
describe('receive message', () => { | ||
it('simple block message', (done) => { | ||
it.only('simple block message', (done) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: remove before merge |
||
const me = PeerId.create({bits: 64}) | ||
const book = new PeerBook() | ||
const bs = new Bitswap(me, libp2pMock, store, book) | ||
|
@@ -56,23 +56,30 @@ module.exports = (repo) => { | |
const b1 = makeBlock() | ||
const b2 = makeBlock() | ||
const msg = new Message(false) | ||
msg.addBlock(b1) | ||
msg.addBlock(b2) | ||
msg.addBlock(b1, 'sha2-256') | ||
msg.addBlock(b2, 'sha2-256') | ||
|
||
bs._receiveMessage(other, msg, (err) => { | ||
if (err) throw err | ||
expect(err).to.not.exist | ||
|
||
expect(bs.blocksRecvd).to.be.eql(2) | ||
expect(bs.dupBlocksRecvd).to.be.eql(0) | ||
|
||
pull( | ||
pull.values([b1, b1]), | ||
pull.map((block) => store.getStream(block.key)), | ||
pull.values([ | ||
b1, | ||
b2 | ||
]), | ||
pull.map((block) => { | ||
return store.getStream(block.key('sha2-256')) | ||
}), | ||
pull.flatten(), | ||
pull.collect((err, blocks) => { | ||
if (err) return done(err) | ||
|
||
expect(blocks).to.be.eql([b1, b1]) | ||
expect(err).to.not.exist | ||
expect(blocks[0].key('sha2-256')) | ||
.to.be.eql(b1.key('sha2-256')) | ||
expect(blocks[1].key('sha2-256')) | ||
.to.be.eql(b2.key('sha2-256')) | ||
done() | ||
}) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't we agree that we would stop doing style refactorings that are based on personal preferences?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be wrong, but I don't see this as a style preference. Seeing
cb = cb || noop
is more simpler thancb = cb || (() => {})
everytime I want a noop.I can revert back though.
As I said at the top of the PR: "Nothing to see here", which was meant to save time from CR, this is far from complete (note that I didn't add the "needs review" label).