123456789101112131415161718192021222324252627282930313233 |
- #pragma once
- #include <string>
- #include <map>
- #include <set>
- #include <pthread.h>
- class BBS2chProxyKeyManager {
- private:
- std::map<std::string, std::string> _keys;
- std::map<std::string, double> _keyIssueTimes;
- std::set<std::string> _expiredKeys;
- pthread_mutex_t _mutex;
- std::string _lastKey;
- std::string _storagePath;
- static const std::string _emptyKey;
- public:
- BBS2chProxyKeyManager() {
- pthread_mutex_init(&_mutex, NULL);
- };
- ~BBS2chProxyKeyManager() {
- pthread_mutex_destroy(&_mutex);
- };
- const std::string& getKey();
- const std::string& getKey(const std::string &userAgent);
- void setKey(const std::string &key, const std::string &oldKey, const std::string &userAgent, int reason);
- bool isExpired(const std::string &key);
- double secondsToWaitBeforePosting(const std::string &key);
- void setStorage(const char *jsonPath);
- int loadKeys();
- private:
- bool saveKeys();
- };
|