|
1 | 1 | import { bytesToUtf8 } from "@waku/utils/bytes";
|
2 | 2 | import debug from "debug";
|
3 |
| -import { Endpoint, query, toEndpoint } from "dns-query"; |
| 3 | +import { Endpoint, query, wellknown } from "dns-query"; |
4 | 4 |
|
5 | 5 | import { DnsClient } from "./dns.js";
|
6 | 6 |
|
7 | 7 | const log = debug("waku:dns-over-https");
|
8 | 8 |
|
9 | 9 | export class DnsOverHttps implements DnsClient {
|
10 |
| - /** |
11 |
| - * Default endpoints to use for DNS queries. |
12 |
| - * Taken from https://github.com/martinheidegger/dns-query as static data |
13 |
| - * to avoid dynamic queries. |
14 |
| - * |
15 |
| - * To dynamically retrieve other endpoints, use https://github.com/martinheidegger/dns-query#well-known-endpoints |
16 |
| - */ |
17 |
| - static DefaultEndpoints: Endpoint[] = [ |
18 |
| - toEndpoint({ |
19 |
| - name: "AhaDNS", |
20 |
| - protocol: "https:", |
21 |
| - host: "doh.la.ahadns.net", |
22 |
| - ipv4: "45.67.219.208", |
23 |
| - }), |
24 |
| - toEndpoint({ |
25 |
| - name: "cloudflare", |
26 |
| - protocol: "https:", |
27 |
| - host: "dns.cloudflare.com", |
28 |
| - ipv4: "1.0.0.1", |
29 |
| - }), |
30 |
| - ]; |
31 |
| - |
32 | 10 | /**
|
33 | 11 | * Create new Dns-Over-Http DNS client.
|
34 | 12 | *
|
35 | 13 | * @param endpoints The endpoints for Dns-Over-Https queries;
|
36 |
| - * Defaults to [[DnsOverHttps.DefaultEndpoints]]. |
| 14 | + * Defaults to using dns-query's API.. |
37 | 15 | * @param retries Retries if a given endpoint fails.
|
38 | 16 | *
|
39 | 17 | * @throws {code: string} If DNS query fails.
|
40 | 18 | */
|
41 |
| - public constructor( |
42 |
| - private endpoints: Endpoint[] = DnsOverHttps.DefaultEndpoints, |
| 19 | + public static async create( |
| 20 | + endpoints?: Endpoint[], |
| 21 | + retries?: number |
| 22 | + ): Promise<DnsOverHttps> { |
| 23 | + const _endpoints = endpoints ?? (await wellknown.endpoints("doh")); |
| 24 | + |
| 25 | + return new DnsOverHttps(_endpoints, retries); |
| 26 | + } |
| 27 | + |
| 28 | + private constructor( |
| 29 | + private endpoints: Endpoint[], |
43 | 30 | private retries: number = 3
|
44 | 31 | ) {}
|
45 | 32 |
|
|
0 commit comments