Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben2424 committed Feb 3, 2025
1 parent 84ae2a4 commit 50745a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 70 deletions.
21 changes: 10 additions & 11 deletions h3/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ where
}

#[allow(missing_docs)]
//#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub fn poll_accept_bi(
&mut self,
cx: &mut Context<'_>,
Expand Down Expand Up @@ -495,7 +495,7 @@ where
}

/// Waits for the control stream to be received and reads subsequent frames.
//#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub fn poll_control(
&mut self,
cx: &mut Context<'_>,
Expand Down Expand Up @@ -657,7 +657,7 @@ where
&mut self,
recv_closing: &mut Option<T>,
id: VarInt,
) -> Result<(), Error>
) -> Result<(), ConnectionError>
where
T: From<VarInt> + Copy,
VarInt: From<T>,
Expand All @@ -678,13 +678,12 @@ where
//= https://www.rfc-editor.org/rfc/rfc9114#section-5.2
//# Receiving a GOAWAY containing a larger identifier than previously
//# received MUST be treated as a connection error of type H3_ID_ERROR.
return Err(self.close(
Code::H3_ID_ERROR,
format!(
"received a GoAway({}) greater than the former one ({})",
id, prev_id
),
));
return Err(self.handle_connection_error(InternalConnectionError::new(
NewCode::H3_ID_ERROR,
// TODO: put the id in the message
//received a GoAway({}) greater than the former one ({})",
"received a GoAway greater than the former one",
)));
}
}
*recv_closing = Some(id.into());
Expand Down Expand Up @@ -843,7 +842,7 @@ impl<S, B> ConnectionState for RequestStream<S, B> {

impl<S, B> RequestStream<S, B> {
/// Close the connection with an error
//#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
#[cfg_attr(feature = "tracing", instrument(skip_all, level = "trace"))]
pub fn close(&self, code: Code, reason: &'static str) -> Error {
let _ = self.error_sender.send((code, reason));
self.maybe_conn_err(code)
Expand Down
59 changes: 0 additions & 59 deletions h3/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,71 +401,12 @@ impl From<proto::headers::HeaderError> for Error {
}
}

impl From<frame::FrameStreamError> for Error {
fn from(e: frame::FrameStreamError) -> Self {
match e {
frame::FrameStreamError::Quic(e) => e.into(),

//= https://www.rfc-editor.org/rfc/rfc9114#section-7.1
//# When a stream terminates cleanly, if the last frame on the stream was
//# truncated, this MUST be treated as a connection error of type
//# H3_FRAME_ERROR.
frame::FrameStreamError::UnexpectedEnd => Code::H3_FRAME_ERROR
.with_reason("received incomplete frame", ErrorLevel::ConnectionError),

frame::FrameStreamError::Proto(e) => match e {
proto::frame::FrameError::InvalidStreamId(_)
| proto::frame::FrameError::InvalidPushId(_) => Code::H3_ID_ERROR,
proto::frame::FrameError::Settings(_) => Code::H3_SETTINGS_ERROR,
proto::frame::FrameError::UnsupportedFrame(_)
| proto::frame::FrameError::UnknownFrame(_) => Code::H3_FRAME_UNEXPECTED,

//= https://www.rfc-editor.org/rfc/rfc9114#section-7.1
//# A frame payload that contains additional bytes
//# after the identified fields or a frame payload that terminates before
//# the end of the identified fields MUST be treated as a connection
//# error of type H3_FRAME_ERROR.

//= https://www.rfc-editor.org/rfc/rfc9114#section-7.1
//# In particular, redundant length
//# encodings MUST be verified to be self-consistent; see Section 10.8.
proto::frame::FrameError::Incomplete(_)
| proto::frame::FrameError::InvalidFrameValue
| proto::frame::FrameError::Malformed => Code::H3_FRAME_ERROR,
}
.with_cause(e),
}
}
}

impl From<Error> for Box<dyn std::error::Error + std::marker::Send> {
fn from(e: Error) -> Self {
Box::new(e)
}
}

impl<T> From<T> for Error
where
T: Into<TransportError>,
{
fn from(e: T) -> Self {
let quic_error: TransportError = e.into();
if quic_error.is_timeout() {
return Error::new(Kind::Timeout);
}

match quic_error.err_code() {
Some(c) if Code::H3_NO_ERROR == c => Error::new(Kind::Closed),
Some(c) => Error::new(Kind::Application {
code: Code { code: c },
reason: None,
level: ErrorLevel::ConnectionError,
}),
None => Error::new(Kind::Transport(Arc::from(quic_error))),
}
}
}

impl From<proto::stream::InvalidStreamId> for Error {
fn from(e: proto::stream::InvalidStreamId) -> Self {
Self::from(Code::H3_ID_ERROR).with_cause(format!("{}", e))
Expand Down

0 comments on commit 50745a6

Please sign in to comment.