]> git.stg.codes - stg.git/commitdiff
TRAFFCOUNTER_IMPL changed to use USER_IMPL instead of USER
authorMaxim Mamontov <faust@gts.dp.ua>
Thu, 14 Apr 2011 11:39:38 +0000 (14:39 +0300)
committerMaxim Mamontov <faust@gts.dp.ua>
Thu, 14 Apr 2011 11:39:38 +0000 (14:39 +0300)
projects/stargazer/traffcounter_impl.cpp
projects/stargazer/traffcounter_impl.h

index a605e284a3c17c73a3d53d89f283aff1de2be2d9..424cc09468f949b5ed5c13b87a8a2c1b4eea2b1b 100644 (file)
@@ -42,6 +42,7 @@
 #include "stg/locker.h"
 #include "traffcounter_impl.h"
 #include "stg_timer.h"
 #include "stg/locker.h"
 #include "traffcounter_impl.h"
 #include "stg_timer.h"
+#include "users_impl.h"
 
 #define FLUSH_TIME  (10)
 #define REMOVE_TIME  (31)
 
 #define FLUSH_TIME  (10)
 #define REMOVE_TIME  (31)
@@ -55,7 +56,7 @@ tcp = 0, udp, icmp, tcp_udp, all
 };
 
 //-----------------------------------------------------------------------------
 };
 
 //-----------------------------------------------------------------------------
-TRAFFCOUNTER_IMPL::TRAFFCOUNTER_IMPL(USERS * u, const TARIFFS *, const std::string & fn)
+TRAFFCOUNTER_IMPL::TRAFFCOUNTER_IMPL(USERS_IMPL * u, const std::string & fn)
     : WriteServLog(GetStgLogger()),
       rulesFileName(fn),
       monitoring(false),
     : WriteServLog(GetStgLogger()),
       rulesFileName(fn),
       monitoring(false),
@@ -97,7 +98,7 @@ if (ReadRules())
 
 printfd(__FILE__, "TRAFFCOUNTER::Start()\n");
 int h = users->OpenSearch();
 
 printfd(__FILE__, "TRAFFCOUNTER::Start()\n");
 int h = users->OpenSearch();
-USER_PTR u;
+USER_IMPL * u;
 if (!h)
     {
     printfd(__FILE__, "TRAFFCOUNTER_IMPL::Start() - Cannot get users\n");
 if (!h)
     {
     printfd(__FILE__, "TRAFFCOUNTER_IMPL::Start() - Cannot get users\n");
@@ -135,7 +136,7 @@ if (!h)
     return -1;
     }
 
     return -1;
     }
 
-USER_PTR u;
+USER_IMPL * u;
 while (users->SearchNext(h, &u) == 0)
     {
     UnSetUserNotifiers(u);
 while (users->SearchNext(h, &u) == 0)
     {
     UnSetUserNotifiers(u);
@@ -351,49 +352,6 @@ while (pi != packets.end())
             }
         }
 
             }
         }
 
