Feat/web (Patchset 4) (#460)

support basic functions in frontend
1. create/del network
2. inspect network running status
This commit is contained in:
Sijie.Sun
2024-11-08 23:33:17 +08:00
committed by GitHub
parent 8aca5851f2
commit e948dbfcc1
64 changed files with 11671 additions and 344 deletions

View File

@@ -4,7 +4,7 @@
extern crate rust_i18n;
use std::{
net::{Ipv4Addr, SocketAddr},
net::{Ipv4Addr, SocketAddr},
path::PathBuf,
};
@@ -505,7 +505,7 @@ impl From<Cli> for TomlConfigLoader {
f.latency_first = cli.latency_first;
f.dev_name = cli.dev_name.unwrap_or_default();
if let Some(mtu) = cli.mtu {
f.mtu = mtu;
f.mtu = mtu as u32;
}
f.enable_exit_node = cli.enable_exit_node;
f.no_tun = cli.no_tun || cfg!(not(feature = "tun"));
@@ -653,13 +653,13 @@ pub fn handle_event(mut events: EventBusSubscriber) -> tokio::task::JoinHandle<(
}
#[cfg(target_os = "windows")]
fn win_service_event_loop(
fn win_service_event_loop(
stop_notify: std::sync::Arc<tokio::sync::Notify>,
inst: launcher::NetworkInstance,
status_handle: windows_service::service_control_handler::ServiceStatusHandle,
) {
use tokio::runtime::Runtime;
inst: launcher::NetworkInstance,
status_handle: windows_service::service_control_handler::ServiceStatusHandle,
) {
use std::time::Duration;
use tokio::runtime::Runtime;
use windows_service::service::*;
std::thread::spawn(move || {
@@ -699,26 +699,23 @@ fn win_service_event_loop(
#[cfg(target_os = "windows")]
fn win_service_main(_: Vec<std::ffi::OsString>) {
use std::time::Duration;
use windows_service::service_control_handler::*;
use windows_service::service::*;
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Notify;
use windows_service::service::*;
use windows_service::service_control_handler::*;
let cli = Cli::parse();
let cfg = TomlConfigLoader::from(cli);
init_logger(&cfg, false).unwrap();
init_logger(&cfg, false).unwrap();
let stop_notify_send = Arc::new(Notify::new());
let stop_notify_recv = Arc::clone(&stop_notify_send);
let event_handler = move |control_event| -> ServiceControlHandlerResult {
match control_event {
ServiceControl::Interrogate => {
ServiceControlHandlerResult::NoError
}
ServiceControl::Stop =>
{
ServiceControl::Interrogate => ServiceControlHandlerResult::NoError,
ServiceControl::Stop => {
stop_notify_send.notify_one();
ServiceControlHandlerResult::NoError
}
@@ -736,10 +733,12 @@ fn win_service_main(_: Vec<std::ffi::OsString>) {
process_id: None,
};
let mut inst = launcher::NetworkInstance::new(cfg).set_fetch_node_info(false);
inst.start().unwrap();
status_handle.set_service_status(next_status).expect("set service status fail");
win_service_event_loop(stop_notify_recv, inst, status_handle);
inst.start().unwrap();
status_handle
.set_service_status(next_status)
.expect("set service status fail");
win_service_event_loop(stop_notify_recv, inst, status_handle);
}
#[tokio::main]
@@ -750,18 +749,19 @@ async fn main() {
#[cfg(target_os = "windows")]
match windows_service::service_dispatcher::start(String::new(), ffi_service_main) {
Ok(_) => std::thread::park(),
Err(e) =>
{
let should_panic = if let windows_service::Error::Winapi(ref io_error) = e {
io_error.raw_os_error() != Some(0x427) // ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
} else { true };
if should_panic {
panic!("SCM start an error: {}", e);
}
}
};
Err(e) => {
let should_panic = if let windows_service::Error::Winapi(ref io_error) = e {
io_error.raw_os_error() != Some(0x427) // ERROR_FAILED_SERVICE_CONTROLLER_CONNECT
} else {
true
};
if should_panic {
panic!("SCM start an error: {}", e);
}
}
};
let cli = Cli::parse();
setup_panic_handler();