use std::net::{IpAddr, SocketAddr};
use std::time::Duration;
use url::Url;
use crate::Result;
use crate::connection::{Connection, ConnectionId};
use crate::diag::{
CheckScope, FirewallBackend, FirewallVerdict, Health, PingOpts, ProbeCapabilities, TraceOpts,
};
use crate::dns::DnsResolution;
use crate::link::{Addr, L4Proto, Link, Neighbor, Route, Socket};
use crate::path::{
Egress, Hop, HttpProbeResult, Path, PingResult, Target, TcpProbeResult, TlsProbeResult,
};
use crate::service::{Flow, Service};
pub trait InventoryRaw: Send + Sync {
fn links(&self) -> Result<Vec<Link>>;
fn addrs(&self) -> Result<Vec<(u32, Addr)>>;
fn routes(&self) -> Result<Vec<Route>>;
fn neighbors(&self) -> Result<Vec<Neighbor>>;
fn sockets(&self) -> Result<Vec<Socket>>;
}
pub trait Inventory: Send + Sync {
fn connections(&self) -> Result<Vec<Connection>>;
fn services(&self) -> Result<Vec<Service>>;
fn flows(&self) -> Result<Vec<Flow>>;
fn egress_for(&self, dst: IpAddr) -> Result<Egress>;
}
pub trait Resolver: Send + Sync {
fn resolve(&self, name: &str) -> Result<DnsResolution>;
fn servers_for(&self, conn: &ConnectionId) -> Result<Vec<IpAddr>>;
fn stub_server(&self) -> Result<Option<IpAddr>>;
}
pub trait Reachability: Send + Sync {
fn ping(&self, ip: IpAddr, opts: PingOpts) -> Result<PingResult>;
fn tcp_connect(&self, sa: SocketAddr, timeout: Duration) -> Result<TcpProbeResult>;
fn tls_handshake(&self, sa: SocketAddr, sni: &str, timeout: Duration)
-> Result<TlsProbeResult>;
fn http_head(&self, url: &Url, timeout: Duration) -> Result<HttpProbeResult>;
fn trace(&self, ip: IpAddr, opts: TraceOpts) -> Result<Vec<Hop>>;
fn capabilities(&self) -> ProbeCapabilities;
}
pub trait Firewall: Send + Sync {
fn verdict_for_inbound(&self, port: u16, proto: L4Proto) -> Result<FirewallVerdict>;
fn backend(&self) -> FirewallBackend;
}
pub trait Actions: Send + Sync {
fn prefer(&self, id: &ConnectionId) -> Result<()>;
fn forget(&self, id: &ConnectionId) -> Result<()>;
fn reconnect(&self, id: &ConnectionId) -> Result<()>;
fn set_autoconnect(&self, id: &ConnectionId, on: bool) -> Result<()>;
}
pub trait Diagnostician: Send + Sync {
fn check(&self, scope: CheckScope) -> Result<Health>;
fn trace_path(&self, target: Target) -> Result<Path>;
}