mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-11-27 01:23:58 +01:00
Global config instance (#769)
* config: global instance * fix: cli tests * fix: owner api tests * config: save tor config * fix: owner rpc tests * fix: set config file path on init and owner api call * tor: store launched services, get global config at command loop, remove unused listen args, check for empty global config to set default, do not save empty tor config at owner * api: update config in memory after successful file write * arti: restart proxy in loop * fix: comment for tor config save * config: set or init, update without error * config: scoped tor config * build: update lock file * config: ability to store multiple configurations at memory from config path * tor: restart service on config change * fix: owner api test * foreign: pass tor config from args, stop service, error handling * arti: move runtime wrapper to single file * config: read existing config from file at create_config * config: handle error on read * arti: single dir for cache * foreign: register config listener before launch * config: save temp * config: remove unused error type * config: make path and members not optional, return an error on config creation if it exists, pass default tor config to send if not set * arti: non public runtime wrapper * config: migrate comments * fix: rpc tests * config: return from cache if exists * config: save disabled tor config when null provided at owner and tor section was not set * config: update tor with args at listener * config: pass pathbuf directly on creation * config: unique tmp file name, setting permissions and providing config version * fix global config handling * fix config persistence * fix tor service restart * fix config synchronization * require wallet close before changing data directory * unify global config updates --------- Co-authored-by: wiesche <wiesche89@googlemail.com>
This commit is contained in:
committed by
wiesche
co-authored by
wiesche
parent
09aebadce0
commit
9e3ec0ed5b
+18
-24
@@ -17,9 +17,9 @@ use crate::libwallet::slate_versions::{SlateVersion, VersionedSlate};
|
||||
use crate::libwallet::{Error, Slate};
|
||||
use crate::tor::arti::{start_tor_client, tor_post};
|
||||
use crate::tor::bridge::TorBridge;
|
||||
use crate::tor::config as tor_config;
|
||||
use crate::tor::process::TorProcess;
|
||||
use crate::tor::proxy::TorProxy;
|
||||
use crate::tor::{config as tor_config, Tor};
|
||||
use crate::SlateSender;
|
||||
use grin_wallet_config::TorConfig;
|
||||
use serde::Serialize;
|
||||
@@ -34,7 +34,7 @@ use std::sync::Arc;
|
||||
pub struct TorSlateSender {
|
||||
base_url: String,
|
||||
config: TorConfig,
|
||||
tor: Arc<Tor>,
|
||||
tor_process: Arc<Option<TorProcess>>,
|
||||
}
|
||||
|
||||
impl TorSlateSender {
|
||||
@@ -43,27 +43,29 @@ impl TorSlateSender {
|
||||
if !base_url.starts_with("http") && !base_url.starts_with("https") {
|
||||
Err(Error::GenericError("Scheme must be http".to_string()))
|
||||
} else {
|
||||
let tor_dir = {
|
||||
let mut path = PathBuf::from(&config.send_config_dir);
|
||||
path.push("tor");
|
||||
path.push("sender");
|
||||
path
|
||||
};
|
||||
let tor = if config.use_integrated.unwrap_or(false) {
|
||||
start_tor_client(tor_dir.to_str().unwrap(), config.clone())?
|
||||
start_tor_client(config.clone())?;
|
||||
None
|
||||
} else {
|
||||
Self::launch_tor_process(&config, &tor_dir)?
|
||||
let tor_dir = {
|
||||
let mut path = PathBuf::from(&config.send_config_dir);
|
||||
path.push("tor");
|
||||
path.push("sender");
|
||||
path
|
||||
};
|
||||
let p = Self::launch_tor_process(&config, &tor_dir)?;
|
||||
Some(p)
|
||||
};
|
||||
Ok(TorSlateSender {
|
||||
base_url: base_url.to_owned(),
|
||||
config,
|
||||
tor: Arc::new(tor),
|
||||
tor_process: Arc::new(tor),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Launch external Tor process.
|
||||
fn launch_tor_process(config: &TorConfig, tor_dir: &PathBuf) -> Result<Tor, Error> {
|
||||
fn launch_tor_process(config: &TorConfig, tor_dir: &PathBuf) -> Result<TorProcess, Error> {
|
||||
let mut tor = TorProcess::new();
|
||||
let socks_proxy_addr = SocketAddr::V4(
|
||||
config
|
||||
@@ -107,11 +109,7 @@ impl TorSlateSender {
|
||||
.completion_percent(100)
|
||||
.launch()
|
||||
.map_err(|e| Error::TorProcess(format!("{:?}", e)))?;
|
||||
Ok(Tor {
|
||||
process: Some(tor),
|
||||
service: None,
|
||||
client: None,
|
||||
})
|
||||
Ok(tor)
|
||||
}
|
||||
|
||||
/// Check version of the listening wallet
|
||||
@@ -177,7 +175,7 @@ impl TorSlateSender {
|
||||
where
|
||||
IN: Serialize,
|
||||
{
|
||||
let res = if self.tor.process.is_some() {
|
||||
let res = if self.tor_process.is_some() {
|
||||
let socks_proxy_addr =
|
||||
SocketAddr::V4(self.config.socks_proxy_addr.parse().map_err(|_| {
|
||||
ClientError::Internal("Socks proxy address is not set".to_string())
|
||||
@@ -189,12 +187,8 @@ impl TorSlateSender {
|
||||
let res = client.send_request(req)?;
|
||||
res
|
||||
} else {
|
||||
if let Some(client) = &self.tor.client {
|
||||
tor_post(client.clone(), &self.config, &input, url)
|
||||
.map_err(|e| ClientError::RequestError(format!("{:?}", e)))?
|
||||
} else {
|
||||
return Err(ClientError::Internal("Tor is not configured".to_string()));
|
||||
}
|
||||
tor_post(&self.config, &input, url)
|
||||
.map_err(|e| ClientError::RequestError(format!("{:?}", e)))?
|
||||
};
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user