fallback list: Move default list into tor-guardmgr

This is where the FallbackList type is.  We are going to want to
provide a builder too, which ought to impl Default.

This means that the default value for the type must be next to the
type.  In any case, it was anomalous that it wasn't.

This commit is pure code motion.
This commit is contained in:
Ian Jackson 2022-04-21 18:04:25 +01:00
parent 91a8bc0c11
commit 61425a96bd
5 changed files with 31 additions and 28 deletions

1
Cargo.lock generated
View File

@ -3456,6 +3456,7 @@ dependencies = [
name = "tor-guardmgr"
version = "0.2.0"
dependencies = [
"base64",
"derive_builder",
"derive_more",
"educe",

View File

@ -310,35 +310,9 @@ impl DownloadScheduleConfig {
}
}
/// Helpers for initializing the fallback list.
/// Compatibility alias, will go away in a moment
mod fallbacks {
use tor_guardmgr::fallback::{FallbackDir, FallbackList};
use tor_llcrypto::pk::{ed25519::Ed25519Identity, rsa::RsaIdentity};
/// Return a list of the default fallback directories shipped with
/// arti.
pub(crate) fn default_fallbacks() -> FallbackList {
/// Build a fallback directory; panic if input is bad.
fn fallback(rsa: &str, ed: &str, ports: &[&str]) -> FallbackDir {
let rsa = RsaIdentity::from_hex(rsa).expect("Bad hex in built-in fallback list");
let ed = base64::decode_config(ed, base64::STANDARD_NO_PAD)
.expect("Bad hex in built-in fallback list");
let ed =
Ed25519Identity::from_bytes(&ed).expect("Wrong length in built-in fallback list");
let mut bld = FallbackDir::builder();
bld.rsa_identity(rsa).ed_identity(ed);
ports
.iter()
.map(|s| s.parse().expect("Bad socket address in fallbacklist"))
.for_each(|p| {
bld.orport(p);
});
bld.build()
.expect("Unable to build default fallback directory!?")
}
include!("fallback_dirs.inc").into()
}
pub(crate) use tor_guardmgr::fallback::default_fallbacks;
}
#[cfg(test)]

View File

@ -29,6 +29,7 @@ tor-proto = { path = "../tor-proto", version = "0.2.0" }
tor-rtcompat = { path = "../tor-rtcompat", version = "0.2.0" }
tor-units = { path = "../tor-units", version = "0.2.0" }
base64 = "0.13.0"
derive_builder = "0.11"
derive_more = "0.99"
educe = "0.4.6"

View File

@ -88,6 +88,33 @@ impl FallbackDirBuilder {
}
}
/// Return a list of the default fallback directories shipped with
/// arti.
//
// TODO: this shouldn't be exposed in the public API; we will deal with that in a moment
pub fn default_fallbacks() -> FallbackList {
/// Build a fallback directory; panic if input is bad.
fn fallback(rsa: &str, ed: &str, ports: &[&str]) -> FallbackDir {
let rsa = RsaIdentity::from_hex(rsa).expect("Bad hex in built-in fallback list");
let ed = base64::decode_config(ed, base64::STANDARD_NO_PAD)
.expect("Bad hex in built-in fallback list");
let ed = Ed25519Identity::from_bytes(&ed).expect("Wrong length in built-in fallback list");
let mut bld = FallbackDir::builder();
bld.rsa_identity(rsa).ed_identity(ed);
ports
.iter()
.map(|s| s.parse().expect("Bad socket address in fallbacklist"))
.for_each(|p| {
bld.orport(p);
});
bld.build()
.expect("Unable to build default fallback directory!?")
}
include!("fallback_dirs.inc").into()
}
impl tor_linkspec::ChanTarget for FallbackDir {
fn addrs(&self) -> &[SocketAddr] {
&self.orports[..]