Struct Router

Source
pub struct Router<N>
where N: Nomenclature,
{ /* private fields */ }
Expand description

Generic router consisting of a queue of routing extensions, implementing specific router logic

Implementations§

Source§

impl<N> Router<N>
where N: Nomenclature + 'static,

Source

pub fn new( extensions: impl IntoIterator<Item = Box<dyn RouterExtension<N>>>, ) -> Self

Constructs router with all used extensions

Source

pub fn extensions(&self) -> Iter<'_, N, Box<dyn RouterExtension<N>>>

Source

pub fn extensions_mut(&mut self) -> IterMut<'_, N, Box<dyn RouterExtension<N>>>

Source

pub fn add_extension(&mut self, extension: Box<dyn RouterExtension<N>>)

Adds new extension to the router.

Source

pub fn compute_route( &mut self, payment: PaymentRequest, ) -> Vec<Hop<N::HopPayload>>

Trait Implementations§

Source§

impl<N> Default for Router<N>
where N: 'static + Nomenclature + Default,

Source§

fn default() -> Self

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

impl<N> Extension<N> for Router<N>

Source§

fn identity(&self) -> N

Source§

fn state_change( &mut self, request: &<N as Nomenclature>::UpdateRequest, message: &mut <N as Nomenclature>::PeerMessage, ) -> Result<(), <N as Nomenclature>::Error>

Perform a sate change and produce a message which should be communicated to peers notifying them about the state change
Source§

fn update_from_local( &mut self, message: &<N as Nomenclature>::UpdateMessage, ) -> Result<(), <N as Nomenclature>::Error>

Updates extension state from some local data
Source§

fn update_from_peer( &mut self, message: &<N as Nomenclature>::PeerMessage, ) -> Result<(), <N as Nomenclature>::Error>

Updates extension state from the data taken from the message received from the remote peer
Source§

fn load_state(&mut self, state: &N::State)

Source§

fn store_state(&self, state: &mut N::State)

Source§

impl<N> RouterExtension<N> for Router<N>
where N: Nomenclature + 'static,

Source§

fn new() -> Box<dyn RouterExtension<N>>
where Self: Sized,

Constructs boxed extension objects which can be inserted into router extension pipeline
Source§

fn build_route( &mut self, payment: PaymentRequest, route: &mut Vec<Hop<N::HopPayload>>, )

Source§

impl<N> StrictDecode for Router<N>
where N: 'static + Nomenclature, N::State: StrictDecode,

Source§

fn strict_decode<D: Read>(d: D) -> Result<Self, Error>

Decode with the given std::io::Read instance; must either construct an instance or return implementation-specific error type.
Source§

fn strict_deserialize(data: impl AsRef<[u8]>) -> Result<Self, Error>

Tries to deserialize byte array into the current type using StrictDecode::strict_decode. If there are some data remains in the buffer once deserialization is completed, fails with Error::DataNotEntirelyConsumed. Use io::Cursor over the buffer and StrictDecode::strict_decode to avoid such failures.
Source§

fn strict_file_load(path: impl AsRef<Path>) -> Result<Self, Error>

Reads data from file at path and reconstructs object from it. Fails with Error::DataNotEntirelyConsumed if file contains remaining data after the object reconstruction.
Source§

impl<N> StrictEncode for Router<N>
where N: 'static + Nomenclature, N::State: StrictEncode,

Source§

fn strict_encode<E: Write>(&self, e: E) -> Result<usize, Error>

Encode with the given std::io::Write instance; must return result with either amount of bytes encoded – or implementation-specific error type.
Source§

fn strict_serialize(&self) -> Result<Vec<u8>, Error>

Serializes data as a byte array using StrictEncode::strict_encode function
Source§

fn strict_file_save(&self, path: impl AsRef<Path>) -> Result<usize, Error>

Saves data to a file at a given path. If the file does not exists, attempts to create the file. If the file already exists, it gets truncated.

Auto Trait Implementations§

§

impl<N> Freeze for Router<N>

§

impl<N> !RefUnwindSafe for Router<N>

§

impl<N> !Send for Router<N>

§

impl<N> !Sync for Router<N>

§

impl<N> Unpin for Router<N>

§

impl<N> !UnwindSafe for Router<N>

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> 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> 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, 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