From d778a922255a75e36baa5296451e9982045ac777 Mon Sep 17 00:00:00 2001 From: Nick Mathewson <nickm@torproject.org> Date: Thu, 17 Mar 2022 09:33:47 -0400 Subject: [PATCH] circmgr: Change API for using FallbackDirs It'll soon more convenient to pass in FallbackDirs as a slice of references, rather than just a slice of FallbackDirs: I'm going to be changing how we handle these in tor-dirmgr. --- crates/tor-circmgr/src/lib.rs | 6 +++--- crates/tor-circmgr/src/mgr.rs | 2 +- crates/tor-circmgr/src/path/dirpath.rs | 5 +++-- crates/tor-dirmgr/src/bootstrap.rs | 6 +++++- doc/semver_status.md | 5 +++++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/tor-circmgr/src/lib.rs b/crates/tor-circmgr/src/lib.rs index c204cc3067..4b0edda655 100644 --- a/crates/tor-circmgr/src/lib.rs +++ b/crates/tor-circmgr/src/lib.rs @@ -105,13 +105,13 @@ const PARETO_TIMEOUT_DATA_KEY: &str = "circuit_timeouts"; #[non_exhaustive] pub enum DirInfo<'a> { /// A list of fallbacks, for use when we don't know a network directory. - Fallbacks(&'a [FallbackDir]), + Fallbacks(&'a [&'a FallbackDir]), /// A complete network directory Directory(&'a NetDir), } -impl<'a> From<&'a [FallbackDir]> for DirInfo<'a> { - fn from(v: &'a [FallbackDir]) -> DirInfo<'a> { +impl<'a> From<&'a [&'a FallbackDir]> for DirInfo<'a> { + fn from(v: &'a [&'a FallbackDir]) -> DirInfo<'a> { DirInfo::Fallbacks(v) } } diff --git a/crates/tor-circmgr/src/mgr.rs b/crates/tor-circmgr/src/mgr.rs index b46b81afc5..9febaad5f4 100644 --- a/crates/tor-circmgr/src/mgr.rs +++ b/crates/tor-circmgr/src/mgr.rs @@ -1460,7 +1460,7 @@ mod test { const FAKE_CIRC_DELAY: Duration = Duration::from_millis(30); - static DI_EMPTY: [tor_netdir::fallback::FallbackDir; 0] = []; + static DI_EMPTY: [&tor_netdir::fallback::FallbackDir; 0] = []; fn di() -> DirInfo<'static> { DI_EMPTY[..].into() diff --git a/crates/tor-circmgr/src/path/dirpath.rs b/crates/tor-circmgr/src/path/dirpath.rs index bc38a2957e..bae973c389 100644 --- a/crates/tor-circmgr/src/path/dirpath.rs +++ b/crates/tor-circmgr/src/path/dirpath.rs @@ -102,7 +102,7 @@ mod test { #[test] fn dirpath_fallback() { - let fb = vec![ + let fb_owned = vec![ FallbackDir::builder() .rsa_identity([0x01; 20].into()) .ed_identity([0x01; 32].into()) @@ -116,6 +116,7 @@ mod test { .build() .unwrap(), ]; + let fb: Vec<_> = fb_owned.iter().collect(); let dirinfo = (&fb[..]).into(); let mut rng = rand::thread_rng(); let guards: OptDummyGuardMgr<'_> = None; @@ -128,7 +129,7 @@ mod test { assert_same_path_when_owned(&p); if let crate::path::TorPathInner::FallbackOneHop(f) = p.inner { - assert!(std::ptr::eq(f, &fb[0]) || std::ptr::eq(f, &fb[1])); + assert!(std::ptr::eq(f, fb[0]) || std::ptr::eq(f, fb[1])); } else { panic!("Generated the wrong kind of path."); } diff --git a/crates/tor-dirmgr/src/bootstrap.rs b/crates/tor-dirmgr/src/bootstrap.rs index d266d3c1d8..4930a29a2c 100644 --- a/crates/tor-dirmgr/src/bootstrap.rs +++ b/crates/tor-dirmgr/src/bootstrap.rs @@ -59,9 +59,13 @@ async fn fetch_single<R: Runtime>( let circmgr = dirmgr.circmgr()?; let cur_netdir = dirmgr.opt_netdir(); let config = dirmgr.config.get(); + let fbs; let dirinfo = match cur_netdir { Some(ref netdir) => netdir.as_ref().into(), - None => config.fallbacks().into(), + None => { + fbs = config.fallbacks().iter().collect::<Vec<_>>(); + fbs[..].into() + } }; let resource = tor_dirclient::get_resource(request.as_requestable(), dirinfo, &dirmgr.runtime, circmgr) diff --git a/doc/semver_status.md b/doc/semver_status.md index 119dfbd6be..59bc6ecd59 100644 --- a/doc/semver_status.md +++ b/doc/semver_status.md @@ -49,6 +49,11 @@ arti-client: api-break: isolation completely revised +tor-circmgr: + + api-break: The fallbacks case of DirInfo now wants a slice of references to + fallbacks. + tor-dirmgr: new-api: DirMgrConfig object now has accessors. DirMgrCfg: totally changed, builder abolished. -- GitLab