Module deltachat::net::dns

source Β·
Expand description

DNS resolution and cache.

DNS cache in Delta Chat has two layers: in-memory cache and persistent dns_cache SQL table.

In-memory cache is using a β€œstale-while-revalidate” strategy. If there is a cached value, it is returned immediately and revalidation task is started in the background to replace old cached IP addresses with new ones. If there is no cached value yet, lookup only finishes when lookup_host returns first results. In-memory cache is shared between all accounts and is never stored on the disk. It can be thought of as an extension of the system resolver.

Persistent dns_cache SQL table is used to collect all IP addresses ever seen for the hostname together with the timestamp of the last time IP address has been seen. Note that this timestamp reflects the time IP address was returned by the in-memory cache rather than the underlying system resolver. Unused entries are removed after 30 days (CACHE_TTL constant) to avoid having old non-working IP addresses in the cache indefinitely.

When Delta Chat needs an IP address for the host, it queries in-memory cache for the next result and merges the list of IP addresses with the list of IP addresses from persistent cache. Resulting list is constructed by taking the first two results from the resolver followed up by persistent cache results and terminated by the rest of resolver results.

Persistent cache results are sorted by the time of the most recent successful connection using the result. For results that have never been used for successful connection timestamp of retrieving them from in-memory cache is used.

Statics§

  • DNS_PRELOAD πŸ”’
    Preloaded DNS results that can be used in case of DNS server failures.
  • Map from hostname to IP addresses.

Functions§