sandbox_runtime/manager/
state.rs1use std::sync::Arc;
4
5
6use crate::config::SandboxRuntimeConfig;
7use crate::proxy::{HttpProxy, Socks5Proxy};
8use crate::violation::SandboxViolationStore;
9
10pub struct ManagerState {
12 pub config: Option<SandboxRuntimeConfig>,
14
15 pub http_proxy: Option<HttpProxy>,
17
18 pub socks_proxy: Option<Socks5Proxy>,
20
21 pub http_proxy_port: Option<u16>,
23
24 pub socks_proxy_port: Option<u16>,
26
27 #[cfg(target_os = "linux")]
29 pub http_socket_path: Option<String>,
30
31 #[cfg(target_os = "linux")]
33 pub socks_socket_path: Option<String>,
34
35 #[cfg(target_os = "linux")]
37 pub bridges: Vec<crate::sandbox::linux::SocatBridge>,
38
39 pub initialized: bool,
41
42 pub network_ready: bool,
44
45 pub violation_store: Arc<SandboxViolationStore>,
47}
48
49impl Default for ManagerState {
50 fn default() -> Self {
51 Self {
52 config: None,
53 http_proxy: None,
54 socks_proxy: None,
55 http_proxy_port: None,
56 socks_proxy_port: None,
57 #[cfg(target_os = "linux")]
58 http_socket_path: None,
59 #[cfg(target_os = "linux")]
60 socks_socket_path: None,
61 #[cfg(target_os = "linux")]
62 bridges: Vec::new(),
63 initialized: false,
64 network_ready: false,
65 violation_store: Arc::new(SandboxViolationStore::new()),
66 }
67 }
68}
69
70impl ManagerState {
71 pub fn new() -> Self {
73 Self::default()
74 }
75
76 pub async fn reset(&mut self) {
78 if let Some(ref mut proxy) = self.http_proxy {
80 proxy.stop();
81 }
82 if let Some(ref mut proxy) = self.socks_proxy {
83 proxy.stop();
84 }
85
86 #[cfg(target_os = "linux")]
88 {
89 for bridge in &mut self.bridges {
90 bridge.stop().await;
91 }
92 self.bridges.clear();
93 self.http_socket_path = None;
94 self.socks_socket_path = None;
95 }
96
97 self.http_proxy = None;
99 self.socks_proxy = None;
100 self.http_proxy_port = None;
101 self.socks_proxy_port = None;
102 self.config = None;
103 self.initialized = false;
104 self.network_ready = false;
105 }
106}