Skip to content

Commit

Permalink
feat(quinn-proto): Support & test wasm32-unknown-unknown target
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus23 committed Nov 6, 2024
1 parent 4974621 commit 75a1b3c
Show file tree
Hide file tree
Showing 28 changed files with 125 additions and 51 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.wasm32-unknown-unknown]
runner = "wasm-bindgen-test-runner"
44 changes: 44 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ jobs:
- run: RUST_BACKTRACE=1 cargo test --manifest-path quinn-proto/Cargo.toml --no-default-features --features rustls-aws-lc-rs-fips
- run: RUST_BACKTRACE=1 cargo test --manifest-path quinn/Cargo.toml --no-default-features --features rustls-aws-lc-rs-fips,runtime-tokio

wasm_test:
name: test wasm32-unknown-unknown
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable

- name: Add wasm target
run: rustup target add wasm32-unknown-unknown

- name: Install nodejs v20
uses: actions/setup-node@v4
with:
node-version: 20

- name: Setup `wasm-tools`
uses: bytecodealliance/actions/wasm-tools/setup@v1

- name: Install cargo binstall
uses: cargo-bins/cargo-binstall@main

# We need to downgrade cc to version 1.1.31 for ring Wasm compilation to work.
# See the upstream issue https://github.com/rust-lang/cc-rs/issues/1275
- name: Use working `cc` version 1.1.31
run: cargo update -p cc --precise 1.1.31

- name: build wasm32 tests (quinn-proto)
run: cargo test -p quinn-proto --target wasm32-unknown-unknown --no-run

# If the Wasm file contains any 'import "env"' declarations, then
# some non-Wasm-compatible code made it into the final code.
- name: Check for 'import "env"' in Wasm
run: |
! wasm-tools print --skeleton target/wasm32-unknown-unknown/debug/deps/quinn_proto-*.wasm | grep 'import "env"'
- name: Install wasm-bindgen-test-runner
run: cargo binstall wasm-bindgen-cli --locked --no-confirm

- name: wasm32 test (quinn-proto)
run: cargo test -p quinn-proto --target wasm32-unknown-unknown

msrv:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ clap = { version = "4", features = ["derive"] }
crc = "3"
directories-next = "2"
futures-io = "0.3.19"
getrandom = { version = "0.2", default-features = false }
hdrhistogram = { version = "7.2", default-features = false }
hex-literal = "0.4"
lazy_static = "1"
Expand All @@ -37,6 +38,7 @@ rustc-hash = "2"
rustls = { version = "0.23.5", default-features = false, features = ["std"] }
rustls-pemfile = "2"
rustls-platform-verifier = "0.4"
rustls-pki-types = "1.7"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
slab = "0.4.6"
Expand All @@ -49,6 +51,8 @@ tracing = { version = "0.1.10", default-features = false, features = ["std"] }
tracing-futures = { version = "0.2.0", default-features = false, features = ["std-future"] }
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["env-filter", "fmt", "ansi", "time", "local-time"] }
url = "2"
wasm-bindgen-test = { version = "0.3.45" }
web-time = "1"
windows-sys = { version = ">=0.52, <=0.59", features = ["Win32_Foundation", "Win32_System_IO", "Win32_Networking_WinSock"] }

[profile.bench]
Expand Down
9 changes: 9 additions & 0 deletions quinn-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,21 @@ thiserror = { workspace = true }
tinyvec = { workspace = true, features = ["alloc"] }
tracing = { workspace = true }

# Feature flags & dependencies for wasm
# wasm-bindgen is assumed for a wasm*-*-unknown target
[target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies]
ring = { workspace = true, features = ["wasm32_unknown_unknown_js"] }
getrandom = { workspace = true, features = ["js"] }
rustls-pki-types = { workspace = true, features = ["web"] } # only added as dependency to enforce the `web` feature for this target
web-time = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
hex-literal = { workspace = true }
rcgen = { workspace = true }
tracing-subscriber = { workspace = true }
lazy_static = "1"
wasm-bindgen-test = { workspace = true }

[lints.rust]
# https://rust-fuzz.github.io/book/cargo-fuzz/guide.html#cfgfuzzing
Expand Down
3 changes: 2 additions & 1 deletion quinn-proto/src/cid_generator.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use std::{hash::Hasher, time::Duration};
use std::hash::Hasher;

use rand::{Rng, RngCore};

use crate::shared::ConnectionId;
use crate::Duration;
use crate::MAX_CID_SIZE;

/// Generates connection IDs for incoming connections
Expand Down
5 changes: 2 additions & 3 deletions quinn-proto/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{
net::{SocketAddrV4, SocketAddrV6},
num::TryFromIntError,
sync::Arc,
time::Duration,
};

