Skip to content

Commit b169d44

Browse files
committed
docs: example showing ipip-484 client filtering
1 parent 61cbbb2 commit b169d44

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

packages/client/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,33 @@ const libp2p = await createLibp2p({
6868
await libp2p.peerRouting.findPeer(peerIdFromString('QmFoo'))
6969
```
7070

71+
### Filtering with IPIP-484
72+
73+
The client can be configured to pass filter options to the delegated routing server as defined in IPIP-484.
74+
The filter options be set globally, by passing them to the client constructor, or on a per-request basis.
75+
76+
## Example
77+
78+
```typescript
79+
import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
80+
import { createLibp2p } from 'libp2p'
81+
import { peerIdFromString } from '@libp2p/peer-id'
82+
83+
// globally set filter options
84+
const client = createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev', {
85+
filterProtocols: ['transport-bitswap', 'unknown', 'transport-ipfs-gateway-http'],
86+
filterAddrs: ['webtransport', 'webrtc-direct', 'wss']
87+
})
88+
89+
// per-request filter options
90+
for await (const peer of client.getPeers(peerIdFromString('QmFoo'), {
91+
filterProtocols: ['transport-ipfs-gateway-http'],
92+
filterAddrs: ['!p2p-circuit']
93+
})) {
94+
// ...
95+
}
96+
```
97+
7198
# Install
7299

73100
```console

packages/client/src/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@
3838
* // later this will use the configured HTTP gateway
3939
* await libp2p.peerRouting.findPeer(peerIdFromString('QmFoo'))
4040
* ```
41+
*
42+
* ### Filtering with IPIP-484
43+
*
44+
* The client can be configured to pass filter options to the delegated routing server as defined in IPIP-484.
45+
* The filter options be set globally, by passing them to the client constructor, or on a per-request basis.
46+
*
47+
* @see https://github.com/ipfs/specs/pull/484
48+
*
49+
* @example
50+
*
51+
* ```typescript
52+
* import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
53+
* import { createLibp2p } from 'libp2p'
54+
* import { peerIdFromString } from '@libp2p/peer-id'
55+
*
56+
* // globally set filter options
57+
* const client = createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev', {
58+
* filterProtocols: ['transport-bitswap', 'unknown', 'transport-ipfs-gateway-http'],
59+
* filterAddrs: ['webtransport', 'webrtc-direct', 'wss']
60+
* })
61+
*
62+
* // per-request filter options
63+
* for await (const peer of client.getPeers(peerIdFromString('QmFoo'), {
64+
* filterProtocols: ['transport-ipfs-gateway-http'],
65+
* filterAddrs: ['!p2p-circuit']
66+
* })) {
67+
* // ...
68+
* }
69+
* ```
4170
*/
4271

4372
import { DefaultDelegatedRoutingV1HttpApiClient } from './client.js'

0 commit comments

Comments
 (0)