Skip to content

Commit

Permalink
feat: support {Free|Net|Open}BSD (#2311)
Browse files Browse the repository at this point in the history
Adds support for `iroh`  on `NetBSD`, `FreeBSD` and `OpenBSD`.

## Status

- NetBsd
  - [x] Compiles
  - [ ] Tests passing
- [ ] Iroh: mostly passing, failures are only due to
shellrow/netdev#69
    - [x] Quinn
  - [x] Implementation adapted
- FreeBsd
  - [x] Compiles
  - [ ] Tests passing
- [ ] Iroh: mostly passing, failures are only due to
shellrow/netdev#69
    - [x] Quinn
  - [x] Implementation adapted
- OpenBsd
  - [x] Compiles
  - [ ] Tests passing
- [ ] Iroh: mostly passing, failures are only due to
shellrow/netdev#69
    - [x] Quinn
  - [x] Implementation adapted


## Caveats

- Build only in CI for now

## Related Issues

- shellrow/netdev#69
- n0-computer/quinn#9

## References

-
https://github.com/freebsd/freebsd-ports/blob/78ad38f04f51/games/jumpy/files/patch-iroh
- rust-lang/libc#3711

Closes #2306

---------

Co-authored-by: Floris Bruynooghe <[email protected]>
  • Loading branch information
dignifiedquire and flub authored May 24, 2024
1 parent 1e31dcf commit cd65470
Show file tree
Hide file tree
Showing 13 changed files with 861 additions and 152 deletions.
43 changes: 36 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ jobs:
if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')"
uses: './.github/workflows/tests.yaml'

cross:
cross_build:
name: Cross Build Only
if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')"
timeout-minutes: 30
name: Cross compile
runs-on: [self-hosted, linux, X64]
strategy:
fail-fast: false
matrix:
target:
- i686-unknown-linux-gnu
# cross tests are currently broken vor armv7 and aarch64
# see https://github.com/cross-rs/cross/issues/1311
- armv7-linux-androideabi
- aarch64-linux-android
# Freebsd execution fails in cross
# - i686-unknown-freebsd # Linking fails :/
- x86_64-unknown-freebsd
- x86_64-unknown-netbsd
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -59,15 +64,39 @@ jobs:
# cross tests are currently broken vor armv7 and aarch64
# see https://github.com/cross-rs/cross/issues/1311. So on
# those platforms we only build but do not run tests.
if: matrix.target != 'i686-unknown-linux-gnu'
run: cross build --all --target ${{ matrix.target }}
env:
RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG'}}

cross_test:
name: Cross Test
if: "github.event_name != 'pull_request' || ! contains(github.event.pull_request.labels.*.name, 'flaky-test')"
timeout-minutes: 30
runs-on: [self-hosted, linux, X64]
strategy:
fail-fast: false
matrix:
target:
- i686-unknown-linux-gnu
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

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

- name: Cleanup Docker
continue-on-error: true
run: |
docker kill $(docker ps -q)
- name: Install cross
# See https://github.com/cross-rs/cross/issues/1222
run: cargo install cross --git https://github.com/cross-rs/cross

- name: test
# cross tests are currently broken vor armv7 and aarch64
# see https://github.com/cross-rs/cross/issues/1311
if: matrix.target == 'i686-unknown-linux-gnu'
run: cross test --all --target ${{ matrix.target }} -- --test-threads=12
env:
RUST_LOG: ${{ runner.debug && 'TRACE' || 'DEBUG' }}
Expand Down
2 changes: 1 addition & 1 deletion 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 iroh-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ parking_lot = "0.12.1"
pin-project = "1"
pkarr = { version = "1.1.4", default-features = false, features = ["async", "relay"] }
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
quinn = { package = "iroh-quinn", version = "0.10.4" }
quinn-proto = { package = "iroh-quinn-proto", version = "0.10.7" }
quinn-udp = { package = "iroh-quinn-udp", version = "0.4" }
quinn = { package = "iroh-quinn", version = "0.10.5" }
quinn-proto = { package = "iroh-quinn-proto", version = "0.10.8" }
quinn-udp = { package = "iroh-quinn-udp", version = "0.4.2" }
rand = "0.8"
rand_core = "0.6.4"
rcgen = "0.11"
rcgen = "0.12"
reqwest = { version = "0.12.4", default-features = false, features = ["rustls-tls"] }
ring = "0.17"
rustls = { version = "0.21.11", default-features = false, features = ["dangerous_configuration"] }
Expand Down
4 changes: 3 additions & 1 deletion iroh-net/bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ anyhow = "1.0.22"
bytes = "1"
hdrhistogram = { version = "7.2", default-features = false }
iroh-net = { path = ".." }
quinn = "0.10"
rcgen = "0.11.1"
rustls = { version = "0.21.0", default-features = false, features = ["quic"] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.0.1", features = ["rt", "sync"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["env-filter", "fmt", "ansi", "time", "local-time"] }
socket2 = "0.5"

[target.'cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))'.dependencies]
quinn = "0.10"
6 changes: 5 additions & 1 deletion iroh-net/bench/src/bin/bulk.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anyhow::Result;
use clap::Parser;

use iroh_net_bench::{configure_tracing_subscriber, iroh, quinn, rt, s2n, Commands, Opt};
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
use iroh_net_bench::quinn;
use iroh_net_bench::{configure_tracing_subscriber, iroh, rt, s2n, Commands, Opt};

fn main() {
let cmd = Commands::parse();
Expand All @@ -13,6 +15,7 @@ fn main() {
eprintln!("failed: {e:#}");
}
}
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
Commands::Quinn(opt) => {
if let Err(e) = run_quinn(opt) {
eprintln!("failed: {e:#}");
Expand Down Expand Up @@ -70,6 +73,7 @@ pub fn run_iroh(opt: Opt) -> Result<()> {
Ok(())
}

#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
pub fn run_quinn(opt: Opt) -> Result<()> {
let server_span = tracing::error_span!("server");
let runtime = rt();
Expand Down
12 changes: 12 additions & 0 deletions iroh-net/bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use tokio::sync::Semaphore;
use tracing::info;

pub mod iroh;
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
pub mod quinn;
pub mod s2n;
pub mod stats;
Expand All @@ -21,6 +22,7 @@ pub mod stats;
#[clap(name = "bulk")]
pub enum Commands {
Iroh(Opt),
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
Quinn(Opt),
S2n(s2n::Opt),
}
Expand Down Expand Up @@ -62,6 +64,7 @@ pub struct Opt {

pub enum EndpointSelector {
Iroh(iroh_net::Endpoint),
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
Quinn(::quinn::Endpoint),
}

Expand All @@ -71,6 +74,7 @@ impl EndpointSelector {
EndpointSelector::Iroh(endpoint) => {
endpoint.close(0u32.into(), b"").await?;
}
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
EndpointSelector::Quinn(endpoint) => {
endpoint.close(0u32.into(), b"");
}
Expand All @@ -81,6 +85,7 @@ impl EndpointSelector {

pub enum ConnectionSelector {
Iroh(iroh_net::endpoint::Connection),
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
Quinn(::quinn::Connection),
}

Expand All @@ -90,6 +95,7 @@ impl ConnectionSelector {
ConnectionSelector::Iroh(connection) => {
println!("{:#?}", connection.stats());
}
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
ConnectionSelector::Quinn(connection) => {
println!("{:#?}", connection.stats());
}
Expand All @@ -101,6 +107,7 @@ impl ConnectionSelector {
ConnectionSelector::Iroh(connection) => {
connection.close(error_code.into(), reason);
}
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
ConnectionSelector::Quinn(connection) => {
connection.close(error_code.into(), reason);
}
Expand Down Expand Up @@ -193,6 +200,11 @@ pub async fn client_handler(
iroh::handle_client_stream(connection, opt.upload_size, opt.read_unordered)
.await
}
#[cfg(not(any(
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd"
)))]
ConnectionSelector::Quinn(connection) => {
quinn::handle_client_stream(connection, opt.upload_size, opt.read_unordered)
.await
Expand Down
Loading

0 comments on commit cd65470

Please sign in to comment.