]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ClientInfo.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / ClientInfo.h
CommitLineData
bbc27441 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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
1c898d4c
AJ
9#ifndef SQUID__SRC_CLIENTINFO_H
10#define SQUID__SRC_CLIENTINFO_H
11
a0864754 12#include "base/ByteCounter.h"
602d9612
A
13#include "cbdata.h"
14#include "enums.h"
1994c73c 15#include "hash.h"
602d9612 16#include "ip/Address.h"
02c8dde5 17#include "LogTags.h"
3c670b50 18#include "mem/forward.h"
1994c73c 19#include "typedefs.h"
a0864754 20
b4cd430a
CT
21#include <deque>
22
9a0a18de 23#if USE_DELAY_POOLS
b4cd430a
CT
24class CommQuotaQueue;
25#endif
1c898d4c 26
04f7fd38
AJ
27class ClientInfo
28{
3c670b50
AJ
29 MEMPROXY_CLASS(ClientInfo);
30
1c898d4c 31public:
3c670b50
AJ
32 explicit ClientInfo(const Ip::Address &);
33 ~ClientInfo();
34
1c898d4c
AJ
35 hash_link hash; /* must be first */
36
b7ac5457 37 Ip::Address addr;
1c898d4c 38
3c670b50
AJ
39 struct Protocol {
40 Protocol() : n_requests(0) {
41 memset(result_hist, 0, sizeof(result_hist));
42 }
43
1c898d4c
AJ
44 int result_hist[LOG_TYPE_MAX];
45 int n_requests;
a0864754
AJ
46 ByteCounter kbytes_in;
47 ByteCounter kbytes_out;
48 ByteCounter hit_kbytes_out;
1c898d4c
AJ
49 } Http, Icp;
50
3c670b50
AJ
51 struct Cutoff {
52 Cutoff() : time(0), n_req(0), n_denied(0) {}
53
1c898d4c
AJ
54 time_t time;
55 int n_req;
56 int n_denied;
57 } cutoff;
58 int n_established; /* number of current established connections */
59 time_t last_seen;
9a0a18de 60#if USE_DELAY_POOLS
f33d34a8
A
61 double writeSpeedLimit;///< Write speed limit in bytes per second, can be less than 1, if too close to zero this could result in timeouts from client
62 double prevTime; ///< previous time when we checked
b4cd430a
CT
63 double bucketSize; ///< how much can be written now
64 double bucketSizeLimit; ///< maximum bucket size
f33d34a8 65 bool writeLimitingActive; ///< Is write limiter active
b4cd430a
CT
66 bool firstTimeConnection;///< is this first time connection for this client
67
68 CommQuotaQueue *quotaQueue; ///< clients waiting for more write quota
69 int rationedQuota; ///< precomputed quota preserving fairness among clients
70 int rationedCount; ///< number of clients that will receive rationedQuota
71 bool selectWaiting; ///< is between commSetSelect and commHandleWrite
72 bool eventWaiting; ///< waiting for commHandleWriteHelper event to fire
73
74 // all those functions access Comm fd_table and are defined in comm.cc
75 bool hasQueue() const; ///< whether any clients are waiting for write quota
76 bool hasQueue(const CommQuotaQueue*) const; ///< has a given queue
77 unsigned int quotaEnqueue(int fd); ///< client starts waiting in queue; create the queue if necessary
78 int quotaPeekFd() const; ///< retuns the next fd reservation
79 unsigned int quotaPeekReserv() const; ///< returns the next reserv. to pop
80 void quotaDequeue(); ///< pops queue head from queue
81 void kickQuotaQueue(); ///< schedule commHandleWriteHelper call
82 int quotaForDequed(); ///< allocate quota for a just dequeued client
83 void refillBucket(); ///< adds bytes to bucket based on rate and time
84
85 void quotaDumpQueue(); ///< dumps quota queue for debugging
f33d34a8
A
86
87 /**
88 * Configure client write limiting (note:"client" here means - IP). It is called
89 * by httpAccept in client_side.cc, where the initial bucket size (anInitialBurst)
90 * computed, using the configured maximum bucket vavlue and configured initial
91 * bucket value(50% by default).
92 *
93 * \param writeSpeedLimit is speed limit configured in config for this pool
94 * \param initialBurst is initial bucket size to use for this client(i.e. client can burst at first)
95 * \param highWatermark is maximum bucket value
96 */
b4cd430a 97 void setWriteLimiter(const int aWriteSpeedLimit, const double anInitialBurst, const double aHighWatermark);
9a0a18de 98#endif /* USE_DELAY_POOLS */
b4cd430a
CT
99};
100
9a0a18de 101#if USE_DELAY_POOLS
b4cd430a
CT
102// a queue of Comm clients waiting for I/O quota controlled by delay pools
103class CommQuotaQueue
104{
5c2f68b7
AJ
105 CBDATA_CLASS(CommQuotaQueue);
106
b4cd430a
CT
107public:
108 CommQuotaQueue(ClientInfo *info);
109 ~CommQuotaQueue();
110
111 bool empty() const { return fds.empty(); }
112 size_t size() const { return fds.size(); }
113 int front() const { return fds.front(); }
114 unsigned int enqueue(int fd);
115 void dequeue();
f33d34a8 116
b4cd430a
CT
117 ClientInfo *clientInfo; ///< bucket responsible for quota maintenance
118
119 // these counters might overflow; that is OK because they are for IDs only
120 int ins; ///< number of enqueue calls, used to generate a "reservation" ID
121 int outs; ///< number of dequeue calls, used to check the "reservation" ID
122
123private:
124 // TODO: optimize using a Ring- or List-based store?
125 typedef std::deque<int> Store;
126 Store fds; ///< descriptor queue
1c898d4c 127};
9a0a18de 128#endif /* USE_DELAY_POOLS */
1c898d4c
AJ
129
130#endif
f53969cc 131