Skip to content
Open
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
12 changes: 6 additions & 6 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const defaultValues = {
}

export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV1HttpApiClient {
public endpoint: URL
private started: boolean
private readonly httpQueue: PQueue
private readonly shutDownController: AbortController
private readonly clientUrl: URL
private readonly timeout: number
private readonly contentRouting: ContentRouting
private readonly peerRouting: PeerRouting
Expand All @@ -51,7 +51,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
concurrency: init.concurrentRequests ?? defaultValues.concurrentRequests
})
this.inFlightRequests = new Map() // Tracks in-flight requests to avoid duplicate requests
this.clientUrl = url instanceof URL ? url : new URL(url)
this.endpoint = url instanceof URL ? url : new URL(url)
this.timeout = init.timeout ?? defaultValues.timeout
this.filterAddrs = init.filterAddrs
this.filterProtocols = init.filterProtocols
Expand Down Expand Up @@ -118,7 +118,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
await onStart.promise

// https://specs.ipfs.tech/routing/http-routing-v1/
const url = new URL(`${this.clientUrl}routing/v1/providers/${cid}`)
const url = new URL(`${this.endpoint}routing/v1/providers/${cid}`)

this.#addFilterParams(url, options.filterAddrs, options.filterProtocols)
const getOptions = { headers: { Accept: 'application/x-ndjson' }, signal }
Expand Down Expand Up @@ -197,7 +197,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
await onStart.promise

// https://specs.ipfs.tech/routing/http-routing-v1/
const url = new URL(`${this.clientUrl}routing/v1/peers/${peerId.toCID().toString()}`)
const url = new URL(`${this.endpoint}routing/v1/peers/${peerId.toCID().toString()}`)
this.#addFilterParams(url, options.filterAddrs, options.filterProtocols)

const getOptions = { headers: { Accept: 'application/x-ndjson' }, signal }
Expand Down Expand Up @@ -264,7 +264,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
})

// https://specs.ipfs.tech/routing/http-routing-v1/
const resource = `${this.clientUrl}routing/v1/ipns/${libp2pKey}`
const resource = `${this.endpoint}routing/v1/ipns/${libp2pKey}`

try {
await onStart.promise
Expand Down Expand Up @@ -336,7 +336,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
})

// https://specs.ipfs.tech/routing/http-routing-v1/
const resource = `${this.clientUrl}routing/v1/ipns/${libp2pKey}`
const resource = `${this.endpoint}routing/v1/ipns/${libp2pKey}`

try {
await onStart.promise
Expand Down
5 changes: 5 additions & 0 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ export type GetProvidersOptions = FilterOptions & AbortOptions
export type GetPeersOptions = FilterOptions & AbortOptions

export interface DelegatedRoutingV1HttpApiClient {
/**
* Where this client sends routing requests
*/
endpoint: URL

/**
* Returns an async generator of {@link PeerRecord}s that can provide the
* content for the passed {@link CID}
Expand Down