tor_proto/congestion/
fixed.rs
1use crate::Result;
8
9use super::{
10 params::{Algorithm, FixedWindowParams},
11 rtt::RoundtripTimeEstimator,
12 sendme::{self, WindowParams},
13 CongestionControlAlgorithm, CongestionSignals, CongestionWindow, State,
14};
15
16#[derive(Clone, Debug)]
19pub(crate) struct FixedWindow {
20 recvwindow: sendme::CircRecvWindow,
22 sendwindow: sendme::CircSendWindow,
24 params: FixedWindowParams,
26}
27
28impl FixedWindow {
29 pub(crate) fn new(params: FixedWindowParams) -> Self {
33 let initial_window = params.circ_window_start();
34 Self {
35 recvwindow: sendme::CircRecvWindow::new(sendme::CircParams::start()),
36 sendwindow: sendme::CircSendWindow::new(initial_window),
37 params,
38 }
39 }
40}
41
42impl CongestionControlAlgorithm for FixedWindow {
43 fn uses_stream_sendme(&self) -> bool {
44 true
45 }
46
47 fn uses_xon_xoff(&self) -> bool {
48 false
49 }
50
51 fn is_next_cell_sendme(&self) -> bool {
52 self.sendwindow.should_record_tag()
53 }
54
55 fn can_send(&self) -> bool {
56 self.sendwindow.window() > 0
57 }
58
59 fn cwnd(&self) -> Option<&CongestionWindow> {
60 None
61 }
62
63 fn sendme_received(
64 &mut self,
65 _state: &mut State,
66 _rtt: &mut RoundtripTimeEstimator,
67 _signals: CongestionSignals,
68 ) -> Result<()> {
69 self.sendwindow.put()
70 }
71
72 fn sendme_sent(&mut self) -> Result<()> {
73 self.recvwindow.put();
74 Ok(())
75 }
76
77 fn data_received(&mut self) -> Result<bool> {
78 self.recvwindow.take()
79 }
80
81 fn data_sent(&mut self) -> Result<()> {
82 self.sendwindow.take()
83 }
84
85 #[cfg(feature = "conflux")]
86 fn inflight(&self) -> Option<u32> {
87 None
88 }
89
90 #[cfg(test)]
91 fn send_window(&self) -> u32 {
92 u32::from(self.sendwindow.window())
93 }
94
95 fn algorithm(&self) -> Algorithm {
96 Algorithm::FixedWindow(self.params)
97 }
98}