bun icon indicating copy to clipboard operation
bun copied to clipboard

DoH dns lookup with cloudflare

Open SheetJSDev opened this issue 3 years ago • 1 comments

This dns fallback uses cloudflare DoH to implement a basic lookup

SheetJSDev avatar Jul 31 '22 02:07 SheetJSDev

The unexpected implementation structure stems from the actual DNS API https://nodejs.org/dist/latest-v18.x/docs/api/dns.html .

Node v6 only had the top-level methods like dns.resolve. Node v8 added the Resolver class and v10 added the promises API

Constants

Constants are in a separate file because each constant is actually exported twice!

https://nodejs.org/dist/latest-v18.x/docs/api/dns.html#error-codes

The dnsPromises API also exports the above error codes, e.g., dnsPromises.NODATA.

For example, the main dns module has to export the constant CONNREFUSED AND it must be an element in the promises export. The separate script reduces line noise but it can be duplicated in the main script if that is preferable.

Resolver Classes and Methods

The dns module exposes a resolve4 function AND the Resolver class has a resolve4 method. The main difference is that the former uses the default settings (tuned with dns.setServers) and the latter uses instance settings (tuned with the Resolver#setServers method). The exported functions are neatly implemented using an internal instance of Resolver and exposing bound methods.

SheetJSDev avatar Jul 31 '22 08:07 SheetJSDev