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"
18 #include "base/DelayedAsyncCalls.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 
28 DelayId::DelayId () : pool_ (0), compositeId(nullptr), markedAsNoDelay(false)
29 {}
30 
31 DelayId::DelayId(const unsigned short aPool, const DelayIdComposite::Pointer &aCompositeId):
32  pool_(aPool), compositeId(aCompositeId), markedAsNoDelay(false)
33 {
34  assert(pool_);
36  debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
37 }
38 
40 {}
41 
42 unsigned short
44 {
45  return pool_;
46 }
47 
48 bool
49 DelayId::operator == (DelayId const &rhs) const
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 
57 DelayId::operator bool() const
58 {
59  return compositeId && !markedAsNoDelay;
60 }
61 
62 /* create a delay Id for a given request */
63 DelayId
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 
108 void
109 DelayId::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  */
118 int
119 DelayId::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  */
134 void
136 {
137  if (! (*this))
138  return;
139 
140  compositeId->bytesIn(qty);
141 }
142 
143 void
145 {
146  assert (compositeId != nullptr);
147  compositeId->delayRead(aRead);
148 
149 }
150 
151 #endif /* USE_DELAY_POOLS */
152 
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:64
Ip::Address src_addr
unsigned short pool_
Definition: DelayId.h:44
unsigned short pool() const
Definition: DelayId.cc:43
bool operator==(DelayId const &rhs) const
Definition: DelayId.cc:49
virtual void delayRead(const AsyncCallPointer &)
DelayId()
Definition: DelayId.cc:28
int bytesWanted(int min, int max) const
Definition: DelayId.cc:119
const A & max(A const &lhs, A const &rhs)
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
bool markedAsNoDelay
Definition: DelayId.h:46
~DelayId()
Definition: DelayId.cc:39
void updateReply(const HttpReply::Pointer &)
virtual void bytesIn(int qty)=0
void bytesIn(int qty)
Definition: DelayId.cc:135
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
const Acl::Answer & fastCheck()
Definition: Checklist.cc:298
SBuf StringToSBuf(const String &s)
create a new SBuf from a String by copying contents
Definition: StringConvert.h:17
virtual int bytesWanted(int min, int max) const =0
#define assert(EX)
Definition: assert.h:17
void setNoDelay(bool const)
Definition: DelayId.cc:109
bool isNoAddr() const
Definition: Address.cc:304
void clientAclChecklistFill(ACLFilledChecklist &checklist, ClientHttpRequest *http)
static unsigned short pools()
Definition: delay_pools.cc:564
struct SquidConfig::@93 onoff
bool allowed() const
Definition: Acl.h:82
static DelayPool * delay_data
Definition: DelayPools.h:46
#define DBG_IMPORTANT
Definition: Stream.h:38
int delay_pool_uses_indirect_client
Definition: SquidConfig.h:327
void delayRead(const AsyncCallPointer &)
Definition: DelayId.cc:144
Ip::Address client_addr
Definition: HttpRequest.h:149
DelayIdComposite::Pointer compositeId
Definition: DelayId.h:45
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
String tag
Definition: HttpRequest.h:174
class SquidConfig Config
Definition: SquidConfig.cc:12
HttpRequest *const request

 

Introduction

Documentation

Support

Miscellaneous