ipfs / helia

An implementation of IPFS in JavaScript
https://helia.io
Other
814 stars 81 forks source link

feat: customize ipns dnsResolvers #445

Closed SgtPooki closed 4 months ago

SgtPooki commented 4 months ago

Title

feat(verified-fetch): customize ipns dnsResolvers

Description

Adds the ability to customize dns resolvers to verified-fetch.

Users should then be able to add custom doh resolvers to helia-service-worker-gateway as mentioned at https://github.com/ipfs-shipyard/helia-service-worker-gateway/issues/22

Notes & open questions

Change checklist

2color commented 4 months ago

I just realised we have another problem now. We cannot instantiate @helia/verified-fetch with a custom instance of Helia and also customising dnsResolver.

This came up in the SW Gateway, where we now are faced with a choice:

  1. Either we instantiate Helia with the IDBBlockstore in the service worker but have no way to customise the dnsResolvers
  2. We customise the dnsResolvers (along with gateways and routers) but cannot use the IDBBlockstore.

This is how they compare:

// option 1
  const helia = await createHeliaHTTP({
    blockstore,
    datastore,
    blockBrokers: [
      trustlessGateway({
        gateways: [...config.gateways, ]
      })
    ],
    routers: [...config.routers, 'https://delegated-ipfs.dev'].map(rUrl => delegatedHTTPRouting(rUrl))
  })

  const verifiedFetch = await createVerifiedFetch(helia, { contentTypeParser })

// ---- OR

// option 2
  const verifiedFetch = await createVerifiedFetch({
    gateways: [...config.gateways, 'https://trustless-gateway.link'],
    routers: [...config.routers, 'https://delegated-ipfs.dev'],
    dnsResolvers: ['https://delegated-ipfs.dev/dns-query'].map(dnsJsonOverHttps)
  }, {
    contentTypeParser
  })

This seems like something we'd want to address. Naively we could move dnsResolvers to the second parameter and frame it as follows: the first config param is to customise Helia or pass a Helia instance, while the second is to customise verified-fetch specific config.

Any thoughts @SgtPooki @achingbrain ?