DelayId.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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
9/* DEBUG: section 77 Delay Pools */
10
11#include "squid.h"
12
13/* MS Visual Studio Projects are monolithic, so we need the following
14 * #if to exclude the delay pools code from compile process when not needed.
15 */
16#if USE_DELAY_POOLS
17#include "acl/FilledChecklist.h"
19#include "client_side_request.h"
20#include "DelayId.h"
21#include "DelayPool.h"
22#include "DelayPools.h"
23#include "http/Stream.h"
24#include "HttpRequest.h"
25#include "SquidConfig.h"
26
27DelayId::DelayId () : pool_ (0), compositeId(nullptr), markedAsNoDelay(false)
28{}
29
30DelayId::DelayId (unsigned short aPool) :
31 pool_ (aPool), compositeId (nullptr), markedAsNoDelay (false)
32{
33 debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
34}
35
37{}
38
39void
41{
42 compositeId = newPosition;
43}
44
45unsigned short
47{
48 return pool_;
49}
50
51bool
53{
54 /* Doesn't compare composites properly....
55 * only use to test against default ID's
56 */
57 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
58}
59
60DelayId::operator bool() const
61{
62 return pool_ || compositeId.getRaw();
63}
64
65/* create a delay Id for a given request */
68{
69 HttpRequest *r;
70 unsigned short pool;
71 assert(http);
72 r = http->request;
73
74 if (r->client_addr.isNoAddr()) {
75 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
76 return DelayId();
77 }
78
79 for (pool = 0; pool < DelayPools::pools(); ++pool) {
80
81 /* pools require explicit 'allow' to assign a client into them */
82 if (!DelayPools::delay_data[pool].access) {
83 debugs(77, DBG_IMPORTANT, "delay_pool " << pool <<
84 " has no delay_access configured. This means that no clients will ever use it.");
85 continue;
86 }
87
88 ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, nullptr);
89 clientAclChecklistFill(ch, http);
90 if (!ch.reply && reply) {
91 ch.reply = reply;
92 HTTPMSGLOCK(reply);
93 }
94 // overwrite ACLFilledChecklist acl_uses_indirect_client-based decision
95#if FOLLOW_X_FORWARDED_FOR
98 else
99#endif /* FOLLOW_X_FORWARDED_FOR */
100 ch.src_addr = r->client_addr;
101
102 if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck().allowed()) {
103
104 DelayId result (pool + 1);
106 details.src_addr = ch.src_addr;
107#if USE_AUTH
108 details.user = r->auth_user_request;
109#endif
110 details.tag = r->tag;
111 result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
112 return result;
113 }
114 }
115
116 return DelayId();
117}
118
119void
120DelayId::setNoDelay(bool const newValue)
121{
122 markedAsNoDelay = newValue;
123}
124
125/*
126 * this returns the number of bytes the client is permitted. it does not take
127 * into account bytes already buffered - that is up to the caller.
128 */
129int
130DelayId::bytesWanted(int minimum, int maximum) const
131{
132 /* unlimited */
133
134 if (! (*this) || markedAsNoDelay)
135 return max(minimum, maximum);
136
137 /* limited */
138 int nbytes = max(minimum, maximum);
139
140 if (compositeId != nullptr)
141 nbytes = compositeId->bytesWanted(minimum, nbytes);
142
143 return nbytes;
144}
145
146/*
147 * this records actual bytes received. always recorded, even if the
148 * class is disabled - it's more efficient to just do it than to do all
149 * the checks.
150 */
151void
153{
154 if (! (*this))
155 return;
156
157 if (markedAsNoDelay)
158 return;
159
160 assert ((unsigned short)(pool() - 1) != 0xFFFF);
161
162 if (compositeId != nullptr)
163 compositeId->bytesIn(qty);
164}
165
166void
168{
169 assert (compositeId != nullptr);
170 compositeId->delayRead(aRead);
171
172}
173
174#endif /* USE_DELAY_POOLS */
175
class SquidConfig Config
Definition: SquidConfig.cc:12
#define assert(EX)
Definition: assert.h:17
Acl::Answer const & fastCheck()
Definition: Checklist.cc:332
Ip::Address src_addr
bool allowed() const
Definition: Acl.h:156
HttpRequest *const request
virtual void bytesIn(int qty)=0
virtual int bytesWanted(int min, int max) const =0
virtual void delayRead(const AsyncCallPointer &)
DelayIdComposite::Pointer compositeId
Definition: DelayId.h:42
DelayIdComposite::Pointer compositePosition()
bool operator==(DelayId const &rhs) const
Definition: DelayId.cc:52
~DelayId()
Definition: DelayId.cc:36
void bytesIn(int qty)
Definition: DelayId.cc:152
unsigned short pool() const
Definition: DelayId.cc:46
unsigned short pool_
Definition: DelayId.h:41
int bytesWanted(int min, int max) const
Definition: DelayId.cc:130
bool markedAsNoDelay
Definition: DelayId.h:43
void setNoDelay(bool const)
Definition: DelayId.cc:120
void delayRead(const AsyncCallPointer &)
Definition: DelayId.cc:167
DelayId()
Definition: DelayId.cc:27
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:67
static unsigned short pools()
Definition: delay_pools.cc:564
static DelayPool * delay_data
Definition: DelayPools.h:46
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
String tag
Definition: HttpRequest.h:176
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
Ip::Address client_addr
Definition: HttpRequest.h:149
bool isNoAddr() const
Definition: Address.cc:284
C * getRaw() const
Definition: RefCount.h:80
int delay_pool_uses_indirect_client
Definition: SquidConfig.h:325
struct SquidConfig::@106 onoff
void clientAclChecklistFill(ACLFilledChecklist &checklist, ClientHttpRequest *http)
A const & max(A const &lhs, A const &rhs)
#define DBG_IMPORTANT
Definition: Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:193
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:160

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors