DelayId.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 "client_side_request.h"
19 #include "CommRead.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 
27 DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
28 {}
29 
30 DelayId::DelayId (unsigned short aPool) :
31  pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
32 {
33  debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
34 }
35 
37 {}
38 
39 void
41 {
42  compositeId = newPosition;
43 }
44 
45 unsigned short
47 {
48  return pool_;
49 }
50 
51 bool
52 DelayId::operator == (DelayId const &rhs) const
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 
60 DelayId::operator bool() const
61 {
62  return pool_ || compositeId.getRaw();
63 }
64 
65 /* create a delay Id for a given request */
66 DelayId
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 
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 
119 void
120 DelayId::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  */
129 int
130 DelayId::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 != NULL)
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  */
151 void
153 {
154  if (! (*this))
155  return;
156 
157  if (markedAsNoDelay)
158  return;
159 
160  assert ((unsigned short)(pool() - 1) != 0xFFFF);
161 
162  if (compositeId != NULL)
163  compositeId->bytesIn(qty);
164 }
165 
166 void
168 {
169  assert (compositeId != NULL);
170  compositeId->delayRead(aRead);
171 
172 }
173 
174 #endif /* USE_DELAY_POOLS */
175 
static DelayId DelayClient(ClientHttpRequest *, HttpReply *reply=nullptr)
Definition: DelayId.cc:67
Ip::Address src_addr
unsigned short pool_
Definition: DelayId.h:40
unsigned short pool() const
Definition: DelayId.cc:46
virtual void delayRead(DeferredRead const &)
bool operator==(DelayId const &rhs) const
Definition: DelayId.cc:52
DelayId()
Definition: DelayId.cc:27
int bytesWanted(int min, int max) const
Definition: DelayId.cc:130
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
C * getRaw() const
Definition: RefCount.h:80
Acl::Answer const & fastCheck()
Definition: Checklist.cc:336
bool markedAsNoDelay
Definition: DelayId.h:42
#define DBG_IMPORTANT
Definition: Debug.h:46
~DelayId()
Definition: DelayId.cc:36
A const & max(A const &lhs, A const &rhs)
virtual void bytesIn(int qty)=0
DelayIdComposite::Pointer compositePosition()
struct SquidConfig::@113 onoff
void bytesIn(int qty)
Definition: DelayId.cc:152
#define NULL
Definition: types.h:166
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:128
Ip::Address indirect_client_addr
Definition: HttpRequest.h:152
virtual int bytesWanted(int min, int max) const =0
#define assert(EX)
Definition: assert.h:19
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161
void delayRead(DeferredRead const &)
Definition: DelayId.cc:167
void setNoDelay(bool const)
Definition: DelayId.cc:120
bool isNoAddr() const
Definition: Address.cc:284
void clientAclChecklistFill(ACLFilledChecklist &checklist, ClientHttpRequest *http)
static unsigned short pools()
Definition: delay_pools.cc:564
bool allowed() const
Definition: Acl.h:143
static DelayPool * delay_data
Definition: DelayPools.h:46
int delay_pool_uses_indirect_client
Definition: SquidConfig.h:334
#define false
Definition: GnuRegex.c:233
Ip::Address client_addr
Definition: HttpRequest.h:149
DelayIdComposite::Pointer compositeId
Definition: DelayId.h:41
String tag
Definition: HttpRequest.h:176
class SquidConfig Config
Definition: SquidConfig.cc:12
HttpRequest *const request

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors