Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

feat/use new bitswap #51

Merged
merged 2 commits into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,24 @@
},
"homepage": "https://github.com/ipfs/js-ipfs-block-service#readme",
"devDependencies": {
"aegir": "^9.2.2",
"aegir": "^9.3.0",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"fs-pull-blob-store": "^0.4.1",
"idb-pull-blob-store": "^0.5.1",
"ipfs-block": "^0.5.3",
"ipfs-block": "^0.5.4",
"ipfs-repo": "^0.11.2",
"lodash": "^4.17.2",
"ncp": "^2.0.0",
"pre-commit": "^1.2.1",
"pre-commit": "^1.2.2",
"rimraf": "^2.5.4"
},
"engines": {
"node": ">=4.0.0"
},
"dependencies": {
"async": "^2.1.4",
"cids": "^0.3.4"
"cids": "^0.3.5"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand All @@ -64,4 +64,4 @@
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>",
"wanderer <mjbecze@gmail.com>"
]
}
}
27 changes: 11 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,19 @@ module.exports = class BlockService {
}

putStream () {
let ps
if (this.isOnline()) {
// NOTE: This will have to change in order for bitswap
// to understand CID
ps = this._bitswap.putStream()
return this._bitswap.putStream()
} else {
ps = this._repo.blockstore.putStream()
return pull(
pull.map((blockAndCID) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really like to change this, currently we are going from having a Block, to this strange object, and inside bitswap back to a Block. Can we please make the Block interface sufficient so we can pass it through the whole stack?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, BlockService is blockAndCID and now bitswap is also blockAndCID, because bitswap needs to know CIDs, where do we in Bitswap move it to just Block?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like the old inefficiency in bitswap is gone with the refactor, then I'm fine with this :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I would love to have something nicer, the blockAndCID isn't my favourite, but we really can't use something as Block right now unless we 'patch' it every time to have the right CID, which won't happen when reading from the repo, and there the only identifier is the multihash. Right now, Block is really just a buffer + a convenience method that invokes multihashing, it might make sense to do what @kumavis brought up in the last call and just remove that type and do { data: cid: } objects all the way. (Still not convinced of what is simpler)

Copy link

@kumavis kumavis Dec 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ipfs-block should just wrap { data, cid }
ipld/js-ipld-block#25

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think with the info about the repo changes in go-ipfs we will have to rethink this anway.

return {
data: blockAndCID.block.data,
key: blockAndCID.cid.multihash
}
}),
this._repo.blockstore.putStream()
)
}

return pull(
pull.map((blockAndCID) => {
return {
data: blockAndCID.block.data,
key: blockAndCID.cid.multihash
}
}),
ps
)
}

get (cid, callback) {
Expand All @@ -78,7 +73,7 @@ module.exports = class BlockService {

getStream (cid) {
if (this.isOnline()) {
return this._bitswap.getStream(cid.multihash)
return this._bitswap.getStream(cid)
}

return this._repo.blockstore.getStream(cid.multihash)
Expand Down