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
48
49
50
51
52
53
54
55
56
57
58
59
60
|
//! Vanguard sets
use std::time::SystemTime;
use serde::{Deserialize, Serialize};
use tor_linkspec::RelayIds;
use tor_netdir::{NetDir, Relay};
use tor_relay_selection::RelayExclusion;
/// A vanguard relay.
//
// TODO HS-VANGUARDS: this is currently just a Relay newtype (if it doesn't grow any additional
// fields, we might want to consider removing it and using Relay instead).
#[derive(Clone, amplify::Getters)]
pub struct Vanguard<'a> {
/// The relay.
relay: Relay<'a>,
}
/// An identifier for a time-bound vanguard.
///
/// Each vanguard [`Layer`](crate::vanguards::Layer) consists of a [`VanguardSet`],
/// which contains multiple `TimeBoundVanguard`s.
///
/// A [`VanguardSet`]'s `TimeBoundVanguard`s are rotated
/// by [`VanguardMgr`](crate::vanguards::VanguardMgr) as soon as they expire.
/// If [Full](crate::vanguards::VanguardMode) vanguards are in use,
/// the `TimeBoundVanguard`s from all layers are persisted to disk.
#[derive(Debug, Clone, Serialize, Deserialize)] //
#[derive(Eq, PartialEq, Ord, PartialOrd, Hash)] //
pub(crate) struct TimeBoundVanguard {
/// The ID of this relay.
id: RelayIds,
/// When to stop using this relay as a vanguard.
expiration: SystemTime,
}
/// A set of vanguards, for use in a particular [`Layer`](crate::vanguards::Layer).
#[derive(Debug, Default, Clone, Serialize, Deserialize)] //
#[derive(Eq, PartialEq, Ord, PartialOrd, Hash)] //
#[allow(unused)] // TODO HS-VANGUARDS
pub(super) struct VanguardSet {
/// The time-bound vanguards of a given [`Layer`](crate::vanguards::Layer).
vanguards: Vec<TimeBoundVanguard>,
}
impl VanguardSet {
/// Pick a relay from this set.
///
/// See [`VanguardMgr::pick_relay`](crate::vanguards::VanguardMgr::select_vanguard)
/// for more information.
pub(super) fn pick_relay<'a>(
&self,
_netdir: &'a NetDir,
_neighbor_exclusion: &RelayExclusion<'a>,
) -> Option<Vanguard<'a>> {
todo!()
}
}
|