Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

fix: use multihash bytes for provide messages keys #405

Merged
merged 1 commit into from
Dec 7, 2022
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 src/content-routing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class ContentRouting {
// Add peer as provider
await this.providers.addProvider(key, this.components.peerId)

const msg = new Message(MESSAGE_TYPE.ADD_PROVIDER, key.bytes, 0)
const msg = new Message(MESSAGE_TYPE.ADD_PROVIDER, key.multihash.bytes, 0)
msg.providerPeers = [{
id: this.components.peerId,
multiaddrs,
Expand Down
2 changes: 1 addition & 1 deletion test/kad-dht.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ describe('KadDHT', () => {

// Expect an ADD_PROVIDER message to be sent to each peer for each value
const fn = dhts[3].lan.network.sendMessage
const valuesBuffs = values.map(v => v.cid.bytes)
const valuesBuffs = values.map(v => v.cid.multihash.bytes)
// @ts-expect-error fn is a spy
const calls = fn.getCalls().map(c => c.args)

Expand Down
4 changes: 3 additions & 1 deletion test/utils/create-values.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { CID } from 'multiformats/cid'
import * as raw from 'multiformats/codecs/raw'

import { sha256 } from 'multiformats/hashes/sha2'
import { randomBytes } from '@libp2p/crypto'

Expand All @@ -13,7 +15,7 @@ export async function createValues (length: number): Promise<Value[]> {
const bytes = randomBytes(32)
const h = await sha256.digest(bytes)
return {
cid: CID.createV0(h),
cid: CID.createV1(raw.code, h),
value: bytes
}
})
Expand Down