Skip to content

Commit

Permalink
fix: apply dns resolvers corectly (#412)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel N <2color@users.noreply.github.com>
  • Loading branch information
2color and 2color authored Oct 31, 2024
1 parent 4915b34 commit ba0ede9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/lib/get-verified-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { keychain } from '@libp2p/keychain'
import { ping } from '@libp2p/ping'
import { webSockets } from '@libp2p/websockets'
import { webTransport } from '@libp2p/webtransport'
import { dns } from '@multiformats/dns'
import { dns, type DNSResolvers } from '@multiformats/dns'
import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'
import { createHelia, type Helia, type Routing } from 'helia'
import { createLibp2p, type Libp2pOptions } from 'libp2p'
Expand All @@ -40,10 +40,11 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
}

// set dns resolver instances
const dnsResolvers = {}
const dnsResolvers: DNSResolvers = {}
for (const [key, value] of Object.entries(config.dnsJsonResolvers)) {
dnsResolvers[key] = dnsJsonOverHttps(value)
}
const dnsConfig = dns({ resolvers: dnsResolvers })

const blockBrokers: Array<(components: any) => BlockBroker> = []

Expand All @@ -56,14 +57,15 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
// If we are using websocket or webtransport, we need to instantiate libp2p
blockBrokers.push(bitswap())
const libp2pOptions = await libp2pDefaults(config)
libp2pOptions.dns = dnsConfig
const libp2p = await createLibp2p(libp2pOptions)
routers.push(libp2pRouting(libp2p))

helia = await createHelia({
libp2p,
routers,
blockBrokers,
dns: dns(dnsResolvers)
dns: dnsConfig
})
} else {
config.routers.forEach((router) => {
Expand All @@ -79,7 +81,7 @@ export async function getVerifiedFetch (config: ConfigDb, logger: ComponentLogge
helia = await createHeliaHTTP({
routers,
blockBrokers,
dns: dns(dnsResolvers)
dns: dnsConfig
})
}

Expand Down

0 comments on commit ba0ede9

Please sign in to comment.