use crate::Result;
use super::{
CongestionControlAlgorithm, CongestionSignals, CongestionWindow, State,
params::{Algorithm, FixedWindowParams},
rtt::RoundtripTimeEstimator,
sendme::{self, WindowParams},
};
#[derive(Clone, Debug)]
pub(crate) struct FixedWindow {
recvwindow: sendme::CircRecvWindow,
sendwindow: sendme::CircSendWindow,
params: FixedWindowParams,
}
impl FixedWindow {
pub(crate) fn new(params: FixedWindowParams) -> Self {
let initial_window = params.circ_window_start();
Self {
recvwindow: sendme::CircRecvWindow::new(sendme::CircParams::start()),
sendwindow: sendme::CircSendWindow::new(initial_window),
params,
}
}
}
impl CongestionControlAlgorithm for FixedWindow {
fn uses_stream_sendme(&self) -> bool {
true
}
fn uses_xon_xoff(&self) -> bool {
false
}
fn is_next_cell_sendme(&self) -> bool {
self.sendwindow.should_record_tag()
}
fn can_send(&self) -> bool {
self.sendwindow.window() > 0
}
fn cwnd(&self) -> Option<CongestionWindow> {
None
}
fn sendme_received(
&mut self,
_state: &mut State,
_rtt: &mut RoundtripTimeEstimator,
_signals: CongestionSignals,
) -> Result<()> {
self.sendwindow.put()
}
fn sendme_sent(&mut self) -> Result<()> {
self.recvwindow.put();
Ok(())
}
fn data_received(&mut self) -> Result<bool> {
self.recvwindow.take()
}
fn data_sent(&mut self) -> Result<()> {
self.sendwindow.take()
}
#[cfg(feature = "conflux")]
fn inflight(&self) -> Option<u32> {
None
}
#[cfg(test)]
fn send_window(&self) -> u32 {
u32::from(self.sendwindow.window())
}
fn algorithm(&self) -> Algorithm {
Algorithm::FixedWindow(self.params)
}
}