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
Add wireformat buffer to DnsResponse #1855
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good to me!
c818eff
to
c21bcb9
Compare
I rebased this PR for two reasons:
When resolving the conflict I also integrated the two clean up commits. I also realized that |
c21bcb9
to
bfc2e29
Compare
For a while I was worried that it would be confusing for people to know if the buffer is supposed to be Some or None. But it should be intuitive enough, right? I.e.:
I tried to come up with ways to make the API foolproof but I was unable to come up with something that carries its own weight. |
I had a closer look at the circumstances in which DnsResponses are constructed. In production code a buffer i always available, and in test code a buffer is seldom (never?) available. But in test code we could afford to serialize a buffer from the Message just so we can construct a DnsResponse, right? This way we can make the DnsResponse buffer into a plain In the test code there are lots of places where a Message is constructed and a DnsResponse is built from that. I thought it was best to keep that constructor for that. But to avoid accidentally creating DnsResponses with generated buffers I thought it best to not use a special method instead of From. The QuicStream::receive() method used to return a Message but I changed it to return DnsResponse instead to give the caller access to the buffer. I have a changeset implementing the above but the commits are in a mess so I need to clean them up before I push them. |
I updated DnsResponse so that its buffer isn't wrapped in an Option but rather is always present. To mitigate the risk of callers unintentionally synthesizing buffers for DnsResponse I replaced the |
If this is only used in test code as you suggested earlier, we could guard the |
It's already used by test code downstream in the client, resolver and server crates as well as in the integration-tests. I tried marking it with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how this is narrow to just the DnsResponse type. Looks good.
This PR adds a wireformat buffer to the DnsResponse struct, allowing the caller to know the exact bytes that were received in a given response.
This is my second attempt at achieving the same goal. During the review of my first attempt (#1823) @djc suggested an alternative approach. We refined his idea a little and agreed that it seemed like a better way. This is an implementation of that idea.
Fixes #1814.