mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: add serde feature to network crate (#653)
* Add serde feature and support for PeersConfig * Add Duration fields and Weights * Add serde for ConnectionInfo field
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -3777,6 +3777,7 @@ dependencies = [
|
||||
"reth-tracing",
|
||||
"reth-transaction-pool",
|
||||
"secp256k1 0.24.2",
|
||||
"serde",
|
||||
"serial_test",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
|
||||
@ -19,7 +19,7 @@ reth-consensus = { path = "../../crates/consensus", features = ["serde"] }
|
||||
reth-executor = { path = "../../crates/executor" }
|
||||
# reth-rpc = {path = "../../crates/net/rpc"}
|
||||
reth-rlp = { path = "../../crates/common/rlp" }
|
||||
reth-network = {path = "../../crates/net/network" }
|
||||
reth-network = {path = "../../crates/net/network", features = ["serde"] }
|
||||
reth-downloaders = {path = "../../crates/net/downloaders" }
|
||||
|
||||
# tracing
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
//! Configuration files.
|
||||
use std::{collections::HashSet, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
|
||||
use reth_db::database::Database;
|
||||
use reth_network::{
|
||||
config::{mainnet_nodes, rng_secret_key},
|
||||
NetworkConfig,
|
||||
NetworkConfig, PeersConfig,
|
||||
};
|
||||
use reth_primitives::{NodeRecord, H256};
|
||||
use reth_primitives::H256;
|
||||
use reth_provider::ProviderImpl;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@ -111,12 +111,3 @@ impl Default for SenderRecoveryConfig {
|
||||
Self { commit_threshold: 5_000, batch_size: 1000 }
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration for peer managing.
|
||||
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
|
||||
pub struct PeersConfig {
|
||||
/// Trusted nodes to connect to.
|
||||
pub trusted_nodes: HashSet<NodeRecord>,
|
||||
/// Connect to trusted nodes only?
|
||||
pub connect_trusted_nodes_only: bool,
|
||||
}
|
||||
|
||||
@ -35,6 +35,9 @@ pin-project = "1.0"
|
||||
tokio = { version = "1", features = ["io-util", "net", "macros", "rt-multi-thread", "time"] }
|
||||
tokio-stream = "0.1"
|
||||
|
||||
# io
|
||||
serde = { version = "1.0", optional = true }
|
||||
|
||||
# misc
|
||||
auto_impl = "1"
|
||||
aquamarine = "0.1" # docs
|
||||
@ -68,3 +71,5 @@ hex = "0.4"
|
||||
tempfile = "3.3"
|
||||
serial_test = "0.10"
|
||||
|
||||
[features]
|
||||
serde = ["dep:serde"]
|
||||
|
||||
@ -108,6 +108,10 @@
|
||||
//! .split_with_handle();
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! # Features
|
||||
//!
|
||||
//! - `serde`: Enable serde support for configuration types.
|
||||
|
||||
mod builder;
|
||||
mod cache;
|
||||
|
||||
@ -582,7 +582,9 @@ impl Default for PeersManager {
|
||||
}
|
||||
|
||||
/// Tracks stats about connected nodes
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
pub struct ConnectionInfo {
|
||||
/// Counter for currently occupied slots for active outbound connections.
|
||||
num_outbound: usize,
|
||||
@ -831,15 +833,19 @@ pub enum PeerAction {
|
||||
}
|
||||
|
||||
/// Config type for initiating a [`PeersManager`] instance
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
pub struct PeersConfig {
|
||||
/// How often to recheck free slots for outbound connections.
|
||||
// #[cfg_attr(feature = "serde", serde(flatten))]
|
||||
pub refill_slots_interval: Duration,
|
||||
/// Restrictions on connections.
|
||||
pub connection_info: ConnectionInfo,
|
||||
/// How to weigh reputation changes.
|
||||
pub reputation_weights: ReputationChangeWeights,
|
||||
/// Restrictions on PeerIds and Ips.
|
||||
#[cfg_attr(feature = "serde", serde(skip))]
|
||||
pub ban_list: BanList,
|
||||
/// How long to ban bad peers.
|
||||
pub ban_duration: Duration,
|
||||
|
||||
@ -62,6 +62,8 @@ pub enum ReputationChangeKind {
|
||||
|
||||
/// How the [`ReputationChangeKind`] are weighted.
|
||||
#[derive(Debug, Clone)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
|
||||
pub struct ReputationChangeWeights {
|
||||
/// Weight for [`ReputationChangeKind::BadMessage`]
|
||||
pub bad_message: Reputation,
|
||||
|
||||
Reference in New Issue
Block a user