Skip to content

Commit

Permalink
chore: workspace lints
Browse files Browse the repository at this point in the history
Signed-off-by: iGxnon <igxnon@gmail.com>
  • Loading branch information
iGxnon committed Sep 4, 2024
1 parent 74dda0d commit 02424ed
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 52 deletions.
41 changes: 41 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,44 @@ required-features = ["micro-bench"]
[profile.bench]
opt-level = 3
lto = true
## WORKSPACE

[lints]
workspace = true

[workspace.lints.rust]
keyword_idents = "warn"
missing_copy_implementations = "warn"
missing_debug_implementations = "warn"
non_ascii_idents = "warn"
noop_method_call = "warn"
unused_extern_crates = "warn"
unused_import_braces = "warn"

[workspace.lints.clippy]
cognitive_complexity = "warn"
dbg_macro = "warn"
debug_assert_with_mut_call = "warn"
doc_link_with_quotes = "warn"
doc_markdown = "warn"
empty_line_after_outer_attr = "warn"
empty_structs_with_brackets = "warn"
float_cmp = "warn"
float_cmp_const = "warn"
float_equality_without_abs = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
option_if_let_else = "warn"
print_stderr = "warn"
print_stdout = "warn"
semicolon_if_nothing_returned = "warn"
unseparated_literal_suffix = "warn"
shadow_unrelated = "warn"
similar_names = "warn"
suspicious_operation_groupings = "warn"
unused_self = "warn"
use_debug = "warn"
used_underscore_binding = "warn"
useless_let_if_seq = "warn"
wildcard_dependencies = "warn"
wildcard_imports = "warn"
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ See [examples](examples/) or [integration testing](src/tests.rs) for basic usage

### Server

Most operations are performed on `Stream` and `Sink`. There will be some optional options in [opts](src/opts.rs).
Most operations are performed on `Stream` and `Sink`. There will be some options in [opts](src/opts.rs).

Keep polling `incoming` because it also serves as the router to every connections.
Apply `Sink::poll_flush` to IO will trigger to flush all pending packets, `ACK`/`NACK`, and stale packets.
Apply `Sink::poll_close` to IO will ensure that all data is received by the peer before returning (i.e It may keep resending infinitely.).

> Notice: All calculations are lazy. You need to decide how long to flush once, and how long to wait when closing before considering the peer is disconnected.
> [!NOTE]
> All calculations are lazy. You need to decide how long to flush once, and how long to wait when closing before considering the peer is disconnected.
```rust
use bytes::Bytes;
Expand All @@ -62,6 +63,7 @@ let data: Bytes = reader.next().await.unwrap();

### Client

> [!WARNING]
> The current version of the client only has the most basic handshake implementation, and it is not recommended to use it directly.
```rust
Expand Down
2 changes: 1 addition & 1 deletion benches/micro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn codec_benchmark(c: &mut Criterion) {
|bencher| {
bencher.to_async(FuturesExecutor).iter_batched(
|| opts.clone(),
|opts| opts.run_bench(),
|o| o.run_bench(),
BatchSize::SmallInput,
);
},
Expand Down
2 changes: 2 additions & 0 deletions examples/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::print_stdout)]

use std::error::Error;
use std::net::SocketAddr;

Expand Down
10 changes: 6 additions & 4 deletions examples/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::print_stdout)]

