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

Make ConnectionIdParser object-safe, and accept trait object impls #1878

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions quinn-proto/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,8 @@ pub struct EndpointConfig {
impl EndpointConfig {
/// Create a default config with a particular `reset_key`
pub fn new(reset_key: Arc<dyn HmacKey>) -> Self {
let cid_factory: fn() -> Box<dyn ConnectionIdGenerator> =
|| Box::<HashedConnectionIdGenerator>::default();
let cid_factory =
|| -> Box<dyn ConnectionIdGenerator> { Box::<HashedConnectionIdGenerator>::default() };
Self {
reset_key,
max_udp_payload_size: (1500u32 - 28).into(), // Ethernet MTU minus IP + UDP headers
Expand Down
8 changes: 4 additions & 4 deletions quinn-proto/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl PartialDecode {
/// Begin decoding a QUIC packet from `bytes`, returning any trailing data not part of that packet
pub fn new(
bytes: BytesMut,
cid_parser: &impl ConnectionIdParser,
cid_parser: &(impl ConnectionIdParser + ?Sized),
supported_versions: &[u32],
grease_quic_bit: bool,
) -> Result<(Self, Option<BytesMut>), PacketDecodeError> {
Expand Down Expand Up @@ -564,7 +564,7 @@ impl ProtectedHeader {
/// Decode a plain header from given buffer, with given [`ConnectionIdParser`].
pub fn decode(
buf: &mut io::Cursor<BytesMut>,
cid_parser: &impl ConnectionIdParser,
cid_parser: &(impl ConnectionIdParser + ?Sized),
supported_versions: &[u32],
grease_quic_bit: bool,
) -> Result<Self, PacketDecodeError> {
Expand Down Expand Up @@ -780,7 +780,7 @@ impl FixedLengthConnectionIdParser {
}

impl ConnectionIdParser for FixedLengthConnectionIdParser {
fn parse(&self, buffer: &mut impl Buf) -> Result<ConnectionId, PacketDecodeError> {
fn parse(&self, buffer: &mut dyn Buf) -> Result<ConnectionId, PacketDecodeError> {
(buffer.remaining() >= self.expected_len)
.then(|| ConnectionId::from_buf(buffer, self.expected_len))
.ok_or(PacketDecodeError::InvalidHeader("packet too small"))
Expand All @@ -790,7 +790,7 @@ impl ConnectionIdParser for FixedLengthConnectionIdParser {
/// Parse connection id in short header packet
pub trait ConnectionIdParser {
/// Parse a connection id from given buffer
fn parse(&self, buf: &mut impl Buf) -> Result<ConnectionId, PacketDecodeError>;
fn parse(&self, buf: &mut dyn Buf) -> Result<ConnectionId, PacketDecodeError>;
}

/// Long packet type including non-uniform cases
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl ConnectionId {
/// Constructs cid by reading `len` bytes from a `Buf`
///
/// Callers need to assure that `buf.remaining() >= len`
pub fn from_buf(buf: &mut impl Buf, len: usize) -> Self {
pub fn from_buf(buf: &mut (impl Buf + ?Sized), len: usize) -> Self {
debug_assert!(len <= MAX_CID_SIZE);
let mut res = Self {
len: len as u8,
Expand Down