mod agreement;
mod join;
mod join_as_relocated;
mod network;
mod node_msg;
mod plain_message;
mod prefix_map;
mod relocation;
mod section;
mod signature_aggregator;
mod signed;
mod src_authority;
mod variant;
pub use agreement::{DkgFailureSigned, DkgFailureSignedSet, DkgKey, Proposal, SectionSigned};
pub use join::{JoinRejectionReason, JoinRequest, JoinResponse, ResourceProofResponse};
pub use join_as_relocated::{JoinAsRelocatedRequest, JoinAsRelocatedResponse};
pub use network::{Network, OtherSection};
pub use node_msg::{
NodeCmd, NodeCmdError, NodeDataError, NodeDataQueryResponse, NodeEvent, NodeMsg, NodeQuery,
NodeQueryResponse, NodeRewardQuery, NodeSystemCmd, NodeSystemQuery, NodeSystemQueryResponse,
NodeTransferCmd, NodeTransferError, NodeTransferQuery, NodeTransferQueryResponse,
};
pub use plain_message::PlainMessage;
pub use prefix_map::PrefixMap;
pub use relocation::{RelocateDetails, RelocatePayload, RelocatePromise, SignedRelocateDetails};
pub use section::{ElderCandidates, MembershipState, NodeState, Peer, Section, SectionPeers};
pub use signature_aggregator::{Error, SignatureAggregator};
pub use signed::{Signed, SignedShare};
pub use src_authority::SrcAuthority;
pub use variant::Variant;
use crate::{Aggregation, DstLocation, MessageId, MessageType, WireMsg};
use bytes::Bytes;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Debug, Formatter};
use threshold_crypto::PublicKey as BlsPublicKey;
use xor_name::XorName;
#[derive(Clone, Eq, Serialize, Deserialize)]
pub struct RoutingMsg {
pub id: MessageId,
pub src: SrcAuthority,
pub dst: DstLocation,
pub aggregation: Aggregation,
pub variant: Variant,
pub section_pk: BlsPublicKey,
}
impl RoutingMsg {
pub fn from(bytes: Bytes) -> crate::Result<Self> {
let deserialized = WireMsg::deserialize(bytes)?;
if let MessageType::Routing { msg, .. } = deserialized {
Ok(msg)
} else {
Err(crate::Error::FailedToParse(
"bytes as a node message".to_string(),
))
}
}
pub fn serialize(&self, dest: XorName, dest_section_pk: BlsPublicKey) -> crate::Result<Bytes> {
WireMsg::serialize_routing_msg(self, dest, dest_section_pk)
}
}
impl PartialEq for RoutingMsg {
fn eq(&self, other: &RoutingMsg) -> bool {
self.src == other.src
&& self.dst == other.dst
&& self.id == other.id
&& self.variant == other.variant
&& self.section_pk == other.section_pk
}
}
impl Debug for RoutingMsg {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
formatter
.debug_struct("RoutingMsg")
.field("id", &self.id)
.field("src", &self.src)
.field("dst", &self.dst)
.field("variant", &self.variant)
.finish()
}
}