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

feat: Support QNS connectionmigration test #2180

Merged
merged 7 commits into from
Oct 21, 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
35 changes: 32 additions & 3 deletions neqo-bin/src/client/http09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use neqo_transport::{
use url::Url;

use super::{get_output_file, qlog_new, Args, CloseState, Res};
use crate::STREAM_IO_BUFFER_SIZE;
use crate::{client::unspecified_addr, STREAM_IO_BUFFER_SIZE};

pub struct Handler<'a> {
streams: HashMap<StreamId, Option<BufWriter<File>>>,
Expand All @@ -37,6 +37,7 @@ pub struct Handler<'a> {
token: Option<ResumptionToken>,
needs_key_update: bool,
read_buffer: Vec<u8>,
migration: Option<&'a (u16, SocketAddr)>,
}

impl Handler<'_> {
Expand Down Expand Up @@ -86,10 +87,33 @@ impl super::Handler for Handler<'_> {
}
}
ConnectionEvent::StateChange(
State::WaitInitial | State::Handshaking | State::Connected,
State::WaitInitial | State::Handshaking | State::Connected | State::Confirmed,
) => {
qdebug!("{event:?}");
self.download_urls(client);
if event == ConnectionEvent::StateChange(State::Confirmed) {
if let Some((local_port, migration_addr)) = &self.migration {
let mut local_addr = unspecified_addr(migration_addr);
local_addr.set_port(*local_port);
qdebug!("Migrating path to {:?} -> {:?}", local_addr, migration_addr);
client
.migrate(
Some(local_addr),
Some(*migration_addr),
false,
Instant::now(),
)
.map(|()| {
qinfo!(
"Connection migrated to {:?} -> {:?}",
local_addr,
migration_addr
);
// Don't do another migration.
self.migration = None;
})?;
}
}
}
ConnectionEvent::ZeroRttRejected => {
qdebug!("{event:?}");
Expand Down Expand Up @@ -211,7 +235,11 @@ impl super::Client for Connection {
}

impl<'b> Handler<'b> {
pub fn new(url_queue: VecDeque<Url>, args: &'b Args) -> Self {
pub fn new(
url_queue: VecDeque<Url>,
args: &'b Args,
migration: Option<&'b (u16, SocketAddr)>,
) -> Self {
Self {
streams: HashMap::new(),
url_queue,
Expand All @@ -221,6 +249,7 @@ impl<'b> Handler<'b> {
token: None,
needs_key_update: args.key_update,
read_buffer: vec![0; STREAM_IO_BUFFER_SIZE],
migration,
}
}

Expand Down
33 changes: 24 additions & 9 deletions neqo-bin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,14 @@ fn qlog_new(args: &Args, hostname: &str, cid: &ConnectionId) -> Res<NeqoQlog> {
.map_err(Error::QlogError)
}

const fn unspecified_addr(addr: &SocketAddr) -> SocketAddr {
match addr {
SocketAddr::V4(..) => SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0),
SocketAddr::V6(..) => SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 0),
}
}

#[allow(clippy::too_many_lines)]
pub async fn client(mut args: Args) -> Res<()> {
neqo_common::log::init(
args.shared
Expand Down Expand Up @@ -529,23 +537,18 @@ pub async fn client(mut args: Args) -> Res<()> {
exit(127);
}

let remote_addr = format!("{host}:{port}").to_socket_addrs()?.find(|addr| {
let mut remote_addrs = format!("{host}:{port}").to_socket_addrs()?.filter(|addr| {
!matches!(
(addr, args.ipv4_only, args.ipv6_only),
(SocketAddr::V4(..), false, true) | (SocketAddr::V6(..), true, false)
)
});
let remote_addr = remote_addrs.next();
let Some(remote_addr) = remote_addr else {
qerror!("No compatible address found for: {host}");
exit(1);
};

let local_addr = match remote_addr {
SocketAddr::V4(..) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from([0; 4])), 0),
SocketAddr::V6(..) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from([0; 16])), 0),
};

let mut socket = crate::udp::Socket::bind(local_addr)?;
let mut socket = crate::udp::Socket::bind(unspecified_addr(&remote_addr))?;
let real_local = socket.local_addr().unwrap();
qinfo!(
"{} Client connecting: {:?} -> {:?}",
Expand All @@ -554,6 +557,18 @@ pub async fn client(mut args: Args) -> Res<()> {
remote_addr,
);

let migration = if args.shared.qns_test == Some("connectionmigration".to_owned()) {
remote_addrs.next().map_or_else(
|| {
qerror!("No migration address found for {host}");
exit(127);
},
|migration_addr| Some((real_local.port(), migration_addr)),
)
} else {
None
};

let hostname = format!("{host}");
let mut token: Option<ResumptionToken> = None;
let mut first = true;
Expand All @@ -571,7 +586,7 @@ pub async fn client(mut args: Args) -> Res<()> {
http09::create_client(&args, real_local, remote_addr, &hostname, token)
.expect("failed to create client");

let handler = http09::Handler::new(to_request, &args);
let handler = http09::Handler::new(to_request, &args, migration.as_ref());

Runner {
args: &args,
Expand Down
Loading