Skip to content
Merged
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
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
- run: cargo build --verbose
- run: cargo test --verbose
# The default backend without HTTP/2, which no other job tests.
- if: matrix.os == 'ubuntu-latest'
run: cargo test --no-default-features --features rustls-tls --verbose

native-tls:
name: Test with the OpenSSL backend
Expand All @@ -50,6 +53,9 @@ jobs:
toolchain: stable
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
- run: cargo test --no-default-features --features native-tls --verbose
# With HTTP/2 this backend offers h2 through OpenSSL's ALPN, which
# tests/alpn.rs checks against a TLS server.
- run: cargo test --no-default-features --features native-tls,http2 --verbose

msrv:
name: Minimum supported Rust version
Expand All @@ -72,7 +78,9 @@ jobs:
toolchain: ${{ steps.msrv.outputs.version }}
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3
- run: cargo check --all-targets
- run: cargo check --all-targets --no-default-features --features rustls-tls
- run: cargo check --all-targets --no-default-features --features native-tls
- run: cargo check --all-targets --no-default-features --features native-tls,http2

fuzz:
name: Fuzz targets build
Expand Down
13 changes: 9 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ name = "librespeed-cli"
path = "src/main.rs"

[features]
default = ["rustls-tls"]
default = ["rustls-tls", "http2"]
# rustls with the ring crypto provider. Statically linked, no system TLS
# library needed. ring has assembly only for x86, x86_64, aarch64 and arm and
# runs portable C elsewhere, which is slow on a core without crypto instructions.
Expand All @@ -57,6 +57,9 @@ rustls-tls = [
# packaging uses: it depends on the libopenssl package instead of carrying a
# TLS library of its own.
native-tls = ["dep:hyper-tls", "dep:native-tls", "dep:tokio-native-tls"]
# HTTP/2 behind --http2. Without it the option is refused and h2 is not
# compiled in, which is what a size-constrained build such as OpenWrt's wants.
http2 = ["hyper/http2", "hyper-util/http2", "hyper-rustls?/http2"]

[dependencies]
anyhow = "1"
Expand All @@ -68,13 +71,13 @@ futures-util = { version = "0.3", default-features = false, features = ["std"] }
http = "1"
http-body = "1"
http-body-util = "0.1"
hyper = { version = "1", features = ["client", "http1", "http2"] }
hyper-rustls = { version = "0.27", default-features = false, features = ["http1", "http2", "tls12", "ring", "rustls-native-certs"], optional = true }
hyper = { version = "1", features = ["client", "http1"] }
hyper-rustls = { version = "0.27", default-features = false, features = ["http1", "tls12", "ring", "rustls-native-certs"], optional = true }
# alpn: without it hyper-tls compiles out its report of the negotiated
# protocol, so hyper would write an HTTP/1.1 head onto a connection both ends
# agreed to speak h2 on. It forwards to native-tls/alpn, already enabled.
hyper-tls = { version = "0.6", features = ["alpn"], optional = true }
hyper-util = { version = "0.1", features = ["client", "client-legacy", "http1", "http2", "tokio"] }
hyper-util = { version = "0.1", features = ["client", "client-legacy", "http1", "tokio"] }
libc = "0.2"
native-tls = { version = "0.2", features = ["alpn"], optional = true }
rand = "0.10"
Expand Down Expand Up @@ -105,5 +108,7 @@ chrono = { version = "0.4", default-features = false, features = ["std", "clock"
# dependency tree through url, so this adds no crate, only a direct edge.
icu_properties = "2.2"
serde_json = "1"
# The TLS server in tests/alpn.rs, so ALPN is checked with either backend.
rustls = { version = "0.23", default-features = false, features = ["ring", "std"] }
# Paused clock for the connection racing tests.
tokio = { version = "1", features = ["test-util"] }
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ librespeed-cli --fwmark 42 # Linux only
| `native-tls` | system OpenSSL | libopenssl | anything OpenSSL builds for |

```sh
cargo build --release --no-default-features --features native-tls
cargo build --release --no-default-features --features native-tls,http2
```

HTTP/2 is the `http2` feature, on by default. `--no-default-features` drops it
as well, so name it again if `--http2` is wanted. A build without it is smaller
and refuses `--http2`.

> [!IMPORTANT]
> `ring` has assembly only for x86, x86_64, aarch64 and arm. Elsewhere it runs
> portable C. On a slow core without crypto instructions that can cost enough
Expand All @@ -82,8 +86,9 @@ The Go client cannot run on 32-bit PowerPC, because Go targets only `ppc64` and
`ppc64le`. Rust reaches that hardware through the Tier 3 target
`powerpc-unknown-linux-muslspe`, so this port also covers Turris 1.x.

The OpenWrt package `librespeed-cli-rust` builds the `native-tls` backend and
depends on `libopenssl`.
The OpenWrt package `librespeed-cli-rust` builds the `native-tls` backend with
`--no-default-features` and depends on `libopenssl`. That leaves HTTP/2 out,
as in the Turris build below, while a plain `cargo build` has it.

To build for Turris 1.x by hand:

Expand Down Expand Up @@ -153,6 +158,7 @@ deliberately different.
over one TCP connection, so `--concurrent` would stop meaning connections.
Go negotiates h2 whenever a server offers it. With `--http2` the flow-control
windows are raised to Go's values, 4 MiB per stream and 1 GiB per connection.
A build without the `http2` feature refuses the option.
- **Scheme-less server URLs with a port work.** `example.com:8080/backend`
becomes an `http://` URL. Go takes `example.com` for the scheme, and
`127.0.0.1:8080/` makes it reject the whole list.
Expand Down
4 changes: 3 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ pub struct Cli {
/// Allow HTTP/2 when the server offers it. Off by default: HTTP/2 carries
/// every stream over one TCP connection, so --concurrent would no longer
/// mean concurrent connections, which is what a speed test measures
#[arg(long = "http2")]
// Hidden from --help in a build without the `http2` feature, where it is
// refused with an error that says why.
#[arg(long = "http2", hide = cfg!(not(feature = "http2")))]
pub http2: bool,
}

Expand Down
6 changes: 6 additions & 0 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ pub const MAX_TELEMETRY_RESPONSE: usize = 64 * 1024;
/// The protocol default is 64 KiB, which caps a stream at window/RTT: about
/// 105 Mbps at 5 ms and 26 Mbps at 20 ms. Leaving it there would silently
/// understate any link faster than that.
#[cfg(feature = "http2")]
const H2_STREAM_WINDOW: u32 = 4 * 1024 * 1024;
#[cfg(feature = "http2")]
const H2_CONNECTION_WINDOW: u32 = 1024 * 1024 * 1024;

pub type ReqBody = BoxBody<Bytes, io::Error>;
Expand Down Expand Up @@ -190,11 +192,15 @@ pub(crate) fn client_builder(
let mut builder = Client::builder(TokioExecutor::new());
builder.pool_max_idle_per_host(concurrent + 2);

#[cfg(feature = "http2")]
if http2 {
builder
.http2_initial_stream_window_size(H2_STREAM_WINDOW)
.http2_initial_connection_window_size(H2_CONNECTION_WINDOW);
}
// A build without the `http2` feature refuses --http2 before it gets here.
#[cfg(not(feature = "http2"))]
let _ = http2;
builder
}

Expand Down
24 changes: 15 additions & 9 deletions src/http/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ mod imp {
fn client_config(tls: &TlsSettings<'_>) -> anyhow::Result<rustls::ClientConfig> {
let provider = Arc::new(rustls::crypto::ring::default_provider());

// ALPN is left untouched: hyper-rustls sets it from `enable_http1()`.
// ALPN is left to hyper-rustls: `enable_all_versions()` offers h2 and
// http/1.1, `enable_http1()` alone offers nothing.
if tls.skip_verify {
// Say so rather than ignoring the bundle in silence: a run that
// named a CA file and verified nothing looks like a run that
Expand Down Expand Up @@ -322,15 +323,20 @@ mod imp {
.https_or_http();

// ALPN decides the protocol, so h2 is only reachable when offered here.
Ok(ReportingConnector(if tls.http2 {
builder
.enable_all_versions()
.wrap_connector(BoundConnector::new(bind))
} else {
#[cfg(feature = "http2")]
if tls.http2 {
return Ok(ReportingConnector(
builder
.enable_all_versions()
.wrap_connector(BoundConnector::new(bind)),
));
}

Ok(ReportingConnector(
builder
.enable_http1()
.wrap_connector(BoundConnector::new(bind))
}))
.wrap_connector(BoundConnector::new(bind)),
))
}
}

Expand Down Expand Up @@ -370,7 +376,7 @@ mod imp {
builder.disable_built_in_roots(true);
}

if tls.http2 {
if cfg!(feature = "http2") && tls.http2 {
builder.request_alpns(&["h2", "http/1.1"]);
}

Expand Down
4 changes: 4 additions & 0 deletions src/speedtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ pub async fn run(cli: &Cli) -> anyhow::Result<()> {
anyhow::bail!("incompatible options 'source' and 'interface'");
}

if cli.http2 && !cfg!(feature = "http2") {
anyhow::bail!("this build has no HTTP/2 support, so --http2 cannot be used");
}

let delimiter = cli.csv_delimiter_byte()?;

// If --csv-header is given, print the header and exit (same behavior as speedtest-cli).
Expand Down
Loading
Loading