m13253 / dns-over-https

High performance DNS over HTTPS client & server
https://developers.google.com/speed/public-dns/docs/dns-over-https
MIT License
1.96k stars 221 forks source link

Feature: cache #109

Closed gdm85 closed 2 years ago

gdm85 commented 3 years ago

This is the caching feature that I developed some time and have been using for a while now; it has to be considered experimental.

Please review the code looking for bugs/wrong assumptions or something to improve.

m13253 commented 3 years ago

I have some suggestions about caching: (The complexity of caching is also the reason why I haven't implement cache)

  1. EDNS-Subnet shouldn't be stripped, the user's IP address masked with the scope field in the response should be used as a part of the cache key. This is to help deliver location-relevant results.
  2. Before the request has yet received a response, the user's IP address masked with the mask field in the request can be used as the key to mark an in-flight or failed request.
  3. The cache can also help deduplicate incoming requests -- same requests sent from similar IP addresses are grouped together. Only one sequence of requests is forwarded to upstream, effectively preventing retransmission storm.
  4. The internal of this software is done on the JSON level, since the software is originally designed for Google JSON protocol, before IETF DoH was a thing. Therefore, it might be easier to do caching at JSON level: I have already parsed those binary into human-readable thing and converted TTL to absolute time. Also this awesome new feature will automatically be compatible with both protocols.