Skip to content

Commit

Permalink
Update WebTransport dependencies (#28)
Browse files Browse the repository at this point in the history
* Update WebTransport dependencies

* Add changelog

* Fix WASM target

* Fix non-WASM target

* CI fixes

* more CI fixes

* fix test??
  • Loading branch information
aecsocket authored Feb 6, 2025
1 parent fb02395 commit 2fdd6d4
Show file tree
Hide file tree
Showing 18 changed files with 93 additions and 59 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- For now, all crates will share the same major and minor version number, but we are now free to bump the patch for individual subcrates
- `aeronet_replicon` properly reports backend statistics to Replicon i.e. RTT, packet loss
- Updated `bevy_replicon` to `0.30.0`
- Update `wtransport` to `0.5.0`, `xwt-wtransport` and `xwt-web`

# 0.11.0

Expand Down
40 changes: 28 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ tokio-tungstenite = "0.24.0"

# aeronet_webtransport
# core
xwt-core = "0.5.0"
xwt-core = "0.6.0"

# native
spki = "0.7.3"
wtransport = "0.3.1"
wtransport = "0.5.0"
x509-cert = "0.2.5"
xwt-wtransport = "0.10.0"
xwt-wtransport = "0.13.0"

# wasm
xwt-web-sys = "0.12.0"
xwt-web = "0.15.0"

# aeronet_replicon

Expand Down
4 changes: 4 additions & 0 deletions crates/aeronet_websocket/examples/websocket_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ fn global_ui(mut egui: EguiContexts, mut commands: Commands, mut ui_state: ResMu

#[cfg(target_family = "wasm")]
fn client_config() -> ClientConfig {
#[expect(
clippy::default_constructed_unit_structs,
reason = "keep parity with non-WASM"
)]
ClientConfig::default()
}

Expand Down
3 changes: 1 addition & 2 deletions crates/aeronet_websocket/examples/websocket_echo_server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Example server using WebSocket which listens for clients sending strings
//! and sends back a string reply.
use aeronet_io::server::Server;

