[GH-ISSUE #3069] Replace iterator types in MessageResponse #1125

Open
opened 2026-03-16 01:41:02 +03:00 by kerem · 1 comment
Owner

Originally created by @divergentdave on GitHub (Jun 18, 2025).
Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/3069

MessageResponse currently contains four iterators for records in various sections. This means that a MessageResponse is single-use, and thus leads to some awkward repetition of work when dealing with message signatures. We could probably replace these generic iterator types with Cow<'a, [Record]>. For reference, here are the five monomorphizations of this type currently used in the codebase.

hickory_server::authority::MessageResponse<'_, '_, std::boxed::Box<dyn std::iter::Iterator<Item = &hickory_proto::rr::Record> + std::marker::Send>, std::boxed::Box<dyn std::iter::Iterator<Item = &hickory_proto::rr::Record> + std::marker::Send>, std::boxed::Box<dyn std::iter::Iterator<Item = &hickory_proto::rr::Record> + std::marker::Send>, std::boxed::Box<dyn std::iter::Iterator<Item = &hickory_proto::rr::Record> + std::marker::Send>>
hickory_server::authority::MessageResponse<'_, '_, std::boxed::Box<std::option::IntoIter<&hickory_proto::rr::Record>>, std::boxed::Box<std::option::IntoIter<&hickory_proto::rr::Record>>, std::boxed::Box<std::option::IntoIter<&hickory_proto::rr::Record>>, std::boxed::Box<std::option::IntoIter<&hickory_proto::rr::Record>>>
hickory_server::authority::MessageResponse<'_, '_, std::iter::Empty<&hickory_proto::rr::Record>, std::iter::Repeat<&hickory_proto::rr::Record>, std::iter::Repeat<&hickory_proto::rr::Record>, std::iter::Repeat<&hickory_proto::rr::Record>>
hickory_server::authority::MessageResponse<'_, '_, std::iter::Repeat<&hickory_proto::rr::Record>, std::iter::Once<&hickory_proto::rr::Record>, std::iter::Once<&hickory_proto::rr::Record>, std::iter::Once<&hickory_proto::rr::Record>>
hickory_server::authority::MessageResponse<'_, '_, std::slice::Iter<'_, hickory_proto::rr::Record>, std::slice::Iter<'_, hickory_proto::rr::Record>, std::array::IntoIter<&hickory_proto::rr::Record, 0>, std::slice::Iter<'_, hickory_proto::rr::Record>>

The Repeat iterator is used in truncation tests, and would be straightforward to replace with an arbitrarily large vector. We can use Option::as_slice() for the std::option::IntoIter cases.

Originally created by @divergentdave on GitHub (Jun 18, 2025). Original GitHub issue: https://github.com/hickory-dns/hickory-dns/issues/3069 `MessageResponse` currently contains four iterators for records in various sections. This means that a `MessageResponse` is single-use, and thus leads to some awkward repetition of work when dealing with message signatures. We could probably replace these generic iterator types with `Cow<'a, [Record]>`. For reference, here are the five monomorphizations of this type currently used in the codebase. ``` hickory_server::authority::MessageResponse<'_, '_, std::boxed::Box<dyn std::iter::Iterator<Item = &hickory_proto::rr::Record> + std::marker::Send>, std::boxed::Box<dyn std::iter::Iterator<Item = &hickory_proto::rr::Record> + std::marker::Send>, std::boxed::Box<dyn std::iter::Iterator<Item = &hickory_proto::rr::Record> + std::marker::Send>, std::boxed::Box<dyn std::iter::Iterator<Item = &hickory_proto::rr::Record> + std::marker::Send>> hickory_server::authority::MessageResponse<'_, '_, std::boxed::Box<std::option::IntoIter<&hickory_proto::rr::Record>>, std::boxed::Box<std::option::IntoIter<&hickory_proto::rr::Record>>, std::boxed::Box<std::option::IntoIter<&hickory_proto::rr::Record>>, std::boxed::Box<std::option::IntoIter<&hickory_proto::rr::Record>>> hickory_server::authority::MessageResponse<'_, '_, std::iter::Empty<&hickory_proto::rr::Record>, std::iter::Repeat<&hickory_proto::rr::Record>, std::iter::Repeat<&hickory_proto::rr::Record>, std::iter::Repeat<&hickory_proto::rr::Record>> hickory_server::authority::MessageResponse<'_, '_, std::iter::Repeat<&hickory_proto::rr::Record>, std::iter::Once<&hickory_proto::rr::Record>, std::iter::Once<&hickory_proto::rr::Record>, std::iter::Once<&hickory_proto::rr::Record>> hickory_server::authority::MessageResponse<'_, '_, std::slice::Iter<'_, hickory_proto::rr::Record>, std::slice::Iter<'_, hickory_proto::rr::Record>, std::array::IntoIter<&hickory_proto::rr::Record, 0>, std::slice::Iter<'_, hickory_proto::rr::Record>> ``` The `Repeat` iterator is used in truncation tests, and would be straightforward to replace with an arbitrarily large vector. We can use `Option::as_slice()` for the `std::option::IntoIter` cases.
Author
Owner

@djc commented on GitHub (Jun 19, 2025):

I like this idea a lot but not entirely sure it's workable? The problem (so far) ends up being the LookupRecords::ManyRecords variant, which collects a Vec<Arc<RecordSet>> and thus makes it harder to collect a contiguous slice of records. Not sure yet if all the LookupRecords::many() callers have meaningful reasons to record Vec<Arc<RecordSet>> instead of just a Vec<Record>...

<!-- gh-comment-id:2987272892 --> @djc commented on GitHub (Jun 19, 2025): I like this idea a lot but not entirely sure it's workable? The problem (so far) ends up being the `LookupRecords::ManyRecords` variant, which collects a `Vec<Arc<RecordSet>>` and thus makes it harder to collect a contiguous slice of records. Not sure yet if all the `LookupRecords::many()` callers have meaningful reasons to record `Vec<Arc<RecordSet>>` instead of just a `Vec<Record>`...
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hickory-dns#1125
No description provided.