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 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 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’s 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_quality(&mut self, address: &Address, quality: f64)
pub fn update_node_quality(&mut self, address: &Address, quality: f64)
Updates the quality of a node (inserting it into the graph if it does not exist yet). The given quality value must always be non-negative.
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 quality 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> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§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>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.