set hostname when connecting to config-server (#712)

This commit is contained in:
kevin
2025-03-23 19:53:49 +08:00
committed by GitHub
parent 2b909e04ea
commit 8dc8c7d9e2
6 changed files with 22 additions and 5 deletions
+7 -1
View File
@@ -19,13 +19,15 @@ use crate::{
pub struct Controller {
token: String,
hostname: String,
instance_map: DashMap<uuid::Uuid, NetworkInstance>,
}
impl Controller {
pub fn new(token: String) -> Self {
pub fn new(token: String, hostname: String) -> Self {
Controller {
token,
hostname,
instance_map: DashMap::new(),
}
}
@@ -80,6 +82,10 @@ impl Controller {
pub fn token(&self) -> String {
self.token.clone()
}
pub fn hostname(&self) -> String {
self.hostname.clone()
}
}
#[async_trait::async_trait]
+3 -2
View File
@@ -11,8 +11,9 @@ pub struct WebClient {
}
impl WebClient {
pub fn new<T: TunnelConnector + 'static, S: ToString>(connector: T, token: S) -> Self {
let controller = Arc::new(controller::Controller::new(token.to_string()));
pub fn new<T: TunnelConnector + 'static, S: ToString, H: ToString>(connector: T, token: S, hostname: H) -> Self {
let controller = Arc::new(controller::Controller::new(token.to_string(),
hostname.to_string()));
let controller_clone = controller.clone();
let tasks = ScopedTask::from(tokio::spawn(async move {
+1 -1
View File
@@ -73,7 +73,7 @@ impl Session {
let mid = get_machine_id();
let inst_id = uuid::Uuid::new_v4();
let token = controller.upgrade().unwrap().token();
let hostname = gethostname::gethostname().to_string_lossy().to_string();
let hostname = controller.upgrade().unwrap().hostname();
let ctx_clone = ctx.clone();
let mut tick = interval(std::time::Duration::from_secs(1));