tor: create runtime only once

This commit is contained in:
ardocrat
2026-05-25 16:32:13 +03:00
parent 4c4b6cd5dc
commit f7287bd9ad
+3 -2
View File
@@ -60,6 +60,7 @@ lazy_static! {
/// Tor client to use as SOCKS proxy for requests and to launch Onion services.
pub struct Tor {
runtime: TokioNativeTlsRuntime,
/// Tor client and config.
client_config: Arc<RwLock<Option<(TorClient<TokioNativeTlsRuntime>, TorClientConfig)>>>,
/// Flag to check if client is launching.
@@ -97,6 +98,7 @@ impl Default for Tor {
}
}
Self {
runtime: TokioNativeTlsRuntime::create().unwrap(),
client_config: Arc::new(RwLock::new(None)),
client_launching: Arc::new(AtomicBool::new(false)),
run: Arc::new(RwLock::new(BTreeMap::new())),
@@ -140,8 +142,7 @@ impl Tor {
/// Build bootstrapped client from provided config.
fn build_client_bootstrap(config: TorClientConfig) -> Option<TorClient<TokioNativeTlsRuntime>> {
let runtime = TokioNativeTlsRuntime::create().unwrap();
let client_res = TorClient::with_runtime(runtime)
let client_res = TorClient::with_runtime(TOR_STATE.runtime.clone())
.config(config.clone())
.create_unbootstrapped();
if client_res.is_err() {