From 5dfedb4c6f7c0788b9fc0a525bae54e9896d2542 Mon Sep 17 00:00:00 2001 From: Neel Chauhan Date: Thu, 6 Jan 2022 12:22:49 -0800 Subject: [PATCH] De-Arc-ify Buildable for ClientCirc --- crates/tor-circmgr/src/build.rs | 19 ++++++------------- crates/tor-circmgr/src/impls.rs | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/crates/tor-circmgr/src/build.rs b/crates/tor-circmgr/src/build.rs index 388919869..cc9875571 100644 --- a/crates/tor-circmgr/src/build.rs +++ b/crates/tor-circmgr/src/build.rs @@ -83,9 +83,8 @@ async fn create_common( Ok(pending_circ) } -// FIXME(eta): de-Arc-ify this #[async_trait] -impl Buildable for Arc { +impl Buildable for ClientCirc { async fn create_chantarget( chanmgr: &ChanMgr, rt: &RT, @@ -93,7 +92,7 @@ impl Buildable for Arc { params: &CircParameters, ) -> Result { let circ = create_common(chanmgr, rt, ct).await?; - Ok(Arc::new(circ.create_firsthop_fast(params).await?)) + Ok(circ.create_firsthop_fast(params).await?) } async fn create( chanmgr: &ChanMgr, @@ -102,9 +101,7 @@ impl Buildable for Arc { params: &CircParameters, ) -> Result { let circ = create_common(chanmgr, rt, ct).await?; - Ok(Arc::new( - circ.create_firsthop_ntor(ct, params.clone()).await?, - )) + Ok(circ.create_firsthop_ntor(ct, params.clone()).await?) } async fn extend( &self, @@ -251,7 +248,7 @@ impl Builder { /// unless you are choosing your own paths. pub struct CircuitBuilder { /// The underlying [`Builder`] object - builder: Arc>>, + builder: Arc>, /// Configuration for how to choose paths for circuits. path_config: tor_config::MutCfg, /// State-manager object to use in storing current state. @@ -334,7 +331,7 @@ impl CircuitBuilder { path: OwnedPath, params: &CircParameters, guard_status: Arc, - ) -> Result> { + ) -> Result { self.builder.build_owned(path, params, guard_status).await } @@ -344,11 +341,7 @@ impl CircuitBuilder { /// This circuit is _not_ automatically registered with any /// circuit manager; if you don't hang on it it, it will /// automatically go away when the last reference is dropped. - pub async fn build( - &self, - path: &TorPath<'_>, - params: &CircParameters, - ) -> Result> { + pub async fn build(&self, path: &TorPath<'_>, params: &CircParameters) -> Result { let owned = path.try_into()?; self.build_owned(owned, params, Arc::new(None.into())).await } diff --git a/crates/tor-circmgr/src/impls.rs b/crates/tor-circmgr/src/impls.rs index 30c51e85f..aaee57c42 100644 --- a/crates/tor-circmgr/src/impls.rs +++ b/crates/tor-circmgr/src/impls.rs @@ -114,7 +114,7 @@ impl crate::mgr::AbstractCircBuilder for crate::build::CircuitBuilde return Err(Error::Internal("Guard usability status cancelled".into())) } } - Ok((final_spec, circuit)) + Ok((final_spec, Arc::new(circuit))) } Err(e) => { // The attempt failed; the builder should have set the