Struct rings_node::prelude::MessageRelay
source · pub struct MessageRelay {
pub method: RelayMethod,
pub path: Vec<Did, Global>,
pub path_end_cursor: usize,
pub next_hop: Option<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:
- Infer the next_hop of a message.
- Get the sender and origin sender of a message.
- Record the whole transport path for inspection.
Examples
Fields§
§method: RelayMethodThe method of message. SEND or REPORT.
path: Vec<Did, Global>A push only stack. Record routes when handling sending messages.
path_end_cursor: usizeMove this cursor to flag the top of the stack when reporting.
Notice that this cursor is not the index of current.
It’s path.len() - <index of current> - 1, which means count down to head of vector.
It will always be 0 while handling sending messages in this way.
next_hop: Option<Did>The next node to handle the message.
When and only when located at the end of the message propagation, the next_hop is none.
A message handler will pick transport by this field.
destination: DidThe destination of the message. It may be customized when sending. It cannot be changed when reporting.
It may help the handler to find out next_hop in some situations.
Implementations§
source§impl MessageRelay
impl MessageRelay
sourcepub fn new(
method: RelayMethod,
path: Vec<Did, Global>,
path_end_cursor: Option<usize>,
next_hop: Option<Did>,
destination: Did
) -> MessageRelay
pub fn new(
method: RelayMethod,
path: Vec<Did, Global>,
path_end_cursor: Option<usize>,
next_hop: Option<Did>,
destination: Did
) -> MessageRelay
Create a new MessageRelay.
Will set path_end_cursor to 0 if pass None as parameter.
sourcepub fn relay(&mut self, current: Did, next_hop: Option<Did>) -> Result<(), Error>
pub fn relay(&mut self, current: Did, next_hop: Option<Did>) -> Result<(), Error>
Check current did, update path and its end cursor, then infer next_hop.
When handling a SEND message, will push current to the self.path stack, and set next_hop parameter to self.next_node.
When handling a REPORT message, will move forward self.path_end_cursor to the position of current in self.path.
If next_hop parameter is none, it will also pick the previous node in self.path as self.next_hop.
(With this feature, one can always pass None as next_hop parameter when handling a REPORT message.)
sourcepub fn report(&self) -> Result<MessageRelay, Error>
pub fn report(&self) -> Result<MessageRelay, Error>
Construct a MessageRelay of method REPORT from a MessageRelay of method REPORT.
It will return Error if method is not SEND.
It will return Error if self.path.len() is less than 2.
sourcepub fn reset_destination(&mut self, destination: Did) -> Result<(), Error>
pub fn reset_destination(&mut self, destination: Did) -> Result<(), Error>
A SEND message can change its destination. Call with REPORT method will get an error imeediately.
sourcepub fn validate(&self) -> Result<(), Error>
pub fn validate(&self) -> Result<(), Error>
Check if path and destination is valid. It will be automatically called at relay started.
sourcepub fn origin(&self) -> Did
pub fn origin(&self) -> Did
Get the original sender of current message. Should always 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<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T> AsTaggedExplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedExplicit<'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,
§impl<'a, T> AsTaggedImplicit<'a> for Twhere
T: 'a,
impl<'a, T> AsTaggedImplicit<'a> for Twhere
T: 'a,
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.