mirror of
https://github.com/jmcorgan/fips.git
synced 2026-08-09 00:04:54 +00:00
transport: extract tcp connection-pool types into pool.rs
Moves the inline TcpConnection/ConnectingEntry structs, the Direction enum, and the ConnectionPool/ConnectingPool type aliases out of the 1147-line tcp/mod.rs into a dedicated pool.rs, matching the canonical per-transport layout. Struct fields are pub(crate) so mod.rs can still construct and read them across the module boundary. Pure relocation; no logic change.
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
//! No additional framing overhead — packets are written directly to the
|
||||
//! TCP stream and the receiver uses phase-dependent size computation.
|
||||
|
||||
mod pool;
|
||||
pub mod stats;
|
||||
|
||||
use super::resolve_socket_addr;
|
||||
@@ -31,6 +32,7 @@ use super::{
|
||||
};
|
||||
use crate::config::TcpConfig;
|
||||
use crate::transport::framing::read_fmp_packet;
|
||||
use pool::{ConnectingEntry, ConnectingPool, ConnectionPool, Direction, TcpConnection};
|
||||
use stats::TcpStats;
|
||||
|
||||
use futures::FutureExt;
|
||||
@@ -47,52 +49,6 @@ use tokio::task::JoinHandle;
|
||||
use tokio::time::Instant;
|
||||
use tracing::{debug, info, trace, warn};
|
||||
|
||||
// ============================================================================
|
||||
// Connection Pool
|
||||
// ============================================================================
|
||||
|
||||
/// Direction of a pooled connection, used to drive separate
|
||||
/// `pool_inbound` / `pool_outbound` accounting for the
|
||||
/// `max_inbound_connections` admission cap.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum Direction {
|
||||
/// Inbound — accepted by the listener.
|
||||
Inbound,
|
||||
/// Outbound — initiated by connect-on-send or background connect.
|
||||
Outbound,
|
||||
}
|
||||
|
||||
/// State for a single TCP connection to a peer.
|
||||
struct TcpConnection {
|
||||
/// Write half of the split stream.
|
||||
writer: Arc<Mutex<OwnedWriteHalf>>,
|
||||
/// Receive task for this connection.
|
||||
recv_task: JoinHandle<()>,
|
||||
/// MSS-derived MTU for this connection (used for dynamic MTU re-reading).
|
||||
#[allow(dead_code)]
|
||||
mtu: u16,
|
||||
/// When the connection was established.
|
||||
#[allow(dead_code)]
|
||||
established_at: Instant,
|
||||
/// Direction of the connection — drives pool-inbound/outbound accounting.
|
||||
direction: Direction,
|
||||
}
|
||||
|
||||
/// Shared connection pool.
|
||||
type ConnectionPool = Arc<Mutex<HashMap<TransportAddr, TcpConnection>>>;
|
||||
|
||||
/// A pending background connection attempt.
|
||||
///
|
||||
/// Holds the JoinHandle for a spawned TCP connect task. The task
|
||||
/// produces a configured `TcpStream` and MSS-derived MTU on success.
|
||||
struct ConnectingEntry {
|
||||
/// Background task performing TCP connect + socket configuration.
|
||||
task: JoinHandle<Result<(TcpStream, u16), TransportError>>,
|
||||
}
|
||||
|
||||
/// Map of addresses with background connection attempts in progress.
|
||||
type ConnectingPool = Arc<Mutex<HashMap<TransportAddr, ConnectingEntry>>>;
|
||||
|
||||
// ============================================================================
|
||||
// TCP Transport
|
||||
// ============================================================================
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//! TCP connection pool types.
|
||||
//!
|
||||
//! Holds the per-connection state and the pooled/connecting maps used by the
|
||||
//! TCP transport.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::net::tcp::OwnedWriteHalf;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio::time::Instant;
|
||||
|
||||
use crate::transport::{TransportAddr, TransportError};
|
||||
|
||||
/// Direction of a pooled connection, used to drive separate
|
||||
/// `pool_inbound` / `pool_outbound` accounting for the
|
||||
/// `max_inbound_connections` admission cap.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum Direction {
|
||||
/// Inbound — accepted by the listener.
|
||||
Inbound,
|
||||
/// Outbound — initiated by connect-on-send or background connect.
|
||||
Outbound,
|
||||
}
|
||||
|
||||
/// State for a single TCP connection to a peer.
|
||||
pub(crate) struct TcpConnection {
|
||||
/// Write half of the split stream.
|
||||
pub(crate) writer: Arc<Mutex<OwnedWriteHalf>>,
|
||||
/// Receive task for this connection.
|
||||
pub(crate) recv_task: JoinHandle<()>,
|
||||
/// MSS-derived MTU for this connection (used for dynamic MTU re-reading).
|
||||
#[allow(dead_code)]
|
||||
pub(crate) mtu: u16,
|
||||
/// When the connection was established.
|
||||
#[allow(dead_code)]
|
||||
pub(crate) established_at: Instant,
|
||||
/// Direction of the connection — drives pool-inbound/outbound accounting.
|
||||
pub(crate) direction: Direction,
|
||||
}
|
||||
|
||||
/// Shared connection pool.
|
||||
pub(crate) type ConnectionPool = Arc<Mutex<HashMap<TransportAddr, TcpConnection>>>;
|
||||
|
||||
/// A pending background connection attempt.
|
||||
///
|
||||
/// Holds the JoinHandle for a spawned TCP connect task. The task
|
||||
/// produces a configured `TcpStream` and MSS-derived MTU on success.
|
||||
pub(crate) struct ConnectingEntry {
|
||||
/// Background task performing TCP connect + socket configuration.
|
||||
pub(crate) task: JoinHandle<Result<(TcpStream, u16), TransportError>>,
|
||||
}
|
||||
|
||||
/// Map of addresses with background connection attempts in progress.
|
||||
pub(crate) type ConnectingPool = Arc<Mutex<HashMap<TransportAddr, ConnectingEntry>>>;
|
||||
Reference in New Issue
Block a user