Skip to main content

Conn

Struct Conn 

Source
pub struct Conn { /* private fields */ }
Expand description

Connection state shared across role-specific FSMs.

Implementations§

Source§

impl Conn

Source

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);
Source

pub fn handle(&self) -> ConnHandle

Stable connection handle.

Source

pub fn role(&self) -> ConnRole

Connection role.

Source

pub fn peer_addr(&self) -> Option<SocketAddr>

Remote address, if the transport could surface one.

Source

pub fn stats(&self) -> &ConnStats

Borrow the rolling counters.

Source

pub fn recv_chain(&self) -> &MbufQueue

Borrow the recv mbuf chain.

Source

pub fn recv_chain_mut(&mut self) -> &mut MbufQueue

Mutably borrow the recv mbuf chain.

Source

pub fn send_chain(&self) -> &MbufQueue

Borrow the send mbuf chain.

Source

pub fn send_chain_mut(&mut self) -> &mut MbufQueue

Mutably borrow the send mbuf chain.

Source

pub fn imsg_q(&self) -> &MsgQueue

Borrow the in-queue.

Source

pub fn imsg_q_mut(&mut self) -> &mut MsgQueue

Mutably borrow the in-queue.

Source

pub fn omsg_q(&self) -> &MsgQueue

Borrow the out-queue.

Source

pub fn omsg_q_mut(&mut self) -> &mut MsgQueue

Mutably borrow the out-queue.

Source

pub fn rmsg(&self) -> Option<&Msg>

Borrow the partially-received message, if any.

Source

pub fn rmsg_mut(&mut self) -> Option<&mut Msg>

Mutably borrow the partially-received message.

Source

pub fn take_rmsg(&mut self) -> Option<Msg>

Take ownership of the partially-received message, leaving the slot empty.

Source

pub fn set_rmsg(&mut self, msg: Option<Msg>)

Install the partially-received message slot.

Source

pub fn smsg(&self) -> Option<&Msg>

Borrow the partially-sent message, if any.

Source

pub fn take_smsg(&mut self) -> Option<Msg>

Take the partially-sent message.

Source

pub fn set_smsg(&mut self, msg: Option<Msg>)

Install the partially-sent message slot.

Source

pub fn is_eof(&self) -> bool

True when the peer has closed its half of the connection.

Source

pub fn set_eof(&mut self)

Mark the peer half as closed.

Source

pub fn is_done(&self) -> bool

True when the connection has finished (either side closed and all queued work drained).

Source

pub fn set_done(&mut self)

Mark the connection as done.

Source

pub fn err(&self) -> Option<&str>

Last recorded error, if any.

Source

pub fn set_err<S: Into<String>>(&mut self, msg: S)

Record a transport-level error string.

Source

pub fn read_consistency(&self) -> ConsistencyLevel

Read consistency level applied to incoming reads on this connection.

Source

pub fn write_consistency(&self) -> ConsistencyLevel

Write consistency level applied to incoming writes on this connection.

Source

pub fn set_read_consistency(&mut self, c: ConsistencyLevel)

Update the read consistency level.

Source

pub fn set_write_consistency(&mut self, c: ConsistencyLevel)

Update the write consistency level.

Source

pub fn same_dc(&self) -> bool

True for peer connections inside the local datacenter.

Source

pub fn set_same_dc(&mut self, on: bool)

Set the same-DC bit. The dnode-peer drivers update this after consulting the snitch.

Source

pub fn dyn_mode(&self) -> bool

True when the connection participates in the dnode peer plane.

Source

pub fn dnode_secured(&self) -> bool

True when the dnode handshake exchanged a per-connection AES key.

Source

pub fn set_dnode_secured(&mut self, on: bool)

Mark the connection as secured (the handshake completed).

Source

pub fn crypto_key_sent(&self) -> bool

True when the local end has emitted the encrypted AES key.

Source

pub fn set_crypto_key_sent(&mut self, on: bool)

Mark the AES key as sent.

Source

pub fn aes_key(&self) -> Option<&[u8; 32]>

Return the per-connection AES key, if one has been installed.

Source

pub fn set_aes_key(&mut self, key: [u8; 32])

Install (or replace) the per-connection AES key.

Source

pub fn outstanding(&self) -> &HashMap<MsgId, MsgId>

Borrow the outstanding-msg map.

Source

pub fn outstanding_mut(&mut self) -> &mut HashMap<MsgId, MsgId>

Mutably borrow the outstanding-msg map.

Source

pub fn mbuf_pool(&self) -> &MbufPool

Borrow the pool used for fresh mbuf chunks.

Source

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.

Source

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).

Source

pub fn set_transport(&mut self, transport: Box<dyn Transport>)

Reinstall a transport. Used by reconnect logic in crate::net::ConnPool.

Source

pub fn has_transport(&self) -> bool

True when a transport is currently installed.

Source

pub fn transport_mut(&mut self) -> Option<&mut Box<dyn Transport>>

Mutably borrow the transport. Driver loops use this to drive AsyncRead / AsyncWrite directly.

Source

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.

Source

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.

Source

pub fn close(&mut self)

Drop the transport and mark the connection as done.

Source

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.

Source

pub fn record_recv(&mut self, bytes: usize)

Bump the recv-bytes counter.

Source

pub fn record_send(&mut self, bytes: usize)

Bump the send-bytes counter.

Trait Implementations§

Source§

impl Debug for Conn

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,