DelayUser.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 
36 int
38 {
39  /* Verify for re-currance of Bug 2127. either of these missing will crash strcasecmp() */
40  assert(left->authUser->username() != NULL);
41  assert(right->authUser->username() != NULL);
42 
43  /* for rate limiting, case insensitive */
44  return strcasecmp(left->authUser->username(), right->authUser->username());
45 }
46 
47 void
49 {}
50 
53  explicit DelayUserStatsVisitor(StoreEntry *s) : se(s) {}
54  void operator() (DelayUserBucket::Pointer const &current) {
55  current->stats(se);
56  }
57 };
58 
59 void
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 
79 void
81 {
82  spec.dump(entry);
83 }
84 
86  DelayUserUpdater (DelaySpec &_spec, int _incr):spec(_spec),incr(_incr) {};
87 
89  int incr;
90 };
91 
94  DelayUserUpdateVisitor(DelayUserUpdater *updater) : t(updater) {}
95  void operator() (DelayUserBucket::Pointer const &current) {
96  const_cast<DelayUserBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr);
97  }
98 };
99 
100 void
102 {
103  DelayUserUpdater updater(spec, incr);
104  DelayUserUpdateVisitor visitor(&updater);
105  buckets.visit(visitor);
106 }
107 
108 void
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 = NULL;
132  debugs(77, 3, "DelayUserBucket::~DelayUserBucket");
133 }
134 
135 void
137 {
138  storeAppendPrintf(entry, " %s:", authUser->username());
139  theBucket.stats(entry);
140 }
141 
142 DelayUser::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 
161 int
163 {
164  return theBucket->theBucket.bytesWanted(min,max);
165 }
166 
167 void
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:19
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
DelayBucket theBucket
Definition: DelayUser.h:35
virtual void bytesIn(int qty)
Definition: DelayUser.cc:168
RefCount< DelayUser > theUser
Definition: DelayUser.h:69
virtual int bytesWanted(int min, int max) const
Definition: DelayUser.cc:162
DelayUserBucket::Pointer theBucket
Definition: DelayUser.h:70
Id(RefCount< DelayUser >, Auth::User::Pointer)
Definition: DelayUser.cc:142
virtual DelayIdComposite::Pointer id(CompositeSelectionDetails &)
Definition: DelayUser.cc:115
virtual void parse()
Definition: DelayUser.cc:109
virtual ~DelayUser()
Definition: DelayUser.cc:28
DelaySpec spec
Definition: DelayUser.h:75
friend class Id
Definition: DelayUser.h:73
Splay< DelayUserBucket::Pointer > buckets
Definition: DelayUser.h:76
virtual void dump(StoreEntry *entry) const
Definition: DelayUser.cc:80
virtual void stats(StoreEntry *sentry)
Definition: DelayUser.cc:60
virtual void update(int incr)
Definition: DelayUser.cc:101
C * getRaw() const
Definition: RefCount.h:80
Definition: splay.h:57
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:196
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:830
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:86
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors