-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a replacement for base::name
#422
base: main
Are you sure you want to change the base?
Conversation
The goal of the 'new_name' module is to provide a simpler and more efficient implementation of the basic domain name types. Rather than being generic over the underlying byte sequence, 'Name' and 'RelName' are just unsized byte slices, leaving their allocation up to the user. Their methods are entirely based in slice manipulations, rather than through generic label iteration. They should be much more performant, but we are lacking benchmarks.
I was worried I'd have to iterate over the labels, but actually, it's pretty straightforward. I hope the compiler can vectorize it nicely.
Unlike the existing 'NameBuilder', this type uses a fixed-size buffer to write the name into. This results in simpler code and it should be more efficient. It provides simple methods to extract domain names by borrowing from the buffer instead of allocating. This is a rewrite of <#394>.
It was returning the value of 'total_len()'. Also fixed a clippy warning.
I also fixed a few bugs in the existing name methods.
@partim, @Philip-NLnetLabs: I'd like to hear your opinion on |
An incomplete and untested Punycode decoder has also been added.
A basic quadratic-time output builder has been implemented. At the moment, no further validation of U-labels is performed; we need a way to represent U-labels (even owned ones) and to validate and encode them from there.
I wasn't comfortable with the 'Owned' paradigm, particularly due to the generic buffer parameter. It's easier to work with an explicit buffer type, and in some cases it may even have useful additional methods.
The
base::new_name
module seeks to provide a simpler and more ergonomic interface for working with domain names. Its core types,Name
,RelName
, etc., are not generic over an underlying octets type: they are simple unsized byte slices, which can be stored in any container. This greatly simplifies their API and makes their methods more amenable to optimization.The idea is to gradually replace the use of
base::name
withbase::new_name
across the crate, and eventually to removebase::name
and letbase::new_name
take its place. Given the large number of modules in the crate, this will likely take a while.While most of the functionality of
base::name
has been replicated, some things have been explicitly omitted. TheToName
andToRelativeName
traits have been dropped, so that most domain name functionality is supported onName
/RelName
etc. but not onChain
orParsedName
. Since domain names are so small (usually less than 64 bytes, always less than 256 bytes),ParsedName
objects can be copied out into regularName
s before being used. By relying on direct byte slice operations, basic methods like domain name comparison have been sped up (from quadratic to linear time, in fact).