#pragma once #include #include #include #include #include #include namespace Echoion::Core { // Session management for RPC clients // Supports 100+ concurrent authenticated sessions class SessionManager { public: struct Session { uint64_t clientId; std::string authToken; std::chrono::steady_clock::time_point lastActivity; std::chrono::steady_clock::time_point createdAt; bool isAuthenticated; // Optional: store client-specific state struct ClientState { std::optional currentPlaylist; float preferredVolume = -1.0f; // -1 = use default // Add more client preferences here }; std::optional clientState; }; struct Config { size_t maxSessions = 150; // 100 users + buffer std::chrono::seconds sessionTimeout{3600}; // 1 hour timeout std::chrono::seconds cleanupInterval{ 300}; // Cleanup every 5 min }; SessionManager(); explicit SessionManager(const Config& config); // Initialize session manager bool initialize(); void shutdown(); // Create new session std::string createSession(uint64_t clientId); // Authenticate session bool authenticateSession(const std::string& token); // Validate and update session bool validateSession(const std::string& token); void updateActivity(const std::string& token); // Get session info std::optional getSession(const std::string& token) const; // End session void endSession(const std::string& token); void endSessionByClientId(uint64_t clientId); // Get all active sessions std::vector getAllSessions() const; // Get session count size_t getSessionCount() const; // Cleanup expired sessions (call periodically) size_t cleanupExpiredSessions(); // Check if at capacity bool isAtCapacity() const; private: std::string generateToken(); Config config_; std::unordered_map sessions_; mutable std::mutex mutex_; std::atomic running_{false}; }; } // namespace Echoion::Core