Skip to content
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

fix: support reading identity cids #429

Merged
merged 1 commit into from
Feb 12, 2024
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
2 changes: 1 addition & 1 deletion packages/car/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"@helia/unixfs": "^3.0.0",
"@ipld/dag-pb": "^4.0.8",
"aegir": "^42.2.2",
"blockstore-core": "^4.3.10",
"blockstore-core": "^4.4.0",
"ipfs-unixfs-importer": "^15.2.4",
"it-to-buffer": "^4.0.5"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dag-cbor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@
},
"devDependencies": {
"aegir": "^42.2.2",
"blockstore-core": "^4.3.10"
"blockstore-core": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/dag-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@
},
"devDependencies": {
"aegir": "^42.2.2",
"blockstore-core": "^4.3.10"
"blockstore-core": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/helia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@libp2p/webrtc": "^4.0.17",
"@libp2p/websockets": "^8.0.13",
"@libp2p/webtransport": "^4.0.17",
"blockstore-core": "^4.3.10",
"blockstore-core": "^4.4.0",
"datastore-core": "^9.2.7",
"interface-blockstore": "^5.2.9",
"interface-datastore": "^8.2.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@helia/interface": "^4.0.0",
"@helia/routers": "^1.0.0",
"@helia/utils": "^0.0.1",
"blockstore-core": "^4.3.10",
"blockstore-core": "^4.4.0",
"datastore-core": "^9.2.7"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,6 @@
},
"devDependencies": {
"aegir": "^42.2.2",
"blockstore-core": "^4.3.10"
"blockstore-core": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/mfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"devDependencies": {
"@ipld/dag-pb": "^4.0.8",
"aegir": "^42.2.2",
"blockstore-core": "^4.3.10",
"blockstore-core": "^4.4.0",
"datastore-core": "^9.2.7",
"delay": "^6.0.0",
"it-all": "^3.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/strings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,6 @@
},
"devDependencies": {
"aegir": "^42.2.2",
"blockstore-core": "^4.3.10"
"blockstore-core": "^4.4.0"
}
}
2 changes: 1 addition & 1 deletion packages/unixfs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
},
"devDependencies": {
"aegir": "^42.2.2",
"blockstore-core": "^4.3.10",
"blockstore-core": "^4.4.0",
"delay": "^6.0.0",
"iso-url": "^1.2.1",
"it-all": "^3.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@libp2p/peer-collections": "^5.1.5",
"@libp2p/utils": "^5.2.3",
"any-signal": "^4.1.1",
"blockstore-core": "^4.4.0",
"cborg": "^4.0.8",
"interface-blockstore": "^5.2.9",
"interface-datastore": "^8.2.10",
Expand All @@ -78,7 +79,6 @@
"devDependencies": {
"@types/sinon": "^17.0.3",
"aegir": "^42.2.2",
"blockstore-core": "^4.3.10",
"datastore-core": "^9.2.7",
"delay": "^6.0.0",
"it-all": "^3.0.4",
Expand Down
7 changes: 6 additions & 1 deletion packages/utils/src/utils/networked-storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { CodeError, start, stop } from '@libp2p/interface'
import { anySignal } from 'any-signal'
import { IdentityBlockstore } from 'blockstore-core/identity'
import { TieredBlockstore } from 'blockstore-core/tiered'
import filter from 'it-filter'
import forEach from 'it-foreach'
import { CustomProgressEvent, type ProgressOptions } from 'progress-events'
Expand Down Expand Up @@ -47,7 +49,10 @@ export class NetworkedStorage implements Blocks, Startable {
*/
constructor (components: NetworkedStorageComponents) {
this.log = components.logger.forComponent('helia:networked-storage')
this.child = components.blockstore
this.child = new TieredBlockstore([
new IdentityBlockstore(),
components.blockstore
])
this.blockRetrievers = (components.blockBrokers ?? []).filter(isBlockRetriever)
this.blockAnnouncers = (components.blockBrokers ?? []).filter(isBlockAnnouncer)
this.hashers = components.hashers ?? {}
Expand Down
13 changes: 12 additions & 1 deletion packages/utils/test/utils/networked-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ import { MemoryBlockstore } from 'blockstore-core'
import delay from 'delay'
import all from 'it-all'
import drain from 'it-drain'
import { CID } from 'multiformats/cid'
import * as raw from 'multiformats/codecs/raw'
import { identity } from 'multiformats/hashes/identity'
import Sinon from 'sinon'
import { type StubbedInstance, stubInterface } from 'sinon-ts'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { defaultHashers } from '../../src/utils/default-hashers.js'
import { NetworkedStorage } from '../../src/utils/networked-storage.js'
import { createBlock } from '../fixtures/create-block.js'
import type { BlockAnnouncer, BlockRetriever } from '@helia/interface/blocks'
import type { Blockstore } from 'interface-blockstore'
import type { CID } from 'multiformats/cid'

describe('networked-storage', () => {
let storage: NetworkedStorage
Expand Down Expand Up @@ -185,4 +188,12 @@ describe('networked-storage', () => {
expect(await blockstore.has(blocks[i].cid)).to.be.true()
}
})

it('supports identity CIDs', async () => {
const data = uint8ArrayFromString('hello world')
const cid = CID.createV1(identity.code, identity.digest(data))

const block = await storage.get(cid)
expect(uint8ArrayToString(block)).to.equal('hello world')
})
})
Loading