Skip to content

Fix bugs in the process of opening a new path #100

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

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
12 changes: 9 additions & 3 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ impl Connection {

let challenge = self.rng.random();
path.challenge = Some(challenge);
path.challenge_pending = true;
self.paths.insert(
path_id,
PathState {
Expand All @@ -657,6 +658,10 @@ impl Connection {

// Inform the remote of the path status.
self.spaces[SpaceId::Data].pending.path_status.push(path_id);
let pn_space = spaces::PacketNumberSpace::new(now, SpaceId::Data, &mut self.rng);
self.spaces[SpaceId::Data]
.number_spaces
.insert(path_id, pn_space);
true
}

Expand Down Expand Up @@ -1366,9 +1371,10 @@ impl Connection {
// that are already created, as well as 1 byte for starting another datagram. If
// there is any anti-amplification budget left, we always allow a full MTU to be
// sent (see https://github.com/quinn-rs/quinn/issues/1082).
if self
.path_data(path_id)
.anti_amplification_blocked(transmit.len() as u64 + 1)
if self.side().is_server()
&& self
.path_data(path_id)
.anti_amplification_blocked(transmit.len() as u64 + 1)
{
trace!(?space_id, ?path_id, "blocked by anti-amplification");
return PathBlocked::AntiAmplification;
Expand Down
12 changes: 8 additions & 4 deletions quinn-proto/src/connection/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use crate::{
};

pub(super) struct PacketSpace {
// TODO(@divma): for debugging purposes
space_id: SpaceId,
pub(super) crypto: Option<Keys>,

/// Data to send
Expand All @@ -39,6 +41,7 @@ impl PacketSpace {
pub(super) fn new(now: Instant, space: SpaceId, rng: &mut (impl Rng + ?Sized)) -> Self {
let number_space_0 = PacketNumberSpace::new(now, space, rng);
Self {
space_id: space,
crypto: None,
pending: Retransmits::default(),
crypto_stream: Assembler::new(),
Expand All @@ -51,6 +54,7 @@ impl PacketSpace {
pub(super) fn new_deterministic(now: Instant, space: SpaceId) -> Self {
let number_space_0 = PacketNumberSpace::new_deterministic(now, space);
Self {
space_id: space,
crypto: None,
pending: Retransmits::default(),
crypto_stream: Assembler::new(),
Expand All @@ -70,7 +74,7 @@ impl PacketSpace {
pub(super) fn for_path(&mut self, path: PathId) -> &mut PacketNumberSpace {
self.number_spaces
.entry(path)
.or_insert_with(PacketNumberSpace::new_default)
.or_insert_with(|| PacketNumberSpace::new_default(self.space_id, path))
}

pub(super) fn iter_paths_mut(&mut self) -> impl Iterator<Item = &mut PacketNumberSpace> {
Expand Down Expand Up @@ -240,7 +244,7 @@ pub(super) struct PacketNumberSpace {
}

impl PacketNumberSpace {
fn new(now: Instant, space: SpaceId, rng: &mut (impl Rng + ?Sized)) -> Self {
pub(super) fn new(now: Instant, space: SpaceId, rng: &mut (impl Rng + ?Sized)) -> Self {
let pn_filter = match space {
SpaceId::Initial | SpaceId::Handshake => None,
SpaceId::Data => Some(PacketNumberFilter::new(rng)),
Expand Down Expand Up @@ -302,8 +306,8 @@ impl PacketNumberSpace {
/// This allows us to be type-safe about always being able to access a
/// PacketNumberSpace. While the space will work it will not skip packet numbers to
/// protect against eaget ack attacks.
fn new_default() -> Self {
error!("PacketNumberSpace created by default");
fn new_default(space_id: SpaceId, path_id: PathId) -> Self {
error!(?path_id, ?space_id, "PacketNumberSpace created by default");
Self {
rx_packet: 0,
next_packet_number: 0,
Expand Down
Loading