use hopr_types::crypto::types::OffchainPublicKey;
#[derive(thiserror::Error, Debug)]
pub enum NetworkGraphError<P>
where
P: MeasurablePath,
{
#[error("timed out for near neighbor probe '{0:?}'")]
ProbeNeighborTimeout(Box<OffchainPublicKey>),
#[error("timed out for loopback probe")]
ProbeLoopbackTimeout(P),
}
pub trait MeasurableNode: Into<OffchainPublicKey> {}
impl<T: Into<OffchainPublicKey>> MeasurableNode for T {}
pub trait MeasurablePeer {
fn peer(&self) -> &OffchainPublicKey;
fn rtt(&self) -> std::time::Duration;
}
pub trait MeasurablePath {
fn id(&self) -> &[u8];
fn path(&self) -> &[u8];
fn timestamp(&self) -> u128;
}
#[derive(Debug, Copy, Clone)]
pub struct EdgeCapacityUpdate {
pub capacity: Option<u128>,
pub src: OffchainPublicKey,
pub dest: OffchainPublicKey,
}
#[derive(Debug)]
pub enum MeasurableEdge<N, P>
where
N: MeasurablePeer + Clone,
P: MeasurablePath + Clone,
{
Probe(std::result::Result<EdgeTransportTelemetry<N, P>, NetworkGraphError<P>>),
Capacity(Box<EdgeCapacityUpdate>),
ConnectionStatus {
peer: OffchainPublicKey,
connected: bool,
},
}
#[derive(Debug, Clone)]
pub enum EdgeTransportTelemetry<N, P>
where
N: MeasurablePeer + Clone,
P: MeasurablePath + Clone,
{
Loopback(P),
Neighbor(N),
}