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: RelayConfigConfiguration
auth_rate_limiter: AuthRateLimiterAuth rate limiter (tracks failed attempts)
token_manager: Option<TokenManager>JWT token manager (optional, for JWT-based auth)
Implementations§
Source§impl RelayState
impl RelayState
Sourcepub fn new(config: RelayConfig) -> Self
pub fn new(config: RelayConfig) -> Self
Create a new relay state with the given configuration
Sourcepub fn validate_token(&self, token: Option<&str>) -> bool
pub fn validate_token(&self, token: Option<&str>) -> bool
Validate an authentication token (simple check, backward compatible)
Sourcepub fn validate_auth(&self, ip: &str, token: Option<&str>) -> AuthResult
pub fn validate_auth(&self, ip: &str, token: Option<&str>) -> AuthResult
Validate authentication with rate limiting and detailed result
Sourcepub fn generate_token(
&self,
subject: &str,
tunnel_id: Option<String>,
) -> Option<String>
pub fn generate_token( &self, subject: &str, tunnel_id: Option<String>, ) -> Option<String>
Generate a JWT token (if JWT is configured)
Sourcepub fn revoke_token(&self, jti: &str)
pub fn revoke_token(&self, jti: &str)
Revoke a JWT token by its ID
Sourcepub fn can_create_tunnel(&self, ip: &str) -> bool
pub fn can_create_tunnel(&self, ip: &str) -> bool
Check if an IP can create more tunnels (rate limiting)
Sourcepub fn register_tunnel(&self, tunnel: TunnelConnection) -> Arc<TunnelConnection>
pub fn register_tunnel(&self, tunnel: TunnelConnection) -> Arc<TunnelConnection>
Register a new tunnel
Sourcepub fn remove_tunnel(&self, tunnel_id: &str) -> Option<Arc<TunnelConnection>>
pub fn remove_tunnel(&self, tunnel_id: &str) -> Option<Arc<TunnelConnection>>
Remove a tunnel by ID
Sourcepub fn get_tunnel(&self, tunnel_id: &str) -> Option<Arc<TunnelConnection>>
pub fn get_tunnel(&self, tunnel_id: &str) -> Option<Arc<TunnelConnection>>
Get a tunnel by ID
Sourcepub fn tunnel_url(&self, tunnel_id: &str) -> String
pub fn tunnel_url(&self, tunnel_id: &str) -> String
Get the URL for a tunnel
Sourcepub fn tunnel_count_for_ip(&self, ip: &str) -> usize
pub fn tunnel_count_for_ip(&self, ip: &str) -> usize
Get the number of active tunnels for an IP
Sourcepub async fn is_tunnel_expired(&self, tunnel: &TunnelConnection) -> bool
pub async fn is_tunnel_expired(&self, tunnel: &TunnelConnection) -> bool
Check if a tunnel has expired (by age or idle time)
Sourcepub async fn cleanup_expired_tunnels(&self) -> usize
pub async fn cleanup_expired_tunnels(&self) -> usize
Clean up expired tunnels Returns the number of tunnels removed
Sourcepub fn tunnel_count(&self) -> usize
pub fn tunnel_count(&self) -> usize
Get total number of active tunnels