Giter VIP home page Giter VIP logo

Comments (16)

lokesh411 avatar lokesh411 commented on May 29, 2024 1

One question, would we be using cloudflare or google DoH APIs for this (Ex.: https://cloudflare-dns.com/dns-query). Interested to contribute here

from cacheable-lookup.

szmarczak avatar szmarczak commented on May 29, 2024

I think the CloudFlare one is a good start to implement, then we can do something like this:

const cacheable = new CacheableLookup();

cacheable.servers = [
	  '8.8.8.8', // DNS over UDP/TCP
	  'https://1.1.1.1/dns-query', // DNS over HTTPS
];

There's a spec at https://datatracker.ietf.org/doc/html/rfc8484


I'd do this by storing HTTP/2 sessions in an object (key would be a string starting with https://). We can detect cacheable.servers changes in

set servers(servers) {
this.clear();
this._resolver.setServers(servers);
}

so when it's updated, we close sessions that are no longer required and open new ones if there shall be. Then when a user makes a DNS request

async _resolve(hostname) {

we simply go through the list and send a HTTP/2 request to the DoH server and handle that. Note that dns.Resolver doesn't accept DoH servers so we need to filter the list before calling resolver.setServers.


It's possible that there may be multiple DoH servers. This can be quite a hassle, so no need to do this all in one PR.

from cacheable-lookup.

lokesh411 avatar lokesh411 commented on May 29, 2024

Thanks, would go through the specification once, DoH queries should be round robin if multiple DoH servers are given right?

from cacheable-lookup.

szmarczak avatar szmarczak commented on May 29, 2024

No, those should be fallback servers. As per Node.js docs:

Fallback DNS servers will only be used if the earlier ones time out or result in some other error.

from cacheable-lookup.

lokesh411 avatar lokesh411 commented on May 29, 2024

Got it, thanks

from cacheable-lookup.

Kikobeats avatar Kikobeats commented on May 29, 2024

I created doh-resolver to use DNS-over-HTTPS as resolver with cacheable-lookup:

const CacheableLookup = require('cacheable-lookup')
const DoHResolver = require('doh-resolver')
const https = require('https')

const resolver = new DoHResolver({ servers: ['1.1.1.1', '8.8.8.8'] })

const cacheable = new CacheableLookup({ resolver })

https.get('https://example.com', { lookup: cacheable.lookup }, response => {
  // Handle the response here
})

from cacheable-lookup.

szmarczak avatar szmarczak commented on May 29, 2024

Awesome! It's quite heavy though, can you reduce the size?

from cacheable-lookup.

Kikobeats avatar Kikobeats commented on May 29, 2024

yea, I'm working on it; the main dependency is dns2 that is exporting a lot of things I really don't need

from cacheable-lookup.

szmarczak avatar szmarczak commented on May 29, 2024

Are you sure?

image

from cacheable-lookup.

Kikobeats avatar Kikobeats commented on May 29, 2024

gotcha; shipped [email protected] that removes the logger dependency

CleanShot 2022-07-05 at 10 54 47@2x

from cacheable-lookup.

szmarczak avatar szmarczak commented on May 29, 2024

Awesome! Would you be up to sending a PR mentioning this in the docs?

from cacheable-lookup.

titanism avatar titanism commented on May 29, 2024

PR #77 fixes this! 🎉

See 🍊 Tangerine and forwardemail/nodejs-dns-over-https-tangerine#1.

from cacheable-lookup.

titanism avatar titanism commented on May 29, 2024

Reported as spam to GitHub

from cacheable-lookup.

titanism avatar titanism commented on May 29, 2024

Reported for spam

from cacheable-lookup.

Kikobeats avatar Kikobeats commented on May 29, 2024

BTW this is how I use cacheable-lookup with tangerine for getting DNS-over-HTTPs:

new CacheableLookup({
  resolver: new Tangerine(
    {
      cache: false,
    },
    require('got').extend({
      responseType: 'buffer',
      decompress: false,
      retry: 0
    })
  )
})

If this looks good to @titanism I can create a PR to add it into the README 🙂

from cacheable-lookup.

titanism avatar titanism commented on May 29, 2024

You're welcome to add whatever you like! This nicely shows how it supports things other than undici.

from cacheable-lookup.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.