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/// Default penalty multiplier for edges lacking probe-based quality observations.
36pub const DEFAULT_EDGE_PENALTY: f64 = 0.5;
37
38/// Default minimum acceptable message acknowledgment rate for path selection.
39pub const DEFAULT_MIN_ACK_RATE: f64 = 0.1;
40
41/// A thread-safe, shareable handle to a [`ChannelGraph`].
42///
43/// This is a convenience alias. Since [`ChannelGraph`] uses interior mutability,
44/// wrapping it in `Arc` is sufficient for concurrent sharing without an
45/// external `RwLock`.
46#[cfg(feature = "petgraph")]
47pub type SharedChannelGraph = std::sync::Arc<ChannelGraph>;
48
49#[derive(Debug, Clone, PartialEq, Eq, Hash)]
50pub struct GraphNode(OffchainPublicKey);
51
52impl From<GraphNode> for OffchainPublicKey {
53 fn from(val: GraphNode) -> Self {
54 val.0
55 }
56}