diff --git a/radicle-cli/src/commands/self.rs b/radicle-cli/src/commands/self.rs index b2fb6edb..f4493e75 100644 --- a/radicle-cli/src/commands/self.rs +++ b/radicle-cli/src/commands/self.rs @@ -106,7 +106,7 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> { term::print(profile.did()); } Show::Home => { - term::print(profile.home().display()); + term::print(profile.home().path().display()); } Show::Config => { term::print(profile.home.config().display()); @@ -171,7 +171,7 @@ fn all(profile: &Profile) -> anyhow::Result<()> { let home = profile.home(); table.push([ term::format::style("Home").into(), - term::format::tertiary(home.display()).into(), + term::format::tertiary(home.path().display()).into(), ]); let config_path = profile.home.config(); diff --git a/radicle-httpd/src/lib.rs b/radicle-httpd/src/lib.rs index 050d4fd8..3ad7ca5c 100644 --- a/radicle-httpd/src/lib.rs +++ b/radicle-httpd/src/lib.rs @@ -60,7 +60,7 @@ pub async fn run(options: Options) -> anyhow::Result<()> { let profile = Profile::load()?; let request_id = RequestId::new(); - tracing::info!("using radicle home at {}", profile.home().display()); + tracing::info!("using radicle home at {}", profile.home().path().display()); let app = router(options, profile)? diff --git a/radicle-node/src/test/environment.rs b/radicle-node/src/test/environment.rs index 76b7977f..e16e1c28 100644 --- a/radicle-node/src/test/environment.rs +++ b/radicle-node/src/test/environment.rs @@ -329,9 +329,9 @@ impl Node { let home = Home::new(home).unwrap(); let signer = MockSigner::default(); let storage = Storage::open(home.storage()).unwrap(); - let addresses = Book::memory().unwrap(); - let tracking = tracking::Config::::memory().unwrap(); - let routing = routing::Table::memory().unwrap(); + let addresses = home.addresses_mut().unwrap(); + let tracking = home.tracking_mut().unwrap(); + let routing = home.routing_mut().unwrap(); Self { id: *signer.public_key(), diff --git a/radicle-tools/src/rad-self.rs b/radicle-tools/src/rad-self.rs index 2058f604..9b7aae41 100644 --- a/radicle-tools/src/rad-self.rs +++ b/radicle-tools/src/rad-self.rs @@ -7,7 +7,7 @@ fn main() -> anyhow::Result<()> { "fingerprint: {}", radicle::crypto::ssh::fmt::fingerprint(profile.id()) ); - println!("home: {}", profile.home().display()); + println!("home: {}", profile.home().path().display()); Ok(()) } diff --git a/radicle/src/profile.rs b/radicle/src/profile.rs index 441d8d07..3872bb83 100644 --- a/radicle/src/profile.rs +++ b/radicle/src/profile.rs @@ -259,30 +259,34 @@ impl Profile { Ok(addresses) } + /// Get radicle home. + pub fn home(&self) -> &Home { + &self.home + } + /// Return a multi-source store for aliases. pub fn aliases(&self) -> Aliases { - let tracking = self.tracking().ok(); - let addresses = self.addresses().ok(); + let tracking = self.home.tracking().ok(); + let addresses = self.home.addresses().ok(); Aliases { tracking, addresses, } } +} - /// Return the path to the keys folder. - pub fn keys(&self) -> PathBuf { - self.home.keys() +impl std::ops::Deref for Profile { + type Target = Home; + + fn deref(&self) -> &Self::Target { + &self.home } +} - /// Get the profile home directory. - pub fn home(&self) -> &Path { - self.home.path() - } - - /// Get the path to the radicle node socket. - pub fn socket(&self) -> PathBuf { - self.home.socket() +impl std::ops::DerefMut for Profile { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.home } } @@ -387,6 +391,54 @@ impl Home { .map(PathBuf::from) .unwrap_or_else(|| self.node().join(node::DEFAULT_SOCKET_NAME)) } + + /// Return a read-only handle to the tracking configuration of the node. + pub fn tracking(&self) -> Result { + let path = self.node().join(node::TRACKING_DB_FILE); + let config = tracking::store::Config::reader(path)?; + + Ok(config) + } + + /// Return a read-write handle to the tracking configuration of the node. + pub fn tracking_mut(&self) -> Result { + let path = self.node().join(node::TRACKING_DB_FILE); + let config = tracking::store::Config::open(path)?; + + Ok(config) + } + + /// Return a read-only handle to the routing database of the node. + pub fn routing(&self) -> Result { + let path = self.node().join(node::ROUTING_DB_FILE); + let router = routing::Table::reader(path)?; + + Ok(router) + } + + /// Return a read-write handle to the routing database of the node. + pub fn routing_mut(&self) -> Result { + let path = self.node().join(node::ROUTING_DB_FILE); + let router = routing::Table::open(path)?; + + Ok(router) + } + + /// Return a handle to a read-only addresses database of the node. + pub fn addresses(&self) -> Result { + let path = self.node().join(node::ADDRESS_DB_FILE); + let addresses = address::Book::reader(path)?; + + Ok(addresses) + } + + /// Return a handle to the addresses database of the node. + pub fn addresses_mut(&self) -> Result { + let path = self.node().join(node::ADDRESS_DB_FILE); + let addresses = address::Book::open(path)?; + + Ok(addresses) + } } #[cfg(test)]