use std::ops::DerefMut;
use arcbox_engine::agent_client::AgentClient;
pub trait SandboxHost: Send + Sync {
type StateGuard<'a>: DerefMut<Target = u64> + Send
where
Self: 'a;
fn lock_host_state(&self) -> impl Future<Output = Self::StateGuard<'_>> + Send;
fn clear_host_state(&self) -> impl Future<Output = ()> + Send;
fn remove_ports(&self, sandbox_id: &str) -> impl Future<Output = ()> + Send;
fn deregister_dns(&self, sandbox_id: &str) -> impl Future<Output = ()> + Send;
fn register_dns(
&self,
sandbox_id: &str,
ip: std::net::IpAddr,
) -> impl Future<Output = ()> + Send;
fn host_state_generation(&self) -> impl Future<Output = u64> + Send;
fn expose_port(
&self,
machine: &str,
exposure: &crate::ports::SandboxPortExposure,
) -> impl Future<Output = arcbox_engine::Result<()>> + Send;
fn unexpose_port(
&self,
sandbox_id: &str,
sandbox_port: u16,
protocol_key: &str,
) -> impl Future<Output = ()> + Send;
fn port_mappings_if_unchanged(
&self,
sandbox_id: &str,
expected_generation: u64,
) -> impl Future<Output = Option<Vec<crate::ports::SandboxPortMapping>>> + Send;
fn agent(&self, machine: &str) -> arcbox_engine::Result<AgentClient>;
}
impl<H: SandboxHost> SandboxHost for std::sync::Arc<H> {
type StateGuard<'a>
= H::StateGuard<'a>
where
Self: 'a;
async fn lock_host_state(&self) -> Self::StateGuard<'_> {
(**self).lock_host_state().await
}
async fn clear_host_state(&self) {
(**self).clear_host_state().await;
}
async fn remove_ports(&self, sandbox_id: &str) {
(**self).remove_ports(sandbox_id).await;
}
async fn deregister_dns(&self, sandbox_id: &str) {
(**self).deregister_dns(sandbox_id).await;
}
async fn register_dns(&self, sandbox_id: &str, ip: std::net::IpAddr) {
(**self).register_dns(sandbox_id, ip).await;
}
async fn host_state_generation(&self) -> u64 {
(**self).host_state_generation().await
}
async fn expose_port(
&self,
machine: &str,
exposure: &crate::ports::SandboxPortExposure,
) -> arcbox_engine::Result<()> {
(**self).expose_port(machine, exposure).await
}
async fn unexpose_port(&self, sandbox_id: &str, sandbox_port: u16, protocol_key: &str) {
(**self)
.unexpose_port(sandbox_id, sandbox_port, protocol_key)
.await;
}
async fn port_mappings_if_unchanged(
&self,
sandbox_id: &str,
expected_generation: u64,
) -> Option<Vec<crate::ports::SandboxPortMapping>> {
(**self)
.port_mappings_if_unchanged(sandbox_id, expected_generation)
.await
}
fn agent(&self, machine: &str) -> arcbox_engine::Result<AgentClient> {
(**self).agent(machine)
}
}