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: RelayMethod

The method of message. SEND or REPORT.

§path: Vec<Did, Global>

A push only stack. Record routes when handling sending messages.

§path_end_cursor: usize

Move 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: Did

The 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§

Create a new MessageRelay. Will set path_end_cursor to 0 if pass None as parameter.

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.)

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.

A SEND message can change its destination. Call with REPORT method will get an error imeediately.

Check if path and destination is valid. It will be automatically called at relay started.

Get the original sender of current message. Should always be the first element of path.

Get sender of current message. With SEND method, it will be the origin() of the message. With REPORT method, it will be the last element of path.

Get the previous element of the element pointed by path_end_cursor.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Attaches the current Context to this type, returning a WithContext wrapper. Read more
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more