Skip to main content

hopr_network_graph/
lib.rs

1//! The library code containing the graph data structure for transport and incentivization layer (through the "channel
2//! graph").
3//!
4//! `NetworkGraph` is the main data structure representing the network of nodes and channels. It combines 2 layers:
5//! 1. The **channel graph** layer, which represents the network topology with nodes and channels as loaded from the
6//!    chain.
7//! 2. The **network layer**, which represents the nodes based on their physical connectability and QoS attributes.
8//!
9//! What does the graph look like:
10//! - Nodes are represented as vertices in the graph.
11//! - Possible connections, a combination of channel availability and or network usability are represented as edges
12//!   between nodes.
13//!
14//! ## Weights
15//! The weights accumulate different properties of the edges to represent the cost of using that edge for routing or
16//! whether the edge can be used at all. Weights are represented as a struct containing different fields, each
17//! representing a different property of the edge. The used properties are:
18//! - presence of incentivization channel with remaining balance (`Option<Balance>`)
19//! - presence of peer for immediate direct network connection and its quality (`Option<ImmediateQoS>`)
20//! - presence of intermediate connection through other nodes (`Option<IntermediateQoS>`)
21
22#[cfg(feature = "petgraph")]
23pub mod petgraph;
24
25pub mod errors;
26#[cfg(feature = "graph-api")]
27pub mod render;
28pub mod weight;
29
30use hopr_api::OffchainPublicKey;
31#[cfg(feature = "petgraph")]
32pub use petgraph::*;
33pub use weight::Observations;
34
35/// A thread-safe, shareable handle to a [`ChannelGraph`].
36///
37/// This is a convenience alias. Since [`ChannelGraph`] uses interior mutability,
38/// wrapping it in `Arc` is sufficient for concurrent sharing without an
39/// external `RwLock`.
40#[cfg(feature = "petgraph")]
41pub type SharedChannelGraph = std::sync::Arc<ChannelGraph>;
42
43#[derive(Debug, Clone, PartialEq, Eq, Hash)]
44pub struct GraphNode(OffchainPublicKey);
45
46impl From<GraphNode> for OffchainPublicKey {
47    fn from(val: GraphNode) -> Self {
48        val.0
49    }
50}