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"
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 (unsigned short aPool) :
32  pool_ (aPool), compositeId (nullptr), markedAsNoDelay (false)
33 {
34  debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
35 }
36 
38 {}
39 
40 void
42 {
43  compositeId = newPosition;
44 }
45 
46 unsigned short
48 {
49  return pool_;
50 }
51 
52 bool
53 DelayId::operator == (DelayId const &rhs) const
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 
61 DelayId::operator bool() const
62 {
63  return pool_ || compositeId.getRaw();
64 }
65 
66 /* create a delay Id for a given request */
67 DelayId
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 
90  clientAclChecklistFill(ch, http);
91  ch.updateReply(reply);
92  // overwrite ACLFilledChecklist acl_uses_indirect_client-based decision
93 #if FOLLOW_X_FORWARDED_FOR
96  else
97 #endif /* FOLLOW_X_FORWARDED_FOR */
98  ch.src_addr = r->client_addr;
99 
100  if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck().allowed()) {
101 
102  DelayId result (pool + 1);
104 #if USE_AUTH
105  details.user = r->auth_user_request;
106 #endif
107  result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
108  return result;
109  }
110  }
111 
112  return DelayId();
113 }
114 
115 void
116 DelayId::setNoDelay(bool const newValue)
117 {
118  markedAsNoDelay = newValue;
119 }
120 
121 /*
122  * this returns the number of bytes the client is permitted. it does not take
123  * into account bytes already buffered - that is up to the caller.
124  */
125 int
126 DelayId::bytesWanted(int minimum, int maximum) const
127 {
128  /* unlimited */
129 
130  if (! (*this) || markedAsNoDelay)
131  return max(minimum, maximum);
132 
133  /* limited */
134  int nbytes = max(minimum, maximum);
135 
136  if (compositeId != nullptr)
137  nbytes = compositeId->bytesWanted(minimum, nbytes);
138 
139  return nbytes;
140 }
141 
142 /*
143  * this records actual bytes received. always recorded, even if the
144  * class is disabled - it's more efficient to just do it than to do all
145  * the checks.
146  */
147 void
149 {
150  if (! (*this))
151  return;
152 
153  if (markedAsNoDelay)
154  return;
155 
156  assert ((unsigned short)(pool() - 1) != 0xFFFF);
157 
158  if (compositeId != nullptr)
159  compositeId->bytesIn(qty);
160 }
161 
162 void
164 {
165  assert (compositeId != nullptr);
166  compositeId->delayRead(aRead);
167 
168 }
169 
170 #endif /* USE_DELAY_POOLS */
171 
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:68
Ip::Address src_addr
unsigned short pool_
Definition: DelayId.h:41
unsigned short pool() const
Definition: DelayId.cc:47
bool operator==(DelayId const &rhs) const
Definition: DelayId.cc:53
virtual void delayRead(const AsyncCallPointer &)
DelayId()
Definition: DelayId.cc:28
int bytesWanted(int min, int max) const
Definition: DelayId.cc:126
const A & max(A const &lhs, A const &rhs)
struct SquidConfig::@97 onoff
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
C * getRaw() const
Definition: RefCount.h:89
bool markedAsNoDelay
Definition: DelayId.h:43
~DelayId()
Definition: DelayId.cc:37
void updateReply(const HttpReply::Pointer &)
virtual void bytesIn(int qty)=0
DelayIdComposite::Pointer compositePosition()
void bytesIn(int qty)
Definition: DelayId.cc:148
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:116
bool isNoAddr() const
Definition: Address.cc:304
void clientAclChecklistFill(ACLFilledChecklist &checklist, ClientHttpRequest *http)
static unsigned short pools()
Definition: delay_pools.cc:564
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:163
Ip::Address client_addr
Definition: HttpRequest.h:149
DelayIdComposite::Pointer compositeId
Definition: DelayId.h:42
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
String tag
Definition: HttpRequest.h:176
class SquidConfig Config
Definition: SquidConfig.cc:12
HttpRequest *const request

 

Introduction

Documentation

Support

Miscellaneous