feat: introduce EthMessage variant to NetworkHandleMessage (#13033)

This commit is contained in:
Tien Nguyen
2024-12-02 17:02:05 +07:00
committed by GitHub
parent 3f93f35c20
commit c2ab690ad1
2 changed files with 17 additions and 2 deletions

View File

@ -644,6 +644,9 @@ impl<N: NetworkPrimitives> NetworkManager<N> {
let _ = tx.send(None);
}
}
NetworkHandleMessage::EthMessage { peer_id, message } => {
self.swarm.sessions_mut().send_message(&peer_id, message)
}
}
}

View File

@ -1,6 +1,6 @@
use crate::{
config::NetworkMode, protocol::RlpxSubProtocol, swarm::NetworkConnectionState,
transactions::TransactionsHandle, FetchClient,
config::NetworkMode, message::PeerMessage, protocol::RlpxSubProtocol,
swarm::NetworkConnectionState, transactions::TransactionsHandle, FetchClient,
};
use alloy_primitives::B256;
use enr::Enr;
@ -136,6 +136,11 @@ impl<N: NetworkPrimitives> NetworkHandle<N> {
})
}
/// Send eth message to the peer.
pub fn send_eth_message(&self, peer_id: PeerId, message: PeerMessage<N>) {
self.send_message(NetworkHandleMessage::EthMessage { peer_id, message })
}
/// Send message to get the [`TransactionsHandle`].
///
/// Returns `None` if no transaction task is installed.
@ -481,6 +486,13 @@ pub(crate) enum NetworkHandleMessage<N: NetworkPrimitives = EthNetworkPrimitives
/// The request to send to the peer's sessions.
request: PeerRequest<N>,
},
/// Sends an `eth` protocol message to the peer.
EthMessage {
/// The peer to send the message to.
peer_id: PeerId,
/// The message to send to the peer's sessions.
message: PeerMessage<N>,
},
/// Applies a reputation change to the given peer.
ReputationChange(PeerId, ReputationChangeKind),
/// Returns the client that can be used to interact with the network.