41 lines
1.0 KiB
Rust
41 lines
1.0 KiB
Rust
use std::sync::Arc;
|
|
|
|
use tokio::sync::Mutex;
|
|
|
|
pub mod ssh;
|
|
|
|
pub type AgentClient = nxmesh_proto::agent_service_client::AgentServiceClient<tonic::transport::Channel>;
|
|
|
|
#[async_trait::async_trait]
|
|
pub trait MasterConnectorTrait: Send + Sync {
|
|
async fn connect(
|
|
&mut self,
|
|
settings: &crate::config::settings::Settings,
|
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
|
fn get_client(&self) -> Arc<Mutex<AgentClient>>;
|
|
}
|
|
|
|
pub struct MasterConnector {
|
|
connector: Box<dyn MasterConnectorTrait>,
|
|
}
|
|
|
|
impl MasterConnector {
|
|
pub fn new(connector: Box<dyn MasterConnectorTrait>) -> Self {
|
|
Self { connector }
|
|
}
|
|
}
|
|
|
|
#[async_trait::async_trait]
|
|
impl MasterConnectorTrait for MasterConnector {
|
|
async fn connect(
|
|
&mut self,
|
|
settings: &crate::config::settings::Settings,
|
|
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
self.connector.connect(settings).await
|
|
}
|
|
|
|
fn get_client(&self) -> Arc<Mutex<AgentClient>> {
|
|
self.connector.get_client()
|
|
}
|
|
}
|