pub struct ServerHook<F> { /* private fields */ }Expand description
Server-side authentication connection hook that validates incoming client tokens.
When a client connects, this connection hook:
- Waits for the client to send an auth token
- Validates the token using the provided validator function
- Sends an ACK on success, or rejects the connection on failure
§Example
use msg_socket::hooks::token::ServerHook;
// Accept all tokens
let hook = ServerHook::accept_all();
// Custom validation
let hook = ServerHook::new(|token| **token == *b"my_secret_token");Implementations§
Source§impl ServerHook<fn(&Bytes) -> bool>
impl ServerHook<fn(&Bytes) -> bool>
Sourcepub fn accept_all() -> Self
pub fn accept_all() -> Self
Creates a server hook that accepts all tokens.
Trait Implementations§
Source§impl<Io, F> ConnectionHook<Io> for ServerHook<F>
impl<Io, F> ConnectionHook<Io> for ServerHook<F>
Source§type Error = ServerHookError
type Error = ServerHookError
The hook-specific error type.
Source§async fn on_connection(&self, io: Io) -> HookResult<Io, Self::Error>
async fn on_connection(&self, io: Io) -> HookResult<Io, Self::Error>
Called when a connection is established. Read more
Auto Trait Implementations§
impl<F> Freeze for ServerHook<F>where
F: Freeze,
impl<F> RefUnwindSafe for ServerHook<F>where
F: RefUnwindSafe,
impl<F> Send for ServerHook<F>where
F: Send,
impl<F> Sync for ServerHook<F>where
F: Sync,
impl<F> Unpin for ServerHook<F>where
F: Unpin,
impl<F> UnsafeUnpin for ServerHook<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for ServerHook<F>where
F: UnwindSafe,
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
Mutably borrows from an owned value. Read more