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

Fix #182: Convert error codes before passing them to QUIC #211

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

barafael
Copy link

@barafael barafael commented Sep 3, 2024

No description provided.

@BiagioFesta
Copy link
Owner

Thank you for taking care of this!

Is the reverse map necessary when receiving the code from stream's peer?

@barafael
Copy link
Author

barafael commented Sep 3, 2024

I have no idea! Sounds like yes it is?

/// Converts this stream [`ErrorCode`] to HTTP/3 error code.
/// <https://ietf-wg-webtrans.github.io/draft-ietf-webtrans-http3/draft-ietf-webtrans-http3.html#section-4.3)>
pub fn to_http3(self) -> VarInt {
let code = self.to_code();
Copy link
Contributor

@finnbear finnbear Sep 3, 2024

Choose a reason for hiding this comment

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

Upon reading all relevant documentation, it appears that the conversion is only for WT application error codes and not any of the existing ErrorCode variants, all of which are in the space of valid HTTP/3 error codes.

This can be seen as follows:

In other words, if we wanted application error codes, they would work like this:

enum ErrorCode{
    Datagram,
    NoError,
    ...
    Application(u8), // Edit: should be u32
}

impl ErrorCode {
    pub fn to_code(self) -> VarInt {
        match self {
            ErrorCode::Datagram => h3_error_codes::H3_DATAGRAM_ERROR,
            ErrorCode::NoError => h3_error_codes::H3_NO_ERROR,
            ...
            ErrorCode::Application(n) => to_http3(n),
        }
    }
}

But I'm not sure Application would be a useful variant. Instead, I suggest looking into whether reset(error_code) should be a u8 (edit: u32) and go through the to_http3 conversion:

/// Closes the send stream immediately.
///
/// No new data can be written after calling this method. Locally buffered data is dropped, and
/// previously transmitted data will no longer be retransmitted if lost. If an attempt has
/// already been made to finish the stream, the peer may still receive all written data.
///
/// If called more than once, subsequent calls will result in `StreamWriteError::Closed`.
#[inline(always)]
pub fn reset(&mut self, error_code: VarInt) -> Result<(), StreamWriteError> {
self.0.reset(error_code)
}

Likewise, consider converting VarInt to u8 (edit: u32) or Option<u8> (edit: Option<u32>), the result of a (potentially fallible) from_http3 conversion:

/// The peer is no longer accepting data on this stream.
#[error("stream stopped (code: {0})")]
Stopped(VarInt),

(or, if non-application error codes are expected, consider exposing pub fn application_error_code(VarInt) -> Option<u8> so users can make sense of the error code).
(or, having a separate StreamWriteError variant for successfully converted application error codes)
(or, using Option<ErrorCode> instead of VarInt for Stopped)

Copy link
Contributor

@finnbear finnbear Sep 3, 2024

Choose a reason for hiding this comment

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

There is one thing I'm unsure about:

I assume this is because these are two different versions of the spec.

Edit: Ah, it changed from 2^8 to 2^32 between drafts 5 and 6 (draft N can be obtained at https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-0N.html#name-resetting-data-streams)

@MOZGIII
Copy link
Contributor

MOZGIII commented Sep 14, 2024

I have no idea! Sounds like yes it is?

It definitely is

@MOZGIII
Copy link
Contributor

MOZGIII commented Sep 14, 2024

Check my implementation at https://github.com/MOZGIII/xwt/blob/ffc8b2cc135acaf7f5229a01775e3da92a22684e/crates/xwt-wtransport/src/lib.rs#L284-L323

Might be relevant for #211 (comment)

@finnbear
Copy link
Contributor

Might be relevant for #211 (comment)

Can confirm; you use the conversion for application error/close codes, which is correct. This conversion could be moved into wtransport.

@MOZGIII
Copy link
Contributor

MOZGIII commented Sep 14, 2024

Let's do it! I'm busy with building the reset support Web part of the xwt now, but feel free to port my code from that PR to wtransport

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.

Wrong model for stream error codes
4 participants