Commit d778a922 authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

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.
parent 451a53a5
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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)
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -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()
+3 −2
Original line number Diff line number Diff line
@@ -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.");
            }
+5 −1
Original line number Diff line number Diff line
@@ -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)
+5 −0
Original line number Diff line number Diff line
@@ -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.