diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-09-22 15:11:51 -0700 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-09-22 15:11:51 -0700 |
| commit | 19c0923a86dc50a7bfa38d0e70459dc7860ce92d (patch) | |
| tree | f9f78c06a3a13468a38e4cbf36ad28ef4af2de58 /controller/SqliteNetworkController.hpp | |
| parent | 6ce64c2557c8eba17c4a27f7c74ce4869070325c (diff) | |
| parent | ddf3d1f94932738d058aa57ce2fa11f3c9bde089 (diff) | |
| download | infinitytier-19c0923a86dc50a7bfa38d0e70459dc7860ce92d.tar.gz infinitytier-19c0923a86dc50a7bfa38d0e70459dc7860ce92d.zip | |
Merge branch 'adamierymenko-dev' into netcon
Diffstat (limited to 'controller/SqliteNetworkController.hpp')
| -rw-r--r-- | controller/SqliteNetworkController.hpp | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/controller/SqliteNetworkController.hpp b/controller/SqliteNetworkController.hpp index 23e16c4b..f0b61c40 100644 --- a/controller/SqliteNetworkController.hpp +++ b/controller/SqliteNetworkController.hpp @@ -40,6 +40,9 @@ #include "../node/NetworkController.hpp" #include "../node/Mutex.hpp" +// Number of in-memory last log entries to maintain per user +#define ZT_SQLITENETWORKCONTROLLER_IN_MEMORY_LOG_SIZE 32 + namespace ZeroTier { class SqliteNetworkController : public NetworkController @@ -104,7 +107,34 @@ private: std::string _dbPath; std::string _instanceId; - std::map< std::pair<Address,uint64_t>,uint64_t > _lastRequestTime; + // A circular buffer last log + struct _LLEntry + { + _LLEntry() + { + for(long i=0;i<ZT_SQLITENETWORKCONTROLLER_IN_MEMORY_LOG_SIZE;++i) + this->l[i].ts = 0; + this->lastRequestTime = 0; + this->totalRequests = 0; + } + + // Circular buffer of last log entries + struct { + uint64_t ts; // timestamp or 0 if circular buffer entry unused + char version[64]; + InetAddress fromAddr; + bool authorized; + } l[ZT_SQLITENETWORKCONTROLLER_IN_MEMORY_LOG_SIZE]; + + // Time of last request whether successful or not + uint64_t lastRequestTime; + + // Total requests by this address / network ID pair (also serves mod IN_MEMORY_LOG_SIZE as circular buffer ptr) + uint64_t totalRequests; + }; + + // Last log entries by address and network ID pair + std::map< std::pair<Address,uint64_t>,_LLEntry > _lastLog; sqlite3 *_db; @@ -151,9 +181,6 @@ private: sqlite3_stmt *_sIncrementMemberRevisionCounter; sqlite3_stmt *_sGetConfig; sqlite3_stmt *_sSetConfig; - sqlite3_stmt *_sPutLog; - sqlite3_stmt *_sGetMemberLog; - sqlite3_stmt *_sGetRecentMemberLog; Mutex _lock; }; |