use std::collections::HashMap;
use std::error::Error;
use std::net::SocketAddr;
Expand Down Expand Up @@ -44,7 +46,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
loop {
if let Some(data) = reader.next().await {
let trace_id = reader.last_trace_id().unwrap_or_else(|| {
eprintln!("Please run with `--features fastrace/enable` and try again");
println!("Please run with `--features fastrace/enable` and try again");
exit(0)
});
let root_span = Span::root(
Expand Down Expand Up @@ -151,7 +153,7 @@ fn display(spans: Vec<SpanRecord>) {
} else {
"├".to_owned() + &"─".repeat(depth) + " "
};
eprintln!(
println!(
"{}{}({}{{{}}}) [{}us]",
prefix,
span.name,
Expand All @@ -175,11 +177,11 @@ fn display(spans: Vec<SpanRecord>) {
if list.is_empty() {
continue;
}
eprintln!("{trace_id:?}",);
println!("{}", trace_id.0);
let l = &list[&SpanId::default()];
for (i, root) in l.iter().enumerate() {
dfs(&list, &spans_map, *root, 0, i == l.len() - 1);
}
eprintln!();
println!();
}
}
35 changes: 0 additions & 35 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,5 @@
//! Raknet implementation by rust

#![warn(
clippy::cognitive_complexity,
clippy::dbg_macro,
clippy::debug_assert_with_mut_call,
clippy::doc_link_with_quotes,
clippy::doc_markdown,
clippy::empty_line_after_outer_attr,
clippy::empty_structs_with_brackets,
clippy::float_cmp,
clippy::float_cmp_const,
clippy::float_equality_without_abs,
keyword_idents,
missing_copy_implementations,
missing_debug_implementations,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
non_ascii_idents,
noop_method_call,
clippy::option_if_let_else,
clippy::print_stderr,
clippy::print_stdout,
clippy::semicolon_if_nothing_returned,
clippy::unseparated_literal_suffix,
clippy::shadow_unrelated,
clippy::similar_names,
clippy::suspicious_operation_groupings,
unused_extern_crates,
unused_import_braces,
clippy::unused_self,
clippy::use_debug,
clippy::used_underscore_binding,
clippy::useless_let_if_seq,
clippy::wildcard_dependencies,
clippy::wildcard_imports
)]
#![feature(impl_trait_in_assoc_type)]
#![feature(ip_bits)]
#![feature(type_changing_struct_update)]
Expand Down
10 changes: 6 additions & 4 deletions src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ where
}

/// Flush strategy can be used as ext data of [`std::task::Context`] to guide how
/// [`Sink::poll_flush`] should perform flush. And the results after flush will be stored here.
/// The default strategy will refresh all buffers.
/// [`Sink::poll_flush`] perform flush. And the results after flush will be stored here.
/// The default strategy will flush all buffers.
///
/// Customizing your own strategy can achieve many features:
///
/// Customizing your own strategy can achieve many functions.
/// 1. [**Delayed ack**](https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment) based on timing,
/// thereby reducing the number of ack packets and improving bandwidth utilization. At the same
/// time, sending based on timing can avoid deadlocks or regressions caused by delaying based on the
/// number of packets.
///
/// 2. More aggressive nack/pack flush strategy which would be more beneficial for retransmitting
/// packets.
///
/// After the flush is completed, the strategy will store the number of frames that have been
/// flushed. You can use this information to determine when to take the next flush.
/// flushed. You can use this number to determine when to take the next flush.
///
/// Note that it can only be used in [`Sink::poll_flush`].
#[derive(Debug, Default, Clone, Copy)]
Expand Down
6 changes: 0 additions & 6 deletions src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! State management for the connection.
//! Perform the 4-ways handshake for the connection close.
//! Reflect the operation in the APIs of Sink and Stream when the connection stops.

use std::io;
use std::net::SocketAddr;
Expand Down Expand Up @@ -99,11 +98,6 @@ pub(crate) trait IncomingStateManage: Sized {
///
/// It will yield None when it receives the `DisconnectNotification`. And will continue to
/// return None in the following.
///
/// You have to repeatedly `poll_next` after receiving `DisconnectNotification` from
/// the peer. This will ensure that the ack you sent to acknowledge the `DisconnectNotification`
/// can be received by the the peer (i.e. ensuring that the the peer's `poll_close` call
/// returns successfully).
fn manage_incoming_state(self) -> impl Stream<Item = FrameBody>;
}

Expand Down

0 comments on commit 02424ed

Please sign in to comment.