use std::mem;
use crate::node::dkg::KeyedSig;
use sn_interface::messaging::system::SectionAuth;
use sn_interface::network_knowledge::SectionAuthorityProvider;
use xor_name::Prefix;
type Entry = (SectionAuth<SectionAuthorityProvider>, KeyedSig);
pub(crate) struct SplitBarrier(Vec<Entry>);
impl SplitBarrier {
pub(crate) fn new() -> Self {
Self(Vec::new())
}
#[instrument(skip(self), level = "trace", name = "split barrier processing")]
pub(crate) fn process(
&mut self,
our_prefix: &Prefix,
section_auth: SectionAuth<SectionAuthorityProvider>,
keyed_sig: KeyedSig,
) -> Vec<Entry> {
if !section_auth.prefix().is_extension_of(our_prefix) {
return vec![(section_auth, keyed_sig)];
}
let (mut give, keep) =
mem::take(&mut self.0)
.into_iter()
.partition(|(cached_section_auth, _)| {
cached_section_auth.prefix() == section_auth.prefix().sibling()
});
self.0 = keep;
if give.is_empty() {
self.0.push((section_auth, keyed_sig));
vec![]
} else {
give.push((section_auth, keyed_sig));
give
}
}
}