1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use async_trait;
/// Trait that implements a `validate` function that determines
/// what records can be set and stored on the [crate::dht::DHTNode].
/// Currently only validates "Value" records.
///
/// # Example
///
/// ```
/// use noosphere_ns::dht::Validator;
/// use async_trait::async_trait;
/// use tokio;
///
/// #[derive(Clone)]
/// struct MyValidator;
///
/// #[async_trait]
/// impl Validator for MyValidator {
/// // Ensures value is "hello" in bytes.
/// async fn validate(&mut self, data: &[u8]) -> bool {
/// data[..] == [104, 101, 108, 108, 111][..]
/// }
/// }
///
/// #[tokio::main(flavor = "multi_thread")]
/// async fn main() {
/// let mut validator = MyValidator {};
/// let data = String::from("hello").into_bytes();
/// let is_valid = validator.validate(&data).await;
/// assert!(is_valid);
/// }
/// An implementation of [Validator] that allows all records.
/// Used for tests.