Squid Web Cache master
Loading...
Searching...
No Matches
DelayId.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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(const unsigned short aPool, const DelayIdComposite::Pointer &aCompositeId):
32 pool_(aPool), compositeId(aCompositeId), markedAsNoDelay(false)
33{
36 debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
37}
38
41
42unsigned short
44{
45 return pool_;
46}
47
48bool
50{
51 /* Doesn't compare composites properly....
52 * only use to test against default ID's
53 */
54 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
55}
56
57DelayId::operator bool() const
58{
59 return compositeId && !markedAsNoDelay;
60}
61
62/* create a delay Id for a given request */
65{
66 HttpRequest *r;
67 unsigned short pool;
68 assert(http);
69 r = http->request;
70
71 if (r->client_addr.isNoAddr()) {
72 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
73 return DelayId();
74 }
75
76 for (pool = 0; pool < DelayPools::pools(); ++pool) {
77
78 /* pools require explicit 'allow' to assign a client into them */
79 if (!DelayPools::delay_data[pool].access) {
80 debugs(77, DBG_IMPORTANT, "delay_pool " << pool <<
81 " has no delay_access configured. This means that no clients will ever use it.");
82 continue;
83 }
84
86 clientAclChecklistFill(ch, http);
87 ch.updateReply(reply);
88 // overwrite ACLFilledChecklist acl_uses_indirect_client-based decision
89#if FOLLOW_X_FORWARDED_FOR
92 else
93#endif /* FOLLOW_X_FORWARDED_FOR */
94 ch.src_addr = r->client_addr;
95
96 if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck().allowed()) {
98#if USE_AUTH
99 details.user = r->auth_user_request;
100#endif
101 return DelayId(pool + 1, DelayPools::delay_data[pool].theComposite()->id(details));
102 }
103 }
104
105 return DelayId();
106}
107
108void
109DelayId::setNoDelay(bool const newValue)
110{
111 markedAsNoDelay = newValue;
112}
113
114/*
115 * this returns the number of bytes the client is permitted. it does not take
116 * into account bytes already buffered - that is up to the caller.
117 */
118int
119DelayId::bytesWanted(int minimum, int maximum) const
120{
121 const auto maxBytes = max(minimum, maximum);
122
123 if (! (*this))
124 return maxBytes;
125
126 return compositeId->bytesWanted(minimum, maxBytes);
127}
128
129/*
130 * this records actual bytes received. always recorded, even if the
131 * class is disabled - it's more efficient to just do it than to do all
132 * the checks.
133 */
134void
136{
137 if (! (*this))
138 return;
139
140 compositeId->bytesIn(qty);
141}
142
143void
145{
146 assert (compositeId != nullptr);
147 compositeId->delayRead(aRead);
148
149}
150
151#endif /* USE_DELAY_POOLS */
152
class SquidConfig Config
SBuf StringToSBuf(const String &s)
create a new SBuf from a String by copying contents
#define assert(EX)
Definition assert.h:17
Acl::Answer const & fastCheck()
Definition Checklist.cc:298
void updateReply(const HttpReply::Pointer &)
bool allowed() const
Definition Acl.h:82
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:45
bool operator==(DelayId const &rhs) const
Definition DelayId.cc:49
~DelayId()
Definition DelayId.cc:39
void bytesIn(int qty)
Definition DelayId.cc:135
unsigned short pool() const
Definition DelayId.cc:43
unsigned short pool_
Definition DelayId.h:44
int bytesWanted(int min, int max) const
Definition DelayId.cc:119
bool markedAsNoDelay
Definition DelayId.h:46
void setNoDelay(bool const)
Definition DelayId.cc:109
void delayRead(const AsyncCallPointer &)
Definition DelayId.cc:144
DelayId()
Definition DelayId.cc:28
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition DelayId.cc:64
static unsigned short pools()
static DelayPool * delay_data
Definition DelayPools.h:46
Ip::Address indirect_client_addr
Auth::UserRequest::Pointer auth_user_request
Ip::Address client_addr
bool isNoAddr() const
Definition Address.cc:304
int delay_pool_uses_indirect_client
struct SquidConfig::@90 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:192