mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-12 20:57:26 +08:00
set hostname when connecting to config-server (#712)
This commit is contained in:
@@ -160,6 +160,7 @@ const createNewNetwork = async () => {
|
|||||||
|
|
||||||
const newNetwork = () => {
|
const newNetwork = () => {
|
||||||
newNetworkConfig.value = NetworkTypes.DEFAULT_NETWORK_CONFIG();
|
newNetworkConfig.value = NetworkTypes.DEFAULT_NETWORK_CONFIG();
|
||||||
|
newNetworkConfig.value.hostname = deviceInfo.value?.hostname;
|
||||||
isEditing.value = false;
|
isEditing.value = false;
|
||||||
showCreateNetworkDialog.value = true;
|
showCreateNetworkDialog.value = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ mod tests {
|
|||||||
mgr.serve(Box::new(listener)).await.unwrap();
|
mgr.serve(Box::new(listener)).await.unwrap();
|
||||||
|
|
||||||
let connector = UdpTunnelConnector::new("udp://127.0.0.1:54333".parse().unwrap());
|
let connector = UdpTunnelConnector::new("udp://127.0.0.1:54333".parse().unwrap());
|
||||||
let _c = WebClient::new(connector, "test");
|
let _c = WebClient::new(connector, "test", "test");
|
||||||
|
|
||||||
wait_for_condition(
|
wait_for_condition(
|
||||||
|| async { mgr.client_sessions.len() == 1 },
|
|| async { mgr.client_sessions.len() == 1 },
|
||||||
|
|||||||
@@ -869,9 +869,18 @@ async fn run_main(cli: Cli) -> anyhow::Result<()> {
|
|||||||
let mut flags = global_ctx.get_flags();
|
let mut flags = global_ctx.get_flags();
|
||||||
flags.bind_device = false;
|
flags.bind_device = false;
|
||||||
global_ctx.set_flags(flags);
|
global_ctx.set_flags(flags);
|
||||||
|
let hostname = match cli.hostname {
|
||||||
|
None => {
|
||||||
|
gethostname::gethostname().to_string_lossy().to_string()
|
||||||
|
}
|
||||||
|
Some(hostname) => {
|
||||||
|
hostname.to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
let _wc = web_client::WebClient::new(
|
let _wc = web_client::WebClient::new(
|
||||||
create_connector_by_url(c_url.as_str(), &global_ctx, IpVersion::Both).await?,
|
create_connector_by_url(c_url.as_str(), &global_ctx, IpVersion::Both).await?,
|
||||||
token.to_string(),
|
token.to_string(),
|
||||||
|
hostname
|
||||||
);
|
);
|
||||||
tokio::signal::ctrl_c().await.unwrap();
|
tokio::signal::ctrl_c().await.unwrap();
|
||||||
DNSTunnelConnector::new("".parse().unwrap(), global_ctx);
|
DNSTunnelConnector::new("".parse().unwrap(), global_ctx);
|
||||||
|
|||||||
@@ -19,13 +19,15 @@ use crate::{
|
|||||||
|
|
||||||
pub struct Controller {
|
pub struct Controller {
|
||||||
token: String,
|
token: String,
|
||||||
|
hostname: String,
|
||||||
instance_map: DashMap<uuid::Uuid, NetworkInstance>,
|
instance_map: DashMap<uuid::Uuid, NetworkInstance>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Controller {
|
impl Controller {
|
||||||
pub fn new(token: String) -> Self {
|
pub fn new(token: String, hostname: String) -> Self {
|
||||||
Controller {
|
Controller {
|
||||||
token,
|
token,
|
||||||
|
hostname,
|
||||||
instance_map: DashMap::new(),
|
instance_map: DashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,6 +82,10 @@ impl Controller {
|
|||||||
pub fn token(&self) -> String {
|
pub fn token(&self) -> String {
|
||||||
self.token.clone()
|
self.token.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hostname(&self) -> String {
|
||||||
|
self.hostname.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ pub struct WebClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl WebClient {
|
impl WebClient {
|
||||||
pub fn new<T: TunnelConnector + 'static, S: ToString>(connector: T, token: S) -> Self {
|
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()));
|
let controller = Arc::new(controller::Controller::new(token.to_string(),
|
||||||
|
hostname.to_string()));
|
||||||
|
|
||||||
let controller_clone = controller.clone();
|
let controller_clone = controller.clone();
|
||||||
let tasks = ScopedTask::from(tokio::spawn(async move {
|
let tasks = ScopedTask::from(tokio::spawn(async move {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ impl Session {
|
|||||||
let mid = get_machine_id();
|
let mid = get_machine_id();
|
||||||
let inst_id = uuid::Uuid::new_v4();
|
let inst_id = uuid::Uuid::new_v4();
|
||||||
let token = controller.upgrade().unwrap().token();
|
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 ctx_clone = ctx.clone();
|
||||||
let mut tick = interval(std::time::Duration::from_secs(1));
|
let mut tick = interval(std::time::Duration::from_secs(1));
|
||||||
|
|||||||
Reference in New Issue
Block a user