tor_proto/congestion/
fixed.rs1use crate::Result;
8
9use super::{
10 CongestionControlAlgorithm, CongestionSignals, CongestionWindow, State,
11 params::{Algorithm, FixedWindowParams},
12 rtt::{ClockStall, RoundtripTimeEstimator},
13 sendme::{self, WindowParams},
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 _clock_stall: ClockStall,
69 ) -> Result<()> {
70 self.sendwindow.put()
71 }
72
73 fn sendme_sent(&mut self) -> Result<()> {
74 self.recvwindow.put();
75 Ok(())
76 }
77
78 fn data_received(&mut self) -> Result<bool> {
79 self.recvwindow.take()
80 }
81
82 fn data_sent(&mut self) -> Result<()> {
83 self.sendwindow.take()
84 }
85
86 #[cfg(feature = "conflux")]
87 fn inflight(&self) -> Option<u32> {
88 None
89 }
90
91 #[cfg(test)]
92 fn send_window(&self) -> u32 {
93 u32::from(self.sendwindow.window())
94 }
95
96 fn algorithm(&self) -> Algorithm {
97 Algorithm::FixedWindow(self.params)
98 }
99}