]>
Commit | Line | Data |
---|---|---|
b67e2c8c | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
26ac0430 | 3 | * |
bbc27441 AJ |
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. | |
b67e2c8c | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 77 Delay Pools */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
b67e2c8c | 12 | |
454e8283 | 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 | */ | |
9a0a18de | 16 | #if USE_DELAY_POOLS |
c0941a6a | 17 | #include "acl/FilledChecklist.h" |
582c2af2 FC |
18 | #include "client_side_request.h" |
19 | #include "CommRead.h" | |
20 | #include "DelayId.h" | |
b67e2c8c | 21 | #include "DelayPool.h" |
582c2af2 | 22 | #include "DelayPools.h" |
3f3ba92f | 23 | #include "http/StreamContext.h" |
8000a965 | 24 | #include "HttpRequest.h" |
4d5904f7 | 25 | #include "SquidConfig.h" |
a46d2c0e | 26 | |
27 | DelayId::DelayId () : pool_ (0), compositeId(NULL), markedAsNoDelay(false) | |
62e76326 | 28 | {} |
b67e2c8c | 29 | |
62e76326 | 30 | DelayId::DelayId (unsigned short aPool) : |
f53969cc | 31 | pool_ (aPool), compositeId (NULL), markedAsNoDelay (false) |
b67e2c8c | 32 | { |
bf8fe701 | 33 | debugs(77, 3, "DelayId::DelayId: Pool " << aPool << "u"); |
b67e2c8c | 34 | } |
35 | ||
36 | DelayId::~DelayId () | |
62e76326 | 37 | {} |
b67e2c8c | 38 | |
39 | void | |
40 | DelayId::compositePosition(DelayIdComposite::Pointer newPosition) | |
41 | { | |
42 | compositeId = newPosition; | |
43 | } | |
44 | ||
45 | unsigned short | |
46 | DelayId::pool() const | |
47 | { | |
48 | return pool_; | |
49 | } | |
50 | ||
51 | bool | |
52 | DelayId::operator == (DelayId const &rhs) const | |
53 | { | |
54 | /* Doesn't compare composites properly.... | |
26ac0430 | 55 | * only use to test against default ID's |
b67e2c8c | 56 | */ |
57 | return pool_ == rhs.pool_ && compositeId == rhs.compositeId; | |
58 | } | |
59 | ||
62e76326 | 60 | DelayId::operator bool() const |
b67e2c8c | 61 | { |
62 | return pool_ || compositeId.getRaw(); | |
63 | } | |
64 | ||
7ec8c6a2 | 65 | /* create a delay Id for a given request */ |
b67e2c8c | 66 | DelayId |
c4a9875e | 67 | DelayId::DelayClient(ClientHttpRequest * http, HttpReply *reply) |
b67e2c8c | 68 | { |
190154cf | 69 | HttpRequest *r; |
b67e2c8c | 70 | unsigned short pool; |
71 | assert(http); | |
72 | r = http->request; | |
73 | ||
4dd643d5 | 74 | if (r->client_addr.isNoAddr()) { |
cc192b50 | 75 | debugs(77, 2, "delayClient: WARNING: Called with 'NO_ADDR' address, ignoring"); |
62e76326 | 76 | return DelayId(); |
b67e2c8c | 77 | } |
78 | ||
95dc7ff4 | 79 | for (pool = 0; pool < DelayPools::pools(); ++pool) { |
b50e327b AJ |
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 | ||
c0941a6a | 88 | ACLFilledChecklist ch(DelayPools::delay_data[pool].access, r, NULL); |
c4a9875e VL |
89 | if (reply) { |
90 | ch.reply = reply; | |
91 | HTTPMSGLOCK(reply); | |
92 | } | |
3d674977 | 93 | #if FOLLOW_X_FORWARDED_FOR |
26ac0430 AJ |
94 | if (Config.onoff.delay_pool_uses_indirect_client) |
95 | ch.src_addr = r->indirect_client_addr; | |
96 | else | |
97 | #endif /* FOLLOW_X_FORWARDED_FOR */ | |
98 | ch.src_addr = r->client_addr; | |
7ec8c6a2 | 99 | ch.my_addr = r->my_addr; |
62e76326 | 100 | |
4d3a24ca | 101 | if (http->getConn() != NULL) |
a2ac85d9 | 102 | ch.conn(http->getConn()); |
62e76326 | 103 | |
2efeb0b7 | 104 | if (DelayPools::delay_data[pool].theComposite().getRaw() && ch.fastCheck() == ACCESS_ALLOWED) { |
b50e327b | 105 | |
62e76326 | 106 | DelayId result (pool + 1); |
1e5562e3 | 107 | CompositePoolNode::CompositeSelectionDetails details; |
108 | details.src_addr = ch.src_addr; | |
79fc6915 | 109 | #if USE_AUTH |
1e5562e3 | 110 | details.user = r->auth_user_request; |
79fc6915 | 111 | #endif |
1e5562e3 | 112 | details.tag = r->tag; |
113 | result.compositePosition(DelayPools::delay_data[pool].theComposite()->id(details)); | |
62e76326 | 114 | return result; |
115 | } | |
7ec8c6a2 | 116 | } |
117 | ||
b67e2c8c | 118 | return DelayId(); |
119 | } | |
120 | ||
a46d2c0e | 121 | void |
122 | DelayId::setNoDelay(bool const newValue) | |
123 | { | |
124 | markedAsNoDelay = newValue; | |
125 | } | |
126 | ||
b67e2c8c | 127 | /* |
128 | * this returns the number of bytes the client is permitted. it does not take | |
129 | * into account bytes already buffered - that is up to the caller. | |
130 | */ | |
131 | int | |
a748a390 | 132 | DelayId::bytesWanted(int minimum, int maximum) const |
b67e2c8c | 133 | { |
134 | /* unlimited */ | |
62e76326 | 135 | |
a46d2c0e | 136 | if (! (*this) || markedAsNoDelay) |
a748a390 | 137 | return max(minimum, maximum); |
62e76326 | 138 | |
b67e2c8c | 139 | /* limited */ |
a748a390 | 140 | int nbytes = max(minimum, maximum); |
62e76326 | 141 | |
4d3a24ca | 142 | if (compositeId != NULL) |
a748a390 | 143 | nbytes = compositeId->bytesWanted(minimum, nbytes); |
62e76326 | 144 | |
b67e2c8c | 145 | return nbytes; |
146 | } | |
147 | ||
148 | /* | |
2324cda2 | 149 | * this records actual bytes received. always recorded, even if the |
b67e2c8c | 150 | * class is disabled - it's more efficient to just do it than to do all |
151 | * the checks. | |
152 | */ | |
153 | void | |
154 | DelayId::bytesIn(int qty) | |
155 | { | |
156 | if (! (*this)) | |
62e76326 | 157 | return; |
b67e2c8c | 158 | |
a46d2c0e | 159 | if (markedAsNoDelay) |
160 | return; | |
161 | ||
e4a67a80 | 162 | assert ((unsigned short)(pool() - 1) != 0xFFFF); |
b67e2c8c | 163 | |
4d3a24ca | 164 | if (compositeId != NULL) |
62e76326 | 165 | compositeId->bytesIn(qty); |
b67e2c8c | 166 | } |
62e76326 | 167 | |
a46d2c0e | 168 | void |
169 | DelayId::delayRead(DeferredRead const &aRead) | |
170 | { | |
4d3a24ca | 171 | assert (compositeId != NULL); |
a46d2c0e | 172 | compositeId->delayRead(aRead); |
b67e2c8c | 173 | |
a46d2c0e | 174 | } |
454e8283 | 175 | |
9a0a18de | 176 | #endif /* USE_DELAY_POOLS */ |
f53969cc | 177 |