Skip to content
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

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft

Introduce a replacement for base::name #422

wants to merge 22 commits into from

Conversation

bal-e
Copy link
Contributor

@bal-e bal-e commented Oct 28, 2024

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 with base::new_name across the crate, and eventually to remove base::name and let base::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. The ToName and ToRelativeName traits have been dropped, so that most domain name functionality is supported on Name/RelName etc. but not on Chain or ParsedName. Since domain names are so small (usually less than 64 bytes, always less than 256 bytes), ParsedName objects can be copied out into regular Names 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).

@bal-e bal-e added enhancement New feature or request needs-review labels Oct 28, 2024
@bal-e bal-e self-assigned this Oct 28, 2024
@bal-e bal-e marked this pull request as draft October 28, 2024 10:49
bal-e added 15 commits October 28, 2024 11:50
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.
@bal-e
Copy link
Contributor Author

bal-e commented Oct 28, 2024

@partim, @Philip-NLnetLabs: I'd like to hear your opinion on base::new_name::octets. I'm still thinking about what this interface should look like -- at least some names will have to be changed. Do you think it represents a good fit for byte slices with bounded sizes? Where should this module be placed? (does it fit in octseq?) And do we need Bytes-like functionality on top of it? (while Arc<Name> works, that does not offer slicing support).

@bal-e bal-e requested a review from a team October 28, 2024 11:05
bal-e added 6 commits October 28, 2024 22:27
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant