Skip to content

Commit

Permalink
refactor: extract configuration types to reth-network-types (#9136)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Jun 27, 2024
1 parent 9542f3b commit 18eef6a
Show file tree
Hide file tree
Showing 22 changed files with 584 additions and 504 deletions.
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 @@ -53,6 +53,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 @@ -310,6 +311,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"] }
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

0 comments on commit 18eef6a

Please sign in to comment.