pub mod client;
pub mod validate;
pub const HELPER_SOCKET: &str = arcbox_constants::paths::privileged::HELPER_SOCKET;
pub const HELPER_SOCKET_ENV: &str = "ARCBOX_HELPER_SOCKET";
pub fn socket_path() -> String {
std::env::var(HELPER_SOCKET_ENV).unwrap_or_else(|_| HELPER_SOCKET.to_string())
}
pub const HOSTS_ALIAS_NAME: &str = "ArcBox";
pub const HOSTS_ALIAS_LINE: &str = "127.0.0.1\tArcBox\t# managed by arcbox-helper";
#[must_use]
pub fn hosts_alias_installed(hosts_content: &str) -> bool {
hosts_content
.lines()
.any(|line| line.trim() == HOSTS_ALIAS_LINE)
}
#[tarpc::service]
pub trait HelperService {
async fn route_add(subnet: String, iface: String) -> Result<(), String>;
async fn route_remove(subnet: String) -> Result<(), String>;
async fn dns_install(domain: String, port: u16) -> Result<(), String>;
async fn dns_uninstall(domain: String) -> Result<(), String>;
async fn dns_status(domain: String) -> Result<bool, String>;
async fn socket_link(target: String) -> Result<(), String>;
async fn socket_unlink() -> Result<(), String>;
async fn cli_link(name: String, target: String) -> Result<(), String>;
async fn cli_unlink(name: String) -> Result<(), String>;
async fn version() -> String;
async fn hosts_alias_install() -> Result<(), String>;
async fn hosts_alias_uninstall() -> Result<(), String>;
async fn hosts_alias_status() -> Result<bool, String>;
}
pub(crate) async fn connect() -> Result<HelperServiceClient, std::io::Error> {
let path = socket_path();
let transport =
tarpc::serde_transport::unix::connect(&path, tarpc::tokio_serde::formats::Bincode::default)
.await?;
Ok(HelperServiceClient::new(tarpc::client::Config::default(), transport).spawn())
}