crossroads

Git mirror of https://crossroads.e-tunity.com/
git clone git://git.finwo.net/app/crossroads
Log | Files | Refs | LICENSE

ipstore (1033B)


      1 #ifndef _IPSTORE_
      2 #define _IPSTORE_
      3 
      4 #include "sys/sys"
      5 #include "config/config"
      6 #include "timestamp/timestamp"
      7 #include "balancer/balancer"
      8 #include "ThreadsAndMutexes/mutex/mutex"
      9 
     10 class IPStore {
     11 public:
     12     struct ClientData {
     13 	int targetbackend;
     14 	time_t lastaccess;
     15     };
     16 
     17     struct ClientDataCmp {
     18 	bool operator() (struct in_addr a, struct in_addr b) const {
     19 	    long la, lb;
     20 	    memcpy (&la, &a, sizeof(long));
     21 	    memcpy (&lb, &b, sizeof(long));
     22 	    return (la - lb) < 0;
     23 	}
     24     };
     25 
     26     typedef  map<struct in_addr, ClientData, ClientDataCmp> StoreMap;
     27     
     28     static int target(struct in_addr clientip);
     29     static void activity(struct in_addr clientip, unsigned curbackend);
     30     static unsigned anticipated(unsigned bckend);
     31     static void clear(struct in_addr clientip);
     32     static void clearoldest();
     33 
     34     static void on()		{ onoff = true; }
     35     static void off()		{ onoff = false; }
     36     
     37 private:
     38     static void dump();
     39     static void weed();
     40     
     41     static StoreMap store;
     42     static bool onoff;
     43 };
     44 
     45 #endif