use crate::{
types::{CurrentStatus, Ident32, InMemoryEnvelope, Neighbour},
Result,
};
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[async_trait]
pub trait EndpointExt {
fn identifier(&self) -> String {
"<unknown>".into()
}
fn status(&self) -> CurrentStatus {
CurrentStatus::Unknown
}
async fn metrics_for_neighbour(&self, _neighbour: Neighbour) -> Result<NeighbourMetrics> {
Err(crate::RatmanError::Netmod(crate::NetmodError::NotSupported))
}
async fn start_peering(&self, _addr: &str) -> Result<u16> {
Err(crate::RatmanError::Netmod(crate::NetmodError::NotSupported))
}
async fn send(
&self,
envelope: InMemoryEnvelope,
target: Neighbour,
exclude: Option<Ident32>,
) -> Result<()>;
async fn next(&self) -> Result<(InMemoryEnvelope, Neighbour)>;
}
#[async_trait]
impl<T: EndpointExt + Send + Sync> EndpointExt for Arc<T> {
async fn send(
&self,
envelope: InMemoryEnvelope,
target: Neighbour,
exclude: Option<Ident32>,
) -> Result<()> {
T::send(self, envelope, target, exclude).await
}
async fn next(&self) -> Result<(InMemoryEnvelope, Neighbour)> {
T::next(self).await
}
}
#[derive(
Default, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
)]
pub struct NeighbourMetrics {
pub write_bandwidth: u64,
pub read_bandwidth: u64,
}