PtMgr: Use a persistent state directory for PT state.
This makes a `pt_state` directory inside .local/share/arti (or the local equivalent), right next to our existing `state` dir. Ideally we would use a separate directory for each PT, but we have a very fuzzy "what is a specific PT" notion. Closes #667
This commit is contained in:
parent
1a9c4c722b
commit
820657b6bc
|
@ -4074,7 +4074,6 @@ dependencies = [
|
||||||
"derive_builder_fork_arti",
|
"derive_builder_fork_arti",
|
||||||
"futures",
|
"futures",
|
||||||
"serde",
|
"serde",
|
||||||
"tempfile",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tor-chanmgr",
|
"tor-chanmgr",
|
||||||
|
|
|
@ -450,8 +450,13 @@ impl<R: Runtime> TorClient<R> {
|
||||||
|
|
||||||
#[cfg(feature = "pt-client")]
|
#[cfg(feature = "pt-client")]
|
||||||
let pt_mgr = {
|
let pt_mgr = {
|
||||||
|
let mut pt_state_dir = config.storage.expand_state_dir()?;
|
||||||
|
pt_state_dir.push("pt_state");
|
||||||
|
config.storage.permissions().make_directory(&pt_state_dir)?;
|
||||||
|
|
||||||
let mgr = Arc::new(tor_ptmgr::PtMgr::new(
|
let mgr = Arc::new(tor_ptmgr::PtMgr::new(
|
||||||
config.bridges.transports.clone(),
|
config.bridges.transports.clone(),
|
||||||
|
pt_state_dir,
|
||||||
runtime.clone(),
|
runtime.clone(),
|
||||||
)?);
|
)?);
|
||||||
|
|
||||||
|
|
|
@ -203,6 +203,10 @@ enum ErrorDetail {
|
||||||
#[error("Problem with a pluggable transport")]
|
#[error("Problem with a pluggable transport")]
|
||||||
PluggableTransport(#[from] tor_ptmgr::err::PtError),
|
PluggableTransport(#[from] tor_ptmgr::err::PtError),
|
||||||
|
|
||||||
|
/// We encountered a problem while inspecting or creating a directory.
|
||||||
|
#[error("Filesystem permissions problem")]
|
||||||
|
FsMistrust(#[from] fs_mistrust::Error),
|
||||||
|
|
||||||
/// Unable to spawn task
|
/// Unable to spawn task
|
||||||
#[error("Unable to spawn {spawning}")]
|
#[error("Unable to spawn {spawning}")]
|
||||||
Spawn {
|
Spawn {
|
||||||
|
@ -317,6 +321,7 @@ impl tor_error::HasKind for ErrorDetail {
|
||||||
E::LocalAddress => EK::ForbiddenStreamTarget,
|
E::LocalAddress => EK::ForbiddenStreamTarget,
|
||||||
E::ChanMgrSetup(e) => e.kind(),
|
E::ChanMgrSetup(e) => e.kind(),
|
||||||
E::NoDir { error, .. } => error.kind(),
|
E::NoDir { error, .. } => error.kind(),
|
||||||
|
E::FsMistrust(_) => EK::FsPermissions,
|
||||||
E::Bug(e) => e.kind(),
|
E::Bug(e) => e.kind(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ async-trait = "0.1.2"
|
||||||
derive_builder = { version = "0.11.2", package = "derive_builder_fork_arti" }
|
derive_builder = { version = "0.11.2", package = "derive_builder_fork_arti" }
|
||||||
futures = "0.3.14"
|
futures = "0.3.14"
|
||||||
serde = { version = "1.0.103", features = ["derive"] }
|
serde = { version = "1.0.103", features = ["derive"] }
|
||||||
tempfile = "3.3"
|
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
tor-chanmgr = { version = "0.7.0", path = "../tor-chanmgr", features = ["pt-client"] }
|
tor-chanmgr = { version = "0.7.0", path = "../tor-chanmgr", features = ["pt-client"] }
|
||||||
tor-config = { version = "0.6.0", path = "../tor-config" }
|
tor-config = { version = "0.6.0", path = "../tor-config" }
|
||||||
|
|
|
@ -52,7 +52,6 @@ use futures::channel::oneshot;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use tempfile::TempDir;
|
|
||||||
use tor_linkspec::PtTransportName;
|
use tor_linkspec::PtTransportName;
|
||||||
use tor_rtcompat::Runtime;
|
use tor_rtcompat::Runtime;
|
||||||
use tracing::warn;
|
use tracing::warn;
|
||||||
|
@ -122,12 +121,8 @@ pub struct PtMgr<R> {
|
||||||
state: Arc<RwLock<PtSharedState>>,
|
state: Arc<RwLock<PtSharedState>>,
|
||||||
/// PtReactor channel.
|
/// PtReactor channel.
|
||||||
tx: UnboundedSender<PtReactorMessage>,
|
tx: UnboundedSender<PtReactorMessage>,
|
||||||
/// Temporary directory to store PT state in.
|
/// Directory to store PT state in.
|
||||||
//
|
state_dir: PathBuf,
|
||||||
// FIXME(eta): This should be configurable.
|
|
||||||
//
|
|
||||||
// TODO pt-client: There should be one of these per PT, if possible.
|
|
||||||
state_dir: TempDir,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Runtime> PtMgr<R> {
|
impl<R: Runtime> PtMgr<R> {
|
||||||
|
@ -150,7 +145,11 @@ impl<R: Runtime> PtMgr<R> {
|
||||||
|
|
||||||
/// Create a new PtMgr.
|
/// Create a new PtMgr.
|
||||||
// TODO pt-client: maybe don't have the Vec directly exposed?
|
// TODO pt-client: maybe don't have the Vec directly exposed?
|
||||||
pub fn new(transports: Vec<ManagedTransportConfig>, rt: R) -> Result<Self, PtError> {
|
pub fn new(
|
||||||
|
transports: Vec<ManagedTransportConfig>,
|
||||||
|
state_dir: PathBuf,
|
||||||
|
rt: R,
|
||||||
|
) -> Result<Self, PtError> {
|
||||||
let state = PtSharedState {
|
let state = PtSharedState {
|
||||||
cmethods: Default::default(),
|
cmethods: Default::default(),
|
||||||
configured: Self::transform_config(transports),
|
configured: Self::transform_config(transports),
|
||||||
|
@ -162,7 +161,7 @@ impl<R: Runtime> PtMgr<R> {
|
||||||
runtime: rt,
|
runtime: rt,
|
||||||
state,
|
state,
|
||||||
tx,
|
tx,
|
||||||
state_dir: TempDir::new().map_err(|e| PtError::TempdirCreateFailed(Arc::new(e)))?,
|
state_dir,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue