tor_dirmgr/filter.rs
1//! A filtering mechanism for directory objects.
2//!
3//! This module and its members are only available when `tor-dirmgr` is built
4//! with the `dirfilter` feature.
5//!
6//! This is unstable code, currently used for testing only. It might go away in
7//! future versions, or its API might change completely. There are no semver
8//! guarantees.
9
10use std::fmt::Debug;
11use std::sync::Arc;
12
13use crate::Result;
14use tor_netdoc::doc::{microdesc::Microdesc, netstatus::UncheckedMdConsensus};
15
16/// Filtering configuration, as provided to the directory code
17pub type FilterConfig = Option<Arc<dyn DirFilter>>;
18
19/// An object that can filter directory documents before they're handled.
20///
21/// Instances of DirFilter can be used for testing, to modify directory data
22/// on-the-fly.
23pub trait DirFilter: Debug + Send + Sync {
24 /// Modify `consensus` in an unspecified way.
25 fn filter_consensus(&self, consensus: UncheckedMdConsensus) -> Result<UncheckedMdConsensus> {
26 Ok(consensus)
27 }
28 /// Modify `md` in an unspecified way.
29 fn filter_md(&self, md: Microdesc) -> Result<Microdesc> {
30 Ok(md)
31 }
32}
33
34/// A [`DirFilter`] that does nothing.
35#[derive(Debug)]
36#[allow(clippy::exhaustive_structs)]
37pub struct NilFilter;
38
39impl DirFilter for NilFilter {}