]> git.ipfire.org Git - thirdparty/squid.git/blob - src/DelayId.cc
sourceformat: split protos.h into more specific headers, change many functions' likag...
[thirdparty/squid.git] / src / DelayId.cc
1
2 /*
3 * DEBUG: section 77 Delay Pools
4 * AUTHOR: Robert Collins <robertc@squid-cache.org>
5 * Based upon original delay pools code by
6 * David Luyer <david@luyer.net>
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
19 *
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 *
35 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 */
37
38 #include "squid.h"
39
40 /* MS Visual Studio Projects are monolithic, so we need the following
41 * #if to exclude the delay pools code from compile process when not needed.
42 */
43 #if USE_DELAY_POOLS
44 #include "acl/FilledChecklist.h"
45 #include "client_side_request.h"
46 #include "CommRead.h"
47 #include "DelayId.h"
48 #include "DelayPool.h"
49 #include "DelayPools.h"
50 #include "HttpRequest.h"
51 #include "SquidConfig.h"
52
53 DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false)
54 {}
55
56 DelayId::DelayId (unsigned short aPool) :
57 pool_ (aPool), compositeId (NULL), markedAsNoDelay (false)
58 {
59 debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u");
60 }
61
62 DelayId::~DelayId ()
63 {}
64
65 void
66 DelayId::compositePosition(DelayIdComposite::Pointer newPosition)
67 {
68 compositeId = newPosition;
69 }
70
71 unsigned short
72 DelayId::pool() const
73 {
74 return pool_;
75 }
76
77 bool
78 DelayId::operator == (DelayId const &rhs) const
79 {
80 /* Doesn't compare composites properly....
81 * only use to test against default ID's
82 */
83 return pool_ == rhs.pool_ && compositeId == rhs.compositeId;
84 }
85
86 DelayId::operator bool() const
87 {
88 return pool_ || compositeId.getRaw();
89 }
90
91 /* create a delay Id for a given request */
92 DelayId
93 DelayId::DelayClient(ClientHttpRequest * http)
94 {
95 HttpRequest *r;
96 unsigned short pool;
97 assert(http);
98 r = http->request;
99
100 if (r->client_addr.IsNoAddr()) {
101 debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring");
102 return DelayId();
103 }
104
105 for (pool = 0; pool < DelayPools::pools(); ++pool) {
106
107 /* pools require explicit 'allow' to assign a client into them */
108 if (!DelayPools::delay_data[pool].access) {
109 debugs(77, DBG_IMPORTANT, "delay_pool " << pool <<
110 " has no delay_access configured. This means that no clients will ever use it.");
111 continue;
112 }
113
114 ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, NULL);
115 #if FOLLOW_X_FORWARDED_FOR
116 if (Config.onoff.delay_pool_uses_indirect_client)
117 ch.src_addr = r->indirect_client_addr;
118 else
119 #endif /* FOLLOW_X_FORWARDED_FOR */
120 ch.src_addr = r->client_addr;
121 ch.my_addr = r->my_addr;
122
123 if (http->getConn() != NULL)
124 ch.conn(http->getConn());
125
126 if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck() == ACCESS_ALLOWED) {
127
128 DelayId result (pool + 1);
129 CompositePoolNode::CompositeSelectionDetails details;
130 details.src_addr = ch.src_addr;
131 #if USE_AUTH
132 details.user = r->auth_user_request;
133 #endif
134 details.tag = r->tag;
135 result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details));
136 return result;
137 }
138 }
139
140 return DelayId();
141 }
142
143 void
144 DelayId::setNoDelay(bool const newValue)
145 {
146 markedAsNoDelay = newValue;
147 }
148
149 /*
150 * this returns the number of bytes the client is permitted. it does not take
151 * into account bytes already buffered - that is up to the caller.
152 */
153 int
154 DelayId::bytesWanted(int minimum, int maximum) const
155 {
156 /* unlimited */
157
158 if (! (*this) || markedAsNoDelay)
159 return max(minimum, maximum);
160
161 /* limited */
162 int nbytes = max(minimum, maximum);
163
164 if (compositeId != NULL)
165 nbytes = compositeId->bytesWanted(minimum, nbytes);
166
167 return nbytes;
168 }
169
170 /*
171 * this records actual bytes received. always recorded, even if the
172 * class is disabled - it's more efficient to just do it than to do all
173 * the checks.
174 */
175 void
176 DelayId::bytesIn(int qty)
177 {
178 if (! (*this))
179 return;
180
181 if (markedAsNoDelay)
182 return;
183
184 assert ((unsigned short)(pool() - 1) != 0xFFFF);
185
186 if (compositeId != NULL)
187 compositeId->bytesIn(qty);
188 }
189
190 void
191 DelayId::delayRead(DeferredRead const &aRead)
192 {
193 assert (compositeId != NULL);
194 compositeId->delayRead(aRead);
195
196 }
197
198 #endif /* USE_DELAY_POOLS */