pub struct ClientSession { /* private fields */ }Expand description
Represents an active client session
Implementations§
Source§impl ClientSession
impl ClientSession
Sourcepub fn new(
client_addr: ClientAddress,
buffer_pool: BufferPool,
auth_handler: Arc<AuthHandler>,
metrics: MetricsCollector,
) -> Self
pub fn new( client_addr: ClientAddress, buffer_pool: BufferPool, auth_handler: Arc<AuthHandler>, metrics: MetricsCollector, ) -> Self
Create a new client session for 1:1 backend mapping
Sourcepub fn new_with_router(
client_addr: ClientAddress,
buffer_pool: BufferPool,
router: Arc<BackendSelector>,
routing_mode: RoutingMode,
auth_handler: Arc<AuthHandler>,
metrics: MetricsCollector,
) -> Self
pub fn new_with_router( client_addr: ClientAddress, buffer_pool: BufferPool, router: Arc<BackendSelector>, routing_mode: RoutingMode, auth_handler: Arc<AuthHandler>, metrics: MetricsCollector, ) -> Self
Create a new client session with per-command routing
Each command will be routed to a potentially different backend server using round-robin load balancing.
Sourcepub fn builder(
client_addr: ClientAddress,
buffer_pool: BufferPool,
auth_handler: Arc<AuthHandler>,
metrics: MetricsCollector,
) -> ClientSessionBuilder
pub fn builder( client_addr: ClientAddress, buffer_pool: BufferPool, auth_handler: Arc<AuthHandler>, metrics: MetricsCollector, ) -> ClientSessionBuilder
Create a builder for constructing a client session
§Examples
use std::net::SocketAddr;
use std::sync::Arc;
use nntp_proxy::session::ClientSession;
use nntp_proxy::pool::BufferPool;
use nntp_proxy::types::BufferSize;
use nntp_proxy::auth::AuthHandler;
use nntp_proxy::metrics::MetricsCollector;
let addr: SocketAddr = "127.0.0.1:8080".parse().unwrap();
let buffer_pool = BufferPool::new(BufferSize::try_new(8192).unwrap(), 10);
let auth_handler = Arc::new(AuthHandler::new(None, None).unwrap());
let metrics = MetricsCollector::new(1);
let session = ClientSession::builder(addr.into(), buffer_pool, auth_handler, metrics)
.build();Sourcepub const fn is_per_command_routing(&self) -> bool
pub const fn is_per_command_routing(&self) -> bool
Check if this session is using per-command routing
Returns true if this session has a router available (regardless of current mode). This is slightly different from checking routing mode - a session can have a router but be in Stateful mode (e.g., after hybrid mode switches).
Sourcepub fn mode(&self) -> SessionMode
pub fn mode(&self) -> SessionMode
Get the current session mode
Source§impl ClientSession
impl ClientSession
Sourcepub async fn handle_per_command_routing(
&self,
client_stream: TcpStream,
) -> Result<TransferMetrics, SessionError>
pub async fn handle_per_command_routing( &self, client_stream: TcpStream, ) -> Result<TransferMetrics, SessionError>
Handle a client connection with per-command routing.
Each command is routed independently to potentially different backends.
§Errors
Returns an error if the router is unavailable, a client write fails, or switching into stateful mode fails.
Source§impl ClientSession
impl ClientSession
Sourcepub async fn handle_stateful_session(
&self,
client_stream: TcpStream,
backend_id: BackendId,
provider: &DeadpoolConnectionProvider,
server_name: &str,
) -> Result<TransferMetrics, SessionError>
pub async fn handle_stateful_session( &self, client_stream: TcpStream, backend_id: BackendId, provider: &DeadpoolConnectionProvider, server_name: &str, ) -> Result<TransferMetrics, SessionError>
Handle stateful session - acquire backend and proxy bidirectionally
§Errors
Returns an error if the proxy cannot acquire a backend connection, send an initial backend-unavailable response, or proxy bytes in either direction.
Auto Trait Implementations§
impl !Freeze for ClientSession
impl !RefUnwindSafe for ClientSession
impl !UnwindSafe for ClientSession
impl Send for ClientSession
impl Sync for ClientSession
impl Unpin for ClientSession
impl UnsafeUnpin for ClientSession
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> 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 more