#pragma once #include #include #include namespace license { namespace server { class LicenseManager { public: class KeyIdCache { struct CacheEntry { std::string key; size_t keyId; std::chrono::system_clock::time_point age; }; public: KeyIdCache(LicenseManager*); void cache_keys(const std::deque& /* keys */); std::string getKey(size_t keyId); size_t getKeyId(const std::string&); private: int insert_entry(int, std::string*, std::string*); LicenseManager* handle; threads::Mutex entry_lock; threads::Mutex entry_update_lock; std::deque entries; }; struct UserStatistics { std::chrono::system_clock::time_point timestamp; uint64_t clients_online; uint64_t web_clients_online; uint64_t bots_online; uint64_t queries_online; uint64_t servers_online; }; struct ExtendedUserStatistics : public UserStatistics{ std::string ip_address; }; struct GlobalUserStatistics : public UserStatistics { uint64_t instance_online; }; struct GlobalVersionsStatistic { std::chrono::system_clock::time_point timestamp; std::map versions; }; public: LicenseManager(sql::SqlManager* database); ~LicenseManager(); bool setup(std::string&); bool validLicenseKey(const std::string& /* key */); std::shared_ptr licenseInfo(const std::string&); std::map> listLicenses(int offset = 0, int limit = -1); bool registerLicense(const std::string& /* key */, const std::shared_ptr& /* info */, const std::string& /* issuer */); bool updateLicenseInfo(const std::string&, const std::shared_ptr&); bool deleteLicense(const std::string& /* key */, bool /* full */ = false); bool logRequest(const std::string& /* key */, const std::string& /* unique_id */, const std::string& /* ip */, const std::string& /* version */, int /* result */); bool logStatistic(const std::string& /* key */, const std::string& /* unique_id */, const std::string& /* ip */, const ts::proto::license::PropertyUpdateRequest&); //std::deque> list_statistics_user(const std::string& key, const std::chrono::system_clock::time_point& begin, const std::chrono::system_clock::time_point& end); std::deque> list_statistics_user(const std::chrono::system_clock::time_point& begin, const std::chrono::system_clock::time_point& end, const std::chrono::milliseconds& /* interval */); std::deque> list_statistics_version(const std::chrono::system_clock::time_point& begin, const std::chrono::system_clock::time_point& end, const std::chrono::milliseconds& /* interval */); inline sql::SqlManager* sql() { return this->database; } private: std::shared_ptr id_cache; sql::SqlManager* database; }; } }