Struct rings_node::prelude::message::MessageRelay
source · pub struct MessageRelay {
pub path: Vec<Did, Global>,
pub next_hop: Did,
pub destination: Did,
}
Expand description
MessageRelay guide message passing on rings network by relay.
All messages should be sent with MessageRelay
.
By calling relay
method in correct place, MessageRelay
help to do things:
- Record the whole transport path for inspection.
- Get the sender of a message.
Fields§
§path: Vec<Did, Global>
A push only stack. Record routes when handling messages.
next_hop: Did
The next node to handle the message. A message handler will pick transport by this field.
destination: Did
The destination of the message.
It may help the handler to find out next_hop
in some situations.
Implementations§
source§impl MessageRelay
impl MessageRelay
sourcepub fn new(
path: Vec<Did, Global>,
next_hop: Did,
destination: Did
) -> MessageRelay
pub fn new( path: Vec<Did, Global>, next_hop: Did, destination: Did ) -> MessageRelay
Create a new MessageRelay
.
sourcepub fn forward(
&self,
current: Did,
next_hop: Did
) -> Result<MessageRelay, Error>
pub fn forward( &self, current: Did, next_hop: Did ) -> Result<MessageRelay, Error>
Validate relay, then create a new MessageRelay
that have current
did in the end of path.
The new relay will use next_hop
as next_hop
and self.destination
as destination
.
sourcepub fn report(&self, current: Did) -> Result<MessageRelay, Error>
pub fn report(&self, current: Did) -> Result<MessageRelay, Error>
Validate relay, then create a new MessageRelay
that used to report the message.
The new relay will use self.path[self.path.len() - 1]
as next_hop
and self.sender()
as destination
.
In the new relay, the path will be cleared and only have current
did.
sourcepub fn reset_destination(&self, destination: Did) -> MessageRelay
pub fn reset_destination(&self, destination: Did) -> MessageRelay
Sometime the sender may not know the destination of the message. They just use next_hop as destination. The next node can find a new next_hop, and may use this function to set that next_hop as destination again.
sourcepub fn validate(&self, current: Did) -> Result<(), Error>
pub fn validate(&self, current: Did) -> Result<(), Error>
Check if path and destination is valid.
sourcepub fn sender(&self) -> Did
👎Deprecated: please use origin_sender
instead
pub fn sender(&self) -> Did
origin_sender
insteadGet the origin sender of current message. Should be the first element of path.
sourcepub fn origin_sender(&self) -> Did
pub fn origin_sender(&self) -> Did
Get the origin sender of current message. Should be the first element of path.
Trait Implementations§
source§impl Clone for MessageRelay
impl Clone for MessageRelay
source§fn clone(&self) -> MessageRelay
fn clone(&self) -> MessageRelay
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MessageRelay
impl Debug for MessageRelay
source§impl<'de> Deserialize<'de> for MessageRelay
impl<'de> Deserialize<'de> for MessageRelay
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<MessageRelay, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<MessageRelay, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
source§impl PartialEq<MessageRelay> for MessageRelay
impl PartialEq<MessageRelay> for MessageRelay
source§fn eq(&self, other: &MessageRelay) -> bool
fn eq(&self, other: &MessageRelay) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for MessageRelay
impl Serialize for MessageRelay
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,
impl Eq for MessageRelay
impl StructuralEq for MessageRelay
impl StructuralPartialEq for MessageRelay
Auto Trait Implementations§
impl RefUnwindSafe for MessageRelay
impl Send for MessageRelay
impl Sync for MessageRelay
impl Unpin for MessageRelay
impl UnwindSafe for MessageRelay
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata ) -> <T as Pointee>::Metadata
§impl<'a, T> AsTaggedExplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedExplicit<'a> for Twhere T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,
§impl<'a, T> AsTaggedImplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedImplicit<'a> for Twhere T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,
§fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.