X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/479b8853c2ab18c98926a9369a03888021e9b986..c59911ca3cd38cf4ab36d2cc62686f97395899f9:/projects/stargazer/traffcounter_impl.cpp diff --git a/projects/stargazer/traffcounter_impl.cpp b/projects/stargazer/traffcounter_impl.cpp index 9b0fd966..ed0f93d5 100644 --- a/projects/stargazer/traffcounter_impl.cpp +++ b/projects/stargazer/traffcounter_impl.cpp @@ -45,11 +45,18 @@ #include "traffcounter_impl.h" #include "stg_timer.h" #include "users_impl.h" +#include "async_pool.h" #define FLUSH_TIME (10) #define REMOVE_TIME (31) using STG::TraffCounterImpl; +using STG::TRF_IP_BEFORE; +using STG::TRF_IP_AFTER; +using STG::ADD_USER_NONIFIER; +using STG::DEL_USER_NONIFIER; + +namespace AsyncPoolST = STG::AsyncPoolST; const char protoName[PROTOMAX][8] = {"TCP", "UDP", "ICMP", "TCP_UDP", "ALL"}; @@ -106,7 +113,7 @@ while (users->SearchNext(h, &u) == 0) SetUserNotifiers(u); users->CloseSearch(h); -m_thread = std::jthread([this](auto token){ Run(token); }); +m_thread = std::jthread([this](auto token){ Run(std::move(token)); }); return 0; } //----------------------------------------------------------------------------- @@ -843,3 +850,32 @@ monitorDir = dir; monitoring = !monitorDir.empty(); } //----------------------------------------------------------------------------- +void TRF_IP_BEFORE::notify(const uint32_t & oldValue, const uint32_t &) +{ +// User changes his address. Remove old IP +if (!oldValue) + return; + +AsyncPoolST::enqueue([this, oldValue](){ traffCnt.DelUser(oldValue); }); +} +//----------------------------------------------------------------------------- +void TRF_IP_AFTER::notify(const uint32_t &, const uint32_t & newValue) +{ +// User changes his address. Add new IP +if (!newValue) + return; + +AsyncPoolST::enqueue([this](){ traffCnt.AddUser(user); }); +} +//----------------------------------------------------------------------------- +void ADD_USER_NONIFIER::notify(const UserImplPtr & user) +{ +AsyncPoolST::enqueue([this, user](){ traffCnt.SetUserNotifiers(user); }); +} +//----------------------------------------------------------------------------- +void DEL_USER_NONIFIER::notify(const UserImplPtr & user) +{ +AsyncPoolST::enqueue([this, user](){ traffCnt.UnSetUserNotifiers(user); }); +AsyncPoolST::enqueue([this, user](){ traffCnt.DelUser(user->GetCurrIP()); }); +} +//-----------------------------------------------------------------------------