Skip to content

Commit

Permalink
fix: reload now can read States from disk
Browse files Browse the repository at this point in the history
  • Loading branch information
XOR-op committed Aug 29, 2024
1 parent c5146de commit 3fb9386
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions boltconn/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct App {
api_dispatching_handler: SharedDispatching,
tun_configure: Arc<std::sync::Mutex<TunConfigure>>,
http_capturer: Arc<HttpCapturer>,
linked_state: Arc<std::sync::Mutex<LinkedState>>,
speedtest_url: Arc<std::sync::RwLock<String>>,
receiver: tokio::sync::mpsc::Receiver<()>,
uds_socket: Arc<UnixListenerGuard>,
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
));
Expand Down Expand Up @@ -233,6 +235,7 @@ impl App {
api_dispatching_handler,
tun_configure,
http_capturer,
linked_state,
speedtest_url,
receiver: reload_receiver,
uds_socket: uds_listener,
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions boltconn/src/external/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Controller {
dispatching: SharedDispatching,
global_setting: Arc<std::sync::Mutex<TunConfigure>>,
reload_sender: tokio::sync::mpsc::Sender<()>,
state: LinkedState,
state: Arc<std::sync::Mutex<LinkedState>>,
stream_logger: StreamLoggerSend,
speedtest_url: Arc<std::sync::RwLock<String>>,
) -> Self {
Expand All @@ -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,
}
Expand Down

0 comments on commit 3fb9386

Please sign in to comment.