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

fix: Check whether CIDs are empty #2034

Merged
merged 9 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 12 additions & 12 deletions neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ impl Connection {
self.paths.make_permanent(path, None, cid);
Ok(())
} else if let Some(primary) = self.paths.primary() {
if primary.borrow().remote_cid().is_empty() {
if primary.borrow().remote_cid().is_none() {
self.paths
.make_permanent(path, None, ConnectionIdEntry::empty_remote());
Ok(())
Expand Down Expand Up @@ -1908,7 +1908,7 @@ impl Connection {
// a packet on a new path, we avoid sending (and the privacy risk) rather
// than reuse a connection ID.
let res = if path.borrow().is_temporary() {
assert!(!cfg!(test), "attempting to close with a temporary path");
debug_assert!(!cfg!(test), "attempting to close with a temporary path");
Err(Error::InternalError)
larseggert marked this conversation as resolved.
Show resolved Hide resolved
} else {
self.output_path(&path, now, &Some(details))
Expand All @@ -1931,18 +1931,18 @@ impl Connection {
grease_quic_bit: bool,
) -> (PacketType, PacketBuilder) {
let pt = PacketType::from(cspace);
let dcid = path
.remote_cid()
.map_or(Vec::new(), |id| id.as_ref().to_vec());
larseggert marked this conversation as resolved.
Show resolved Hide resolved
let mut builder = if pt == PacketType::Short {
qdebug!("Building Short dcid {}", path.remote_cid());
PacketBuilder::short(encoder, tx.key_phase(), path.remote_cid())
qdebug!("Building Short dcid {:?}", dcid);
PacketBuilder::short(encoder, tx.key_phase(), dcid)
} else {
qdebug!(
"Building {:?} dcid {} scid {}",
pt,
path.remote_cid(),
path.local_cid(),
);

PacketBuilder::long(encoder, pt, version, path.remote_cid(), path.local_cid())
let scid = path
.local_cid()
.map_or(Vec::new(), |id| id.as_ref().to_vec());
qdebug!("Building {:?} dcid {:?} scid {:?}", pt, dcid, scid,);
PacketBuilder::long(encoder, pt, version, dcid, scid)
};
if builder.remaining() > 0 {
builder.scramble(grease_quic_bit);
Expand Down
2 changes: 1 addition & 1 deletion neqo-transport/src/connection/tests/datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ fn datagram_fill() {
let path = p.borrow();
// Minimum overhead is connection ID length, 1 byte short header, 1 byte packet number,
// 1 byte for the DATAGRAM frame type, and 16 bytes for the AEAD.
path.plpmtu() - path.remote_cid().len() - 19
path.plpmtu() - path.remote_cid().unwrap().len() - 19
};
assert!(space >= 64); // Unlikely, but this test depends on the datagram being this large.

Expand Down
12 changes: 8 additions & 4 deletions neqo-transport/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,8 +660,8 @@ impl Path {

/// Get the first local connection ID.
/// Only do this for the primary path during the handshake.
pub fn local_cid(&self) -> &ConnectionId {
self.local_cid.as_ref().unwrap()
pub const fn local_cid(&self) -> Option<&ConnectionId> {
self.local_cid.as_ref()
}

/// Set the remote connection ID based on the peer's choice.
Expand All @@ -674,8 +674,12 @@ impl Path {
}

/// Access the remote connection ID.
pub fn remote_cid(&self) -> &ConnectionId {
self.remote_cid.as_ref().unwrap().connection_id()
pub fn remote_cid(&self) -> Option<&ConnectionId> {
if self.remote_cid.is_some() {
Some(self.remote_cid.as_ref().unwrap().connection_id())
} else {
None
}
larseggert marked this conversation as resolved.
Show resolved Hide resolved
}

/// Set the stateless reset token for the connection ID that is currently in use.
Expand Down
11 changes: 9 additions & 2 deletions neqo-transport/src/qlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,15 @@ fn connection_started(qlog: &NeqoQlog, path: &PathRef) {
protocol: Some("QUIC".into()),
src_port: p.local_address().port().into(),
dst_port: p.remote_address().port().into(),
src_cid: Some(format!("{}", p.local_cid())),
dst_cid: Some(format!("{}", p.remote_cid())),
src_cid: Some(format!("{:?}", p.local_cid())),
dst_cid: {
let dcid = p.remote_cid();
if dcid.is_some() {
Some(format!("{}", dcid.unwrap()))
} else {
None
}
},
});

Some(ev_data)
Expand Down
Loading