chore: misc raw message (#13006)

This commit is contained in:
Matthias Seitz
2024-11-29 11:50:24 +01:00
committed by GitHub
parent 37dca23402
commit 4d65b2f5db
2 changed files with 18 additions and 2 deletions

View File

@ -27,6 +27,22 @@ pub struct RawCapabilityMessage {
pub payload: Bytes,
}
impl RawCapabilityMessage {
/// Creates a new capability message with the given id and payload.
pub const fn new(id: usize, payload: Bytes) -> Self {
Self { id, payload }
}
/// Creates a raw message for the eth sub-protocol.
///
/// Caller must ensure that the rlp encoded `payload` matches the given `id`.
///
/// See also [`EthMessage`]
pub const fn eth(id: EthMessageID, payload: Bytes) -> Self {
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)]
@ -38,7 +54,7 @@ pub enum CapabilityMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
serde(bound = "EthMessage<N>: Serialize + serde::de::DeserializeOwned")
)]
Eth(EthMessage<N>),
/// Any other capability message.
/// Any other or manually crafted eth message.
Other(RawCapabilityMessage),
}

View File

@ -55,7 +55,7 @@ pub enum PeerMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
PooledTransactions(NewPooledTransactionHashes),
/// All `eth` request variants.
EthRequest(PeerRequest<N>),
/// Other than eth namespace message
/// Any other or manually crafted eth message.
Other(RawCapabilityMessage),
}