cfg_if::cfg_if! {
if #[cfg(target_family = "wasm")] {
fn main() {
Expand All @@ -13,6 +11,7 @@ cfg_if::cfg_if! {
use {
aeronet_io::{
connection::{DisconnectReason, Disconnected, LocalAddr},
server::Server,
SessionEndpoint, Session,
},
aeronet_websocket::server::{Identity, ServerConfig, WebSocketServer, WebSocketServerPlugin},
Expand Down
7 changes: 6 additions & 1 deletion crates/aeronet_websocket/tests/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![expect(missing_docs, clippy::too_many_lines, reason = "testing")]
#![expect(missing_docs, reason = "testing")]
#![cfg(not(target_family = "wasm"))]
#![cfg_attr(
not(target_family = "wasm"),
expect(clippy::too_many_lines, reason = "testing")
)]

use {
aeronet_io::{
Expand Down
2 changes: 1 addition & 1 deletion crates/aeronet_webtransport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ gloo-timers = { workspace = true, features = ["futures"] }
js-sys = { workspace = true }
wasm-bindgen = { workspace = true }
wasm-bindgen-futures = { workspace = true }
xwt-web-sys = { workspace = true }
xwt-web = { workspace = true }

[target.'cfg(not(target_family = "wasm"))'.dependencies]
spki = { workspace = true, features = ["fingerprint"] }
Expand Down
26 changes: 16 additions & 10 deletions crates/aeronet_webtransport/examples/webtransport_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,22 @@ fn global_ui(mut egui: EguiContexts, mut commands: Commands, mut ui_state: ResMu

#[cfg(target_family = "wasm")]
fn client_config(cert_hash: String) -> Result<ClientConfig, anyhow::Error> {
use aeronet_webtransport::xwt_web_sys::{CertificateHash, HashAlgorithm};

let server_certificate_hashes = match cert::hash_from_b64(&cert_hash) {
Ok(hash) => vec![CertificateHash {
algorithm: HashAlgorithm::Sha256,
value: Vec::from(hash),
}],
Err(err) => {
warn!("Failed to read certificate hash from string: {err:?}",);
Vec::new()
use {
aeronet_webtransport::xwt_web::{CertificateHash, HashAlgorithm},
anyhow::bail,
};

let server_certificate_hashes = if cert_hash.is_empty() {
Vec::new()
} else {
match cert::hash_from_b64(&cert_hash) {
Ok(hash) => vec![CertificateHash {
algorithm: HashAlgorithm::Sha256,
value: Vec::from(hash),
}],
Err(err) => {
bail!("Failed to read certificate hash from string: {err:?}");
}
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Example server using WebTransport which listens for clients sending strings
//! and sends back a string reply.
use aeronet_io::{Session, server::Server};

cfg_if::cfg_if! {
if #[cfg(target_family = "wasm")] {
fn main() {
Expand All @@ -13,6 +11,8 @@ cfg_if::cfg_if! {
use {
aeronet_io::{
connection::{DisconnectReason, Disconnected, LocalAddr},
server::Server,
Session,
},
aeronet_webtransport::{
cert,
Expand Down Expand Up @@ -53,11 +53,11 @@ fn open_server(mut commands: Commands) {
info!(" {cert_hash}");
info!("************************");

let config = server_config(&identity);
let config = server_config(identity);
commands.spawn_empty().queue(WebTransportServer::open(config));
}

fn server_config(identity: &wtransport::Identity) -> ServerConfig {
fn server_config(identity: wtransport::Identity) -> ServerConfig {
wtransport::ServerConfig::builder()
.with_bind_default(25565)
.with_identity(identity)
Expand Down
9 changes: 3 additions & 6 deletions crates/aeronet_webtransport/src/client/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,18 @@ pub async fn start(
target: ConnectTarget,
send_next: oneshot::Sender<ToConnected>,
) -> Result<Never, DisconnectReason<ClientError>> {
// TODO: On native, debug log the target after this is merged:
// https://github.com/BiagioFesta/wtransport/pull/226
#[cfg(target_family = "wasm")]
debug!("Spawning backend task to connect to {target:?}");

let endpoint = {
#[cfg(target_family = "wasm")]
{
xwt_web_sys::Endpoint {
debug!("Spawning backend task to connect to {target:?}");
xwt_web::Endpoint {
options: config.to_js(),
}
}

#[cfg(not(target_family = "wasm"))]
{
debug!("Spawning backend task to connect to {:?}", target.url());
wtransport::Endpoint::client(config)
.map(xwt_wtransport::Endpoint)
.map_err(SessionError::CreateEndpoint)
Expand Down
2 changes: 1 addition & 1 deletion crates/aeronet_webtransport/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use {
cfg_if::cfg_if! {
if #[cfg(target_family = "wasm")] {
/// Configuration for the [`WebTransportClient`] on WASM platforms.
pub type ClientConfig = xwt_web_sys::WebTransportOptions;
pub type ClientConfig = xwt_web::WebTransportOptions;

type ConnectTarget = String;

Expand Down
6 changes: 3 additions & 3 deletions crates/aeronet_webtransport/src/js_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {
///
/// You can get one [from][`From`] a:
/// - [`JsValue`]
/// - [`xwt_web_sys::Error`]
/// - [`xwt_web::Error`]
#[derive(Debug, Clone)]
pub struct JsError(pub String);

Expand All @@ -32,8 +32,8 @@ impl From<JsValue> for JsError {
}
}

impl From<xwt_web_sys::Error> for JsError {
fn from(value: xwt_web_sys::Error) -> Self {
impl From<xwt_web::Error> for JsError {
fn from(value: xwt_web::Error) -> Self {
Self::from(value.0)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/aeronet_webtransport/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ cfg_if::cfg_if! {
mod js_error;
pub use js_error::JsError;

pub use xwt_web_sys;
pub use xwt_web;
} else {
#[cfg(feature = "server")]
pub mod server;
Expand Down
2 changes: 1 addition & 1 deletion crates/aeronet_webtransport/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl WebTransportServer {
///
/// let config = ServerConfig::builder()
/// .with_bind_default(12345) // server port
/// .with_identity(&identity)
/// .with_identity(identity)
/// .build();
///
/// // using `Commands`
Expand Down
14 changes: 7 additions & 7 deletions crates/aeronet_webtransport/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use {

cfg_if::cfg_if! {
if #[cfg(target_family = "wasm")] {
type Connection = xwt_web_sys::Session;
type Connection = xwt_web::Session;
type ConnectionError = crate::JsError;
} else {
type Connection = xwt_wtransport::Connection;
Expand Down Expand Up @@ -463,20 +463,20 @@ async fn disconnect(conn: Arc<Connection>, reason: &str) {

#[cfg(target_family = "wasm")]
{
use {wasm_bindgen_futures::JsFuture, xwt_web_sys::sys::WebTransportCloseInfo};
use {js_sys::JsString, xwt_web::web_wt_sys::WebTransportCloseInfo};

let mut close_info = WebTransportCloseInfo::new();
close_info.close_code(DISCONNECT_ERROR_CODE);
close_info.reason(reason);
let close_info = WebTransportCloseInfo::new();
close_info.set_close_code(DISCONNECT_ERROR_CODE);
close_info.set_reason(JsString::from(reason));

// TODO: This seems to not close the connection properly
// Could it be because of this?
// https://github.com/BiagioFesta/wtransport/issues/182
//
// Tested: the server times us out instead of actually
// reading the disconnect
conn.transport.close_with_close_info(&close_info);
_ = JsFuture::from(conn.transport.closed()).await;
conn.transport.close_with_info(&close_info);
_ = conn.transport.closed().await;
}

#[cfg(not(target_family = "wasm"))]
Expand Down
12 changes: 9 additions & 3 deletions crates/aeronet_webtransport/tests/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#![expect(missing_docs, clippy::too_many_lines, reason = "testing")]
#![expect(missing_docs, reason = "testing")]
#![cfg(not(target_family = "wasm"))]
#![cfg_attr(
not(target_family = "wasm"),
expect(clippy::too_many_lines, reason = "testing")
)]

use {
aeronet_io::{
Expand Down Expand Up @@ -28,14 +33,15 @@ fn connect() {

_ = wtransport::tls::rustls::crypto::ring::default_provider().install_default();
let identity = Identity::self_signed(["127.0.0.1", "::1", "localhost"]).unwrap();
let cert_hash = identity.certificate_chain().as_slice()[0].hash();
ping_pong(
ServerConfig::builder()
.with_bind_default(PORT)
.with_identity(&identity)
.with_identity(identity)
.build(),
ClientConfig::builder()
.with_bind_default()
.with_server_certificate_hashes([identity.certificate_chain().as_slice()[0].hash()])
.with_server_certificate_hashes([cert_hash])
.build(),
format!("https://[::1]:{PORT}"),
);
Expand Down
2 changes: 1 addition & 1 deletion examples/move_box_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ type WebTransportClientConfig = aeronet_webtransport::client::ClientConfig;

#[cfg(target_family = "wasm")]
fn web_transport_config(cert_hash: String) -> WebTransportClientConfig {
use aeronet_webtransport::xwt_web_sys::{CertificateHash, HashAlgorithm};
use aeronet_webtransport::xwt_web::{CertificateHash, HashAlgorithm};

let server_certificate_hashes = match cert::hash_from_b64(&cert_hash) {
Ok(hash) => vec![CertificateHash {
Expand Down
Loading

0 comments on commit 2fdd6d4

Please sign in to comment.