diff --git a/boltconn/src/app.rs b/boltconn/src/app.rs index e281170..4a97007 100644 --- a/boltconn/src/app.rs +++ b/boltconn/src/app.rs @@ -43,6 +43,7 @@ pub struct App { api_dispatching_handler: SharedDispatching, tun_configure: Arc>, http_capturer: Arc, + linked_state: Arc>, speedtest_url: Arc>, receiver: tokio::sync::mpsc::Receiver<()>, uds_socket: Arc, @@ -186,6 +187,10 @@ impl App { let api_dispatching_handler = Arc::new(ArcSwap::new(dispatching)); let (reload_sender, reload_receiver) = tokio::sync::mpsc::channel::<()>(1); let speedtest_url = Arc::new(std::sync::RwLock::new(config.speedtest_url.clone())); + let linked_state = Arc::new(std::sync::Mutex::new(LinkedState { + state_path: LoadedConfig::state_path(&data_path), + state: loaded_config.state, + })); let controller = Arc::new(Controller::new( manager.clone(), dns.clone(), @@ -195,10 +200,7 @@ impl App { api_dispatching_handler.clone(), tun_configure.clone(), reload_sender, - LinkedState { - state_path: LoadedConfig::state_path(&data_path), - state: loaded_config.state, - }, + linked_state.clone(), stream_logger, speedtest_url.clone(), )); @@ -233,6 +235,7 @@ impl App { api_dispatching_handler, tun_configure, http_capturer, + linked_state, speedtest_url, receiver: reload_receiver, uds_socket: uds_listener, @@ -312,6 +315,8 @@ impl App { .map_err(|e| anyhow!("Load intercept rules failed: {}", e))?, ); + self.linked_state.lock().unwrap().state = loaded_config.state; + self.dns.replace_resolvers(&self.outbound_iface, group); self.dns.replace_ns_policy(ns_policy); self.dns.replace_hosts(&config.dns.hosts); diff --git a/boltconn/src/external/controller.rs b/boltconn/src/external/controller.rs index 9bef4c7..bc97b7f 100644 --- a/boltconn/src/external/controller.rs +++ b/boltconn/src/external/controller.rs @@ -42,7 +42,7 @@ impl Controller { dispatching: SharedDispatching, global_setting: Arc>, reload_sender: tokio::sync::mpsc::Sender<()>, - state: LinkedState, + state: Arc>, stream_logger: StreamLoggerSend, speedtest_url: Arc>, ) -> Self { @@ -55,7 +55,7 @@ impl Controller { dispatcher, dispatching, reload_sender: Arc::new(reload_sender), - state: Arc::new(std::sync::Mutex::new(state)), + state, stream_logger, speedtest_url, }