From: Ian Jackson Date: Sat, 24 Jul 2021 16:27:27 +0000 (+0100) Subject: identify links before away from trait again? X-Git-Tag: hippotat/1.0.0~470 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=f3cd09cbc961d97a1c61a69d3e094816d70cdcc5;p=hippotat.git identify links before away from trait again? Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index b03e639..59556a9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -330,6 +330,136 @@ impl Aggregate { } } +#[derive(Debug)] +enum Which { + All, + These(T), +} + +struct MeansForEnd<'m,U,P> { + us_spec: Which<&'m U>, + peer: Which<&'m P>, +} + +trait InstancesForEnd: Eq { + type Peer: Ord + Eq + Hash + Debug; + fn section_means<'s>(&self, s: &'s SectionName) + -> MeansForEnd<'s, Self, Peer> +} + +impl InstanceForEnd for ServerName { + type Peer = ClientName; + fn section_means<'s>(&'_ self, s: &'s SectionName) + -> Option> { + use Which:*; + let (us_spec, peer) = match s { + SN::Link(l) => (These(l.server), These(l.client)), + SN::Server(server) => (These( server), All), + SN::Client(client) => (All, These( client)), + SN::Common => (All, All), + _ => return None, + }; + MeansForEnd { us_spec, peer } + } +} + +impl Aggregate { + fn instances_for(&self, us: N) -> Vec + where N: InstancesForEnd, + { + use Which::*; + let mut secrets = Which::These(BTreeSet::new()); + let mut putative_selves = BTreeSet::new(); + let mut putative_peers = BTreeSet::new(); + + let matching_means = |section: &SectionName| { + let means = us.section_means(section)?; + if match means.us_spec { + These(u) => if u == us, + All => true, + } { Some(means) } else { None } + }; + + for (section, vars) in &self.agg.sections { + + if let Some(means) = matching_means(section) { + + + if ! vars.has_key("secret") { continue } + + let tsecrets = match secrets { + These(ref mut s) => s, + All => break, + }; + + if let Some(means) = matching_means(section) { + match means.peer { + Which::These(ypeer) => tsecrets.insert(ypeer), + Which::All => secrets = Which::All, + } + } + + } + + let links = vec![]; + + for (section, vars) in &self.agg.sections { + + if let Some(means) = matching_means(section) { + + if match secrets { + All => true, + These(s) => s.contains(means.peer), + } { + + links.push( us. + + + match section { + SN::Link(LinkName { ref client, ref srver }) + if server == &server_name + => tclients.insert(client), + + SN::Client(ref client) + => tclients.insert(client), + + SN::Server(ref server) | SN::Common + => tclients. + + } + + + let has_secret = .iter().filter_map(|section, vars| { + + + + match section { + + SN:: + + + + let links = self.agg.sections.iter().filter_map(|section| match section { + + SN::Link(LinkName { ref client, .. }) | + SN::Client(ref client) => Some(client.clone()), + + SN::Server(_) | SN::ServerLimit(_) | + SN::GlobalLimit : SN::Common => None => None, + + }).filter(|client| { + + self.lookup_raw("secret", SKL::Ordinary).is_some() + + }).map(|client| { + + + + + | + } +} + struct ResolveContext<'c> { agg: &'c Aggregate, link: &'c LinkName, @@ -574,6 +704,9 @@ pub fn read() { ], }; + let server_name = self.establish_server_name() + .context("establish server name")?; + let ic = InstanceConfig::resolve_instance(&rctx) .context("resolve config xxx for")?;