Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Aug 25, 2023
1 parent 63294d3 commit f430787
Show file tree
Hide file tree
Showing 19 changed files with 602 additions and 151 deletions.
90 changes: 90 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[target.'cfg(all())']
rustflags = [
# Deny `unsafe`.
"-Dunsafe_code",
# Clippy groups.
"-Wclippy::pedantic",
"-Wclippy::cargo",
# Clippy lints.
"-Wclippy::allow_attributes_without_reason",
"-Wclippy::as_conversions",
"-Wclippy::as_underscore",
"-Wclippy::assertions_on_result_states",
"-Wclippy::clone_on_ref_ptr",
"-Wclippy::create_dir",
"-Wclippy::dbg_macro",
"-Wclippy::decimal_literal_representation",
"-Wclippy::default_numeric_fallback",
"-Wclippy::deref_by_slicing",
"-Wclippy::empty_drop",
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::filetype_is_file",
"-Wclippy::format_push_string",
"-Wclippy::get_unwrap",
"-Wclippy::if_then_some_else_none",
"-Wclippy::impl_trait_in_params",
"-Wclippy::inline_asm_x86_att_syntax",
"-Wclippy::large_include_file",
"-Wclippy::lossy_float_literal",
"-Wclippy::min_ident_chars",
"-Wclippy::missing_docs_in_private_items",
"-Wclippy::mixed_read_write_in_expression",
"-Wclippy::multiple_inherent_impl",
"-Wclippy::multiple_unsafe_ops_per_block",
"-Wclippy::mutex_atomic",
"-Wclippy::needless_raw_strings",
"-Wclippy::partial_pub_fields",
"-Wclippy::pub_without_shorthand",
"-Wclippy::rc_mutex",
"-Wclippy::redundant_type_annotations",
"-Wclippy::ref_patterns",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::same_name_method",
"-Wclippy::self_named_module_files",
"-Wclippy::single_char_lifetime_names",
"-Wclippy::str_to_string",
"-Wclippy::string_add",
"-Wclippy::string_slice",
"-Wclippy::string_to_string",
"-Wclippy::suspicious_xor_used_as_pow",
"-Wclippy::todo",
"-Wclippy::try_err",
"-Wclippy::undocumented_unsafe_blocks",
"-Wclippy::unimplemented",
"-Wclippy::unnecessary_safety_doc",
"-Wclippy::unnecessary_self_imports",
"-Wclippy::unneeded_field_pattern",
"-Wclippy::unseparated_literal_suffix",
"-Wclippy::verbose_file_reads",
# Allowed Clippy lints.
"-Aclippy::tabs_in_doc_comments",
# Rustdoc group.
"-Wrustdoc::all",
# Rust groups.
"-Wfuture_incompatible",
"-Wrust_2018_compatibility",
"-Wrust_2018_idioms",
"-Wrust_2021_compatibility",
"-Wunused",
# Rust lints.
"-Wdeprecated_in_future",
"-Wffi_unwind_calls",
"-Winvalid-reference_casting",
"-Wmacro_use_extern_crate",
"-Wmeta_variable_misuse",
"-Wmissing_abi",
"-Wmissing_copy_implementations",
"-Wmissing_debug_implementations",
"-Wmissing_docs",
"-Wnon_ascii_idents",
"-Wnoop_method_call",
"-Wsingle_use_lifetimes",
"-Wtrivial_casts",
"-Wtrivial_numeric_casts",
"-Wunreachable_pub",
"-Wunsafe_op_in_unsafe_fn",
"-Wunused_import_braces",
"-Wunused_lifetimes",
"-Wunused_qualifications",
"-Wunused_tuple_struct_fields",
]
13 changes: 9 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ jobs:
- name: Run doc tests
run: |
rustup toolchain install nightly --profile minimal --allow-downgrade
cargo +nightly test --workspace --doc --all-features
cargo test --workspace --doc --all-features
msrv:
runs-on: ubuntu-latest
Expand All @@ -43,7 +42,7 @@ jobs:
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: "1.68.2"
toolchain: "1.72"

- name: Run unit tests
run: |
Expand All @@ -63,6 +62,12 @@ jobs:
run: |
cargo clippy --workspace --all-targets --all-features -- -D warnings
- name: Run Rustdoc
run: |
cargo doc --no-deps --workspace --all-features
env:
RUSTDOCFLAGS: -D warnings

docs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
Expand All @@ -79,7 +84,7 @@ jobs:
rustup install nightly --profile minimal
cargo +nightly doc --no-deps --workspace --all-features
env:
RUSTDOCFLAGS: -D warnings
RUSTDOCFLAGS: --cfg docsrs

