Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: use custom DNS resolver in @helia/ipns for DNSLink #466

Merged
merged 11 commits into from
Mar 14, 2024
3 changes: 2 additions & 1 deletion packages/helia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@
"@libp2p/webrtc": "^4.0.20",
"@libp2p/websockets": "^8.0.16",
"@libp2p/webtransport": "^4.0.20",
"@multiformats/dns": "^1.0.1",
"blockstore-core": "^4.4.0",
"datastore-core": "^9.2.9",
"interface-blockstore": "^5.2.10",
"interface-datastore": "^8.2.11",
"ipns": "^9.0.0",
"libp2p": "^1.2.4",
"libp2p": "^1.3.0",
"multiformats": "^13.1.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/helia/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export async function createHelia (init: Partial<HeliaInit> = {}): Promise<Helia
libp2p = await createLibp2p<DefaultLibp2pServices>({
...init,
libp2p: {
dns: init.dns,
...init.libp2p,

// ignore the libp2p start parameter as it should be on the main init
Expand Down
1 change: 1 addition & 0 deletions packages/helia/src/utils/libp2p-defaults.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions<DefaultLibp2pServices> {
return {
peerId: options.peerId,
dns: options.dns,
addresses: {
listen: [
'/webrtc'
Expand Down
1 change: 1 addition & 0 deletions packages/helia/src/utils/libp2p-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface DefaultLibp2pServices extends Record<string, unknown> {
export function libp2pDefaults (options: Libp2pDefaultsOptions = {}): Libp2pOptions<DefaultLibp2pServices> {
return {
peerId: options.peerId,
dns: options.dns,
addresses: {
listen: [
'/ip4/0.0.0.0/tcp/0',
Expand Down
2 changes: 2 additions & 0 deletions packages/helia/src/utils/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { libp2pDefaults } from './libp2p-defaults.js'
import type { DefaultLibp2pServices } from './libp2p-defaults.js'
import type { ComponentLogger, Libp2p, PeerId } from '@libp2p/interface'
import type { Keychain, KeychainInit } from '@libp2p/keychain'
import type { DNS } from '@multiformats/dns'
import type { Datastore } from 'interface-datastore'
import type { Libp2pOptions } from 'libp2p'

Expand All @@ -20,6 +21,7 @@ export interface CreateLibp2pOptions<T extends Record<string, unknown>> {
export interface Libp2pDefaultsOptions {
peerId?: PeerId
keychain?: KeychainInit
dns?: DNS
}

export async function createLibp2p <T extends Record<string, unknown> = DefaultLibp2pServices> (options: CreateLibp2pOptions<T>): Promise<Libp2p<T>> {
Expand Down
1 change: 1 addition & 0 deletions packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions packages/interface/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -67,6 +68,12 @@ export interface Helia {
*/
hashers: Record<number, MultihashHasher>

/**
* 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
*/
Expand Down
45 changes: 45 additions & 0 deletions packages/interop/src/ipns-dnslink.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-env mocha */

import { ipns } from '@helia/ipns'
import { expect } from 'aegir/chai'
import { createHeliaNode } from './fixtures/create-helia.js'
import type { IPNS } from '@helia/ipns'
import type { HeliaLibp2p } from 'helia'

const TEST_DOMAINS: string[] = [
'ipfs.io',
'docs.ipfs.tech',
'en.wikipedia-on-ipfs.org',
'blog.libp2p.io',
'consensuslab.world',
'n0.computer',
'protocol.ai',
'research.protocol.ai',
'probelab.io',
'singularity.storage',
'saturn.tech'
]

describe('@helia/ipns - dnslink', () => {
let helia: HeliaLibp2p
let name: IPNS

beforeEach(async () => {
helia = await createHeliaNode()
name = ipns(helia)
})

afterEach(async () => {
if (helia != null) {
await helia.stop()
}
})

TEST_DOMAINS.forEach(domain => {
it(`should resolve ${domain}`, async () => {
const result = await name.resolveDNSLink(domain)

expect(result).to.have.property('cid')
})
})
})
5 changes: 1 addition & 4 deletions packages/ipns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,10 @@
"@libp2p/kad-dht": "^12.0.8",
"@libp2p/logger": "^4.0.7",
"@libp2p/peer-id": "^4.0.7",
"dns-over-http-resolver": "^3.0.2",
"dns-packet": "^5.6.1",
"hashlru": "^2.3.0",
"@multiformats/dns": "^1.0.1",
"interface-datastore": "^8.2.11",
"ipns": "^9.0.0",
"multiformats": "^13.1.0",
"p-queue": "^8.0.1",
"progress-events": "^1.0.0",
"uint8arrays": "^5.0.2"
},
Expand Down
9 changes: 0 additions & 9 deletions packages/ipns/src/dns-resolvers/default.ts

This file was deleted.

90 changes: 0 additions & 90 deletions packages/ipns/src/dns-resolvers/dns-json-over-https.ts

This file was deleted.

146 changes: 0 additions & 146 deletions packages/ipns/src/dns-resolvers/dns-over-https.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/ipns/src/dns-resolvers/index.ts

This file was deleted.

Loading
Loading