mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: rm unused capabilities code (#13935)
This commit is contained in:
@ -9,17 +9,14 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use alloy_primitives::bytes::Bytes;
|
use alloy_primitives::bytes::Bytes;
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use reth_eth_wire_types::{EthMessage, EthNetworkPrimitives, NetworkPrimitives};
|
|
||||||
#[cfg(feature = "serde")]
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
collections::{BTreeSet, HashMap},
|
collections::{BTreeSet, HashMap},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A Capability message consisting of the message-id and the payload
|
/// A Capability message consisting of the message-id and the payload.
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct RawCapabilityMessage {
|
pub struct RawCapabilityMessage {
|
||||||
/// Identifier of the message.
|
/// Identifier of the message.
|
||||||
pub id: usize,
|
pub id: usize,
|
||||||
@ -37,27 +34,12 @@ impl RawCapabilityMessage {
|
|||||||
///
|
///
|
||||||
/// Caller must ensure that the rlp encoded `payload` matches the given `id`.
|
/// Caller must ensure that the rlp encoded `payload` matches the given `id`.
|
||||||
///
|
///
|
||||||
/// See also [`EthMessage`]
|
/// See also [`EthMessage`](crate::EthMessage)
|
||||||
pub const fn eth(id: EthMessageID, payload: Bytes) -> Self {
|
pub const fn eth(id: EthMessageID, payload: Bytes) -> Self {
|
||||||
Self::new(id as usize, payload)
|
Self::new(id as usize, payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Various protocol related event types bubbled up from a session that need to be handled by the
|
|
||||||
/// network.
|
|
||||||
#[derive(Debug)]
|
|
||||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
|
||||||
pub enum CapabilityMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
|
|
||||||
/// Eth sub-protocol message.
|
|
||||||
#[cfg_attr(
|
|
||||||
feature = "serde",
|
|
||||||
serde(bound = "EthMessage<N>: Serialize + serde::de::DeserializeOwned")
|
|
||||||
)]
|
|
||||||
Eth(EthMessage<N>),
|
|
||||||
/// Any other or manually crafted eth message.
|
|
||||||
Other(RawCapabilityMessage),
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This represents a shared capability, its version, and its message id offset.
|
/// This represents a shared capability, its version, and its message id offset.
|
||||||
///
|
///
|
||||||
/// The [offset](SharedCapability::message_id_offset) is the message ID offset for this shared
|
/// The [offset](SharedCapability::message_id_offset) is the message ID offset for this shared
|
||||||
|
|||||||
@ -37,10 +37,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use futures::{Future, StreamExt};
|
use futures::{Future, StreamExt};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use reth_eth_wire::{
|
use reth_eth_wire::{DisconnectReason, EthNetworkPrimitives, NetworkPrimitives};
|
||||||
capability::CapabilityMessage, Capabilities, DisconnectReason, EthNetworkPrimitives,
|
|
||||||
NetworkPrimitives,
|
|
||||||
};
|
|
||||||
use reth_fs_util::{self as fs, FsPathError};
|
use reth_fs_util::{self as fs, FsPathError};
|
||||||
use reth_metrics::common::mpsc::UnboundedMeteredSender;
|
use reth_metrics::common::mpsc::UnboundedMeteredSender;
|
||||||
use reth_network_api::{
|
use reth_network_api::{
|
||||||
@ -441,20 +438,6 @@ impl<N: NetworkPrimitives> NetworkManager<N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Event hook for an unexpected message from the peer.
|
|
||||||
fn on_invalid_message(
|
|
||||||
&mut self,
|
|
||||||
peer_id: PeerId,
|
|
||||||
_capabilities: Arc<Capabilities>,
|
|
||||||
_message: CapabilityMessage<N>,
|
|
||||||
) {
|
|
||||||
trace!(target: "net", ?peer_id, "received unexpected message");
|
|
||||||
self.swarm
|
|
||||||
.state_mut()
|
|
||||||
.peers_mut()
|
|
||||||
.apply_reputation_change(&peer_id, ReputationChangeKind::BadProtocol);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sends an event to the [`TransactionsManager`](crate::transactions::TransactionsManager) if
|
/// Sends an event to the [`TransactionsManager`](crate::transactions::TransactionsManager) if
|
||||||
/// configured.
|
/// configured.
|
||||||
fn notify_tx_manager(&self, event: NetworkTransactionEvent<N>) {
|
fn notify_tx_manager(&self, event: NetworkTransactionEvent<N>) {
|
||||||
@ -702,10 +685,6 @@ impl<N: NetworkPrimitives> NetworkManager<N> {
|
|||||||
// handle event
|
// handle event
|
||||||
match event {
|
match event {
|
||||||
SwarmEvent::ValidMessage { peer_id, message } => self.on_peer_message(peer_id, message),
|
SwarmEvent::ValidMessage { peer_id, message } => self.on_peer_message(peer_id, message),
|
||||||
SwarmEvent::InvalidCapabilityMessage { peer_id, capabilities, message } => {
|
|
||||||
self.on_invalid_message(peer_id, capabilities, message);
|
|
||||||
self.metrics.invalid_messages_received.increment(1);
|
|
||||||
}
|
|
||||||
SwarmEvent::TcpListenerClosed { remote_addr } => {
|
SwarmEvent::TcpListenerClosed { remote_addr } => {
|
||||||
trace!(target: "net", ?remote_addr, "TCP listener closed.");
|
trace!(target: "net", ?remote_addr, "TCP listener closed.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,6 +56,8 @@ pub enum PeerMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
|
|||||||
/// All `eth` request variants.
|
/// All `eth` request variants.
|
||||||
EthRequest(PeerRequest<N>),
|
EthRequest(PeerRequest<N>),
|
||||||
/// Any other or manually crafted eth message.
|
/// Any other or manually crafted eth message.
|
||||||
|
///
|
||||||
|
/// Caution: It is expected that this is a valid `eth_` capability message.
|
||||||
Other(RawCapabilityMessage),
|
Other(RawCapabilityMessage),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -505,7 +505,7 @@ pub(crate) enum NetworkHandleMessage<N: NetworkPrimitives = EthNetworkPrimitives
|
|||||||
EthMessage {
|
EthMessage {
|
||||||
/// The peer to send the message to.
|
/// The peer to send the message to.
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
/// The message to send to the peer's sessions.
|
/// The `eth` protocol message to send to the peer's session.
|
||||||
message: PeerMessage<N>,
|
message: PeerMessage<N>,
|
||||||
},
|
},
|
||||||
/// Applies a reputation change to the given peer.
|
/// Applies a reputation change to the given peer.
|
||||||
|
|||||||
@ -7,8 +7,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use reth_ecies::ECIESError;
|
use reth_ecies::ECIESError;
|
||||||
use reth_eth_wire::{
|
use reth_eth_wire::{
|
||||||
capability::CapabilityMessage, errors::EthStreamError, Capabilities, DisconnectReason,
|
errors::EthStreamError, Capabilities, DisconnectReason, EthVersion, NetworkPrimitives, Status,
|
||||||
EthVersion, NetworkPrimitives, Status,
|
|
||||||
};
|
};
|
||||||
use reth_network_api::PeerInfo;
|
use reth_network_api::PeerInfo;
|
||||||
use reth_network_peers::{NodeRecord, PeerId};
|
use reth_network_peers::{NodeRecord, PeerId};
|
||||||
@ -257,15 +256,6 @@ pub enum ActiveSessionMessage<N: NetworkPrimitives> {
|
|||||||
/// Message received from the peer.
|
/// Message received from the peer.
|
||||||
message: PeerMessage<N>,
|
message: PeerMessage<N>,
|
||||||
},
|
},
|
||||||
/// Received a message that does not match the announced capabilities of the peer.
|
|
||||||
InvalidMessage {
|
|
||||||
/// Identifier of the remote peer.
|
|
||||||
peer_id: PeerId,
|
|
||||||
/// Announced capabilities of the remote peer.
|
|
||||||
capabilities: Arc<Capabilities>,
|
|
||||||
/// Message received from the peer.
|
|
||||||
message: CapabilityMessage<N>,
|
|
||||||
},
|
|
||||||
/// Received a bad message from the peer.
|
/// Received a bad message from the peer.
|
||||||
BadMessage {
|
BadMessage {
|
||||||
/// Identifier of the remote peer.
|
/// Identifier of the remote peer.
|
||||||
|
|||||||
@ -33,9 +33,9 @@ use counter::SessionCounter;
|
|||||||
use futures::{future::Either, io, FutureExt, StreamExt};
|
use futures::{future::Either, io, FutureExt, StreamExt};
|
||||||
use reth_ecies::{stream::ECIESStream, ECIESError};
|
use reth_ecies::{stream::ECIESStream, ECIESError};
|
||||||
use reth_eth_wire::{
|
use reth_eth_wire::{
|
||||||
capability::CapabilityMessage, errors::EthStreamError, multiplex::RlpxProtocolMultiplexer,
|
errors::EthStreamError, multiplex::RlpxProtocolMultiplexer, Capabilities, DisconnectReason,
|
||||||
Capabilities, DisconnectReason, EthVersion, HelloMessageWithProtocols, NetworkPrimitives,
|
EthVersion, HelloMessageWithProtocols, NetworkPrimitives, Status, UnauthedEthStream,
|
||||||
Status, UnauthedEthStream, UnauthedP2PStream,
|
UnauthedP2PStream,
|
||||||
};
|
};
|
||||||
use reth_ethereum_forks::{ForkFilter, ForkId, ForkTransition, Head};
|
use reth_ethereum_forks::{ForkFilter, ForkId, ForkTransition, Head};
|
||||||
use reth_metrics::common::mpsc::MeteredPollSender;
|
use reth_metrics::common::mpsc::MeteredPollSender;
|
||||||
@ -444,9 +444,6 @@ impl<N: NetworkPrimitives> SessionManager<N> {
|
|||||||
ActiveSessionMessage::ValidMessage { peer_id, message } => {
|
ActiveSessionMessage::ValidMessage { peer_id, message } => {
|
||||||
Poll::Ready(SessionEvent::ValidMessage { peer_id, message })
|
Poll::Ready(SessionEvent::ValidMessage { peer_id, message })
|
||||||
}
|
}
|
||||||
ActiveSessionMessage::InvalidMessage { peer_id, capabilities, message } => {
|
|
||||||
Poll::Ready(SessionEvent::InvalidMessage { peer_id, message, capabilities })
|
|
||||||
}
|
|
||||||
ActiveSessionMessage::BadMessage { peer_id } => {
|
ActiveSessionMessage::BadMessage { peer_id } => {
|
||||||
Poll::Ready(SessionEvent::BadMessage { peer_id })
|
Poll::Ready(SessionEvent::BadMessage { peer_id })
|
||||||
}
|
}
|
||||||
@ -703,15 +700,6 @@ pub enum SessionEvent<N: NetworkPrimitives> {
|
|||||||
/// Message received from the peer.
|
/// Message received from the peer.
|
||||||
message: PeerMessage<N>,
|
message: PeerMessage<N>,
|
||||||
},
|
},
|
||||||
/// Received a message that does not match the announced capabilities of the peer.
|
|
||||||
InvalidMessage {
|
|
||||||
/// The remote node's public key
|
|
||||||
peer_id: PeerId,
|
|
||||||
/// Announced capabilities of the remote peer.
|
|
||||||
capabilities: Arc<Capabilities>,
|
|
||||||
/// Message received from the peer.
|
|
||||||
message: CapabilityMessage<N>,
|
|
||||||
},
|
|
||||||
/// Received a bad message from the peer.
|
/// Received a bad message from the peer.
|
||||||
BadMessage {
|
BadMessage {
|
||||||
/// Identifier of the remote peer.
|
/// Identifier of the remote peer.
|
||||||
|
|||||||
@ -8,8 +8,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use reth_eth_wire::{
|
use reth_eth_wire::{
|
||||||
capability::CapabilityMessage, errors::EthStreamError, Capabilities, DisconnectReason,
|
errors::EthStreamError, Capabilities, DisconnectReason, EthNetworkPrimitives, EthVersion,
|
||||||
EthNetworkPrimitives, EthVersion, NetworkPrimitives, Status,
|
NetworkPrimitives, Status,
|
||||||
};
|
};
|
||||||
use reth_network_api::{PeerRequest, PeerRequestSender};
|
use reth_network_api::{PeerRequest, PeerRequestSender};
|
||||||
use reth_network_peers::PeerId;
|
use reth_network_peers::PeerId;
|
||||||
@ -149,9 +149,6 @@ impl<N: NetworkPrimitives> Swarm<N> {
|
|||||||
SessionEvent::ValidMessage { peer_id, message } => {
|
SessionEvent::ValidMessage { peer_id, message } => {
|
||||||
Some(SwarmEvent::ValidMessage { peer_id, message })
|
Some(SwarmEvent::ValidMessage { peer_id, message })
|
||||||
}
|
}
|
||||||
SessionEvent::InvalidMessage { peer_id, capabilities, message } => {
|
|
||||||
Some(SwarmEvent::InvalidCapabilityMessage { peer_id, capabilities, message })
|
|
||||||
}
|
|
||||||
SessionEvent::IncomingPendingSessionClosed { remote_addr, error } => {
|
SessionEvent::IncomingPendingSessionClosed { remote_addr, error } => {
|
||||||
Some(SwarmEvent::IncomingPendingSessionClosed { remote_addr, error })
|
Some(SwarmEvent::IncomingPendingSessionClosed { remote_addr, error })
|
||||||
}
|
}
|
||||||
@ -344,14 +341,6 @@ pub(crate) enum SwarmEvent<N: NetworkPrimitives = EthNetworkPrimitives> {
|
|||||||
/// Message received from the peer
|
/// Message received from the peer
|
||||||
message: PeerMessage<N>,
|
message: PeerMessage<N>,
|
||||||
},
|
},
|
||||||
/// Received a message that does not match the announced capabilities of the peer.
|
|
||||||
InvalidCapabilityMessage {
|
|
||||||
peer_id: PeerId,
|
|
||||||
/// Announced capabilities of the remote peer.
|
|
||||||
capabilities: Arc<Capabilities>,
|
|
||||||
/// Message received from the peer.
|
|
||||||
message: CapabilityMessage<N>,
|
|
||||||
},
|
|
||||||
/// Received a bad message from the peer.
|
/// Received a bad message from the peer.
|
||||||
BadMessage {
|
BadMessage {
|
||||||
/// Identifier of the remote peer.
|
/// Identifier of the remote peer.
|
||||||
|
|||||||
Reference in New Issue
Block a user