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

basic wasm compat #8

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 28 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ jobs:
- run: cargo test --manifest-path fuzz/Cargo.toml
if: ${{ matrix.rust }} == "stable"

wasm_build:
name: Build wasm32
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: wasm32 build (quinn)
run: cargo build -p iroh-quinn --no-default-features --features log,ring,rustls,wasm,runtime-wasm --target wasm32-unknown-unknown
env:
RUST_BACKTRACE: 1

- name: wasm32 build (quinn-proto)
run: cargo build -p iroh-quinn-proto --features wasm --target wasm32-unknown-unknown
env:
RUST_BACKTRACE: 1
- name: wasm32 build (quinn-udp)
run: cargo build -p iroh-quinn-udp --no-default-features --features log --target wasm32-unknown-unknown
env:
RUST_BACKTRACE: 1

msrv:
runs-on: ubuntu-latest
env:
Expand All @@ -42,7 +69,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: mozilla-actions/sccache-action@v0.0.4
- uses: dtolnay/rust-toolchain@1.63.0
- uses: dtolnay/rust-toolchain@1.73.0
- run: cargo check --lib --all-features -p iroh-quinn-udp -p iroh-quinn-proto -p iroh-quinn

lint:
Expand Down
10 changes: 7 additions & 3 deletions quinn-proto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "iroh-quinn-proto"
version = "0.10.8"
edition = "2021"
rust-version = "1.63"
rust-version = "1.73"
license = "MIT OR Apache-2.0"
repository = "https://github.com/quinn-rs/quinn"
description = "State machine for the QUIC transport protocol"
Expand All @@ -18,24 +18,28 @@ maintenance = { status = "experimental" }

[features]
default = ["tls-rustls", "log"]
tls-rustls = ["rustls", "ring"]
tls-rustls = ["rustls", "ring", "rustls-pki-types"]
# Provides `ClientConfig::with_native_roots()` convenience method
native-certs = ["rustls-native-certs"]
# Write logs via the `log` crate when no `tracing` subscriber exists
log = ["tracing/log"]
wasm = ["getrandom/js", "ring?/wasm32_unknown_unknown_js", "rustls-pki-types?/web", "dep:web-time"]

[dependencies]
arbitrary = { version = "1.0.1", features = ["derive"], optional = true }
bytes = "1"
rustc-hash = "1.1"
rand = "0.8"
ring = { version = "0.17", optional = true }
rustls = { version = "0.21.0", default-features = false, features = ["quic"], optional = true }
rustls = { git = "https://github.com/matheus23/rustls", branch = "0.21-wasm", default-features = false, features = ["quic"], optional = true }
rustls-native-certs = { version = "0.6", optional = true }
slab = "0.4"
thiserror = "1.0.21"
tinyvec = { version = "1.1", features = ["alloc"] }
tracing = "0.1.10"
getrandom = { version = "0.2", default-features = false }
rustls-pki-types = { version = "1.7", optional = true }
web-time = { version = "1", optional = true }

[dev-dependencies]
assert_matches = "1.1"
Expand Down
4 changes: 1 addition & 3 deletions quinn-proto/src/cid_generator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::time::Duration;

use rand::RngCore;

use crate::shared::ConnectionId;
use crate::MAX_CID_SIZE;
use crate::{Duration, MAX_CID_SIZE};

/// Generates connection IDs for incoming connections
pub trait ConnectionIdGenerator: Send {
Expand Down
13 changes: 7 additions & 6 deletions quinn-proto/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt, num::TryFromIntError, sync::Arc, time::Duration};
use std::{fmt, num::TryFromIntError, sync::Arc};

use thiserror::Error;

Expand All @@ -9,7 +9,8 @@ use crate::{
cid_generator::{ConnectionIdGenerator, RandomConnectionIdGenerator},
congestion,
crypto::{self, HandshakeTokenKey, HmacKey},
VarInt, VarIntBoundsExceeded, DEFAULT_SUPPORTED_VERSIONS, INITIAL_MTU, MAX_UDP_PAYLOAD,
Duration, VarInt, VarIntBoundsExceeded, DEFAULT_SUPPORTED_VERSIONS, INITIAL_MTU,
MAX_UDP_PAYLOAD,
};

