diff --git a/packages/client/README.md b/packages/client/README.md index 2c7fe09..c5dde34 100644 --- a/packages/client/README.md +++ b/packages/client/README.md @@ -68,6 +68,33 @@ const libp2p = await createLibp2p({ await libp2p.peerRouting.findPeer(peerIdFromString('QmFoo')) ``` +### Filtering with IPIP-484 + +The client can be configured to pass filter options to the delegated routing server as defined in IPIP-484. +The filter options be set globally, by passing them to the client constructor, or on a per-request basis. + +## Example + +```typescript +import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client' +import { createLibp2p } from 'libp2p' +import { peerIdFromString } from '@libp2p/peer-id' + +// globally set filter options +const client = createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev', { + filterProtocols: ['transport-bitswap', 'unknown', 'transport-ipfs-gateway-http'], + filterAddrs: ['webtransport', 'webrtc-direct', 'wss'] +}) + +// per-request filter options +for await (const prov of getProviders(CID.parse('bafy'), { + filterProtocols: ['transport-ipfs-gateway-http'], + filterAddrs: ['!p2p-circuit'] +})) { + // ... +} +``` + # Install ```console diff --git a/packages/client/src/index.ts b/packages/client/src/index.ts index 101d88e..67b81e9 100644 --- a/packages/client/src/index.ts +++ b/packages/client/src/index.ts @@ -38,6 +38,35 @@ * // later this will use the configured HTTP gateway * await libp2p.peerRouting.findPeer(peerIdFromString('QmFoo')) * ``` + * + * ### Filtering with IPIP-484 + * + * The client can be configured to pass filter options to the delegated routing server as defined in IPIP-484. + * The filter options be set globally, by passing them to the client constructor, or on a per-request basis. + * + * @see https://github.com/ipfs/specs/pull/484 + * + * @example + * + * ```typescript + * import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client' + * import { createLibp2p } from 'libp2p' + * import { peerIdFromString } from '@libp2p/peer-id' + * + * // globally set filter options + * const client = createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev', { + * filterProtocols: ['transport-bitswap', 'unknown', 'transport-ipfs-gateway-http'], + * filterAddrs: ['webtransport', 'webrtc-direct', 'wss'] + * }) + * + * // per-request filter options + * for await (const prov of getProviders(CID.parse('bafy'), { + * filterProtocols: ['transport-ipfs-gateway-http'], + * filterAddrs: ['!p2p-circuit'] + * })) { + * // ... + * } + * ``` */ import { DefaultDelegatedRoutingV1HttpApiClient } from './client.js'