diff options
| author | tv <tv@krebsco.de> | 2026-10-28 06:02:14 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-28 06:02:14 +0100 |
| commit | 46e2b985b34831c893500d43261d0b4ee45d8b70 (patch) | |
| tree | de5450744443ce6b62dca934c440a42ee3e9c470 /src | |
| parent | fe4c11424d0ad8b155fe1b45c95b5b472a536b8e (diff) | |
start tor in background
Diffstat (limited to 'src')
| -rw-r--r-- | src/transport/tor.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/transport/tor.rs b/src/transport/tor.rs index b826b4b..91d7f86 100644 --- a/src/transport/tor.rs +++ b/src/transport/tor.rs @@ -153,8 +153,10 @@ pub(crate) struct TorTransport { } impl TorTransport { - /// Bootstraps arti (this takes a while: it fetches what it needs to know of the Tor - /// network) and launches our onion service. + /// Launches our onion service, and bootstraps arti in the background (that takes a + /// while: it fetches what it needs to know of the Tor network). Until it is done, + /// dials wait for it (arti bootstraps on demand), and the onion service is published + /// once it is: the node starts without waiting for Tor. pub(crate) async fn start(config: TorConfig) -> Result<Self> { let tor_config = TorClientConfigBuilder::from_directories( config.state_dir.join("state"), @@ -162,10 +164,24 @@ impl TorTransport { ) .build() .context("Configuring Tor")?; - info!(state_dir = %config.state_dir.display(), "Bootstrapping Tor"); - let client = TorClient::create_bootstrapped(tor_config) + let client = TorClient::builder() + .config(tor_config) + .create_unbootstrapped_async() .await - .context("Bootstrapping Tor")?; + .context("Starting Tor")?; + { + let client = client.clone(); + let state_dir = config.state_dir.display().to_string(); + info!(state_dir = %state_dir, "Bootstrapping Tor"); + // Launching the onion service starts it too; this waits for it to be done. + tokio::spawn(async move { + match client.bootstrap().await { + Ok(()) => info!("Tor bootstrapped"), + // Dials try again (on demand). + Err(error) => warn!(error = %error, "Bootstrapping Tor failed"), + } + }); + } let service_config = OnionServiceConfigBuilder::default() .nickname( NICKNAME |
