From eb6369806e5b9bf2b5e80f7dde0516478b40c4b9 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 12 Mar 2024 10:34:32 +0100 Subject: [PATCH] feat: expose .dns property on @helia/interface Exposes a `.dns` property on the Helia interface for use with other modules such as @helia/ipns. Refs: https://github.com/ipfs/helia-verified-fetch/pull/13#issuecomment-1983944596 --- packages/interface/package.json | 1 + packages/interface/src/index.ts | 7 +++++++ packages/utils/src/index.ts | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/packages/interface/package.json b/packages/interface/package.json index 6a3fee995..b54609812 100644 --- a/packages/interface/package.json +++ b/packages/interface/package.json @@ -71,6 +71,7 @@ }, "dependencies": { "@libp2p/interface": "^1.1.4", + "@multiformats/dns": "^1.0.1", "interface-blockstore": "^5.2.10", "interface-datastore": "^8.2.11", "interface-store": "^5.1.8", diff --git a/packages/interface/src/index.ts b/packages/interface/src/index.ts index a12024ccb..303dcea1a 100644 --- a/packages/interface/src/index.ts +++ b/packages/interface/src/index.ts @@ -18,6 +18,7 @@ import type { Blocks } from './blocks.js' import type { Pins } from './pins.js' import type { Routing } from './routing.js' import type { AbortOptions, ComponentLogger } from '@libp2p/interface' +import type { DNS } from '@multiformats/dns' import type { Datastore } from 'interface-datastore' import type { MultihashHasher } from 'multiformats' import type { CID } from 'multiformats/cid' @@ -67,6 +68,12 @@ export interface Helia { */ hashers: Record + /** + * The DNS property can be used to perform lookups of various record types and + * will use a resolver appropriate to the current platform. + */ + dns: DNS + /** * Starts the Helia node */ diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 7890f8795..f0d84cd08 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -19,6 +19,7 @@ import { contentRoutingSymbol, peerRoutingSymbol, start, stop } from '@libp2p/interface' import { defaultLogger } from '@libp2p/logger' +import { dns } from '@multiformats/dns' import drain from 'it-drain' import { CustomProgressEvent } from 'progress-events' import { PinsImpl } from './pins.js' @@ -32,6 +33,7 @@ import type { DAGWalker, GCOptions, Helia as HeliaInterface, Routing } from '@he import type { BlockBroker } from '@helia/interface/blocks' import type { Pins } from '@helia/interface/pins' import type { ComponentLogger, Logger } from '@libp2p/interface' +import type { DNS } from '@multiformats/dns' import type { Blockstore } from 'interface-blockstore' import type { Datastore } from 'interface-datastore' import type { CID } from 'multiformats/cid' @@ -103,6 +105,11 @@ export interface HeliaInit { * Components used by subclasses */ components?: Record + + /** + * An optional DNS implementation used the perform queries. + */ + dns?: DNS } interface Components { @@ -112,6 +119,7 @@ interface Components { dagWalkers: Record logger: ComponentLogger blockBrokers: BlockBroker[] + dns: DNS } export class Helia implements HeliaInterface { @@ -122,6 +130,7 @@ export class Helia implements HeliaInterface { public routing: Routing public dagWalkers: Record public hashers: Record + public dns: DNS private readonly log: Logger constructor (init: HeliaInit) { @@ -129,6 +138,7 @@ export class Helia implements HeliaInterface { this.log = this.logger.forComponent('helia') this.hashers = defaultHashers(init.hashers) this.dagWalkers = defaultDagWalkers(init.dagWalkers) + this.dns = init.dns ?? dns() const components: Components = { blockstore: init.blockstore, @@ -137,6 +147,7 @@ export class Helia implements HeliaInterface { dagWalkers: this.dagWalkers, logger: this.logger, blockBrokers: [], + dns: this.dns, ...(init.components ?? {}) }