-    /*//Removing
-    if (stgTime - pi->second.updateTime > REMOVE_TIME)
-        {
-        // Remove packet and references from ip2packets index
-        //printfd(__FILE__, "+++ Removing +++\n");
-        pair<ip2p_iter, ip2p_iter> be(
-                ip2packets.equal_range(pi->first.GetSrcIP()));
-        while (be.first != be.second)
-            {
-            // Have a reference to a packet?
-            if (be.first->second == pi)
-                {
-                ip2packets.erase(be.first++);
-                //printfd(__FILE__, "Remove U from ip2packets %s\n", inet_ntostring(pi->first.GetSrcIP()).c_str());
-                }
-            else
-                {
-                ++be.first;
-                }
-            }
-
-        //printfd(__FILE__, "-------------------\n");
-        be = ip2packets.equal_range(pi->first.GetDstIP());
-        while (be.first != be.second)
-            {
-            // Have a reference to a packet?
-            if (be.first->second == pi)
-                {
-                ip2packets.erase(be.first++);
-                //printfd(__FILE__, "Remove D from ip2packets %s\n", inet_ntostring(pi->first.GetDstIP()).c_str());
-                }
-            else
-                {
-                ++be.first;
-                }
-            }
-        //printfd(__FILE__, "Remove packet\n");
-        packets.erase(pi++);
-        }
-    else
-        {
-        ++pi;
-        }*/
     if (stgTime - pi->second.updateTime < REMOVE_TIME)
         {
         std::pair<pp_iter, bool> res = newPackets.insert(*pi);
     if (stgTime - pi->second.updateTime < REMOVE_TIME)
         {
         std::pair<pp_iter, bool> res = newPackets.insert(*pi);
@@ -414,7 +372,7 @@ printfd(__FILE__, "FlushAndRemove() packets: %d(rem %d) ip2packets: %d(rem %d)\n
 
 }
 //-----------------------------------------------------------------------------
 
 }
 //-----------------------------------------------------------------------------
-void TRAFFCOUNTER_IMPL::AddUser(USER_PTR user)
+void TRAFFCOUNTER_IMPL::AddUser(USER_IMPL * user)
 {
 printfd(__FILE__, "AddUser: %s\n", user->GetLogin().c_str());
 uint32_t uip = user->GetCurrIP();
 {
 printfd(__FILE__, "AddUser: %s\n", user->GetLogin().c_str());
 uint32_t uip = user->GetCurrIP();
@@ -505,7 +463,7 @@ while (pi.first != pi.second)
 ip2packets.erase(pi.first, pi.second);
 }
 //-----------------------------------------------------------------------------
 ip2packets.erase(pi.first, pi.second);
 }
 //-----------------------------------------------------------------------------
-void TRAFFCOUNTER_IMPL::SetUserNotifiers(USER_PTR user)
+void TRAFFCOUNTER_IMPL::SetUserNotifiers(USER_IMPL * user)
 {
 // Adding user. Adding notifiers to user.
 TRF_IP_BEFORE ipBNotifier(*this, user);
 {
 // Adding user. Adding notifiers to user.
 TRF_IP_BEFORE ipBNotifier(*this, user);
@@ -517,7 +475,7 @@ ipAfterNotifiers.push_front(ipANotifier);
 user->AddCurrIPAfterNotifier(&(*ipAfterNotifiers.begin()));
 }
 //-----------------------------------------------------------------------------
 user->AddCurrIPAfterNotifier(&(*ipAfterNotifiers.begin()));
 }
 //-----------------------------------------------------------------------------
-void TRAFFCOUNTER_IMPL::UnSetUserNotifiers(USER_PTR user)
+void TRAFFCOUNTER_IMPL::UnSetUserNotifiers(USER_IMPL * user)
 {
 // Removing user. Removing notifiers from user.
 std::list<TRF_IP_BEFORE>::iterator bi;
 {
 // Removing user. Removing notifiers from user.
 std::list<TRF_IP_BEFORE>::iterator bi;
index c30f6be4f01754b3dcc45a4873f4bf07b5b92390..7d01c2e4b24d9b968186e515703d8e70c518a153 100644 (file)
 #include "stg/os_int.h"
 #include "stg/logger.h"
 #include "stg/raw_ip_packet.h"
 #include "stg/os_int.h"
 #include "stg/logger.h"
 #include "stg/raw_ip_packet.h"
-#include "stg/users.h"
 #include "stg/noncopyable.h"
 #include "stg/noncopyable.h"
+#include "stg/notifer.h"
 #include "actions.h"
 #include "eventloop.h"
 #include "actions.h"
 #include "eventloop.h"
+#include "user_impl.h"
 
 #define PROTOMAX    (5)
 
 
 #define PROTOMAX    (5)
 
-class TARIFFS;
+class USERS_IMPL;
 
 //-----------------------------------------------------------------------------
 struct RULE {
 
 //-----------------------------------------------------------------------------
 struct RULE {
@@ -62,9 +63,9 @@ struct PACKET_EXTRA_DATA {
 PACKET_EXTRA_DATA()
     : flushTime(0),
       updateTime(0),
 PACKET_EXTRA_DATA()
     : flushTime(0),
       updateTime(0),
-      userU(),
+      userU(NULL),
       userUPresent(false),
       userUPresent(false),
-      userD(),
+      userD(NULL),
       userDPresent(false),
       dirU(DIR_NUM),
       dirD(DIR_NUM),
       userDPresent(false),
       dirU(DIR_NUM),
       dirD(DIR_NUM),
@@ -87,9 +88,9 @@ PACKET_EXTRA_DATA(const PACKET_EXTRA_DATA & pp)
 
 time_t      flushTime;          // Last flush time
 time_t      updateTime;         // Last update time
 
 time_t      flushTime;          // Last flush time
 time_t      updateTime;         // Last update time
-USER_PTR    userU;              // Uploader
+USER_IMPL * userU;              // Uploader
 bool        userUPresent;       // Uploader is registered user
 bool        userUPresent;       // Uploader is registered user
-USER_PTR    userD;              // Downloader
+USER_IMPL * userD;              // Downloader
 bool        userDPresent;       // Downloader is registered user
 int         dirU;               // Upload direction
 int         dirD;               // Download direction
 bool        userDPresent;       // Downloader is registered user
 int         dirU;               // Upload direction
 int         dirD;               // Download direction
@@ -101,55 +102,55 @@ class TRAFFCOUNTER_IMPL;
 //-----------------------------------------------------------------------------
 class TRF_IP_BEFORE: public PROPERTY_NOTIFIER_BASE<uint32_t> {
 public:
 //-----------------------------------------------------------------------------
 class TRF_IP_BEFORE: public PROPERTY_NOTIFIER_BASE<uint32_t> {
 public:
-                    TRF_IP_BEFORE(TRAFFCOUNTER_IMPL & t, USER_PTR u)
+                    TRF_IP_BEFORE(TRAFFCOUNTER_IMPL & t, USER_IMPL * u)
                         : PROPERTY_NOTIFIER_BASE<uint32_t>(),
                           traffCnt(t),
                           user(u)
                     {}
     void            Notify(const uint32_t & oldValue, const uint32_t & newValue);
                         : PROPERTY_NOTIFIER_BASE<uint32_t>(),
                           traffCnt(t),
                           user(u)
                     {}
     void            Notify(const uint32_t & oldValue, const uint32_t & newValue);
-    void            SetUser(USER_PTR u) { user = u; }
-    USER_PTR        GetUser() const { return user; }
+    void            SetUser(USER_IMPL * u) { user = u; }
+    USER_IMPL *     GetUser() const { return user; }
 
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
-    USER_PTR            user;
+    USER_IMPL *         user;
 };
 //-----------------------------------------------------------------------------
 class TRF_IP_AFTER: public PROPERTY_NOTIFIER_BASE<uint32_t> {
 public:
 };
 //-----------------------------------------------------------------------------
 class TRF_IP_AFTER: public PROPERTY_NOTIFIER_BASE<uint32_t> {
 public:
-                    TRF_IP_AFTER(TRAFFCOUNTER_IMPL & t, USER_PTR u)
+                    TRF_IP_AFTER(TRAFFCOUNTER_IMPL & t, USER_IMPL * u)
                         : PROPERTY_NOTIFIER_BASE<uint32_t>(),
                           traffCnt(t),
                           user(u)
                     {}
     void            Notify(const uint32_t & oldValue, const uint32_t & newValue);
                         : PROPERTY_NOTIFIER_BASE<uint32_t>(),
                           traffCnt(t),
                           user(u)
                     {}
     void            Notify(const uint32_t & oldValue, const uint32_t & newValue);
-    void            SetUser(USER_PTR u) { user = u; }
-    USER_PTR        GetUser() const { return user; }
+    void            SetUser(USER_IMPL * u) { user = u; }
+    USER_IMPL *     GetUser() const { return user; }
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
-    USER_PTR            user;
+    USER_IMPL *         user;
 };
 //-----------------------------------------------------------------------------
 };
 //-----------------------------------------------------------------------------
-class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
+class ADD_USER_NONIFIER: public NOTIFIER_BASE<USER_IMPL_PTR> {
 public:
             ADD_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) :
 public:
             ADD_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) :
-                NOTIFIER_BASE<USER_PTR>(),
+                NOTIFIER_BASE<USER_IMPL_PTR>(),
                 traffCnt(t)
             {}
     virtual ~ADD_USER_NONIFIER() {}
                 traffCnt(t)
             {}
     virtual ~ADD_USER_NONIFIER() {}
-    void    Notify(const USER_PTR & user);
+    void    Notify(const USER_IMPL_PTR & user);
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 };
 //-----------------------------------------------------------------------------
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 };
 //-----------------------------------------------------------------------------
-class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_PTR> {
+class DEL_USER_NONIFIER: public NOTIFIER_BASE<USER_IMPL_PTR> {
 public:
             DEL_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) :
 public:
             DEL_USER_NONIFIER(TRAFFCOUNTER_IMPL & t) :
-                NOTIFIER_BASE<USER_PTR>(),
+                NOTIFIER_BASE<USER_IMPL_PTR>(),
                 traffCnt(t)
             {}
     virtual ~DEL_USER_NONIFIER() {}
                 traffCnt(t)
             {}
     virtual ~DEL_USER_NONIFIER() {}
-    void    Notify(const USER_PTR & user);
+    void    Notify(const USER_IMPL_PTR & user);
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 };
 private:
     TRAFFCOUNTER_IMPL & traffCnt;
 };
@@ -160,7 +161,7 @@ friend class DEL_USER_NONIFIER;
 friend class TRF_IP_BEFORE;
 friend class TRF_IP_AFTER;
 public:
 friend class TRF_IP_BEFORE;
 friend class TRF_IP_AFTER;
 public:
-    TRAFFCOUNTER_IMPL(USERS * users, const TARIFFS * tariffs, const std::string & rulesFileName);
+    TRAFFCOUNTER_IMPL(USERS_IMPL * users, const std::string & rulesFileName);
     ~TRAFFCOUNTER_IMPL();
 
     void        SetRulesFile(const std::string & rulesFileName);
     ~TRAFFCOUNTER_IMPL();
 
     void        SetRulesFile(const std::string & rulesFileName);
@@ -187,10 +188,10 @@ private:
 
     void        FlushAndRemove();
 
 
     void        FlushAndRemove();
 
-    void        AddUser(USER_PTR user);
+    void        AddUser(USER_IMPL * user);
     void        DelUser(uint32_t uip);
     void        DelUser(uint32_t uip);
-    void        SetUserNotifiers(USER_PTR user);
-    void        UnSetUserNotifiers(USER_PTR user);
+    void        SetUserNotifiers(USER_IMPL * user);
+    void        UnSetUserNotifiers(USER_IMPL * user);
 
     typedef std::list<RULE>::iterator rule_iter;
     typedef std::map<RAW_PACKET, PACKET_EXTRA_DATA>::iterator pp_iter;
 
     typedef std::list<RULE>::iterator rule_iter;
     typedef std::map<RAW_PACKET, PACKET_EXTRA_DATA>::iterator pp_iter;
@@ -211,7 +212,7 @@ private:
     std::string              monitorDir;
     bool                     monitoring;
 
     std::string              monitorDir;
     bool                     monitoring;
 
-    USERS *                  users;
+    USERS_IMPL *             users;
 
     bool                     running;
     bool                     stopped;
 
     bool                     running;
     bool                     stopped;
@@ -246,13 +247,13 @@ EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::AddUse
 }
 //-----------------------------------------------------------------------------
 inline
 }
 //-----------------------------------------------------------------------------
 inline
-void ADD_USER_NONIFIER::Notify(const USER_PTR & user)
+void ADD_USER_NONIFIER::Notify(const USER_IMPL_PTR & user)
 {
 EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::SetUserNotifiers, user);
 }
 //-----------------------------------------------------------------------------
 inline
 {
 EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::SetUserNotifiers, user);
 }
 //-----------------------------------------------------------------------------
 inline
-void DEL_USER_NONIFIER::Notify(const USER_PTR & user)
+void DEL_USER_NONIFIER::Notify(const USER_IMPL_PTR & user)
 {
 EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::UnSetUserNotifiers, user);
 EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::DelUser, user->GetCurrIP());
 {
 EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::UnSetUserNotifiers, user);
 EVENT_LOOP_SINGLETON::GetInstance().Enqueue(traffCnt, &TRAFFCOUNTER_IMPL::DelUser, user->GetCurrIP());