tor_proto/channel/kist.rs
1//! KIST-related parameters.
2
3/// A set of parameters derived from the consensus document,
4/// controlling the KIST behavior of channels.
5#[derive(Debug, Clone, Copy, PartialEq, amplify::Getters)]
6pub struct KistParams {
7 /// Whether KIST is enabled.
8 #[getter(as_copy)]
9 kist_enabled: KistMode,
10 /// The value to set for the [`TCP_NOTSENT_LOWAT`] socket option
11 /// (on platforms that support it)
12 /// if the `KistMode` is [`TcpNotSentLowat`](KistMode::TcpNotSentLowat).
13 ///
14 /// [`TCP_NOTSENT_LOWAT`]: https://lwn.net/Articles/560082/
15 #[getter(as_copy)]
16 tcp_notsent_lowat: u32,
17}
18
19impl KistParams {
20 /// Create a new `KistParams` from the given `KistMode` and options.
21 pub fn new(kist_enabled: KistMode, tcp_notsent_lowat: u32) -> Self {
22 Self {
23 kist_enabled,
24 tcp_notsent_lowat,
25 }
26 }
27}
28
29/// A set of parameters, derived from the consensus document,
30/// specifying the desired KIST behavior.
31#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd)]
32#[non_exhaustive]
33pub enum KistMode {
34 /// KIST using TCP_NOTSENT_LOWAT.
35 TcpNotSentLowat = 1,
36 /// KIST is disabled.
37 Disabled = 0,
38}