Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
8 changes: 4 additions & 4 deletions interop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn run(log: Logger, options: Opt) -> Result<()> {
.map(move |data| {
println!("read {} bytes, closing", data.len());
*stream_data = true;
conn.close(0, b"done");
conn.close(0u32.into(), b"done");
})
.and_then(|_| {
println!("attempting resumption");
Expand Down Expand Up @@ -161,7 +161,7 @@ fn run(log: Logger, options: Opt) -> Result<()> {
})
.map(move |_| {
*rebinding = true;
conn.close(0, b"done");
conn.close(0u32.into(), b"done");
})
})
})
Expand Down Expand Up @@ -203,7 +203,7 @@ fn run(log: Logger, options: Opt) -> Result<()> {
.connect_with(client_config.clone(), &remote, host)?
.and_then(|(conn_driver, conn, _)| {
retry = true;
conn.close(0, b"done");
conn.close(0u32.into(), b"done");
conn_driver
})
.map(|()| {
Expand Down Expand Up @@ -259,7 +259,7 @@ fn run(log: Logger, options: Opt) -> Result<()> {
data.len(),
String::from_utf8_lossy(&data)
);
conn.close(0, b"done");
conn.close(0u32.into(), b"done");
});
control_fut.and_then(|_| req_fut).map(|_| h3 = true)
}),
Expand Down
29 changes: 16 additions & 13 deletions quinn-h3/src/proto/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::mem::size_of;

use bytes::{Buf, BufMut, Bytes};
use quinn_proto::coding::{BufExt, BufMutExt, Codec, UnexpectedEnd};
use quinn_proto::varint;
use quinn_proto::VarInt;

