Implement DNS name compression & EDNS #17
Closed
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.
This implements DNS name compression (see the decription added in dns/encode.cpp
encode_name()for details).This reduces the sizes of nearly all query responses (because every response answer includes the question, and then uses the name again for the response), and in some cases significantly so.
This is rather important for Session Router all of our names are 52 byte pubkeys (plus the 4 or 5 byte tld), and so we are potentially running up against the DNS 512-byte max message size.
(We should also enable EDNS to allow longer messages, but that is left here as a FIXME and not yet implemented).
An example shows how the compression helps:
For example, an AAAA query for
localhost.seshresponds with an answer of:The repeated question doesn't compress anything, of course, but once you hit the answer, you start getting savings:
The repeated
localhost.seshin the first answer gets compressed from 16 bytes (without compression) to a 2 byte pointer (back to the same address in the question).The first PUBKEY.sesh (in the CNAME target) gets slightly reduced by being able to encode the trailing
seshfrom 6 bytes uncompressed (4+"sesh"+\0) to a 2-byte pointer (again backinto the question, pointing just at the sesh tld rather than the entire lokinet.sesh value).
The pubkey.sesh. in the second answers gets hugely reduced: an uncompressed 59 bytes (52+"pubkey"+4+"sesh"+0) becomes a simple 2-byte pointer to the same name in the previous answer line.
For some queries like SRV records the savings are even potentially even larger, especially when there are multiple SRV entries for a .sesh address.
Edit: and EDNS support!
EDNS support (including DNS cookies) wasn't too difficult, so I added that here too.