DelayUser.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#if USE_DELAY_POOLS && USE_AUTH
14#include "auth/User.h"
15#include "auth/UserRequest.h"
16#include "comm/Connection.h"
17#include "DelayUser.h"
18#include "NullDelayId.h"
19#include "Store.h"
20
22{
24}
25
27
29{
31 buckets.destroy(DelayUserFree);
32}
33
35
36int
38{
39 /* Verify for re-currance of Bug 2127. either of these missing will crash strcasecmp() */
40 assert(left->authUser->username() != nullptr);
41 assert(right->authUser->username() != nullptr);
42
43 /* for rate limiting, case insensitive */
44 return strcasecmp(left->authUser->username(), right->authUser->username());
45}
46
47void
49{}
50
53 explicit DelayUserStatsVisitor(StoreEntry *s) : se(s) {}
55 current->stats(se);
56 }
57};
58
59void
61{
62 spec.stats (sentry, "Per User");
63
64 if (spec.restore_bps == -1)
65 return;
66
67 storeAppendPrintf(sentry, "\t\tCurrent: ");
68
69 if (buckets.empty()) {
70 storeAppendPrintf (sentry, "Not used yet.\n\n");
71 return;
72 }
73
74 DelayUserStatsVisitor visitor(sentry);
75 buckets.visit(visitor);
76 storeAppendPrintf(sentry, "\n\n");
77}
78
79void
81{
82 spec.dump(entry);
83}
84
86 DelayUserUpdater (DelaySpec &_spec, int _incr):spec(_spec),incr(_incr) {};
87
89 int incr;
90};
91
96 const_cast<DelayUserBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr);
97 }
98};
99
100void
102{
103 DelayUserUpdater updater(spec, incr);
104 DelayUserUpdateVisitor visitor(&updater);
105 buckets.visit(visitor);
106}
107
108void
110{
111 spec.parse();
112}
113
116{
117 if (!details.user || !details.user->user() || !details.user->user()->username())
118 return new NullDelayId;
119
120 debugs(77, 3, "Adding a slow-down for User '" << details.user->user()->username() << "'");
121 return new Id(this, details.user->user());
122}
123
125{
126 debugs(77, 3, "DelayUserBucket::DelayUserBucket");
127}
128
130{
131 authUser = nullptr;
132 debugs(77, 3, "DelayUserBucket::~DelayUserBucket");
133}
134
135void
137{
138 storeAppendPrintf(entry, " %s:", authUser->username());
139 theBucket.stats(entry);
140}
141
142DelayUser::Id::Id(DelayUser::Pointer aDelayUser, Auth::User::Pointer aUser) : theUser(aDelayUser)
143{
144 theBucket = new DelayUserBucket(aUser);
146
147 if (existing) {
148 theBucket = *existing;
149 return;
150 }
151
154}
155
157{
158 debugs(77, 3, "DelayUser::Id::~Id");
159}
160
161int
163{
164 return theBucket->theBucket.bytesWanted(min,max);
165}
166
167void
169{
170 theBucket->theBucket.bytesIn(qty);
171}
172
173#endif /* USE_DELAY_POOLS && USE_AUTH */
174
static Splay< DelayUserBucket::Pointer >::SPLAYFREE DelayUserFree
Definition: DelayUser.cc:26
static Splay< DelayUserBucket::Pointer >::SPLAYCMP DelayUserCmp
Definition: DelayUser.cc:34
#define assert(EX)
Definition: assert.h:17
virtual User::Pointer user()
Definition: UserRequest.h:143
void init(DelaySpec const &)
Definition: DelayBucket.cc:47
void stats(StoreEntry *) const
Definition: DelayBucket.cc:20
static void deregisterForUpdates(Updateable *)
Definition: delay_pools.cc:515
static void registerForUpdates(Updateable *)
Definition: delay_pools.cc:508
int restore_bps
Definition: DelaySpec.h:23
void parse()
Definition: DelaySpec.cc:42
void dump(StoreEntry *) const
Definition: DelaySpec.cc:36
void stats(StoreEntry *sentry, char const *) const
Definition: DelaySpec.cc:23
Auth::User::Pointer authUser
Definition: DelayUser.h:36
DelayUserBucket(Auth::User::Pointer)
Definition: DelayUser.cc:124
void stats(StoreEntry *) const
Definition: DelayUser.cc:136
~DelayUserBucket() override
Definition: DelayUser.cc:129
DelayBucket theBucket
Definition: DelayUser.h:35
~Id() override
Definition: DelayUser.cc:156
int bytesWanted(int min, int max) const override
Definition: DelayUser.cc:162
RefCount< DelayUser > theUser
Definition: DelayUser.h:69
void bytesIn(int qty) override
Definition: DelayUser.cc:168
DelayUserBucket::Pointer theBucket
Definition: DelayUser.h:70
Id(RefCount< DelayUser >, Auth::User::Pointer)
Definition: DelayUser.cc:142
void dump(StoreEntry *entry) const override
Definition: DelayUser.cc:80
void update(int incr) override
Definition: DelayUser.cc:101
DelaySpec spec
Definition: DelayUser.h:75
friend class Id
Definition: DelayUser.h:73
void parse() override
Definition: DelayUser.cc:109
void stats(StoreEntry *sentry) override
Definition: DelayUser.cc:60
~DelayUser() override
Definition: DelayUser.cc:28
Splay< DelayUserBucket::Pointer > buckets
Definition: DelayUser.h:76
DelayIdComposite::Pointer id(CompositeSelectionDetails &) override
Definition: DelayUser.cc:115
C * getRaw() const
Definition: RefCount.h:89
Definition: splay.h:50
A const & max(A const &lhs, A const &rhs)
A const & min(A const &lhs, A const &rhs)
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:841
void operator()(DelayUserBucket::Pointer const &current)
Definition: DelayUser.cc:54
DelayUserStatsVisitor(StoreEntry *s)
Definition: DelayUser.cc:53
StoreEntry * se
Definition: DelayUser.cc:52
DelayUserUpdateVisitor(DelayUserUpdater *updater)
Definition: DelayUser.cc:94
void operator()(DelayUserBucket::Pointer const &current)
Definition: DelayUser.cc:95
DelayUserUpdater * t
Definition: DelayUser.cc:93
DelayUserUpdater(DelaySpec &_spec, int _incr)
Definition: DelayUser.cc:86
DelaySpec spec
Definition: DelayUser.cc:88

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors