pub struct NetworkFactory { /* private fields */ }Expand description
Factory for creating TCP listeners and outbound connections.
In production, use NetworkFactory::tokio() to get a factory that
delegates to real tokio networking. For simulation/testing, construct
via NetworkFactory::new() with custom closures that route through
in-memory channels.
Implementations§
Source§impl NetworkFactory
impl NetworkFactory
Sourcepub fn new(
bind_tcp: Box<dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = Result<Box<dyn TransportListener>>> + Send>> + Send + Sync>,
connect_tcp: Box<dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = Result<BoxedStream>> + Send>> + Send + Sync>,
is_simulated: bool,
) -> Self
pub fn new( bind_tcp: Box<dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = Result<Box<dyn TransportListener>>> + Send>> + Send + Sync>, connect_tcp: Box<dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = Result<BoxedStream>> + Send>> + Send + Sync>, is_simulated: bool, ) -> Self
Create a factory with custom bind/connect closures.
This is the primary constructor for simulation backends. The
resulting factory has no UDP bind installed; chain
Self::with_bind_udp to plumb a sim UDP transport into the
irontide-utp socket actor.
Sourcepub fn with_bind_udp(
self,
bind_udp: Box<dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = Result<Box<dyn UdpTransport>>> + Send>> + Send + Sync>,
) -> Self
pub fn with_bind_udp( self, bind_udp: Box<dyn Fn(SocketAddr) -> Pin<Box<dyn Future<Output = Result<Box<dyn UdpTransport>>> + Send>> + Send + Sync>, ) -> Self
Install a UDP bind closure on this factory.
Used by simulation backends to route uTP datagrams through the
in-memory packet bus. Production callers should leave this unset
— irontide-session::session falls back to UtpSocket::bind so
FD-level DSCP / TCLASS configuration stays in irontide-utp.
Sourcepub async fn bind_tcp(
&self,
addr: SocketAddr,
) -> Result<Box<dyn TransportListener>>
pub async fn bind_tcp( &self, addr: SocketAddr, ) -> Result<Box<dyn TransportListener>>
Bind a TCP listener on the given address.
§Errors
Returns an error if the connection or binding fails.
Sourcepub async fn connect_tcp(&self, addr: SocketAddr) -> Result<BoxedStream>
pub async fn connect_tcp(&self, addr: SocketAddr) -> Result<BoxedStream>
Open an outbound TCP connection to the given address.
§Errors
Returns an error if the connection or binding fails.
Sourcepub fn is_simulated(&self) -> bool
pub fn is_simulated(&self) -> bool
Returns true if this factory uses simulated networking.
Sourcepub fn has_bind_udp(&self) -> bool
pub fn has_bind_udp(&self) -> bool
Returns true if this factory has a UDP bind closure installed.
Stage U: callers branch on this to choose between the production
UtpSocket::bind path (DSCP / TCLASS aware) and the sim
UtpSocket::bind_with_transport path (in-memory packet bus).
Sourcepub async fn bind_udp(&self, addr: SocketAddr) -> Result<Box<dyn UdpTransport>>
pub async fn bind_udp(&self, addr: SocketAddr) -> Result<Box<dyn UdpTransport>>
Bind a UDP transport at the given address.
§Errors
Returns Unsupported if no UDP bind closure is installed
(the tokio factory’s default), otherwise the underlying
transport’s I/O error.