use async_trait::async_trait;
use uuid::Uuid;
use crate::types::*;
#[async_trait]
pub trait NetworkPlane: Send + Sync {
async fn connect_peer(&self, peer: &MeshPeerInfo) -> Result<(), NetError>;
async fn disconnect_peer(&self, node_id: u64) -> Result<(), NetError>;
async fn mesh_status(&self) -> Result<Vec<MeshPeerInfo>, NetError>;
async fn register_endpoint(
&self,
identity: &ServiceIdentity,
endpoint: &ServiceEndpoint,
) -> Result<(), NetError>;
async fn deregister_endpoint(
&self,
identity: &ServiceIdentity,
alloc_id: Uuid,
) -> Result<(), NetError>;
async fn update_endpoint_health(
&self,
identity: &ServiceIdentity,
alloc_id: Uuid,
health: EndpointHealth,
) -> Result<(), NetError>;
async fn apply_policy(&self, policy: &NetworkPolicy) -> Result<(), NetError>;
async fn remove_policy(&self, name: &str) -> Result<(), NetError>;
async fn list_policies(&self) -> Result<Vec<NetworkPolicy>, NetError>;
async fn get_flows(&self, filter: &FlowFilter) -> Result<Vec<Flow>, NetError>;
async fn get_service_metrics(
&self,
source: &str,
dest: &str,
) -> Result<ServicePairMetrics, NetError>;
}
#[derive(Debug, thiserror::Error)]
pub enum NetError {
#[error("tunnel error: {0}")]
Tunnel(String),
#[error("policy error: {0}")]
Policy(String),
#[error("routing error: {0}")]
Routing(String),
#[error("platform not supported: {0}")]
PlatformNotSupported(String),
#[error("eBPF error: {0}")]
Ebpf(String),
#[error("WASI error: {0}")]
Wasi(String),
#[error("{0}")]
Other(#[from] anyhow::Error),
}