diff --git a/src/frame.rs b/src/frame.rs index d243f2c..37f1e27 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -52,82 +52,7 @@ pub async fn recv_raw<'b>(recv: &mut RecvStream, buf: &mut Vec) -> io::Resul fn from_read_exact_error_to_io_error(e: quinn::ReadExactError) -> io::Error { match e { quinn::ReadExactError::FinishedEarly(_) => io::Error::from(io::ErrorKind::UnexpectedEof), - quinn::ReadExactError::ReadError(e) => from_read_error_to_io_error(e), - } -} - -fn from_read_error_to_io_error(e: quinn::ReadError) -> io::Error { - use quinn::ReadError; - - match e { - ReadError::Reset(_) => io::Error::from(io::ErrorKind::ConnectionReset), - ReadError::ConnectionLost(e) => from_connection_error_to_io_error(e), - ReadError::ClosedStream => io::Error::new(io::ErrorKind::Other, "closed stream"), - ReadError::IllegalOrderedRead => { - io::Error::new(io::ErrorKind::InvalidInput, "illegal ordered read") - } - ReadError::ZeroRttRejected => { - io::Error::new(io::ErrorKind::ConnectionRefused, "0-RTT rejected") - } - } -} - -fn from_connection_error_to_io_error(e: quinn::ConnectionError) -> io::Error { - use quinn::ConnectionError; - - match e { - ConnectionError::VersionMismatch => io::Error::from(io::ErrorKind::ConnectionRefused), - ConnectionError::TransportError(e) => from_transport_error_to_io_error(e), - ConnectionError::ConnectionClosed(e) => io::Error::new( - io::ErrorKind::ConnectionAborted, - String::from_utf8_lossy(&e.reason), - ), - ConnectionError::ApplicationClosed(e) => io::Error::new( - io::ErrorKind::ConnectionAborted, - String::from_utf8_lossy(&e.reason), - ), - ConnectionError::Reset => io::Error::from(io::ErrorKind::ConnectionReset), - ConnectionError::TimedOut => io::Error::from(io::ErrorKind::TimedOut), - ConnectionError::LocallyClosed => { - io::Error::new(io::ErrorKind::Other, "connection locally closed") - } - ConnectionError::CidsExhausted => { - io::Error::new(io::ErrorKind::Other, "cid space exhausted") - } - } -} - -fn from_transport_error_to_io_error(e: quinn_proto::TransportError) -> io::Error { - use quinn_proto::TransportErrorCode; - - match e.code { - TransportErrorCode::CONNECTION_REFUSED => { - io::Error::new(io::ErrorKind::ConnectionRefused, e.reason) - } - TransportErrorCode::CONNECTION_ID_LIMIT_ERROR - | TransportErrorCode::CRYPTO_BUFFER_EXCEEDED - | TransportErrorCode::FINAL_SIZE_ERROR - | TransportErrorCode::FLOW_CONTROL_ERROR - | TransportErrorCode::FRAME_ENCODING_ERROR - | TransportErrorCode::INVALID_TOKEN - | TransportErrorCode::PROTOCOL_VIOLATION - | TransportErrorCode::STREAM_LIMIT_ERROR - | TransportErrorCode::STREAM_STATE_ERROR - | TransportErrorCode::TRANSPORT_PARAMETER_ERROR => { - io::Error::new(io::ErrorKind::InvalidData, e.reason) - } - TransportErrorCode::NO_VIABLE_PATH => { - // TODO: Use `io::ErrorKind::HostUnreachable` when it is stabilized - io::Error::new(io::ErrorKind::Other, e.reason) - } - _ => { - // * TransportErrorCode::AEAD_LIMIT_REACHED - // * TransportErrorCode::APPLICATION_ERROR - // * TransportErrorCode::INTERNAL_ERROR - // * TransportErrorCode::KEY_UPDATE_ERROR - // * TransportErrorCode::NO_ERROR - io::Error::new(io::ErrorKind::Other, e.reason) - } + quinn::ReadExactError::ReadError(e) => e.into(), } }