X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/cb062b7ca4e03597c0b25c5a2b6cbc554900fff6..a84a49ca1eb7c31f79f6328e9dc453399ee120f9:/projects/stargazer/traffcounter_impl.h diff --git a/projects/stargazer/traffcounter_impl.h b/projects/stargazer/traffcounter_impl.h index 7d01c2e4..a1dfa743 100644 --- a/projects/stargazer/traffcounter_impl.h +++ b/projects/stargazer/traffcounter_impl.h @@ -28,13 +28,6 @@ #ifndef TRAFFCOUNTER_IMPL_H #define TRAFFCOUNTER_IMPL_H -#include - -#include -#include -#include -#include - #include "stg/traffcounter.h" #include "stg/os_int.h" #include "stg/logger.h" @@ -45,6 +38,13 @@ #include "eventloop.h" #include "user_impl.h" +#include +#include +#include +#include + +#include + #define PROTOMAX (5) class USERS_IMPL; @@ -102,56 +102,78 @@ class TRAFFCOUNTER_IMPL; //----------------------------------------------------------------------------- class TRF_IP_BEFORE: public PROPERTY_NOTIFIER_BASE { public: - TRF_IP_BEFORE(TRAFFCOUNTER_IMPL & t, USER_IMPL * u) - : PROPERTY_NOTIFIER_BASE(), - traffCnt(t), - user(u) - {} - void Notify(const uint32_t & oldValue, const uint32_t & newValue); - void SetUser(USER_IMPL * u) { user = u; } - USER_IMPL * GetUser() const { return user; } + TRF_IP_BEFORE(TRAFFCOUNTER_IMPL & t, USER_IMPL * u) + : PROPERTY_NOTIFIER_BASE(), + traffCnt(t), + user(u) + {} + TRF_IP_BEFORE(const TRF_IP_BEFORE & rvalue) + : PROPERTY_NOTIFIER_BASE(), + traffCnt(rvalue.traffCnt), + user(rvalue.user) + {} + void Notify(const uint32_t & oldValue, const uint32_t & newValue); + void SetUser(USER_IMPL * u) { user = u; } + USER_IMPL * GetUser() const { return user; } private: + TRF_IP_BEFORE & operator=(const TRF_IP_BEFORE & rvalue); + TRAFFCOUNTER_IMPL & traffCnt; - USER_IMPL * user; + USER_IMPL * user; }; //----------------------------------------------------------------------------- class TRF_IP_AFTER: public PROPERTY_NOTIFIER_BASE { public: - TRF_IP_AFTER(TRAFFCOUNTER_IMPL & t, USER_IMPL * u) - : PROPERTY_NOTIFIER_BASE(), - traffCnt(t), - user(u) - {} - void Notify(const uint32_t & oldValue, const uint32_t & newValue); - void SetUser(USER_IMPL * u) { user = u; } - USER_IMPL * GetUser() const { return user; } + TRF_IP_AFTER(TRAFFCOUNTER_IMPL & t, USER_IMPL * u) + : PROPERTY_NOTIFIER_BASE(), + traffCnt(t), + user(u) + {} + TRF_IP_AFTER(const TRF_IP_AFTER & rvalue) + : PROPERTY_NOTIFIER_BASE(), + traffCnt(rvalue.traffCnt), + user(rvalue.user) + {} + void Notify(const uint32_t & oldValue, const uint32_t & newValue); + void SetUser(USER_IMPL * u) { user = u; } + USER_IMPL * GetUser() const { return user; } private: + TRF_IP_AFTER & operator=(const TRF_IP_AFTER & rvalue); + TRAFFCOUNTER_IMPL & traffCnt; - USER_IMPL * user; + USER_IMPL * user; }; //----------------------------------------------------------------------------- class ADD_USER_NONIFIER: public NOTIFIER_BASE { public: - ADD_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) : + explicit ADD_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) : NOTIFIER_BASE(), traffCnt(t) {} virtual ~ADD_USER_NONIFIER() {} void Notify(const USER_IMPL_PTR & user); + private: + ADD_USER_NONIFIER(const ADD_USER_NONIFIER & rvalue); + ADD_USER_NONIFIER & operator=(const ADD_USER_NONIFIER & rvalue); + TRAFFCOUNTER_IMPL & traffCnt; }; //----------------------------------------------------------------------------- class DEL_USER_NONIFIER: public NOTIFIER_BASE { public: - DEL_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) : + explicit DEL_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) : NOTIFIER_BASE(), traffCnt(t) {} virtual ~DEL_USER_NONIFIER() {} void Notify(const USER_IMPL_PTR & user); + private: + DEL_USER_NONIFIER(const DEL_USER_NONIFIER & rvalue); + DEL_USER_NONIFIER & operator=(const DEL_USER_NONIFIER & rvalue); + TRAFFCOUNTER_IMPL & traffCnt; }; //----------------------------------------------------------------------------- @@ -164,8 +186,6 @@ public: TRAFFCOUNTER_IMPL(USERS_IMPL * users, const std::string & rulesFileName); ~TRAFFCOUNTER_IMPL(); - void SetRulesFile(const std::string & rulesFileName); - int Reload(); int Start(); int Stop(); @@ -173,11 +193,15 @@ public: void Process(const RAW_PACKET & rawPacket); void SetMonitorDir(const std::string & monitorDir); + size_t RulesCount() const { return rules.size(); } + private: + TRAFFCOUNTER_IMPL(const TRAFFCOUNTER_IMPL & rvalue); + TRAFFCOUNTER_IMPL & operator=(const TRAFFCOUNTER_IMPL & rvalue); + bool ParseAddress(const char * ta, RULE * rule) const; uint32_t CalcMask(uint32_t msk) const; void FreeRules(); - void PrintRule(RULE rule) const; bool ReadRules(bool test = false); static void * Run(void * data); @@ -194,15 +218,18 @@ private: void UnSetUserNotifiers(USER_IMPL * user); typedef std::list::iterator rule_iter; - typedef std::map::iterator pp_iter; - typedef std::multimap::iterator ip2p_iter; - typedef std::multimap::const_iterator ip2p_citer; std::list rules; - std::map packets; // Packets tree + typedef std::map Packets; + typedef Packets::iterator pp_iter; + typedef std::multimap Index; + typedef Index::iterator ip2p_iter; + typedef Index::const_iterator ip2p_citer; + + Packets packets; // Packets tree - std::multimap ip2packets; // IP-to-Packet index + Index ip2packets; // IP-to-Packet index std::string dirName[DIR_NUM + 1]; @@ -211,6 +238,7 @@ private: std::string monitorDir; bool monitoring; + time_t touchTimeP; USERS_IMPL * users;