Skip to content

Commit c988cd7

Browse files
authored
fix: add routing field to providers (#180)
Adds field to report where provider came from
1 parent b243313 commit c988cd7

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

packages/client/src/routings.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CID } from 'multiformats/cid'
66
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
77
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
88
import type { DelegatedRoutingV1HttpApiClient } from './index.js'
9-
import type { ContentRouting, PeerRouting, AbortOptions, PeerId, PeerInfo } from '@libp2p/interface'
9+
import type { ContentRouting, PeerRouting, AbortOptions, PeerId, PeerInfo, Provider } from '@libp2p/interface'
1010

1111
const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
1212

@@ -24,12 +24,13 @@ export class DelegatedRoutingV1HttpApiClientContentRouting implements ContentRou
2424
this.client = client
2525
}
2626

27-
async * findProviders (cid: CID, options: AbortOptions = {}): AsyncIterable<PeerInfo> {
27+
async * findProviders (cid: CID, options: AbortOptions = {}): AsyncIterable<Provider> {
2828
try {
2929
yield * map(this.client.getProviders(cid, options), (record) => {
3030
return {
3131
id: record.ID,
32-
multiaddrs: record.Addrs ?? []
32+
multiaddrs: record.Addrs ?? [],
33+
routing: 'delegated-http-routing-v1'
3334
}
3435
})
3536
} catch (err) {

packages/server/test/index.spec.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CID } from 'multiformats'
99
import { stubInterface } from 'sinon-ts'
1010
import { createDelegatedRoutingV1HttpApiServer } from '../src/index.js'
1111
import type { Helia } from '@helia/interface'
12-
import type { PeerInfo } from '@libp2p/interface'
12+
import type { PeerInfo, Provider } from '@libp2p/interface'
1313
import type { FastifyInstance } from 'fastify'
1414
import type { StubbedInstance } from 'sinon-ts'
1515

@@ -94,17 +94,19 @@ describe('delegated-routing-v1-http-api-server', () => {
9494
})
9595

9696
it('GET providers returns providers', async () => {
97-
const provider1: PeerInfo = {
97+
const provider1: Provider = {
9898
id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')),
9999
multiaddrs: [
100100
multiaddr('/ip4/123.123.123.123/tcp/123')
101-
]
101+
],
102+
routing: 'test-routing'
102103
}
103-
const provider2: PeerInfo = {
104+
const provider2: Provider = {
104105
id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')),
105106
multiaddrs: [
106107
multiaddr('/ip4/123.123.123.123/tcp/123')
107-
]
108+
],
109+
routing: 'test-routing'
108110
}
109111

110112
helia.routing.findProviders = async function * () {
@@ -129,17 +131,19 @@ describe('delegated-routing-v1-http-api-server', () => {
129131
})
130132

131133
it('GET providers returns provider stream', async () => {
132-
const provider1: PeerInfo = {
134+
const provider1: Provider = {
133135
id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')),
134136
multiaddrs: [
135137
multiaddr('/ip4/123.123.123.123/tcp/123')
136-
]
138+
],
139+
routing: 'test-routing'
137140
}
138-
const provider2: PeerInfo = {
141+
const provider2: Provider = {
139142
id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')),
140143
multiaddrs: [
141144
multiaddr('/ip4/123.123.123.123/tcp/123')
142-
]
145+
],
146+
routing: 'test-routing'
143147
}
144148

145149
helia.routing.findProviders = async function * () {

0 commit comments

Comments
 (0)