Create separate context for TOR runtime

This commit is contained in:
yeastplume 2024-07-29 13:40:21 +01:00
parent d448fe87a7
commit 1b33f924ac
4 changed files with 22 additions and 13 deletions

View file

@ -161,14 +161,17 @@ fn real_main() -> Result<(), Box<dyn std::error::Error>> {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?;
if let Err(e) = rt.block_on(node.async_get_chain_tip()) {
let rt_handle = rt.handle().clone();
if let Err(e) = rt_handle.block_on(node.async_get_chain_tip()) {
eprintln!("Node communication failure. Is node listening?");
return Err(e.into());
};
// Open wallet
let wallet_pass = prompt_wallet_password(&args.value_of("wallet_pass"));
let wallet = rt.block_on(HttpWallet::async_open_wallet(
let wallet = rt_handle.block_on(HttpWallet::async_open_wallet(
&server_config.wallet_owner_url,
&server_config.wallet_owner_api_secret(),
&wallet_pass,
@ -181,8 +184,14 @@ fn real_main() -> Result<(), Box<dyn std::error::Error>> {
}
};
let tor_instance = rt.block_on(tor::async_init_tor(
PreferredRuntime::current().unwrap(),
let tor_runtime = if let Ok(r) = PreferredRuntime::create() {
r
} else {
return Err("No runtime found".into());
};
let tor_instance = rt_handle.block_on(tor::async_init_tor(
tor_runtime,
&config::get_grin_path(&chain_type).to_str().unwrap(),
&server_config,
))?;
@ -192,7 +201,7 @@ fn real_main() -> Result<(), Box<dyn std::error::Error>> {
let stop_state = Arc::new(StopState::new());
let stop_state_clone = stop_state.clone();
rt.spawn(async move {
rt_handle.spawn(async move {
futures::executor::block_on(build_signals_fut());
tor_clone.lock().stop();
stop_state_clone.stop();
@ -215,7 +224,7 @@ fn real_main() -> Result<(), Box<dyn std::error::Error>> {
);
let (_, http_server) = servers::mix_rpc::listen(
rt.handle(),
&rt_handle,
server_config,
next_mixer,
Arc::new(wallet),

View file

@ -70,7 +70,7 @@ impl IntegrationGrinNode {
}
pub fn to_client(&self) -> Arc<dyn GrinNode> {
Arc::new(HttpGrinNode::new(&self.api_address(), &None))
Arc::new(HttpGrinNode::new(&self.api_address().to_string(), &None))
}
}

View file

@ -63,9 +63,9 @@ where
.unwrap()
.local_addr()
.unwrap(),
grin_node_url: node.lock().api_address(),
grin_node_url: node.lock().api_address().to_string(),
grin_node_secret_path: None,
wallet_owner_url: wallet.lock().owner_address(),
wallet_owner_url: wallet.lock().owner_address().to_string(),
wallet_owner_secret_path: None,
prev_server: None,
next_server: match next_server {
@ -128,9 +128,9 @@ where
.unwrap()
.local_addr()
.unwrap(),
grin_node_url: node.lock().api_address(),
grin_node_url: node.lock().api_address().to_string(),
grin_node_secret_path: None,
wallet_owner_url: wallet.lock().owner_address(),
wallet_owner_url: wallet.lock().owner_address().to_string(),
wallet_owner_secret_path: None,
prev_server: Some(prev_server),
next_server: match next_server {

View file

@ -108,7 +108,7 @@ impl IntegrationGrinWallet {
let owner_api = Arc::new(Owner::new(wallet.clone(), None));
let address_str = format!("127.0.0.1:{}", api_listen_port);
let owner_addr: SocketAddr = address_str.parse().unwrap();
let address_str_2 = format!("127.0.0.1:{}", api_listen_port);
let thr_wallet = wallet.clone();
let _thread_handle = thread::spawn(move || {
controller::owner_listener(
@ -125,7 +125,7 @@ impl IntegrationGrinWallet {
});
let http_client = Arc::new(
HttpWallet::async_open_wallet(&owner_addr, &None, &ZeroingString::from("pass"))
HttpWallet::async_open_wallet(&address_str_2, &None, &ZeroingString::from("pass"))
.await
.unwrap(),
);