#[cfg(any(feature = "rustls-aws-lc-rs", feature = "rustls-ring"))]
Expand All @@ -19,8 +18,8 @@ use crate::{
congestion,
crypto::{self, HandshakeTokenKey, HmacKey},
shared::ConnectionId,
RandomConnectionIdGenerator, VarInt, VarIntBoundsExceeded, DEFAULT_SUPPORTED_VERSIONS,
INITIAL_MTU, MAX_CID_SIZE, MAX_UDP_PAYLOAD,
Duration, RandomConnectionIdGenerator, VarInt, VarIntBoundsExceeded,
DEFAULT_SUPPORTED_VERSIONS, INITIAL_MTU, MAX_CID_SIZE, MAX_UDP_PAYLOAD,
};

/// Parameters governing the core QUIC state machine
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Logic for controlling the rate at which data is sent

use crate::connection::RttEstimator;
use crate::Instant;
use std::any::Any;
use std::sync::Arc;
use std::time::Instant;

mod bbr;
mod cubic;
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion/bbr/bw_estimation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::{Debug, Display, Formatter};
use std::time::{Duration, Instant};

use super::min_max::MinMax;
use crate::{Duration, Instant};

#[derive(Clone, Debug)]
pub(crate) struct BandwidthEstimation {
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion/bbr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::any::Any;
use std::fmt::Debug;
use std::sync::Arc;
use std::time::{Duration, Instant};

use rand::{Rng, SeedableRng};

use crate::congestion::bbr::bw_estimation::BandwidthEstimation;
use crate::congestion::bbr::min_max::MinMax;
use crate::connection::RttEstimator;
use crate::{Duration, Instant};

use super::{Controller, ControllerFactory, BASE_DATAGRAM_SIZE};

Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/congestion/cubic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::any::Any;
use std::cmp;
use std::sync::Arc;
use std::time::{Duration, Instant};

use super::{Controller, ControllerFactory, BASE_DATAGRAM_SIZE};
use crate::connection::RttEstimator;
use std::cmp;
use crate::{Duration, Instant};

/// CUBIC Constants.
///
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion/new_reno.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::any::Any;
use std::sync::Arc;
use std::time::Instant;

use super::{Controller, ControllerFactory, BASE_DATAGRAM_SIZE};
use crate::connection::RttEstimator;
use crate::Instant;

/// A simple, standard congestion controller
#[derive(Debug, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/ack_frequency.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::connection::spaces::PendingAcks;
use crate::frame::AckFrequency;
use crate::transport_parameters::TransportParameters;
use crate::Duration;
use crate::{AckFrequencyConfig, TransportError, VarInt, TIMER_GRANULARITY};
use std::time::Duration;

/// State associated to ACK frequency
pub(super) struct AckFrequencyState {
Expand Down
7 changes: 2 additions & 5 deletions quinn-proto/src/connection/cid_state.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
//! Maintain the state of local connection IDs
use std::{
collections::VecDeque,
time::{Duration, Instant},
};
use std::collections::VecDeque;

use rustc_hash::FxHashSet;
use tracing::{debug, trace};

use crate::{shared::IssuedCid, TransportError};
use crate::{shared::IssuedCid, Duration, Instant, TransportError};

/// Local connection ID management
pub(super) struct CidState {
Expand Down
6 changes: 3 additions & 3 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
fmt, io, mem,
net::{IpAddr, SocketAddr},
sync::Arc,
time::{Duration, Instant},
};

use bytes::{Bytes, BytesMut};
Expand All @@ -32,8 +31,9 @@ use crate::{
},
token::ResetToken,
transport_parameters::TransportParameters,
Dir, EndpointConfig, Frame, Side, StreamId, Transmit, TransportError, TransportErrorCode,
VarInt, MAX_CID_SIZE, MAX_STREAM_COUNT, MIN_INITIAL_SIZE, TIMER_GRANULARITY,
Dir, Duration, EndpointConfig, Frame, Instant, Side, StreamId, Transmit, TransportError,
TransportErrorCode, VarInt, MAX_CID_SIZE, MAX_STREAM_COUNT, MIN_INITIAL_SIZE,
TIMER_GRANULARITY,
};

mod ack_frequency;
Expand Down
6 changes: 3 additions & 3 deletions quinn-proto/src/connection/mtud.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{packet::SpaceId, MtuDiscoveryConfig, MAX_UDP_PAYLOAD};
use std::{cmp, time::Instant};
use crate::{packet::SpaceId, Instant, MtuDiscoveryConfig, MAX_UDP_PAYLOAD};
use std::cmp;
use tracing::trace;

/// Implements Datagram Packetization Layer Path Maximum Transmission Unit Discovery
Expand Down Expand Up @@ -519,9 +519,9 @@ const BLACK_HOLE_THRESHOLD: usize = 3;
mod tests {
use super::*;
use crate::packet::SpaceId;
use crate::Duration;
use crate::MAX_UDP_PAYLOAD;
use assert_matches::assert_matches;
use std::time::Duration;

fn default_mtud() -> MtuDiscovery {
let config = MtuDiscoveryConfig::default();
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/pacing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Pacing of packet transmissions.

use std::time::{Duration, Instant};
use crate::{Duration, Instant};

use tracing::warn;

Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/connection/packet_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cmp, time::Instant};
use std::cmp;

use bytes::Bytes;
use rand::Rng;
Expand All @@ -8,7 +8,7 @@ use super::{spaces::SentPacket, Connection, SentFrames};
use crate::{
frame::{self, Close},
packet::{Header, InitialHeader, LongType, PacketNumber, PartialEncode, SpaceId, FIXED_BIT},
ConnectionId, TransportError, TransportErrorCode, INITIAL_MTU,
ConnectionId, Instant, TransportError, TransportErrorCode, INITIAL_MTU,
};

pub(super) struct PacketBuilder {
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/packet_crypto.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::time::Instant;
use tracing::{debug, trace};

use crate::connection::spaces::PacketSpace;
use crate::crypto::{HeaderKey, KeyPair, PacketKey};
use crate::packet::{Packet, PartialDecode, SpaceId};
use crate::token::ResetToken;
use crate::Instant;
use crate::{TransportError, RESET_TOKEN_SIZE};

/// Removes header protection of a packet, or returns `None` if the packet was dropped
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/connection/paths.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cmp, net::SocketAddr, time::Duration, time::Instant};
use std::{cmp, net::SocketAddr};

use tracing::trace;

Expand All @@ -7,7 +7,7 @@ use super::{
pacing::Pacer,
spaces::{PacketSpace, SentPacket},
};
use crate::{congestion, packet::SpaceId, TransportConfig, TIMER_GRANULARITY};
use crate::{congestion, packet::SpaceId, Duration, Instant, TransportConfig, TIMER_GRANULARITY};

/// Description of a particular network path
pub(super) struct PathData {
Expand Down
3 changes: 1 addition & 2 deletions quinn-proto/src/connection/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::{
collections::{BTreeMap, VecDeque},
mem,
ops::{Bound, Index, IndexMut},
time::{Duration, Instant},
};

use rand::Rng;
Expand All @@ -13,7 +12,7 @@ use tracing::trace;
use super::assembler::Assembler;
use crate::{
connection::StreamsState, crypto::Keys, frame, packet::SpaceId, range_set::ArrayRangeSet,
shared::IssuedCid, Dir, StreamId, TransportError, VarInt,
shared::IssuedCid, Dir, Duration, Instant, StreamId, TransportError, VarInt,
};

pub(super) struct PacketSpace {
Expand Down
3 changes: 1 addition & 2 deletions quinn-proto/src/connection/stats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Connection statistics

use crate::{frame::Frame, Dir};
use std::time::Duration;
use crate::{frame::Frame, Dir, Duration};

/// Statistics about UDP datagrams transmitted or received on a connection
#[derive(Default, Debug, Copy, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/timer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::time::Instant;
use crate::Instant;

#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
pub(crate) enum Timer {
Expand Down
5 changes: 2 additions & 3 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
net::{IpAddr, SocketAddr},
ops::{Index, IndexMut},
sync::Arc,
time::{Instant, SystemTime},
};

use bytes::{BufMut, Bytes, BytesMut};
Expand All @@ -32,8 +31,8 @@ use crate::{
},
token::TokenDecodeError,
transport_parameters::{PreferredAddress, TransportParameters},
ResetToken, RetryToken, Side, Transmit, TransportConfig, TransportError, INITIAL_MTU,
MAX_CID_SIZE, MIN_INITIAL_SIZE, RESET_TOKEN_SIZE,
Instant, ResetToken, RetryToken, Side, SystemTime, Transmit, TransportConfig, TransportError,
INITIAL_MTU, MAX_CID_SIZE, MIN_INITIAL_SIZE, RESET_TOKEN_SIZE,
};

/// The main entry point to the library
Expand Down
7 changes: 6 additions & 1 deletion quinn-proto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::{
fmt,
net::{IpAddr, SocketAddr},
ops,
time::Duration,
};

mod cid_queue;
Expand Down Expand Up @@ -89,6 +88,12 @@ use token::{ResetToken, RetryToken};
#[cfg(feature = "arbitrary")]
use arbitrary::Arbitrary;

// Deal with time
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
pub(crate) use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
pub(crate) use web_time::{Duration, Instant, SystemTime, UNIX_EPOCH};

#[doc(hidden)]
#[cfg(fuzzing)]
pub mod fuzzing {
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{fmt, net::SocketAddr, time::Instant};
use std::{fmt, net::SocketAddr};

use bytes::{Buf, BufMut, BytesMut};

use crate::{coding::BufExt, packet::PartialDecode, ResetToken, MAX_CID_SIZE};
use crate::{coding::BufExt, packet::PartialDecode, Instant, ResetToken, MAX_CID_SIZE};

/// Events sent from an Endpoint to a Connection
#[derive(Debug)]
Expand Down
Loading

0 comments on commit 75a1b3c

Please sign in to comment.