Use a builder pattern for NetDir.

This commit is contained in:
Nick Mathewson 2020-11-20 09:02:11 -05:00
parent ff821d3f31
commit 4721e95c06
2 changed files with 5 additions and 9 deletions

View File

@ -112,7 +112,7 @@ fn get_netdir(args: &Args) -> Result<tor_netdir::NetDir> {
eprintln!("Can't specify both --tor-dir and --chutney-dir");
return Err(anyhow!("Conflicting --tor-dir and --chutney-dir"));
}
let mut cfg = tor_netdir::NetDirConfig::new();
let mut cfg = tor_netdir::NetDirConfigBuilder::new();
if let Some(ref d) = args.tor_dir {
cfg.add_default_authorities();
@ -125,6 +125,7 @@ fn get_netdir(args: &Args) -> Result<tor_netdir::NetDir> {
eprintln!("Must specify --tor-dir or --chutney-dir");
return Err(anyhow!("Missing --tor-dir or --chutney-dir"));
}
let cfg = cfg.finalize();
let partial = cfg.load().context("Loading directory from disk")?;
Ok(partial.unwrap_if_sufficient().unwrap())
@ -268,8 +269,9 @@ fn main() -> Result<()> {
let store = tor_netdir::storage::sqlite::SqliteStore::from_path("/home/nickm/.arti")?;
let store = tor_dirmgr::DirStoreHandle::new(store);
let circmgr = Arc::new(circmgr);
let mut cfg = tor_netdir::NetDirConfig::new();
let mut cfg = tor_netdir::NetDirConfigBuilder::new();
cfg.add_default_authorities();
let cfg = cfg.finalize();
let authorities = cfg.into_authorities();
let outcome = tor_dirmgr::bootstrap_directory(

View File

@ -40,7 +40,7 @@ pub use err::Error;
pub type Result<T> = std::result::Result<T, Error>;
pub use authority::Authority;
pub use config::NetDirConfig;
pub use config::{NetDirConfig, NetDirConfigBuilder};
/// Internal: how should we find the base weight of each relay? This
/// value is global over a whole directory, and depends on the bandwidth
@ -140,12 +140,6 @@ pub trait MDReceiver {
fn add_microdesc(&mut self, md: Microdesc) -> bool;
}
impl Default for NetDirConfig {
fn default() -> Self {
NetDirConfig::new()
}
}
impl PartialNetDir {
/// Create a new PartialNetDir with a given consensus, and no
/// microdecriptors loaded.