Skip to content

Commit

Permalink
Restore find_path_with_rebinding
Browse files Browse the repository at this point in the history
  • Loading branch information
larseggert committed Nov 4, 2024
1 parent 56c19d5 commit 302961f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,7 @@ impl Connection {
/// This takes two times: when the datagram was received, and the current time.
fn input(&mut self, d: Datagram<impl AsRef<[u8]>>, received: Instant, now: Instant) {
// First determine the path.
let path = self.paths.find_path(
let path = self.paths.find_path_with_rebinding(
d.destination(),
d.source(),
self.conn_params.get_cc_algorithm(),
Expand Down
50 changes: 47 additions & 3 deletions neqo-transport/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Paths {
self.paths
.iter()
.find_map(|p| {
if p.borrow().received_on(local, remote) {
if p.borrow().received_on(local, remote, false) {
Some(Rc::clone(p))
} else {
None
Expand All @@ -98,6 +98,48 @@ impl Paths {
})
}

/// Find the path, but allow for rebinding. That matches the pair of addresses
/// to paths that match the remote address only based on IP addres, not port.
/// We use this when the other side migrates to skip address validation and
/// creating a new path.
pub fn find_path_with_rebinding(
&self,
local: SocketAddr,
remote: SocketAddr,
cc: CongestionControlAlgorithm,
pacing: bool,
now: Instant,
) -> PathRef {
self.paths
.iter()
.find_map(|p| {
if p.borrow().received_on(local, remote, false) {
Some(Rc::clone(p))
} else {
None
}
})
.or_else(|| {
self.paths.iter().find_map(|p| {
if p.borrow().received_on(local, remote, true) {
Some(Rc::clone(p))
} else {
None
}
})
})
.unwrap_or_else(|| {
Rc::new(RefCell::new(Path::temporary(
local,
remote,
cc,
pacing,
self.qlog.clone(),
now,
)))
})
}

/// Get a reference to the primary path, if one exists.
pub fn primary(&self) -> Option<PathRef> {
self.primary.clone()
Expand Down Expand Up @@ -582,8 +624,10 @@ impl Path {
}

/// Determine if this path was the one that the provided datagram was received on.
fn received_on(&self, local: SocketAddr, remote: SocketAddr) -> bool {
self.local == local && self.remote == remote
fn received_on(&self, local: SocketAddr, remote: SocketAddr, flexible: bool) -> bool {
self.local == local
&& self.remote.ip() == remote.ip()
&& (flexible || self.remote.port() == remote.port())
}

/// Update the remote port number. Any flexibility we allow in `received_on`
Expand Down

0 comments on commit 302961f

Please sign in to comment.