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

proto: make PartialDecode API public #1865

Merged
merged 3 commits into from
May 22, 2024
Merged

Conversation

thynson
Copy link
Contributor

@thynson thynson commented May 17, 2024

Context: #1860.

This PR did a bit more than just expose symbols to public, a trait ConnectionIdValidator was introduced, due to the fact that a QUIC Load balancer have to support different kind of Connection ID Schemes, per QUIC-LB-DRAFT Secion 4.1.
Also some documents was added to suppress the clippy warning after those symbol being made public.

@thynson
Copy link
Contributor Author

thynson commented May 17, 2024

I'm not sure if ConnectionIdValidator should be move to quinn_proto::shared.

@Ralith
Copy link
Collaborator

Ralith commented May 17, 2024

What does this new trait add over the caller performing whatever validation they like themselves after decoding a header, as is already done with ConnectionIdGenerator::validate?

Copy link
Collaborator

@djc djc left a comment

Choose a reason for hiding this comment

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

I'm not convinced this ConnectionIdValidator is the right abstraction. Given that we're dealing with parsing, it seems like that should be front and center, maybe something like:

trait ConnectionIdParser {
     fn parse(&self, buf: &mut impl Buf) -> Result<ConnectionId, PacketDecodeError>;
}

(Feels like it could even be TryFrom impl?)

Also in terms of commit history, I'd like to see one commit that makes all the existing API that you need public, and then a separate commit that adds any new stuff you need (with as little as possible duplication).

quinn-proto/src/cid_generator.rs Outdated Show resolved Hide resolved
quinn-proto/src/cid_generator.rs Outdated Show resolved Hide resolved
quinn-proto/src/cid_generator.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
@djc
Copy link
Collaborator

djc commented May 17, 2024

What does this new trait add over the caller performing whatever validation they like themselves after decoding a header, as is already done with ConnectionIdGenerator::validate?

It looks like parsing the header needs the expected CID len as input.

@thynson
Copy link
Contributor Author

thynson commented May 17, 2024

Thanks for review. I'm going to polish it based on your comments

@thynson
Copy link
Contributor Author

thynson commented May 17, 2024

The idea of ConnectionIdValidator comes from s2n-quic, but they have Validator and Generator and Format: Validator + Generator(see here is what s2n-quic does).

While in quinn, ConnectionIdGenerator has validate for now, so the duplication of functionality seems unavoidable unless we change trait ConnectionIdGenerator to requires ConnectionIdParser. Shall we go in this way?

@thynson
Copy link
Contributor Author

thynson commented May 17, 2024

While in quinn, ConnectionIdGenerator has validate for now, so the duplication of functionality seems unavoidable unless we change trait ConnectionIdGenerator to requires ConnectionIdParser. Shall we go in this way?

After further digging, I believe ConnectionIdGenerator.parse and ConnectionIdValidator.validate provides different semantics. The former is used to decide whether a state-less reset should be sent, so rename ConnectionIdValidator to ConnectionIdParser seems right to me.

@thynson thynson force-pushed the expose-packet branch 2 times, most recently from a53bc78 to 6a2a1cc Compare May 17, 2024 11:01
Copy link
Collaborator

@djc djc left a comment

Choose a reason for hiding this comment

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

This is looking much better already.

quinn-proto/src/shared.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
@thynson thynson force-pushed the expose-packet branch 8 times, most recently from 6d4504a to b4e35b9 Compare May 17, 2024 15:55
Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

Mostly cosmetic issues, general direction looks good. Could you squash the constructor-unification commits down into the commits that introduce the new constructors?

quinn-proto/src/shared.rs Outdated Show resolved Hide resolved
quinn-proto/src/shared.rs Outdated Show resolved Hide resolved
quinn-proto/src/shared.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
@thynson thynson force-pushed the expose-packet branch 3 times, most recently from 211e7f0 to d9190e7 Compare May 18, 2024 01:42
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
@thynson thynson force-pushed the expose-packet branch 3 times, most recently from 433f69f to b16911c Compare May 18, 2024 10:15
Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@thynson thynson changed the title proto: introduce ConnectionIdValidator and expose PlainHeader parsing stuffes proto: introduce ConnectionIdParser and expose PlainHeader parsing stuffes May 21, 2024
@djc
Copy link
Collaborator

djc commented May 22, 2024

I ended up squashing and reordering these changes. I changed the commits to (a) first make the APIs public and then (b) add the ConnectionIdParser trait and implementation. The previous approach had some intermediate states that did not make sense. @thynson can you check that this still satisfies your use case (there should be no changes in terms of the final public API, but still good to check)?

@thynson
Copy link
Contributor Author

thynson commented May 22, 2024

It's totally fine to me .

quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
quinn-proto/src/packet.rs Outdated Show resolved Hide resolved
thynson and others added 2 commits May 22, 2024 15:41
Currently `PlainHeader::decode` and `PartialDecoder::new` expect a
`local_cid_len`, which means they cannot support variable length
Connection ID format and make it less useful in various use cases,
such as implementing a [QUIC-LB] confirming load balancer.

[QUIC-LB]: https://www.ietf.org/archive/id/draft-ietf-quic-load-balancers-19.html
@djc djc changed the title proto: introduce ConnectionIdParser and expose PlainHeader parsing stuffes proto: make PartialDecode API public May 22, 2024
@djc djc merged commit 6c9c252 into quinn-rs:main May 22, 2024
8 checks passed
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.

None yet

3 participants