#[derive(Debug, PartialEq)]
pub enum Error {
Expand Down Expand Up @@ -166,7 +166,7 @@ pub struct PushPromiseFrame {
impl FrameHeader for PushPromiseFrame {
const TYPE: Type = Type::PUSH_PROMISE;
fn len(&self) -> usize {
varint::size(self.push_id).unwrap() + self.encoded.as_ref().len()
VarInt::from_u64(self.push_id).unwrap().size() + self.encoded.as_ref().len()
}
}

Expand Down Expand Up @@ -266,13 +266,13 @@ impl FrameHeader for PriorityFrame {

size += match self.prioritized {
Priority::RequestStream(id) | Priority::PushStream(id) | Priority::Placeholder(id) => {
varint::size(id).unwrap()
VarInt::from_u64(id).unwrap().size()
}
_ => 0,
};
size += match self.dependency {
Priority::RequestStream(id) | Priority::PushStream(id) | Priority::Placeholder(id) => {
varint::size(id).unwrap()
VarInt::from_u64(id).unwrap().size()
}
_ => 0,
};
Expand Down Expand Up @@ -346,14 +346,17 @@ impl SettingsFrame {
impl FrameHeader for SettingsFrame {
const TYPE: Type = Type::SETTINGS;
fn len(&self) -> usize {
varint::size(SettingId::NUM_PLACEHOLDERS.0).unwrap()
+ varint::size(self.num_placeholders).unwrap()
+ varint::size(SettingId::MAX_HEADER_LIST_SIZE.0).unwrap()
+ varint::size(self.max_header_list_size).unwrap()
+ varint::size(SettingId::QPACK_MAX_TABLE_CAPACITY.0).unwrap()
+ varint::size(self.qpack_max_table_capacity).unwrap()
+ varint::size(SettingId::QPACK_BLOCKED_STREAMS.0).unwrap()
+ varint::size(self.qpack_blocked_streams).unwrap()
fn sz(x: u64) -> usize {
VarInt::from_u64(x).unwrap().size()
}
sz(SettingId::NUM_PLACEHOLDERS.0)
+ sz(self.num_placeholders)
+ sz(SettingId::MAX_HEADER_LIST_SIZE.0)
+ sz(self.max_header_list_size)
+ sz(SettingId::QPACK_MAX_TABLE_CAPACITY.0)
+ sz(self.qpack_max_table_capacity)
+ sz(SettingId::QPACK_BLOCKED_STREAMS.0)
+ sz(self.qpack_blocked_streams)
}
}

Expand Down Expand Up @@ -540,7 +543,7 @@ mod tests {
#[test]
fn reserved_frame() {
let mut raw = vec![];
varint::write(0x21 + 2 * 0x1f, &mut raw).unwrap();
VarInt::from_u32(0x21 + 2 * 0x1f).encode(&mut raw);
raw.extend(&[6, 0, 255, 128, 0, 250, 218]);
let mut buf = Cursor::new(&raw);
let decoded = HttpFrame::decode(&mut buf);
Expand Down
6 changes: 3 additions & 3 deletions quinn-proto/src/coding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::net::{Ipv4Addr, Ipv6Addr};
use bytes::{Buf, BufMut};
use err_derive::Error;

use crate::varint;
use crate::VarInt;

#[derive(Error, Debug, Copy, Clone, Eq, PartialEq)]
#[error(display = "unexpected end of buffer")]
Expand Down Expand Up @@ -103,7 +103,7 @@ impl<T: Buf> BufExt for T {
}

fn get_var(&mut self) -> Result<u64> {
varint::read(self).ok_or(UnexpectedEnd)
Ok(VarInt::decode(self)?.into_inner())
}
}

Expand All @@ -118,6 +118,6 @@ impl<T: BufMut> BufMutExt for T {
}

fn write_var(&mut self, x: u64) {
varint::write(x, self).unwrap()
VarInt::from_u64(x).unwrap().encode(self);
}
}
12 changes: 6 additions & 6 deletions quinn-proto/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::timer::{Timer, TimerKind, TimerTable};
use crate::transport_parameters::{self, TransportParameters};
use crate::{
frame, Directionality, Frame, Side, StreamId, Transmit, TransportError, TransportErrorCode,
MAX_STREAM_COUNT, MIN_INITIAL_SIZE, MIN_MTU, RESET_TOKEN_SIZE, TIMER_GRANULARITY,
VarInt, MAX_STREAM_COUNT, MIN_INITIAL_SIZE, MIN_MTU, RESET_TOKEN_SIZE, TIMER_GRANULARITY,
};

/// Protocol state and logic for a single QUIC connection
Expand Down Expand Up @@ -831,12 +831,12 @@ where
///
/// # Panics
/// - when applied to a receive stream or an unopened send stream
pub fn reset(&mut self, stream_id: StreamId, error_code: u64) {
pub fn reset(&mut self, stream_id: StreamId, error_code: VarInt) {
self.reset_inner(stream_id, error_code, false);
}

/// `stopped` should be set iff this is an internal implicit reset due to `STOP_SENDING`
fn reset_inner(&mut self, stream_id: StreamId, error_code: u64, stopped: bool) {
fn reset_inner(&mut self, stream_id: StreamId, error_code: VarInt, stopped: bool) {
assert!(
stream_id.directionality() == Directionality::Bi || stream_id.initiator() == self.side,
"only streams supporting outgoing data may be reset"
Expand Down Expand Up @@ -2486,7 +2486,7 @@ where
///
/// This does not ensure delivery of outstanding data. It is the application's responsibility
/// to call this only when all important communications have been completed.
pub fn close(&mut self, now: Instant, error_code: u64, reason: Bytes) {
pub fn close(&mut self, now: Instant, error_code: VarInt, reason: Bytes) {
let was_closed = self.state.is_closed();
if !was_closed {
self.close_common();
Expand Down Expand Up @@ -2640,7 +2640,7 @@ where
}

/// Signal to the peer that it should stop sending on the given recv stream
pub fn stop_sending(&mut self, id: StreamId, error_code: u64) {
pub fn stop_sending(&mut self, id: StreamId, error_code: VarInt) {
assert!(
id.directionality() == Directionality::Bi || id.initiator() != self.side,
"only streams supporting incoming data may be stopped"
Expand Down Expand Up @@ -3350,7 +3350,7 @@ pub enum Event {
/// Which stream has been finished
stream: StreamId,
/// Error code supplied by the peer if the stream was stopped
stop_reason: Option<u64>,
stop_reason: Option<VarInt>,
},
/// At least one new stream of a certain directionality may be opened
StreamAvailable {
Expand Down
27 changes: 14 additions & 13 deletions quinn-proto/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::coding::{self, BufExt, BufMutExt, UnexpectedEnd};
use crate::range_set::RangeSet;
use crate::shared::{EcnCodepoint, ResetToken};
use crate::{
varint, ConnectionId, Directionality, StreamId, TransportError, TransportErrorCode,
ConnectionId, Directionality, StreamId, TransportError, TransportErrorCode, VarInt,
MAX_CID_SIZE, MIN_CID_SIZE, RESET_TOKEN_SIZE,
};

Expand Down Expand Up @@ -264,8 +264,8 @@ impl ConnectionClose {
out.write_var(ty); // <= 8 bytes
let max_len = max_len
- 3
- varint::size(ty).unwrap()
- varint::size(self.reason.len() as u64).unwrap();
- VarInt::from_u64(ty).unwrap().size()
- VarInt::from_u64(self.reason.len() as u64).unwrap().size();
let actual_len = self.reason.len().min(max_len);
out.write_var(actual_len as u64); // <= 8 bytes
out.put_slice(&self.reason[0..actual_len]); // whatever's left
Expand All @@ -278,7 +278,7 @@ impl ConnectionClose {
#[derive(Debug, Clone)]
pub struct ApplicationClose {
/// Application-specific reason code
pub error_code: u64,
pub error_code: VarInt,
/// Human-readable reason for the close
pub reason: Bytes,
}
Expand All @@ -304,8 +304,9 @@ impl FrameStruct for ApplicationClose {
impl ApplicationClose {
pub(crate) fn encode<W: BufMut>(&self, out: &mut W, max_len: usize) {
out.write(Type::APPLICATION_CLOSE); // 1 byte
out.write_var(self.error_code); // <= 8 bytes
let max_len = max_len as usize - 3 - varint::size(self.reason.len() as u64).unwrap();
out.write(self.error_code); // <= 8 bytes
let max_len =
max_len as usize - 3 - VarInt::from_u64(self.reason.len() as u64).unwrap().size();
let actual_len = self.reason.len().min(max_len);
out.write_var(actual_len as u64); // <= 8 bytes
out.put_slice(&self.reason[0..actual_len]); // whatever's left
Expand Down Expand Up @@ -505,7 +506,7 @@ impl Iter {
Type::PADDING => Frame::Padding,
Type::RESET_STREAM => Frame::ResetStream(ResetStream {
id: self.bytes.get()?,
error_code: self.bytes.get_var()?,
error_code: self.bytes.get()?,
final_offset: self.bytes.get_var()?,
}),
Type::CONNECTION_CLOSE => Frame::ConnectionClose(ConnectionClose {
Expand All @@ -521,7 +522,7 @@ impl Iter {
reason: self.take_len()?,
}),
Type::APPLICATION_CLOSE => Frame::ApplicationClose(ApplicationClose {
error_code: self.bytes.get_var()?,
error_code: self.bytes.get()?,
reason: self.take_len()?,
}),
Type::MAX_DATA => Frame::MaxData(self.bytes.get_var()?),
Expand Down Expand Up @@ -555,7 +556,7 @@ impl Iter {
},
Type::STOP_SENDING => Frame::StopSending(StopSending {
id: self.bytes.get()?,
error_code: self.bytes.get_var()?,
error_code: self.bytes.get()?,
}),
Type::RETIRE_CONNECTION_ID => Frame::RetireConnectionId {
sequence: self.bytes.get_var()?,
Expand Down Expand Up @@ -701,7 +702,7 @@ impl<'a> Iterator for AckIter<'a> {
#[derive(Debug, Copy, Clone)]
pub struct ResetStream {
pub id: StreamId,
pub error_code: u64,
pub error_code: VarInt,
pub final_offset: u64,
}

Expand All @@ -713,15 +714,15 @@ impl ResetStream {
pub fn encode<W: BufMut>(&self, out: &mut W) {
out.write(Type::RESET_STREAM); // 1 byte
out.write(self.id); // <= 8 bytes
out.write_var(self.error_code); // <= 8 bytes
out.write(self.error_code); // <= 8 bytes
out.write_var(self.final_offset); // <= 8 bytes
}
}

#[derive(Debug, Copy, Clone)]
pub struct StopSending {
pub id: StreamId,
pub error_code: u64,
pub error_code: VarInt,
}

impl FrameStruct for StopSending {
Expand All @@ -732,7 +733,7 @@ impl StopSending {
pub fn encode<W: BufMut>(&self, out: &mut W) {
out.write(Type::STOP_SENDING); // 1 byte
out.write(self.id); // <= 8 bytes
out.write_var(self.error_code) // <= 8 bytes
out.write(self.error_code) // <= 8 bytes
}
}

Expand Down
9 changes: 5 additions & 4 deletions quinn-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ mod spaces;
#[cfg(all(test, feature = "rustls"))]
mod tests;
mod transport_parameters;
#[doc(hidden)]
pub mod varint;
mod varint;

pub use varint::{VarInt, VarIntBoundsExceeded};

mod timer;
pub use timer::{Timer, TimerTable, TimerTableIter, TimerTableIterMut};
Expand Down Expand Up @@ -230,10 +231,10 @@ impl StreamId {

impl coding::Codec for StreamId {
fn decode<B: bytes::Buf>(buf: &mut B) -> coding::Result<StreamId> {
varint::read(buf).map(StreamId).ok_or(coding::UnexpectedEnd)
VarInt::decode(buf).map(|x| StreamId(x.into_inner()))
}
fn encode<B: bytes::BufMut>(&self, buf: &mut B) {
varint::write(self.0, buf).unwrap()
VarInt::from_u64(self.0).unwrap().encode(buf);
}
}

Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use slog::Logger;

use crate::frame::NewConnectionId;
use crate::packet::PartialDecode;
use crate::{crypto, varint, MAX_CID_SIZE, MIN_CID_SIZE, RESET_TOKEN_SIZE};
use crate::{crypto, VarInt, MAX_CID_SIZE, MIN_CID_SIZE, RESET_TOKEN_SIZE};

/// Parameters governing the core QUIC state machine
///
Expand Down Expand Up @@ -165,7 +165,7 @@ impl TransportConfig {
("idle_timeout", self.idle_timeout),
]
.iter()
.find(|&&(_, x)| x > varint::MAX_VALUE)
.find(|&&(_, x)| x > VarInt::MAX.into_inner())
{
return Err(ConfigError::VarIntBounds(name));
}
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fnv::FnvHashSet;

use crate::assembler::Assembler;
use crate::range_set::RangeSet;
use crate::{crypto, frame, StreamId};
use crate::{crypto, frame, StreamId, VarInt};

pub struct PacketSpace<K>
where
Expand Down Expand Up @@ -169,7 +169,7 @@ pub struct Retransmits {
pub max_uni_stream_id: bool,
pub max_bi_stream_id: bool,
pub stream: VecDeque<frame::Stream>,
pub rst_stream: Vec<(StreamId, u64)>,
pub rst_stream: Vec<(StreamId, VarInt)>,
pub stop_sending: Vec<frame::StopSending>,
pub max_stream_data: FnvHashSet<StreamId>,
pub crypto: VecDeque<frame::Crypto>,
Expand Down
Loading