TransportMsgHeader

Struct TransportMsgHeader 

Source
pub struct TransportMsgHeader {
    pub version: u8,
    pub encrypt: bool,
    pub route: RouteRule,
    pub ttl: u8,
    pub feature: u8,
    pub meta: u8,
    pub from_node: Option<u32>,
}
Expand description

Fixed Header Fields

    0                   1                   2                   3
    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |V=0|E|N|   R   |      TTL      |  Feature       |     Meta     |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                         Route destination (Opt)               |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   |                         FromNodeId (Opt)                      |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

In there

  • Version (V) : 2 bits (now is 0)

  • Encrypt (E): 1 bits, If this bit is set, this msg should be encrypted

  • From Node (N) : 1 bits, If this bit is set, from node_id will occupy 32 bits in header

  • Route Type (R): 4 bits

    • 0: Direct : which node received this msg will handle it, no route destination
    • 1: ToNode : which node received this msg will route it to node_id
    • 2: ToService : which node received this msg will route it to service meta
    • 3: ToKey : which node received this msg will route it to key
    • .. Not used
  • Ttl (TTL): 8 bits

  • Feature Id: 8 bits

  • Route destination (Route Destination): 32 bits (if R is not Direct)

    • If route type is ToNode, this field is 32bit node_id
    • If route type is ToService, this field is 32bit service meta
    • If route type is ToKey, this field is 32bit key
  • From Node Id: 32 bits (optional if N bit is set)

Fields§

§version: u8§encrypt: bool§route: RouteRule§ttl: u8§feature: u8§meta: u8§from_node: Option<u32>

Which can be anonymous or specific node

Implementations§

Source§

impl TransportMsgHeader

Source

pub fn is_secure(first_byte: u8) -> bool

Source

pub fn new() -> TransportMsgHeader

Builds a message with the given service_id, route rule.

Source

pub fn build(feature: u8, meta: u8, route: RouteRule) -> TransportMsgHeader

Source

pub fn set_ttl(self, ttl: u8) -> TransportMsgHeader

Set ttl

Source

pub fn set_encrypt(self, encrypt: bool) -> TransportMsgHeader

Set secure

Source

pub fn set_from_node(self, from_node: Option<u32>) -> TransportMsgHeader

Set from node

Source

pub fn set_feature(self, feature: u8) -> TransportMsgHeader

Set to feature

Source

pub fn set_meta(self, meta: u8) -> TransportMsgHeader

Set to service_id

Source

pub fn set_route(self, route: RouteRule) -> TransportMsgHeader

Set rule

Source

pub fn to_bytes(&self, output: &mut [u8]) -> Option<usize>

Converts the message to a byte representation and appends it to the given output vector.

§Arguments
  • output - A mutable vector of bytes to append the serialized message to.
§Returns

An Option containing the number of bytes written if the output vector was large enough, or None if the output vector was too small.

Source

pub fn rewrite_ttl(buf: &mut [u8], new_ttl: u8) -> Option<()>

Rewrite the ttl in the given buffer with the new ttl.

§Arguments
  • buf - A mutable slice of bytes representing the buffer to rewrite the ttl in.
  • new_ttl - The new ttl to use for rewriting the ttl.
§Returns

An Option containing () if the ttl was successfully rewritten, or None if the buffer is too small to hold the new ttl.

Source

pub fn decrease_ttl(buf: &mut [u8]) -> bool

Decrease the ttl in the given buffer.

§Arguments
  • buf - A mutable slice of bytes representing the buffer to decrease the ttl in.
§Returns

An Option containing () if the ttl was successfully decreased, or None if the buffer is too small to hold the new ttl or ttl too small.

Source

pub fn serialize_size(&self) -> usize

Returns the size of the serialized message.

Trait Implementations§

Source§

impl Clone for TransportMsgHeader

Source§

fn clone(&self) -> TransportMsgHeader

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TransportMsgHeader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for TransportMsgHeader

Source§

fn default() -> TransportMsgHeader

Returns the “default value” for a type. Read more
Source§

impl From<&TransportMsgHeader> for NetIncomingMeta

Source§

fn from(value: &TransportMsgHeader) -> NetIncomingMeta

Converts to this type from the input type.
Source§

impl PartialEq for TransportMsgHeader

Source§

fn eq(&self, other: &TransportMsgHeader) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&[u8]> for TransportMsgHeader

Source§

type Error = TransportMsgHeaderError

The type returned in the event of a conversion error.
Source§

fn try_from( bytes: &[u8], ) -> Result<TransportMsgHeader, <TransportMsgHeader as TryFrom<&[u8]>>::Error>

Performs the conversion.
Source§

impl Eq for TransportMsgHeader

Source§

impl StructuralPartialEq for TransportMsgHeader

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V