-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
602 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
Oops, something went wrong.