forked from gigablast/open-source-search-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoBan.h
110 lines (84 loc) · 2.13 KB
/
AutoBan.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef _AUTOBAN_H_
#define _AUTOBAN_H_
#include "TcpServer.h"
#include "HttpRequest.h"
#include "Parms.h"
#include "TuringTest.h"
#include "HashTableT.h"
//must be a power of 2!!!!!!
#define AUTOBAN_INITSIZE 262144
//#define AUTOBAN_INITSIZE 65536
//#define AUTOBAN_INITSIZE 32768
//#define AUTOBAN_INITSIZE 128
#define ONE_DAY 60*60*24
struct CodeVal {
char m_code[32];
long m_ip;
long long m_count;
long m_outstanding;
long m_maxEver;
long m_maxOutstanding;
long long m_bytesSent;
long long m_bytesRead;
};
class AutoBan {
public:
enum AutobanFlags {
CLEAR = 0x0,
ALLOW = 0x80,
DENY = 0x40,
FROMCONF = 0x20
};
struct DetectVal {
unsigned char m_flags;
unsigned char m_minuteCount;
unsigned char m_timesBanned;
long m_dayCount;
long m_minuteExpires;
long m_dayExpires;
};
//init functions
AutoBan();
~AutoBan();
bool init();
void reset();
bool save();
bool restore();
bool hasCode(char *code, long codeLen, long ip);
bool hasPerm(long ip,
char *code, long codeLen,
char *uip, long uipLen,
TcpSocket *s,
HttpRequest *r,
SafeBuf *testBuf,
bool justCheck ); // check, not incmreneting though
bool isBanned(unsigned long ip);
long getSlot(long ip);
bool addIp(long ip, char allow);
bool addKey(long ip, DetectVal* v);
bool growTable();
bool printTable( TcpSocket *s , HttpRequest *r );
void removeIp(long ip);
void cleanHouse();
void setFromConf();
// . each client is now limited to a max oustanding requests
// . Proxy.cpp performs this limitation calculation
bool incRequestCount ( long h , long bytesRead );
void decRequestCount ( long h , long bytesSent );
protected:
long *m_detectKeys;
DetectVal *m_detectVals;
long m_tableSize;
long m_numEntries;
bool setCodesFromConf();
// hash table for mapping client codes to various stats/counts,
// called "CodeVals"
HashTableT <long,CodeVal> m_ht;
//long *m_codeKeys;
//CodeVal *m_codeVals;
long m_codeResetTime;
//long m_codeTabSize;
//long m_numCodes;
};
extern AutoBan g_autoBan;
#endif