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

Commit d7e7b5d

Browse files
authored
fix: use multihash bytes for provide message keys (#405)
This fixes a bug where `ADD_PROVIDER` message keys were CID bytes instead of multihash bytes, and changes the CIDs generated in tests to be V1s with `raw` codec instead of V0s so that the difference is actually tested. Fixes #381
1 parent 9815e8e commit d7e7b5d

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/content-routing/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class ContentRouting {
6464
// Add peer as provider
6565
await this.providers.addProvider(key, this.components.peerId)
6666

67-
const msg = new Message(MESSAGE_TYPE.ADD_PROVIDER, key.bytes, 0)
67+
const msg = new Message(MESSAGE_TYPE.ADD_PROVIDER, key.multihash.bytes, 0)
6868
msg.providerPeers = [{
6969
id: this.components.peerId,
7070
multiaddrs,

test/kad-dht.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ describe('KadDHT', () => {
414414

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

test/utils/create-values.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { CID } from 'multiformats/cid'
2+
import * as raw from 'multiformats/codecs/raw'
3+
24
import { sha256 } from 'multiformats/hashes/sha2'
35
import { randomBytes } from '@libp2p/crypto'
46

@@ -13,7 +15,7 @@ export async function createValues (length: number): Promise<Value[]> {
1315
const bytes = randomBytes(32)
1416
const h = await sha256.digest(bytes)
1517
return {
16-
cid: CID.createV0(h),
18+
cid: CID.createV1(raw.code, h),
1719
value: bytes
1820
}
1921
})

0 commit comments

Comments
 (0)