[GIT PULL] DNS cache system rework #5
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The old DNS cache setup in dns.c was kinda clunky because it needed to
slog through everything in O(n) time. This patch series swaps it out
for something way better and tidier. Create a new C file, dns_cache.c,
just for the DNS cache stuff to keep things nice and separate.
Plus, the storage is now smarter about memory, using this compact structure:
Also, the lookup now uses a hashmap, so it's super fast, O(1) on average.
There are six commits in this series:
1) Initial DNS cache rework.
A preparation patch to split the DNS cache code into a separate C file.
This implementation uses a better data structure, a hashmap, which has
an average O(1) time complexity. The cache storage is also more compact
and more efficient with respect to memory.
2) Add
nr_entriesfor accounting purpose.Add a counter to keep track of the number of entries in the cache.
3) Add a forward declaration of 'struct addrinfo'.
To avoid missing declaration when included before netdb.h.
4) Don't return expired cache entry.
gwp_dns_cache_getent()should only return a cache entry if the domainname is found and is not expired. The expired case was not handled. Fix
it by returning -ETIMEDOUT.
5) Introduce entry block getter functions.
Introduce
gwp_dns_cache_entget_i4()andgwp_dns_cache_entget_i6()to get pointers to the list of IP addresses.
6) Replace the old DNS cache system with a new one.
The new DNS cache library uses a hashmap data structure, which
has an average O(1) time complexity for lookup. It's also cleaner
to split the caching logic into a smaller, more manageable
C files.