Skip to content

Commit bd8245e

Browse files
committed
fix(tcp): make some types regading congestion control private
Signed-off-by: Yuuki Takano <ytakanoster@gmail.com>
1 parent f50d476 commit bd8245e

File tree

3 files changed

+26
-44
lines changed

3 files changed

+26
-44
lines changed

src/iface/interface/tcp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::*;
22

3-
use crate::socket::tcp::{congestion_controller::no_control::NoControl, Socket};
3+
use crate::socket::tcp::Socket;
44

55
impl InterfaceInner {
66
pub(crate) fn process_tcp<'frame>(
@@ -38,7 +38,7 @@ impl InterfaceInner {
3838
None
3939
} else {
4040
// The packet wasn't handled by a socket, send a TCP RST packet.
41-
let (ip, tcp) = tcp::Socket::<NoControl>::rst_reply(&ip_repr, &tcp_repr);
41+
let (ip, tcp) = tcp::Socket::rst_reply(&ip_repr, &tcp_repr);
4242
Some(Packet::new(ip, IpPayload::Tcp(tcp)))
4343
}
4444
}

src/socket/tcp.rs

+9-41
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use crate::wire::{
1717
TCP_HEADER_LEN,
1818
};
1919

20-
use self::congestion_controller::CongestionController;
20+
use self::congestion_controller::{ActiveCC, CongestionController};
2121

22-
pub mod congestion_controller;
22+
mod congestion_controller;
2323

2424
macro_rules! tcp_trace {
2525
($($arg:expr),*) => (net_log!(trace, $($arg),*));
@@ -156,7 +156,7 @@ const RTTE_MAX_RTO: u32 = 10000;
156156

157157
#[derive(Debug, Clone, Copy)]
158158
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
159-
pub struct RttEstimator {
159+
struct RttEstimator {
160160
// Using u32 instead of Duration to save space (Duration is i64)
161161
rtt: u32,
162162
deviation: u32,
@@ -178,14 +178,6 @@ impl Default for RttEstimator {
178178
}
179179

180180
impl RttEstimator {
181-
pub fn get_rtt(&self) -> u32 {
182-
self.rtt
183-
}
184-
185-
pub fn get_deviation(&self) -> u32 {
186-
self.deviation
187-
}
188-
189181
fn retransmission_timeout(&self) -> Duration {
190182
let margin = RTTE_MIN_MARGIN.max(self.deviation * 4);
191183
let ms = (self.rtt + margin).clamp(RTTE_MIN_RTO, RTTE_MAX_RTO);
@@ -402,23 +394,14 @@ impl Display for Tuple {
402394
}
403395
}
404396

405-
#[cfg(feature = "socket-tcp-cubic")]
406-
type DefaultCC = congestion_controller::cubic::Cubic;
407-
408-
#[cfg(feature = "socket-tcp-reno")]
409-
type DefaultCC = congestion_controller::reno::Reno;
410-
411-
#[cfg(not(any(feature = "socket-tcp-cubic", feature = "socket-tcp-reno")))]
412-
type DefaultCC = congestion_controller::no_control::NoControl;
413-
414397
/// A Transmission Control Protocol socket.
415398
///
416399
/// A TCP socket may passively listen for connections or actively connect to another endpoint.
417400
/// Note that, for listening sockets, there is no "backlog"; to be able to simultaneously
418401
/// accept several connections, as many sockets must be allocated, or any new connection
419402
/// attempts will be reset.
420403
#[derive(Debug)]
421-
pub struct Socket<'a, CC: CongestionController = DefaultCC> {
404+
pub struct Socket<'a> {
422405
state: State,
423406
timer: Timer,
424407
rtte: RttEstimator,
@@ -486,7 +469,7 @@ pub struct Socket<'a, CC: CongestionController = DefaultCC> {
486469
nagle: bool,
487470

488471
/// The congestion control algorithm.
489-
congestion_controller: CC,
472+
congestion_controller: ActiveCC,
490473

491474
#[cfg(feature = "async")]
492475
rx_waker: WakerRegistration,
@@ -496,22 +479,10 @@ pub struct Socket<'a, CC: CongestionController = DefaultCC> {
496479

497480
const DEFAULT_MSS: usize = 536;
498481

499-
impl<'a> Socket<'a, DefaultCC> {
500-
/// Create a socket using the given buffers with the default
501-
/// congestion controller
502-
pub fn new<T>(rx_buffer: T, tx_buffer: T) -> Socket<'a, DefaultCC>
503-
where
504-
T: Into<SocketBuffer<'a>>,
505-
{
506-
Socket::new_with_cc(rx_buffer, tx_buffer)
507-
}
508-
}
509-
510-
impl<'a, CC: CongestionController> Socket<'a, CC> {
482+
impl<'a> Socket<'a> {
511483
#[allow(unused_comparisons)] // small usize platforms always pass rx_capacity check
512484
/// Create a socket using the given buffers
513-
/// with the `CC` of a congestion controller.
514-
pub fn new_with_cc<T>(rx_buffer: T, tx_buffer: T) -> Socket<'a, CC>
485+
pub fn new<T>(rx_buffer: T, tx_buffer: T) -> Socket<'a>
515486
where
516487
T: Into<SocketBuffer<'a>>,
517488
{
@@ -558,7 +529,7 @@ impl<'a, CC: CongestionController> Socket<'a, CC> {
558529
ack_delay_timer: AckDelayTimer::Idle,
559530
challenge_ack_timer: Instant::from_secs(0),
560531
nagle: true,
561-
congestion_controller: CC::default(),
532+
congestion_controller: ActiveCC::default(),
562533

563534
#[cfg(feature = "async")]
564535
rx_waker: WakerRegistration::new(),
@@ -2436,7 +2407,7 @@ impl<'a, CC: CongestionController> Socket<'a, CC> {
24362407
}
24372408
}
24382409

2439-
impl<'a, CC: CongestionController> fmt::Write for Socket<'a, CC> {
2410+
impl<'a> fmt::Write for Socket<'a> {
24402411
fn write_str(&mut self, slice: &str) -> fmt::Result {
24412412
let slice = slice.as_bytes();
24422413
if self.send_slice(slice) == Ok(slice.len()) {
@@ -7365,8 +7336,5 @@ mod test {
73657336
r.sample(100);
73667337
assert_eq!(r.retransmission_timeout(), Duration::from_millis(rto));
73677338
}
7368-
7369-
r.get_deviation();
7370-
r.get_rtt();
73717339
}
73727340
}

src/socket/tcp/congestion_controller.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,24 @@ use crate::time::Instant;
22

33
use super::RttEstimator;
44

5+
#[cfg(feature = "socket-tcp-cubic")]
56
pub mod cubic;
6-
pub mod no_control;
7+
8+
#[cfg(feature = "socket-tcp-reno")]
79
pub mod reno;
810

11+
#[cfg(not(any(feature = "socket-tcp-cubic", feature = "socket-tcp-reno")))]
12+
pub mod no_control;
13+
14+
#[cfg(feature = "socket-tcp-cubic")]
15+
pub type ActiveCC = cubic::Cubic;
16+
17+
#[cfg(feature = "socket-tcp-reno")]
18+
pub type ActiveCC = reno::Reno;
19+
20+
#[cfg(not(any(feature = "socket-tcp-cubic", feature = "socket-tcp-reno")))]
21+
pub type ActiveCC = no_control::NoControl;
22+
923
pub trait CongestionController: Default {
1024
/// Returns the number of bytes that can be sent.
1125
fn window(&self) -> usize;

0 commit comments

Comments
 (0)