Skip to content

Commit

Permalink
fix: add dht validators/selectors for ipns
Browse files Browse the repository at this point in the history
This allows use of `@helia/ipns` without any further configuration.
  • Loading branch information
achingbrain committed May 24, 2023
1 parent 1ac389c commit 274e260
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/helia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
"interface-datastore": "^8.0.0",
"interface-store": "^5.0.1",
"ipfs-bitswap": "^18.0.0",
"ipns": "^6.0.0",
"it-all": "^3.0.1",
"it-drain": "^3.0.1",
"it-filter": "^3.0.1",
Expand Down
10 changes: 9 additions & 1 deletion packages/helia/src/utils/libp2p.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { mplex } from '@libp2p/mplex'
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
import { webTransport } from '@libp2p/webtransport'
import { ipnsSelector } from 'ipns/selector'
import { ipnsValidator } from 'ipns/validator'
import { createLibp2p as create } from 'libp2p'
import { autoNATService } from 'libp2p/autonat'
import { circuitRelayTransport, circuitRelayServer } from 'libp2p/circuit-relay'
Expand Down Expand Up @@ -52,7 +54,13 @@ export async function createLibp2p (opts: CreateLibp2pOptions): Promise<Libp2p<{
autoNAT: autoNATService(),
pubsub: gossipsub(),
dht: kadDHT({
clientMode: true
clientMode: true,
validators: {
ipns: ipnsValidator
},
selectors: {
ipns: ipnsSelector
}
}),
relay: circuitRelayServer({
advertise: true
Expand Down
11 changes: 10 additions & 1 deletion packages/helia/src/utils/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { mdns } from '@libp2p/mdns'
import { mplex } from '@libp2p/mplex'
import { tcp } from '@libp2p/tcp'
import { webSockets } from '@libp2p/websockets'
import { ipnsSelector } from 'ipns/selector'
import { ipnsValidator } from 'ipns/validator'
import { createLibp2p as create } from 'libp2p'
import { autoNATService } from 'libp2p/autonat'
import { circuitRelayTransport, circuitRelayServer, type CircuitRelayService } from 'libp2p/circuit-relay'
Expand Down Expand Up @@ -57,7 +59,14 @@ export async function createLibp2p (opts: CreateLibp2pOptions): Promise<Libp2p<{
autoNAT: autoNATService(),
upnp: uPnPNATService(),
pubsub: gossipsub(),
dht: kadDHT(),
dht: kadDHT({
validators: {
ipns: ipnsValidator
},
selectors: {
ipns: ipnsSelector
}
}),
relay: circuitRelayServer({
advertise: true
})
Expand Down

0 comments on commit 274e260

Please sign in to comment.