]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
bbc27441 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
ff9d9458 FC |
9 | #ifndef SQUID_SRC_CLIENTINFO_H |
10 | #define SQUID_SRC_CLIENTINFO_H | |
1c898d4c | 11 | |
b27668ec EB |
12 | #if USE_DELAY_POOLS |
13 | #include "BandwidthBucket.h" | |
14 | #endif | |
a0864754 | 15 | #include "base/ByteCounter.h" |
602d9612 A |
16 | #include "cbdata.h" |
17 | #include "enums.h" | |
1994c73c | 18 | #include "hash.h" |
602d9612 | 19 | #include "ip/Address.h" |
02c8dde5 | 20 | #include "LogTags.h" |
3c670b50 | 21 | #include "mem/forward.h" |
1994c73c | 22 | #include "typedefs.h" |
a0864754 | 23 | |
b4cd430a CT |
24 | #include <deque> |
25 | ||
9a0a18de | 26 | #if USE_DELAY_POOLS |
b4cd430a CT |
27 | class CommQuotaQueue; |
28 | #endif | |
1c898d4c | 29 | |
b27668ec EB |
30 | class ClientInfo : public hash_link |
31 | #if USE_DELAY_POOLS | |
32 | , public BandwidthBucket | |
33 | #endif | |
04f7fd38 | 34 | { |
3c670b50 AJ |
35 | MEMPROXY_CLASS(ClientInfo); |
36 | ||
1c898d4c | 37 | public: |
3c670b50 | 38 | explicit ClientInfo(const Ip::Address &); |
337b9aa4 AR |
39 | #if USE_DELAY_POOLS |
40 | ~ClientInfo() override; | |
41 | #else | |
3c670b50 | 42 | ~ClientInfo(); |
337b9aa4 | 43 | #endif |
3c670b50 | 44 | |
b7ac5457 | 45 | Ip::Address addr; |
1c898d4c | 46 | |
3c670b50 AJ |
47 | struct Protocol { |
48 | Protocol() : n_requests(0) { | |
49 | memset(result_hist, 0, sizeof(result_hist)); | |
50 | } | |
51 | ||
1c898d4c AJ |
52 | int result_hist[LOG_TYPE_MAX]; |
53 | int n_requests; | |
a0864754 AJ |
54 | ByteCounter kbytes_in; |
55 | ByteCounter kbytes_out; | |
56 | ByteCounter hit_kbytes_out; | |
1c898d4c AJ |
57 | } Http, Icp; |
58 | ||
3c670b50 AJ |
59 | struct Cutoff { |
60 | Cutoff() : time(0), n_req(0), n_denied(0) {} | |
61 | ||
1c898d4c AJ |
62 | time_t time; |
63 | int n_req; | |
64 | int n_denied; | |
65 | } cutoff; | |
66 | int n_established; /* number of current established connections */ | |
67 | time_t last_seen; | |
9a0a18de | 68 | #if USE_DELAY_POOLS |
f33d34a8 | 69 | bool writeLimitingActive; ///< Is write limiter active |
b4cd430a CT |
70 | bool firstTimeConnection;///< is this first time connection for this client |
71 | ||
72 | CommQuotaQueue *quotaQueue; ///< clients waiting for more write quota | |
73 | int rationedQuota; ///< precomputed quota preserving fairness among clients | |
74 | int rationedCount; ///< number of clients that will receive rationedQuota | |
b4cd430a CT |
75 | bool eventWaiting; ///< waiting for commHandleWriteHelper event to fire |
76 | ||
77 | // all those functions access Comm fd_table and are defined in comm.cc | |
78 | bool hasQueue() const; ///< whether any clients are waiting for write quota | |
79 | bool hasQueue(const CommQuotaQueue*) const; ///< has a given queue | |
80 | unsigned int quotaEnqueue(int fd); ///< client starts waiting in queue; create the queue if necessary | |
2f8abb64 | 81 | int quotaPeekFd() const; ///< returns the next fd reservation |
b4cd430a CT |
82 | unsigned int quotaPeekReserv() const; ///< returns the next reserv. to pop |
83 | void quotaDequeue(); ///< pops queue head from queue | |
84 | void kickQuotaQueue(); ///< schedule commHandleWriteHelper call | |
b90a3414 EB |
85 | /// either selects the head descriptor for writing or calls quotaDequeue() |
86 | void writeOrDequeue(); | |
b27668ec EB |
87 | |
88 | /* BandwidthBucket API */ | |
337b9aa4 AR |
89 | int quota() override; ///< allocate quota for a just dequeued client |
90 | bool applyQuota(int &nleft, Comm::IoCallback *state) override; | |
91 | void scheduleWrite(Comm::IoCallback *state) override; | |
92 | void onFdClosed() override; | |
93 | void reduceBucket(int len) override; | |
b4cd430a CT |
94 | |
95 | void quotaDumpQueue(); ///< dumps quota queue for debugging | |
f33d34a8 A |
96 | |
97 | /** | |
98 | * Configure client write limiting (note:"client" here means - IP). It is called | |
99 | * by httpAccept in client_side.cc, where the initial bucket size (anInitialBurst) | |
2f8abb64 | 100 | * computed, using the configured maximum bucket value and configured initial |
f33d34a8 A |
101 | * bucket value(50% by default). |
102 | * | |
103 | * \param writeSpeedLimit is speed limit configured in config for this pool | |
104 | * \param initialBurst is initial bucket size to use for this client(i.e. client can burst at first) | |
105 | * \param highWatermark is maximum bucket value | |
106 | */ | |
b4cd430a | 107 | void setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBurst, const double aHighWatermark); |
9a0a18de | 108 | #endif /* USE_DELAY_POOLS */ |
b4cd430a CT |
109 | }; |
110 | ||
9a0a18de | 111 | #if USE_DELAY_POOLS |
b4cd430a CT |
112 | // a queue of Comm clients waiting for I/O quota controlled by delay pools |
113 | class CommQuotaQueue | |
114 | { | |
5c2f68b7 AJ |
115 | CBDATA_CLASS(CommQuotaQueue); |
116 | ||
b4cd430a CT |
117 | public: |
118 | CommQuotaQueue(ClientInfo *info); | |
119 | ~CommQuotaQueue(); | |
120 | ||
121 | bool empty() const { return fds.empty(); } | |
122 | size_t size() const { return fds.size(); } | |
123 | int front() const { return fds.front(); } | |
124 | unsigned int enqueue(int fd); | |
125 | void dequeue(); | |
f33d34a8 | 126 | |
b4cd430a CT |
127 | ClientInfo *clientInfo; ///< bucket responsible for quota maintenance |
128 | ||
129 | // these counters might overflow; that is OK because they are for IDs only | |
130 | int ins; ///< number of enqueue calls, used to generate a "reservation" ID | |
131 | int outs; ///< number of dequeue calls, used to check the "reservation" ID | |
132 | ||
133 | private: | |
134 | // TODO: optimize using a Ring- or List-based store? | |
135 | typedef std::deque<int> Store; | |
136 | Store fds; ///< descriptor queue | |
1c898d4c | 137 | }; |
9a0a18de | 138 | #endif /* USE_DELAY_POOLS */ |
1c898d4c | 139 | |
ff9d9458 | 140 | #endif /* SQUID_SRC_CLIENTINFO_H */ |
f53969cc | 141 |