-
Notifications
You must be signed in to change notification settings - Fork 63
refactor(proto): Move PathStatus state to the PacketNumberSpace #780
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
Open
flub
wants to merge
5
commits into
main
Choose a base branch
from
flub/status-on-pns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,15 +74,14 @@ use packet_crypto::CryptoState; | |
| pub(crate) use packet_crypto::EncryptionLevel; | ||
|
|
||
| mod paths; | ||
| pub use paths::{ | ||
| ClosedPath, PathAbandonReason, PathEvent, PathId, PathStatus, RttEstimator, SetPathStatusError, | ||
| }; | ||
| pub use paths::{ClosedPath, PathAbandonReason, PathEvent, PathId, RttEstimator, SetPathStatusError}; | ||
| use paths::{PathData, PathState}; | ||
|
|
||
| pub(crate) mod qlog; | ||
| pub(crate) mod send_buffer; | ||
|
|
||
| pub(crate) mod spaces; | ||
| pub use spaces::PathStatus; | ||
| #[cfg(fuzzing)] | ||
| pub use spaces::Retransmits; | ||
| #[cfg(not(fuzzing))] | ||
|
|
@@ -584,8 +583,9 @@ impl Connection { | |
| return Err(PathError::RemoteCidsExhausted); | ||
| } | ||
|
|
||
| let path = self.create_path(path_id, network_path, now, None); | ||
| path.status.local_update(initial_status); | ||
| self.create_network_path(path_id, network_path, now, None); | ||
| let pns = self.spaces[SpaceKind::Data].for_path(path_id); | ||
| pns.status.local_update(initial_status); | ||
|
|
||
| Ok(path_id) | ||
| } | ||
|
|
@@ -794,8 +794,10 @@ impl Connection { | |
|
|
||
| /// Gets the local [`PathStatus`] for a known [`PathId`] | ||
| pub fn path_status(&self, path_id: PathId) -> Result<PathStatus, ClosedPath> { | ||
| self.path(path_id) | ||
| .map(PathData::local_status) | ||
| self.spaces[SpaceKind::Data] | ||
| .number_spaces | ||
| .get(&path_id) | ||
| .map(|pns| pns.local_status()) | ||
| .ok_or(ClosedPath { _private: () }) | ||
| } | ||
|
|
||
|
|
@@ -817,28 +819,32 @@ impl Connection { | |
| if !self.is_multipath_negotiated() { | ||
| return Err(SetPathStatusError::MultipathNotNegotiated); | ||
| } | ||
| let path = self | ||
| .path_mut(path_id) | ||
| let pns = self.spaces[SpaceKind::Data] | ||
| .number_spaces | ||
| .get_mut(&path_id) | ||
| .ok_or(SetPathStatusError::ClosedPath)?; | ||
| let prev = match path.status.local_update(status) { | ||
| let prev = match pns.status.local_update(status) { | ||
| Some(prev) => { | ||
| self.spaces[SpaceId::Data] | ||
| self.spaces[SpaceKind::Data] | ||
| .pending | ||
| .path_status | ||
| .insert(path_id); | ||
| prev | ||
| } | ||
| None => path.local_status(), | ||
| None => pns.local_status(), | ||
| }; | ||
| Ok(prev) | ||
| } | ||
|
|
||
| /// Returns the remote path status | ||
| /// Returns the remote path status. | ||
| // TODO(flub): Probably should also be some kind of path event? Not even sure if I like | ||
| // this as an API, but for now it allows me to write a test easily. | ||
| // TODO(flub): Technically this should be a Result<Option<PathSTatus>>? | ||
| // TODO(flub): Technically this should be a Result<Option<PathStatus>>? | ||
| pub fn remote_path_status(&self, path_id: PathId) -> Option<PathStatus> { | ||
| self.path(path_id).and_then(|path| path.remote_status()) | ||
| self.spaces[SpaceKind::Data] | ||
| .number_spaces | ||
| .get(&path_id) | ||
| .and_then(|pns| pns.remote_status()) | ||
| } | ||
|
|
||
| /// Sets the max_idle_timeout for a specific path. | ||
|
|
@@ -934,7 +940,7 @@ impl Connection { | |
| /// Creates the [`PathData`] for a new [`PathId`]. | ||
| /// | ||
| /// Called for incoming packets as well as when opening a new path locally. | ||
| fn create_path( | ||
| fn create_network_path( | ||
| &mut self, | ||
| path_id: PathId, | ||
| network_path: FourTuple, | ||
|
|
@@ -1154,10 +1160,12 @@ impl Connection { | |
| fn scheduling_info(&self, path_id: PathId) -> PathSchedulingInfo { | ||
| // Such a space is preferred for SpaceKind::Data frames. | ||
| let have_validated_status_available_space = self.paths.iter().any(|(path_id, path)| { | ||
| // pns can never be None here, that would be a logical error. | ||
| let pns = self.spaces[SpaceKind::Data].number_spaces.get(path_id); | ||
| self.remote_cids.contains_key(path_id) | ||
| && !self.abandoned_paths.contains(path_id) | ||
| && path.data.validated | ||
| && path.data.local_status() == PathStatus::Available | ||
| && pns.map(|pns| pns.local_status()).unwrap_or_default() == PathStatus::Available | ||
| }); | ||
|
|
||
| // Such a space is able to send SpaceKind::Data frames. | ||
|
|
@@ -1172,7 +1180,10 @@ impl Connection { | |
| let is_abandoned = self.abandoned_paths.contains(&path_id); | ||
| let path_data = self.path_data(path_id); | ||
| let validated = path_data.validated; | ||
| let status = path_data.local_status(); | ||
|
|
||
| // pns can never be None here, that would be a logical error. | ||
| let pns = self.spaces[SpaceKind::Data].number_spaces.get(&path_id); | ||
| let status = pns.map(|pns| pns.local_status()).unwrap_or_default(); | ||
|
Comment on lines
+1184
to
+1186
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
|
||
| // This is the core packet scheduling, whether this space ID may send | ||
| // SpaceKind::Data frames. | ||
|
|
@@ -4354,7 +4365,7 @@ impl Connection { | |
|
|
||
| if self.side().is_server() && !self.abandoned_paths.contains(&path_id) { | ||
| // Only the client is allowed to open paths | ||
| self.create_path(path_id, network_path, now, pn); | ||
| self.create_network_path(path_id, network_path, now, pn); | ||
| } | ||
| if self.paths.contains_key(&path_id) { | ||
| self.on_packet_authenticated( | ||
|
|
@@ -5840,12 +5851,14 @@ impl Connection { | |
| let is_client = self.side().is_client(); | ||
| let immediate_ack_allowed = self.peer_supports_ack_frequency(); | ||
|
|
||
| for (path_id, path) in self.paths.iter_mut() { | ||
| for path_id in self.spaces[SpaceKind::Data].number_spaces.keys() { | ||
| if self.abandoned_paths.contains(path_id) { | ||
| continue; | ||
| } | ||
| open_paths += 1; | ||
|
|
||
| let path = self.paths.get_mut(path_id).expect("PathData missing"); | ||
|
|
||
| // Read the network path BEFORE clearing local_ip, so the hint can | ||
| // check which interface the path was using. | ||
| let network_path = path.data.network_path; | ||
|
|
@@ -5872,7 +5885,7 @@ impl Connection { | |
| if attempt_to_recover { | ||
| recoverable_paths.push((*path_id, remote)); | ||
| } else { | ||
| non_recoverable_paths.push((*path_id, remote, path.data.local_status())) | ||
| non_recoverable_paths.push((*path_id, remote)); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -5886,12 +5899,16 @@ impl Connection { | |
| // We prefer closing paths first unless we identify this is the last open path. | ||
| let open_first = open_paths == non_recoverable_paths.len(); | ||
|
|
||
| for (path_id, remote, status) in non_recoverable_paths.into_iter() { | ||
| for (path_id, remote) in non_recoverable_paths.into_iter() { | ||
| let network_path = FourTuple { | ||
| remote, | ||
| local_ip: None, /* allow the local ip to be discovered */ | ||
| }; | ||
|
|
||
| let status = self.spaces[SpaceKind::Data] | ||
| .number_spaces | ||
| .get(&path_id) | ||
| .map(|pns| pns.local_status()) | ||
| .expect("spaces iterated above"); | ||
| if open_first && let Err(e) = self.open_path(network_path, status, now) { | ||
| if self.side().is_client() { | ||
| debug!(%e, "Failed to open new path for network change"); | ||
|
|
@@ -6342,13 +6359,13 @@ impl Connection { | |
| let Some(path_id) = space.pending.path_status.pop_first() else { | ||
| break; | ||
| }; | ||
| let Some(path) = self.paths.get(&path_id).map(|path_state| &path_state.data) else { | ||
| let Some(pns) = space.number_spaces.get(&path_id) else { | ||
| trace!(%path_id, "discarding queued path status for unknown path"); | ||
| continue; | ||
| }; | ||
|
|
||
| let seq = path.status.seq(); | ||
| match path.local_status() { | ||
| let seq = pns.status.seq(); | ||
| match pns.local_status() { | ||
| PathStatus::Available => { | ||
| let frame = frame::PathStatusAvailable { | ||
| path_id, | ||
|
|
@@ -7033,18 +7050,18 @@ impl Connection { | |
|
|
||
| /// Handle new path status information: PATH_STATUS_AVAILABLE, PATH_STATUS_BACKUP | ||
| fn on_path_status(&mut self, path_id: PathId, status: PathStatus, status_seq_no: VarInt) { | ||
| if let Some(path) = self.paths.get_mut(&path_id) { | ||
| path.data.status.remote_update(status, status_seq_no); | ||
| if let Some(pns) = self.spaces[SpaceKind::Data].number_spaces.get_mut(&path_id) { | ||
| pns.status.remote_update(status, status_seq_no); | ||
| self.events.push_back( | ||
| PathEvent::RemoteStatus { | ||
| id: path_id, | ||
| status, | ||
| } | ||
| .into(), | ||
| ); | ||
| } else { | ||
| debug!("PATH_STATUS_AVAILABLE received unknown path {:?}", path_id); | ||
| } | ||
| self.events.push_back( | ||
| PathEvent::RemoteStatus { | ||
| id: path_id, | ||
| status, | ||
| } | ||
| .into(), | ||
| ); | ||
| } | ||
|
|
||
| /// Returns the maximum [`PathId`] to be used for sending in this connection. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here. (And probably more of those above)