Skip to main content

RelayState

Struct RelayState 

Source
pub struct RelayState {
    pub tunnels: DashMap<String, Arc<TunnelConnection>>,
    pub tunnels_per_ip: DashMap<String, usize>,
    pub config: RelayConfig,
    pub auth_rate_limiter: AuthRateLimiter,
    pub token_manager: Option<TokenManager>,
}
Expand description

Shared state for the relay server

Fields§

§tunnels: DashMap<String, Arc<TunnelConnection>>

Active tunnels indexed by tunnel_id

§tunnels_per_ip: DashMap<String, usize>

Tunnel count per IP address (for rate limiting)

§config: RelayConfig

Configuration

§auth_rate_limiter: AuthRateLimiter

Auth rate limiter (tracks failed attempts)

§token_manager: Option<TokenManager>

JWT token manager (optional, for JWT-based auth)

Implementations§

Source§

impl RelayState

Source

pub fn new(config: RelayConfig) -> Self

Create a new relay state with the given configuration

Source

pub fn validate_token(&self, token: Option<&str>) -> bool

Validate an authentication token (simple check, backward compatible)

Source

pub fn validate_auth(&self, ip: &str, token: Option<&str>) -> AuthResult

Validate authentication with rate limiting and detailed result

Source

pub fn generate_token( &self, subject: &str, tunnel_id: Option<String>, ) -> Option<String>

Generate a JWT token (if JWT is configured)

Source

pub fn revoke_token(&self, jti: &str)

Revoke a JWT token by its ID

Source

pub fn can_create_tunnel(&self, ip: &str) -> bool

Check if an IP can create more tunnels (rate limiting)

Source

pub fn register_tunnel(&self, tunnel: TunnelConnection) -> Arc<TunnelConnection>

Register a new tunnel

Source

pub fn remove_tunnel(&self, tunnel_id: &str) -> Option<Arc<TunnelConnection>>

Remove a tunnel by ID

Source

pub fn get_tunnel(&self, tunnel_id: &str) -> Option<Arc<TunnelConnection>>

Get a tunnel by ID

Source

pub fn tunnel_url(&self, tunnel_id: &str) -> String

Get the URL for a tunnel

Source

pub fn tunnel_count_for_ip(&self, ip: &str) -> usize

Get the number of active tunnels for an IP

Source

pub async fn is_tunnel_expired(&self, tunnel: &TunnelConnection) -> bool

Check if a tunnel has expired (by age or idle time)

Source

pub async fn cleanup_expired_tunnels(&self) -> usize

Clean up expired tunnels Returns the number of tunnels removed

Source

pub fn tunnel_count(&self) -> usize

Get total number of active tunnels

Auto Trait Implementations§

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<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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