]>
Commit | Line | Data |
---|---|---|
88a03fda | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 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. | |
88a03fda | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 77 Delay Pools */ |
10 | ||
f7f3304a | 11 | #include "squid.h" |
88a03fda | 12 | |
79fc6915 | 13 | #if USE_DELAY_POOLS && USE_AUTH |
2d2b0bb7 | 14 | #include "auth/User.h" |
582c2af2 | 15 | #include "auth/UserRequest.h" |
1b76e6c1 | 16 | #include "comm/Connection.h" |
582c2af2 | 17 | #include "DelayUser.h" |
88a03fda | 18 | #include "NullDelayId.h" |
19 | #include "Store.h" | |
20 | ||
88a03fda | 21 | DelayUser::DelayUser() |
22 | { | |
23 | DelayPools::registerForUpdates (this); | |
24 | } | |
25 | ||
1a005c0e | 26 | static Splay<DelayUserBucket::Pointer>::SPLAYFREE DelayUserFree; |
29b17d63 | 27 | |
88a03fda | 28 | DelayUser::~DelayUser() |
29 | { | |
30 | DelayPools::deregisterForUpdates (this); | |
d6349cfb | 31 | buckets.destroy(DelayUserFree); |
29b17d63 | 32 | } |
33 | ||
1a005c0e | 34 | static Splay<DelayUserBucket::Pointer>::SPLAYCMP DelayUserCmp; |
29b17d63 | 35 | |
36 | int | |
37 | DelayUserCmp(DelayUserBucket::Pointer const &left, DelayUserBucket::Pointer const &right) | |
38 | { | |
98e025e1 | 39 | /* Verify for re-currance of Bug 2127. either of these missing will crash strcasecmp() */ |
aee3523a AR |
40 | assert(left->authUser->username() != nullptr); |
41 | assert(right->authUser->username() != nullptr); | |
98e025e1 | 42 | |
29b17d63 | 43 | /* for rate limiting, case insensitive */ |
44 | return strcasecmp(left->authUser->username(), right->authUser->username()); | |
45 | } | |
46 | ||
47 | void | |
48 | DelayUserFree(DelayUserBucket::Pointer &) | |
62e76326 | 49 | {} |
29b17d63 | 50 | |
d6349cfb FC |
51 | struct DelayUserStatsVisitor { |
52 | StoreEntry *se; | |
53 | explicit DelayUserStatsVisitor(StoreEntry *s) : se(s) {} | |
54 | void operator() (DelayUserBucket::Pointer const ¤t) { | |
55 | current->stats(se); | |
56 | } | |
57 | }; | |
58 | ||
88a03fda | 59 | void |
60 | DelayUser::stats(StoreEntry * sentry) | |
61 | { | |
62 | spec.stats (sentry, "Per User"); | |
62e76326 | 63 | |
88a03fda | 64 | if (spec.restore_bps == -1) |
62e76326 | 65 | return; |
66 | ||
88a03fda | 67 | storeAppendPrintf(sentry, "\t\tCurrent: "); |
62e76326 | 68 | |
d6349cfb | 69 | if (buckets.empty()) { |
62e76326 | 70 | storeAppendPrintf (sentry, "Not used yet.\n\n"); |
71 | return; | |
88a03fda | 72 | } |
62e76326 | 73 | |
d6349cfb FC |
74 | DelayUserStatsVisitor visitor(sentry); |
75 | buckets.visit(visitor); | |
88a03fda | 76 | storeAppendPrintf(sentry, "\n\n"); |
77 | } | |
78 | ||
79 | void | |
80 | DelayUser::dump(StoreEntry *entry) const | |
81 | { | |
82 | spec.dump(entry); | |
83 | } | |
84 | ||
26ac0430 AJ |
85 | struct DelayUserUpdater { |
86 | DelayUserUpdater (DelaySpec &_spec, int _incr):spec(_spec),incr(_incr) {}; | |
62e76326 | 87 | |
29b17d63 | 88 | DelaySpec spec; |
89 | int incr; | |
90 | }; | |
62e76326 | 91 | |
d6349cfb FC |
92 | struct DelayUserUpdateVisitor { |
93 | DelayUserUpdater *t; | |
94 | DelayUserUpdateVisitor(DelayUserUpdater *updater) : t(updater) {} | |
95 | void operator() (DelayUserBucket::Pointer const ¤t) { | |
96 | const_cast<DelayUserBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr); | |
97 | } | |
98 | }; | |
99 | ||
88a03fda | 100 | void |
101 | DelayUser::update(int incr) | |
102 | { | |
29b17d63 | 103 | DelayUserUpdater updater(spec, incr); |
d6349cfb FC |
104 | DelayUserUpdateVisitor visitor(&updater); |
105 | buckets.visit(visitor); | |
88a03fda | 106 | } |
107 | ||
108 | void | |
109 | DelayUser::parse() | |
110 | { | |
111 | spec.parse(); | |
112 | } | |
113 | ||
114 | DelayIdComposite::Pointer | |
1e5562e3 | 115 | DelayUser::id(CompositePoolNode::CompositeSelectionDetails &details) |
88a03fda | 116 | { |
98e025e1 | 117 | if (!details.user || !details.user->user() || !details.user->user()->username()) |
62e76326 | 118 | return new NullDelayId; |
119 | ||
bf95c10a | 120 | debugs(77, 3, "Adding a slow-down for User '" << details.user->user()->username() << "'"); |
f5691f9c | 121 | return new Id(this, details.user->user()); |
88a03fda | 122 | } |
123 | ||
d87154ee | 124 | DelayUserBucket::DelayUserBucket(Auth::User::Pointer aUser) : authUser(aUser) |
88a03fda | 125 | { |
bf8fe701 | 126 | debugs(77, 3, "DelayUserBucket::DelayUserBucket"); |
88a03fda | 127 | } |
128 | ||
129 | DelayUserBucket::~DelayUserBucket() | |
130 | { | |
aee3523a | 131 | authUser = nullptr; |
bf8fe701 | 132 | debugs(77, 3, "DelayUserBucket::~DelayUserBucket"); |
88a03fda | 133 | } |
134 | ||
135 | void | |
136 | DelayUserBucket::stats (StoreEntry *entry) const | |
137 | { | |
138 | storeAppendPrintf(entry, " %s:", authUser->username()); | |
56a49fda | 139 | theBucket.stats(entry); |
88a03fda | 140 | } |
141 | ||
d87154ee | 142 | DelayUser::Id::Id(DelayUser::Pointer aDelayUser, Auth::User::Pointer aUser) : theUser(aDelayUser) |
88a03fda | 143 | { |
88a03fda | 144 | theBucket = new DelayUserBucket(aUser); |
29b17d63 | 145 | DelayUserBucket::Pointer const *existing = theUser->buckets.find(theBucket, DelayUserCmp); |
62e76326 | 146 | |
29b17d63 | 147 | if (existing) { |
62e76326 | 148 | theBucket = *existing; |
149 | return; | |
29b17d63 | 150 | } |
62e76326 | 151 | |
88a03fda | 152 | theBucket->theBucket.init(theUser->spec); |
d6349cfb | 153 | theUser->buckets.insert (theBucket, DelayUserCmp); |
88a03fda | 154 | } |
155 | ||
156 | DelayUser::Id::~Id() | |
157 | { | |
bf8fe701 | 158 | debugs(77, 3, "DelayUser::Id::~Id"); |
88a03fda | 159 | } |
160 | ||
161 | int | |
162 | DelayUser::Id::bytesWanted (int min, int max) const | |
163 | { | |
164 | return theBucket->theBucket.bytesWanted(min,max); | |
165 | } | |
166 | ||
167 | void | |
168 | DelayUser::Id::bytesIn(int qty) | |
169 | { | |
170 | theBucket->theBucket.bytesIn(qty); | |
171 | } | |
62e76326 | 172 | |
79fc6915 | 173 | #endif /* USE_DELAY_POOLS && USE_AUTH */ |
f53969cc | 174 |