Commit 72eaa9fc authored by Ian Jackson's avatar Ian Jackson
Browse files

DirMgrConfig: Remove unnecessary accessors

These fields are pub.

Retain two convenience accessor functions that access sub-fields of
network.
parent 20d61dd4
Loading
Loading
Loading
Loading
+3 −19
Original line number Diff line number Diff line
@@ -8,10 +8,10 @@
//! The types in this module are re-exported from `arti-client`: any changes
//! here must be reflected in the version of `arti-client`.

use crate::authority::AuthorityList;
use crate::authority::{Authority, AuthorityList};
use crate::retry::{DownloadSchedule, DownloadScheduleBuilder};
use crate::storage::DynStore;
use crate::{Authority, AuthorityListBuilder, Result};
use crate::{AuthorityListBuilder, Result};
use tor_config::ConfigBuildError;
use tor_guardmgr::fallback::FallbackListBuilder;
use tor_netdoc::doc::netstatus;
@@ -226,11 +226,6 @@ impl DirMgrConfig {
        )?))
    }

    /// Return the configured cache path.
    pub fn cache_path(&self) -> &std::path::Path {
        self.cache_path.as_ref()
    }

    /// Return a slice of the configured authorities
    pub fn authorities(&self) -> &[Authority] {
        &self.network.authorities
@@ -241,17 +236,6 @@ impl DirMgrConfig {
        &self.network.fallbacks
    }

    /// Return set of configured networkstatus parameter overrides.
    pub fn override_net_params(&self) -> &netstatus::NetParams<i32> {
        &self.override_net_params
    }

    /// Return the schedule configuration we should use to decide when to
    /// attempt and retry downloads.
    pub fn schedule(&self) -> &DownloadScheduleConfig {
        &self.schedule
    }

    /// Construct a new configuration object where all replaceable fields in
    /// `self` are replaced with those from  `new_config`.
    ///
@@ -393,7 +377,7 @@ mod test {
        bld.override_net_params.set("circwindow".into(), 999);
        bld.cache_path = tmp.path().into();

        assert_eq!(bld.override_net_params().get("circwindow").unwrap(), &999);
        assert_eq!(bld.override_net_params.get("circwindow").unwrap(), &999);

        Ok(())
    }
+4 −4
Original line number Diff line number Diff line
@@ -534,7 +534,7 @@ impl<R: Runtime> DirMgr<R> {
                // TODO(nickm): instead of getting this every time we loop, it
                // might be a good idea to refresh it with each attempt, at
                // least at the point of checking the number of attempts.
                dirmgr.config.get().schedule().retry_bootstrap
                dirmgr.config.get().schedule.retry_bootstrap
            };
            let mut retry_delay = retry_config.schedule();

@@ -607,7 +607,7 @@ impl<R: Runtime> DirMgr<R> {
        // We don't support changing these: doing so basically would require us
        // to abort all our in-progress downloads, since they might be based on
        // no-longer-viable information.
        if new_config.cache_path() != config.cache_path() {
        if new_config.cache_path != config.cache_path {
            how.cannot_change("storage.cache_path")?;
        }
        if new_config.authorities() != config.authorities() {
@@ -618,14 +618,14 @@ impl<R: Runtime> DirMgr<R> {
            return Ok(());
        }

        let params_changed = new_config.override_net_params() != config.override_net_params();
        let params_changed = new_config.override_net_params != config.override_net_params;

        self.config
            .map_and_replace(|cfg| cfg.update_from_config(new_config));

        if params_changed {
            let _ignore_err = self.netdir.mutate(|netdir| {
                netdir.replace_overridden_parameters(new_config.override_net_params());
                netdir.replace_overridden_parameters(&new_config.override_net_params);
                Ok(())
            });
            // (It's okay to ignore the error, since it just means that there
+5 −5
Original line number Diff line number Diff line
@@ -217,7 +217,7 @@ impl<DM: WriteNetDir> DirState for GetConsensusState<DM> {
    }
    fn dl_config(&self) -> Result<DownloadSchedule> {
        if let Some(wd) = Weak::upgrade(&self.writedir) {
            Ok(wd.config().schedule().retry_consensus)
            Ok(wd.config().schedule.retry_consensus)
        } else {
            Err(Error::ManagerDropped)
        }
@@ -398,7 +398,7 @@ impl<DM: WriteNetDir> DirState for GetCertsState<DM> {
    }
    fn dl_config(&self) -> Result<DownloadSchedule> {
        if let Some(wd) = Weak::upgrade(&self.writedir) {
            Ok(wd.config().schedule().retry_certs)
            Ok(wd.config().schedule.retry_certs)
        } else {
            Err(Error::ManagerDropped)
        }
@@ -627,7 +627,7 @@ impl<DM: WriteNetDir> GetMicrodescsState<DM> {
        let partial_dir = match Weak::upgrade(&writedir) {
            Some(wd) => {
                let config = wd.config();
                let params = config.override_net_params();
                let params = &config.override_net_params;
                let mut dir = PartialNetDir::new(consensus, Some(params));
                if let Some(old_dir) = wd.netdir().get() {
                    dir.fill_from_previous_netdir(&old_dir);
@@ -696,7 +696,7 @@ impl<DM: WriteNetDir> GetMicrodescsState<DM> {
                        self.reset_time = pick_download_time(netdir.lifetime());
                        // We re-set the parameters here, in case they have been
                        // reconfigured.
                        netdir.replace_overridden_parameters(wd.config().override_net_params());
                        netdir.replace_overridden_parameters(&wd.config().override_net_params);
                        wd.netdir().replace(netdir);
                        wd.netdir_consensus_changed();
                        wd.netdir_descriptors_changed();
@@ -791,7 +791,7 @@ impl<DM: WriteNetDir> DirState for GetMicrodescsState<DM> {
    }
    fn dl_config(&self) -> Result<DownloadSchedule> {
        if let Some(wd) = Weak::upgrade(&self.writedir) {
            Ok(wd.config().schedule().retry_microdescs)
            Ok(wd.config().schedule.retry_microdescs)
        } else {
            Err(Error::ManagerDropped)
        }