Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: extract configuration types to reth-network-types #9136

Merged
merged 6 commits into from
Jun 27, 2024
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
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ members = [
"crates/net/eth-wire/",
"crates/net/nat/",
"crates/net/network-api/",
"crates/net/network-types/",
"crates/net/network/",
"crates/net/p2p/",
"crates/net/peers/",
Expand Down Expand Up @@ -305,6 +306,7 @@ reth-net-banlist = { path = "crates/net/banlist" }
reth-net-nat = { path = "crates/net/nat" }
reth-network = { path = "crates/net/network" }
reth-network-api = { path = "crates/net/network-api" }
reth-network-types = { path = "crates/net/network-types" }
reth-network-peers = { path = "crates/net/peers", default-features = false }
reth-network-p2p = { path = "crates/net/p2p" }
reth-nippy-jar = { path = "crates/storage/nippy-jar" }
Expand Down
2 changes: 1 addition & 1 deletion crates/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ workspace = true

[dependencies]
# reth
reth-network.workspace = true
reth-network-types = { workspace = true, features = ["serde"] }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect

reth-prune-types.workspace = true

# serde
Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Configuration files.

use reth_network::{PeersConfig, SessionsConfig};
use reth_network_types::{PeersConfig, SessionsConfig};
use reth_prune_types::PruneModes;
use serde::{Deserialize, Deserializer, Serialize};
use std::{
Expand Down
30 changes: 30 additions & 0 deletions crates/net/network-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "reth-network-types"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
homepage.workspace = true
repository.workspace = true
description = "Commonly used network types"

[lints]
workspace = true

[dependencies]
# reth
reth-network-api.workspace = true
reth-network-peers.workspace = true
reth-net-banlist.workspace = true

# io
serde = { workspace = true, optional = true }
humantime-serde = { workspace = true, optional = true }
serde_json = { workspace = true }

# misc
tracing.workspace = true

[features]
serde = ["dep:serde", "dep:humantime-serde"]
test-utils = []
27 changes: 27 additions & 0 deletions crates/net/network-types/src/backoff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/// Describes the type of backoff should be applied.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum BackoffKind {
/// Use the lowest configured backoff duration.
///
/// This applies to connection problems where there is a chance that they will be resolved
/// after the short duration.
Low,
/// Use a slightly higher duration to put a peer in timeout
///
/// This applies to more severe connection problems where there is a lower chance that they
/// will be resolved.
Medium,
/// Use the max configured backoff duration.
///
/// This is intended for spammers, or bad peers in general.
High,
}

// === impl BackoffKind ===

impl BackoffKind {
/// Returns true if the backoff is considered severe.
pub const fn is_severe(&self) -> bool {
matches!(self, Self::Medium | Self::High)
}
}
24 changes: 24 additions & 0 deletions crates/net/network-types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Commonly used networking types.
//!
//! ## Feature Flags
//!
//! - `serde` (default): Enable serde support

#![doc(
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

/// Types related to peering.
pub mod peers;
pub use peers::{ConnectionsConfig, PeersConfig, ReputationChangeWeights};

pub mod session;
pub use session::{SessionLimits, SessionsConfig};

/// [`BackoffKind`] definition.
mod backoff;
pub use backoff::BackoffKind;
Loading
Loading