- name: Deploy Docs
uses: JamesIves/github-pages-deploy-action@releases/v4
Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repository = "https://github.com/khonsulabs/fabruic"
keywords = ["quic"]
categories = ["network-programming"]
edition = "2021"
rust-version = "1.68.2"
rust-version = "1.72"

[features]
dangerous = []
Expand All @@ -24,12 +24,10 @@ flume = { version = "0.11" }
futures-channel = "0.3"
futures-executor = "0.3"
futures-util = "0.3"
if_chain = "1"
parking_lot = { version = "0.12", features = ["send_guard"] }
pin-project = "1"
quinn = "0.10.1"
rcgen = { version = "0.11.0", default-features = false, optional = true }
ring = "0.16"
rustls = { version = "0.21.1", default-features = false, features = [
"dangerous_configuration",
] }
Expand Down Expand Up @@ -65,4 +63,5 @@ lto = true

[package.metadata.docs.rs]
features = ["dangerous", "rcgen", "trust-dns"]
rustdoc-args = ["--cfg", "docsrs"]
targets = []
6 changes: 5 additions & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
//! TODO

use anyhow::{Error, Result};
use fabruic::{Endpoint, KeyPair};
use futures_util::{future, StreamExt, TryFutureExt};

/// Used in the certificate.
const SERVER_NAME: &str = "test";
/// Some random port.
const SERVER_PORT: u16 = 34857;
/// Number of clients to simulate.
const CLIENTS: usize = 100;

#[tokio::main]
Expand Down Expand Up @@ -55,7 +59,7 @@ async fn main() -> Result<()> {
);

// send message
sender.send(&format!("hello from client {}", index))?;
sender.send(&format!("hello from client {index}"))?;

// start listening to new incoming messages
// in this example we know there is only 1 incoming message, so we will
Expand Down
100 changes: 100 additions & 0 deletions examples/onestream.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//! TODO

#![allow(clippy::missing_docs_in_private_items)]

use anyhow::{Error, Result};
use fabruic::{Endpoint, KeyPair};
use futures_util::StreamExt;

const SERVER_NAME: &str = "test";
const SERVER_PORT: u16 = 5001;
const CLIENTS: usize = 100;

#[tokio::main]
#[cfg_attr(test, test)]
async fn main() -> Result<()> {
// generate a certificate pair
let key_pair = KeyPair::new_self_signed(SERVER_NAME);

// start the server
let server = Endpoint::new_server(SERVER_PORT, key_pair.clone())?;
let address = format!("quic://{}", server.local_address()?);
println!("[server] Listening on {address}");
tokio::spawn(run_server(server));

// build a client
let client = Endpoint::new_client()?;

let connection = client
.connect_pinned(address, key_pair.end_entity_certificate(), None)
.await?
.accept::<()>()
.await?;
connection.close_incoming().await?;

// initiate a stream
let (sender, receiver) = connection.open_stream::<String, String>(&()).await?;

let tasks = (0..CLIENTS)
.map(|_| {
let sender = sender.clone();
let mut receiver = receiver.clone();
async move {
sender.send(&String::from("test"))?;
let value = receiver.next().await.expect("didn't get a response")?;
assert_eq!(value, "test");
Ok(())
}
})
.collect::<Vec<_>>();

futures_util::future::join_all(tasks)
.await
.into_iter()
.collect::<Result<Vec<()>, Error>>()?;

// wait for client to finish cleanly
client.wait_idle().await;

Ok(())
}

async fn run_server(mut server: Endpoint) -> Result<(), Error> {
// start listening to new incoming connections
// in this example we know there is `CLIENTS` number of clients, so we will not
// wait for more
let mut connection = server
.next()
.await
.expect("connection failed")
.accept::<()>()
.await?;
println!("[server] New Connection: {}", connection.remote_address());

// start listening to new incoming streams
// in this example we know there is only 1 incoming stream, so we will not wait
// for more
let incoming = connection.next().await.expect("no stream found")?;
connection.close_incoming().await?;
println!(
"[server] New incoming stream from: {}",
connection.remote_address()
);

// accept stream
let (sender, mut receiver) = incoming.accept::<String, String>().await?;

// start listening to new incoming messages
// in this example we know there is only 1 incoming message, so we will not wait
// for more
while let Some(message) = receiver.next().await {
let message = message?;
sender.send(&message)?;
}

// wait for stream to finish
sender.finish().await?;
receiver.finish().await?;

Ok(())
}
Loading

0 comments on commit f430787

Please sign in to comment.