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 "sbuf/StringConvert.h"
26#include "SquidConfig.h"
27
28DelayId::DelayId () : pool_ (0), compositeId(nullptr), markedAsNoDelay(false)
29{}
30
31DelayId::DelayId (unsigned short aPool) :
32 pool_ (aPool), compositeId (nullptr), markedAsNoDelay (false)
33{
34 debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
35}
36
38{}
39
40void
42{
43 compositeId = newPosition;
44}
45
46unsigned short
48{
49 return pool_;
50}
51
52bool
54{
55 /* Doesn't compare composites properly....
56 * only use to test against default ID's
57 */
58 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
59}
60
61DelayId::operator bool() const
62{
63 return pool_ || compositeId.getRaw();
64}
65
66/* create a delay Id for a given request */
69{
70 HttpRequest *r;
71 unsigned short pool;
72 assert(http);
73 r = http->request;
74
75 if (r->client_addr.isNoAddr()) {
76 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
77 return DelayId();
78 }
79
80 for (pool = 0; pool < DelayPools::pools(); ++pool) {
81
82 /* pools require explicit 'allow' to assign a client into them */
83 if (!DelayPools::delay_data[pool].access) {
84 debugs(77, DBG_IMPORTANT, "delay_pool " << pool <<
85 " has no delay_access configured. This means that no clients will ever use it.");
86 continue;
87 }
88
89 ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, nullptr);
90 clientAclChecklistFill(ch, http);
91 if (!ch.reply && reply) {
92 ch.reply = reply;
93 HTTPMSGLOCK(reply);
94 }
95 // overwrite ACLFilledChecklist acl_uses_indirect_client-based decision
96#if FOLLOW_X_FORWARDED_FOR
99 else
100#endif /* FOLLOW_X_FORWARDED_FOR */
101 ch.src_addr = r->client_addr;
102
103 if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck().allowed()) {
104
105 DelayId result (pool + 1);
107#if USE_AUTH
108 details.user = r->auth_user_request;
109#endif
110 result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
111 return result;
112 }
113 }
114
115 return DelayId();
116}
117
118void
119DelayId::setNoDelay(bool const newValue)
120{
121 markedAsNoDelay = newValue;
122}
123
124/*
125 * this returns the number of bytes the client is permitted. it does not take
126 * into account bytes already buffered - that is up to the caller.
127 */
128int
129DelayId::bytesWanted(int minimum, int maximum) const
130{
131 /* unlimited */
132
133 if (! (*this) || markedAsNoDelay)
134 return max(minimum, maximum);
135
136 /* limited */
137 int nbytes = max(minimum, maximum);
138
139 if (compositeId != nullptr)
140 nbytes = compositeId->bytesWanted(minimum, nbytes);
141
142 return nbytes;
143}
144
145/*
146 * this records actual bytes received. always recorded, even if the
147 * class is disabled - it's more efficient to just do it than to do all
148 * the checks.
149 */
150void
152{
153 if (! (*this))
154 return;
155
156 if (markedAsNoDelay)
157 return;
158
159 assert ((unsigned short)(pool() - 1) != 0xFFFF);
160
161 if (compositeId != nullptr)
162 compositeId->bytesIn(qty);
163}
164
165void
167{
168 assert (compositeId != nullptr);
169 compositeId->delayRead(aRead);
170
171}
172
173#endif /* USE_DELAY_POOLS */
174
class SquidConfig Config
Definition: SquidConfig.cc:12
SBuf StringToSBuf(const String &s)
create a new SBuf from a String by copying contents
Definition: StringConvert.h:17
#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:53
~DelayId()
Definition: DelayId.cc:37
void bytesIn(int qty)
Definition: DelayId.cc:151
unsigned short pool() const
Definition: DelayId.cc:47
unsigned short pool_
Definition: DelayId.h:41
int bytesWanted(int min, int max) const
Definition: DelayId.cc:129
bool markedAsNoDelay
Definition: DelayId.h:43
void setNoDelay(bool const)
Definition: DelayId.cc:119
void delayRead(const AsyncCallPointer &)
Definition: DelayId.cc:166
DelayId()
Definition: DelayId.cc:28
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:68
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:89
int delay_pool_uses_indirect_client
Definition: SquidConfig.h:327
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:194
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors