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

refactor: switch from simple-dns to hickory-proto #107

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

dignifiedquire
Copy link
Contributor

@dignifiedquire dignifiedquire commented Jan 9, 2025

Due to the segfaults we have seen with simple-dns, and to reduce the dependency load in iroh this switches to hickory-proto

Ref n0-computer/iroh#2844

Open Questions

/// Signed DNS packet
pub struct SignedPacket {
inner: Inner,
message: Message,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A SignedPacket is now a wrapper around a hickory Message, which is a Vec<Query> and a bunch of Vec<Record>. The previous SignedPacket was basically free to clone and would be backed by at most 1 heap allocation. The new one is not cheap to clone and has possibly a large number of heap allocations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the alternative is to reparse the structure everytime you request details, like the previous version did for some parts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear to me, what the usage patterns are in practice, and which ones should be optimized, so I went with the simplest and most typesafe one.

Copy link
Contributor Author

@dignifiedquire dignifiedquire Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this actually gets mutated, so this could also be wrapped in an Arc under the hood, to optimize the cloning path again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed a version that does the last variant

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the alternative is to reparse the structure everytime you request details, like the previous version did for some parts.

No, the current version has the parsed Packet already, no need to reparse, and that is memory efficient because simple-dns packet takes a reference of the bytes and read from them using offsets on demand.

I don't think this actually gets mutated, so this could also be wrapped in an Arc under the hood, to optimize the cloning path again.

Yes it is not mutated after its creation, still, simple-dns Packet + Bytes, is more efficient than an Arc and a bunch of vectors.

But I can tolerate memory inefficiency if simple-dns can't be made robust.

@dignifiedquire dignifiedquire marked this pull request as ready for review January 9, 2025 14:47
}

/// Returns a slice of the serialized [SignedPacket] omitting the leading public_key,
/// to be sent as a request/response body to or from [relays](https://github.com/Nuhvi/pkarr/blob/main/design/relays.md).
pub fn to_relay_payload(&self) -> Bytes {
self.inner.borrow_owner().slice(32..)
pub fn to_relay_payload(&self) -> Vec<u8> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another example of allocation that isn't happening currently in SignedPacket, because currently the original packet is stored as is, which you can do even with hickory message, but then you would be doubling the amount of data, because simple-dns Packet doesn't copy the data, instead it just points to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants