pub struct Conn { /* private fields */ }Expand description
Connection state shared across role-specific FSMs.
Implementations§
Source§impl Conn
impl Conn
Sourcepub fn new(transport: Box<dyn Transport>, role: ConnRole) -> Self
pub fn new(transport: Box<dyn Transport>, role: ConnRole) -> Self
Build a new connection wrapping transport and tagged with
role.
The connection starts with empty mbuf chains, no in-flight
messages, and the default consistency knobs (DcOne).
Role-specific drivers in this module set extra fields (the
dnode peer paths set same_dc, dyn_mode, etc.) before
invoking Conn::run.
§Examples
use dynomite::io::reactor::{ConnRole, TcpTransport};
use dynomite::net::Conn;
use tokio::net::TcpStream;
let s = TcpStream::connect("127.0.0.1:6379").await.unwrap();
let _ = Conn::new(Box::new(TcpTransport::new(s, ConnRole::Server)), ConnRole::Server);Sourcepub fn handle(&self) -> ConnHandle
pub fn handle(&self) -> ConnHandle
Stable connection handle.
Sourcepub fn peer_addr(&self) -> Option<SocketAddr>
pub fn peer_addr(&self) -> Option<SocketAddr>
Remote address, if the transport could surface one.
Sourcepub fn recv_chain(&self) -> &MbufQueue
pub fn recv_chain(&self) -> &MbufQueue
Borrow the recv mbuf chain.
Sourcepub fn recv_chain_mut(&mut self) -> &mut MbufQueue
pub fn recv_chain_mut(&mut self) -> &mut MbufQueue
Mutably borrow the recv mbuf chain.
Sourcepub fn send_chain(&self) -> &MbufQueue
pub fn send_chain(&self) -> &MbufQueue
Borrow the send mbuf chain.
Sourcepub fn send_chain_mut(&mut self) -> &mut MbufQueue
pub fn send_chain_mut(&mut self) -> &mut MbufQueue
Mutably borrow the send mbuf chain.
Sourcepub fn imsg_q_mut(&mut self) -> &mut MsgQueue
pub fn imsg_q_mut(&mut self) -> &mut MsgQueue
Mutably borrow the in-queue.
Sourcepub fn omsg_q_mut(&mut self) -> &mut MsgQueue
pub fn omsg_q_mut(&mut self) -> &mut MsgQueue
Mutably borrow the out-queue.
Sourcepub fn take_rmsg(&mut self) -> Option<Msg>
pub fn take_rmsg(&mut self) -> Option<Msg>
Take ownership of the partially-received message, leaving the slot empty.
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
True when the connection has finished (either side closed and all queued work drained).
Sourcepub fn read_consistency(&self) -> ConsistencyLevel
pub fn read_consistency(&self) -> ConsistencyLevel
Read consistency level applied to incoming reads on this connection.
Sourcepub fn write_consistency(&self) -> ConsistencyLevel
pub fn write_consistency(&self) -> ConsistencyLevel
Write consistency level applied to incoming writes on this connection.
Sourcepub fn set_read_consistency(&mut self, c: ConsistencyLevel)
pub fn set_read_consistency(&mut self, c: ConsistencyLevel)
Update the read consistency level.
Sourcepub fn set_write_consistency(&mut self, c: ConsistencyLevel)
pub fn set_write_consistency(&mut self, c: ConsistencyLevel)
Update the write consistency level.
Sourcepub fn set_same_dc(&mut self, on: bool)
pub fn set_same_dc(&mut self, on: bool)
Set the same-DC bit. The dnode-peer drivers update this after consulting the snitch.
Sourcepub fn dnode_secured(&self) -> bool
pub fn dnode_secured(&self) -> bool
True when the dnode handshake exchanged a per-connection AES key.
Sourcepub fn set_dnode_secured(&mut self, on: bool)
pub fn set_dnode_secured(&mut self, on: bool)
Mark the connection as secured (the handshake completed).
Sourcepub fn crypto_key_sent(&self) -> bool
pub fn crypto_key_sent(&self) -> bool
True when the local end has emitted the encrypted AES key.
Sourcepub fn set_crypto_key_sent(&mut self, on: bool)
pub fn set_crypto_key_sent(&mut self, on: bool)
Mark the AES key as sent.
Sourcepub fn aes_key(&self) -> Option<&[u8; 32]>
pub fn aes_key(&self) -> Option<&[u8; 32]>
Return the per-connection AES key, if one has been installed.
Sourcepub fn set_aes_key(&mut self, key: [u8; 32])
pub fn set_aes_key(&mut self, key: [u8; 32])
Install (or replace) the per-connection AES key.
Sourcepub fn outstanding(&self) -> &HashMap<MsgId, MsgId>
pub fn outstanding(&self) -> &HashMap<MsgId, MsgId>
Borrow the outstanding-msg map.
Sourcepub fn outstanding_mut(&mut self) -> &mut HashMap<MsgId, MsgId>
pub fn outstanding_mut(&mut self) -> &mut HashMap<MsgId, MsgId>
Mutably borrow the outstanding-msg map.
Sourcepub fn set_mbuf_pool(&mut self, pool: MbufPool)
pub fn set_mbuf_pool(&mut self, pool: MbufPool)
Replace the mbuf pool. Useful when the embedding application wants every connection to share a single pool.
Sourcepub fn take_transport(&mut self) -> Option<Box<dyn Transport>>
pub fn take_transport(&mut self) -> Option<Box<dyn Transport>>
Take ownership of the underlying transport, leaving the
connection in a half-closed state. Returns None if the
transport has already been moved out (typically by
Conn::run).
Sourcepub fn set_transport(&mut self, transport: Box<dyn Transport>)
pub fn set_transport(&mut self, transport: Box<dyn Transport>)
Reinstall a transport. Used by reconnect logic in
crate::net::ConnPool.
Sourcepub fn has_transport(&self) -> bool
pub fn has_transport(&self) -> bool
True when a transport is currently installed.
Sourcepub fn transport_mut(&mut self) -> Option<&mut Box<dyn Transport>>
pub fn transport_mut(&mut self) -> Option<&mut Box<dyn Transport>>
Mutably borrow the transport. Driver loops use this to drive
AsyncRead / AsyncWrite directly.
Sourcepub fn enqueue_in(&mut self, msg: Msg) -> Result<(), NetError>
pub fn enqueue_in(&mut self, msg: Msg) -> Result<(), NetError>
Enqueue a request onto the in-queue.
§Errors
Returns NetError::PoolExhausted when the queue is at
MAX_CONN_QUEUE_SIZE.
Sourcepub fn enqueue_out(&mut self, msg: Msg) -> Result<(), NetError>
pub fn enqueue_out(&mut self, msg: Msg) -> Result<(), NetError>
Enqueue a message onto the out-queue.
§Errors
Returns NetError::PoolExhausted when the queue is at
MAX_CONN_QUEUE_SIZE.
Sourcepub fn run(&mut self) -> Result<(), NetError>
pub fn run(&mut self) -> Result<(), NetError>
Idle no-op driver hook.
Stage 9 wires the PROXY / CLIENT / SERVER / DNODE_PEER_*
roles into dedicated drivers in the sibling modules. Calling
run on a Conn without first installing a driver does
nothing: the connection idles until Conn::close is
invoked. Real drivers (for example super::client::client_loop)
take a &mut Conn directly.
§Errors
Returns NetError::Closed when the transport has already
been moved out, e.g. by an earlier driver.
Sourcepub fn record_recv(&mut self, bytes: usize)
pub fn record_recv(&mut self, bytes: usize)
Bump the recv-bytes counter.
Sourcepub fn record_send(&mut self, bytes: usize)
pub fn record_send(&mut self, bytes: usize)
Bump the send-bytes counter.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Conn
impl !RefUnwindSafe for Conn
impl Send for Conn
impl !Sync for Conn
impl Unpin for Conn
impl UnsafeUnpin for Conn
impl !UnwindSafe for Conn
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.