/// Parameters governing the core QUIC state machine
Expand Down Expand Up @@ -79,8 +80,8 @@ impl TransportConfig {
/// idle timeout can result in permanently hung futures!
///
/// ```
/// # use std::{convert::TryInto, time::Duration};
/// # use iroh_quinn_proto::{TransportConfig, VarInt, VarIntBoundsExceeded};
/// # use std::{convert::TryInto};
/// # use iroh_quinn_proto::{TransportConfig, VarInt, VarIntBoundsExceeded, Duration};
/// # fn main() -> Result<(), VarIntBoundsExceeded> {
/// let mut config = TransportConfig::default();
///
Expand Down Expand Up @@ -863,8 +864,8 @@ impl From<VarIntBoundsExceeded> for ConfigError {
/// constructed by converting directly from `VarInt`, or using `TryFrom<Duration>`.
///
/// ```
/// # use std::{convert::TryFrom, time::Duration};
/// # use iroh_quinn_proto::{IdleTimeout, VarIntBoundsExceeded, VarInt};
/// # use std::{convert::TryFrom};
/// # use iroh_quinn_proto::{IdleTimeout, VarIntBoundsExceeded, VarInt, Duration};
/// # fn main() -> Result<(), VarIntBoundsExceeded> {
/// // A `VarInt`-encoded value in milliseconds
/// let timeout = IdleTimeout::from(VarInt::from_u32(10_000));
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/congestion.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Logic for controlling the rate at which data is sent

use crate::connection::RttEstimator;
use crate::Instant;
use std::any::Any;
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
3 changes: 1 addition & 2 deletions quinn-proto/src/congestion/cubic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::any::Any;
use std::sync::Arc;
use std::time::{Duration, Instant};

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

/// CUBIC Constants.
Expand Down
3 changes: 1 addition & 2 deletions quinn-proto/src/congestion/new_reno.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
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::{connection::RttEstimator, Instant};

/// A simple, standard congestion controller
#[derive(Debug, Clone)]
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 @@ -30,8 +29,9 @@ use crate::{
},
token::ResetToken,
transport_parameters::TransportParameters,
Dir, EndpointConfig, Frame, Side, StreamId, Transmit, TransportError, TransportErrorCode,
VarInt, MAX_STREAM_COUNT, MIN_INITIAL_SIZE, RESET_TOKEN_SIZE, TIMER_GRANULARITY,
Dir, Duration, EndpointConfig, Frame, Instant, Side, StreamId, Transmit, TransportError,
TransportErrorCode, VarInt, MAX_STREAM_COUNT, MIN_INITIAL_SIZE, RESET_TOKEN_SIZE,
TIMER_GRANULARITY,
};

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

/// Implements Datagram Packetization Layer Path Maximum Transmission Unit Discovery
Expand Down Expand Up @@ -484,9 +483,8 @@ const BINARY_SEARCH_MINIMUM_CHANGE: u16 = 20;
mod tests {
use super::*;
use crate::packet::SpaceId;
use crate::MAX_UDP_PAYLOAD;
use crate::{Duration, MAX_UDP_PAYLOAD};
use assert_matches::assert_matches;
use std::time::Duration;

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

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

use tracing::warn;

use crate::{Duration, Instant};

/// A simple token-bucket pacer
///
/// The pacer's capacity is derived on a fraction of the congestion window
Expand Down
4 changes: 1 addition & 3 deletions quinn-proto/src/connection/packet_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::time::Instant;

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

pub(super) struct PacketBuilder {
Expand Down
6 changes: 4 additions & 2 deletions quinn-proto/src/connection/paths.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::{cmp, net::SocketAddr, time::Duration, time::Instant};
use std::{cmp, net::SocketAddr};

use super::{mtud::MtuDiscovery, pacing::Pacer};
use crate::{config::MtuDiscoveryConfig, congestion, packet::SpaceId, TIMER_GRANULARITY};
use crate::{
config::MtuDiscoveryConfig, congestion, packet::SpaceId, Duration, Instant, 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,15 +3,14 @@ use std::{
collections::{BTreeMap, VecDeque},
mem,
ops::{Index, IndexMut},
time::{Duration, Instant},
};

use rustc_hash::FxHashSet;

use super::assembler::Assembler;
use crate::{
connection::StreamsState, crypto::Keys, frame, packet::SpaceId, range_set::ArrayRangeSet,
shared::IssuedCid, Dir, StreamId, VarInt,
shared::IssuedCid, Dir, Duration, Instant, StreamId, 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 @@ -28,8 +27,8 @@ use crate::{
EndpointEventInner, IssuedCid,
},
transport_parameters::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 @@ -286,6 +285,12 @@ pub struct Transmit {
pub src_ip: Option<IpAddr>,
}

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

//
// Useful internal constants
//
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
3 changes: 1 addition & 2 deletions quinn-proto/src/token.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
fmt, io,
net::{IpAddr, SocketAddr},
time::{Duration, SystemTime, UNIX_EPOCH},
};

use bytes::BufMut;
Expand All @@ -10,7 +9,7 @@ use crate::{
coding::{BufExt, BufMutExt},
crypto::{CryptoError, HandshakeTokenKey, HmacKey},
shared::ConnectionId,
RESET_TOKEN_SIZE,
Duration, SystemTime, RESET_TOKEN_SIZE, UNIX_EPOCH,
};

pub(crate) struct RetryToken<'a> {
Expand Down
Loading
Loading