tor: handle client creation error
This commit is contained in:
parent
1424a820f0
commit
fa0232d4c4
1 changed files with 12 additions and 4 deletions
|
@ -19,7 +19,7 @@ use std::collections::{BTreeMap, BTreeSet};
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
use std::{fs, thread};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use arti_client::config::{CfgPath, TorClientConfigBuilder};
|
use arti_client::config::{CfgPath, TorClientConfigBuilder};
|
||||||
|
@ -83,10 +83,18 @@ impl Default for Tor {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let runtime = TokioNativeTlsRuntime::create().unwrap();
|
let runtime = TokioNativeTlsRuntime::create().unwrap();
|
||||||
let config = Self::build_config();
|
let config = Self::build_config();
|
||||||
let client = TorClient::with_runtime(runtime)
|
let client = if let Ok(c) = TorClient::with_runtime(runtime)
|
||||||
.config(config.clone())
|
.config(config.clone())
|
||||||
.create_unbootstrapped()
|
.create_unbootstrapped() {
|
||||||
.unwrap();
|
c
|
||||||
|
} else {
|
||||||
|
fs::remove_dir_all(TorConfig::state_path()).unwrap();
|
||||||
|
fs::remove_dir_all(TorConfig::cache_path()).unwrap();
|
||||||
|
let runtime = TokioNativeTlsRuntime::create().unwrap();
|
||||||
|
TorClient::with_runtime(runtime)
|
||||||
|
.config(config.clone())
|
||||||
|
.create_unbootstrapped().unwrap()
|
||||||
|
};
|
||||||
Self {
|
Self {
|
||||||
running_services: Arc::new(RwLock::new(BTreeMap::new())),
|
running_services: Arc::new(RwLock::new(BTreeMap::new())),
|
||||||
starting_services: Arc::new(RwLock::new(BTreeSet::new())),
|
starting_services: Arc::new(RwLock::new(BTreeSet::new())),
|
||||||
|
|
Loading…
Reference in a new issue