mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: Support sending raw capability messages (#13028)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -23,6 +23,7 @@ use alloy_primitives::Sealable;
|
||||
use futures::{stream::Fuse, SinkExt, StreamExt};
|
||||
use metrics::Gauge;
|
||||
use reth_eth_wire::{
|
||||
capability::RawCapabilityMessage,
|
||||
errors::{EthHandshakeError, EthStreamError, P2PStreamError},
|
||||
message::{EthBroadcastMessage, RequestPair},
|
||||
Capabilities, DisconnectP2P, DisconnectReason, EthMessage, NetworkPrimitives,
|
||||
@ -278,6 +279,7 @@ impl<N: NetworkPrimitives> ActiveSession<N> {
|
||||
}
|
||||
PeerMessage::Other(other) => {
|
||||
debug!(target: "net::session", message_id=%other.id, "Ignoring unsupported message");
|
||||
self.queued_outgoing.push_back(OutgoingMessage::Raw(other));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -559,6 +561,7 @@ impl<N: NetworkPrimitives> Future for ActiveSession<N> {
|
||||
let res = match msg {
|
||||
OutgoingMessage::Eth(msg) => this.conn.start_send_unpin(msg),
|
||||
OutgoingMessage::Broadcast(msg) => this.conn.start_send_broadcast(msg),
|
||||
OutgoingMessage::Raw(msg) => this.conn.start_send_raw(msg),
|
||||
};
|
||||
if let Err(err) = res {
|
||||
debug!(target: "net::session", %err, remote_peer_id=?this.remote_peer_id, "failed to send message");
|
||||
@ -738,6 +741,8 @@ pub(crate) enum OutgoingMessage<N: NetworkPrimitives> {
|
||||
Eth(EthMessage<N>),
|
||||
/// A message that may be shared by multiple sessions.
|
||||
Broadcast(EthBroadcastMessage<N>),
|
||||
/// A raw capability message
|
||||
Raw(RawCapabilityMessage),
|
||||
}
|
||||
|
||||
impl<N: NetworkPrimitives> From<EthMessage<N>> for OutgoingMessage<N> {
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
use futures::{Sink, Stream};
|
||||
use reth_ecies::stream::ECIESStream;
|
||||
use reth_eth_wire::{
|
||||
capability::RawCapabilityMessage,
|
||||
errors::EthStreamError,
|
||||
message::EthBroadcastMessage,
|
||||
multiplex::{ProtocolProxy, RlpxSatelliteStream},
|
||||
@ -84,6 +85,14 @@ impl<N: NetworkPrimitives> EthRlpxConnection<N> {
|
||||
Self::Satellite(conn) => conn.primary_mut().start_send_broadcast(item),
|
||||
}
|
||||
}
|
||||
|
||||
/// Sends a raw capability message over the connection
|
||||
pub fn start_send_raw(&mut self, msg: RawCapabilityMessage) -> Result<(), EthStreamError> {
|
||||
match self {
|
||||
Self::EthOnly(conn) => conn.start_send_raw(msg),
|
||||
Self::Satellite(conn) => conn.primary_mut().start_send_raw(msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: NetworkPrimitives> From<EthPeerConnection<N>> for EthRlpxConnection<N> {
|
||||
|
||||
Reference in New Issue
Block a user