pub struct ChannelGraph { /* private fields */ }
Expand description
Implements a HOPR payment channel graph (directed) cached in-memory.
This structure is useful for tracking channel state changes and packet path finding.
The edges are updated only from the Indexer, and therefore the graph contains only the channels seen on-chain. The nodes and their qualities are updated as they are observed on the network.
Using this structure is much faster than querying the DB and therefore
is preferred for per-packet path-finding computations.
Per default, the graph does not track channels in the Closed
state and therefore
cannot detect channel re-openings.
When a node reaches zero quality and there are no edges (channels) containing this node, it is removed from the graph entirely.
Implementations§
Source§impl ChannelGraph
impl ChannelGraph
Sourcepub const INTERMEDIATE_HOPS: usize = 3usize
pub const INTERMEDIATE_HOPS: usize = 3usize
The maximum number of intermediate hops the automatic path-finding algorithm will look for.
Sourcepub fn new(me: Address, cfg: ChannelGraphConfig) -> Self
pub fn new(me: Address, cfg: ChannelGraphConfig) -> Self
Creates a new instance with the given self Address
.
Sourcepub fn count_channels(&self) -> usize
pub fn count_channels(&self) -> usize
Number of channels (edges) in the graph.
Sourcepub fn count_nodes(&self) -> usize
pub fn count_nodes(&self) -> usize
Number of nodes in the graph.
Sourcepub fn is_own_channel(&self, channel: &ChannelEntry) -> bool
pub fn is_own_channel(&self, channel: &ChannelEntry) -> bool
Checks if the channel is incoming to or outgoing from this node
Sourcepub fn my_address(&self) -> Address
pub fn my_address(&self) -> Address
Convenience method to get this node’s own address
Sourcepub fn get_channel(
&self,
source: &Address,
destination: &Address,
) -> Option<&ChannelEntry>
pub fn get_channel( &self, source: &Address, destination: &Address, ) -> Option<&ChannelEntry>
Looks up an Open
or PendingToClose
channel given the source and destination.
Returns None
if no such edge exists in the graph.
Sourcepub fn get_node(&self, node: &Address) -> Option<&Node>
pub fn get_node(&self, node: &Address) -> Option<&Node>
Gets the node information.
Returns None
if no such node exists in the graph.
Sourcepub fn open_channels_from(
&self,
source: Address,
) -> impl Iterator<Item = (&Node, &ChannelEdge)>
pub fn open_channels_from( &self, source: Address, ) -> impl Iterator<Item = (&Node, &ChannelEdge)>
Gets all Open
outgoing channels going from the given source.
Sourcepub fn has_path(&self, source: &Address, destination: &Address) -> bool
pub fn has_path(&self, source: &Address, destination: &Address) -> bool
Checks whether there is any path via Open channels that connects source
and destination
This does not need to be necessarily a multi-hop path.
Sourcepub fn update_channel(
&mut self,
channel: ChannelEntry,
) -> Option<Vec<ChannelChange>>
pub fn update_channel( &mut self, channel: ChannelEntry, ) -> Option<Vec<ChannelChange>>
Inserts or updates the given channel in the channel graph. Returns a set of changes if the channel was already present in the graphs or None if the channel was not previously present in the channel graph.
Sourcepub fn update_node_score(
&mut self,
address: &Address,
score_update: NodeScoreUpdate,
)
pub fn update_node_score( &mut self, address: &Address, score_update: NodeScoreUpdate, )
Updates the quality of a node (inserting it into the graph if it does not exist yet),
based on the given NodeScoreUpdate
.
Sourcepub fn update_channel_score(
&mut self,
source: &Address,
destination: &Address,
score: f64,
)
pub fn update_channel_score( &mut self, source: &Address, destination: &Address, score: f64, )
Updates the score value of network connection between source
and destination
The given score value must always be non-negative.
Sourcepub fn get_channel_score(
&self,
source: &Address,
destination: &Address,
) -> Option<f64>
pub fn get_channel_score( &self, source: &Address, destination: &Address, ) -> Option<f64>
Gets quality of the given channel. Returns None
if no such channel exists, or no
quality has been set for that channel.
Sourcepub fn contains_channel(&self, channel: &ChannelEntry) -> bool
pub fn contains_channel(&self, channel: &ChannelEntry) -> bool
Checks whether the given channel is in the graph already.
Sourcepub fn contains_node(&self, address: &Address) -> bool
pub fn contains_node(&self, address: &Address) -> bool
Checks whether the given node is in the channel graph.
Sourcepub fn as_dot(&self, cfg: GraphExportConfig) -> String
pub fn as_dot(&self, cfg: GraphExportConfig) -> String
Outputs the channel graph in the DOT (graphviz) format with the given config
.
Trait Implementations§
Source§impl Clone for ChannelGraph
impl Clone for ChannelGraph
Source§fn clone(&self) -> ChannelGraph
fn clone(&self) -> ChannelGraph
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ChannelGraph
impl Debug for ChannelGraph
Source§impl<'de> Deserialize<'de> for ChannelGraph
impl<'de> Deserialize<'de> for ChannelGraph
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ChannelGraph
impl RefUnwindSafe for ChannelGraph
impl Send for ChannelGraph
impl Sync for ChannelGraph
impl Unpin for ChannelGraph
impl UnwindSafe for ChannelGraph
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more