DelayUser.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
51 void
52 DelayUserStatsWalkee(DelayUserBucket::Pointer const &current, void *state)
53 {
54  current->stats ((StoreEntry *)state);
55 }
56 
59  explicit DelayUserStatsVisitor(StoreEntry *s) : se(s) {}
60  void operator() (DelayUserBucket::Pointer const &current) {
61  current->stats(se);
62  }
63 };
64 
65 void
67 {
68  spec.stats (sentry, "Per User");
69 
70  if (spec.restore_bps == -1)
71  return;
72 
73  storeAppendPrintf(sentry, "\t\tCurrent: ");
74 
75  if (buckets.empty()) {
76  storeAppendPrintf (sentry, "Not used yet.\n\n");
77  return;
78  }
79 
80  DelayUserStatsVisitor visitor(sentry);
81  buckets.visit(visitor);
82  storeAppendPrintf(sentry, "\n\n");
83 }
84 
85 void
87 {
88  spec.dump(entry);
89 }
90 
92  DelayUserUpdater (DelaySpec &_spec, int _incr):spec(_spec),incr(_incr) {};
93 
95  int incr;
96 };
97 
98 void
99 DelayUserUpdateWalkee(DelayUserBucket::Pointer const &current, void *state)
100 {
101  DelayUserUpdater *t = (DelayUserUpdater *)state;
102  /* This doesn't change the value of the DelayUserBucket, so is safe */
103  const_cast<DelayUserBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr);
104 }
105 
108  DelayUserUpdateVisitor(DelayUserUpdater *updater) : t(updater) {}
109  void operator() (DelayUserBucket::Pointer const &current) {
110  const_cast<DelayUserBucket *>(current.getRaw())->theBucket.update(t->spec, t->incr);
111  }
112 };
113 
114 void
116 {
117  DelayUserUpdater updater(spec, incr);
118  DelayUserUpdateVisitor visitor(&updater);
119  buckets.visit(visitor);
120 }
121 
122 void
124 {
125  spec.parse();
126 }
127 
130 {
131  if (!details.user || !details.user->user() || !details.user->user()->username())
132  return new NullDelayId;
133 
134  debugs(77, 3, HERE << "Adding a slow-down for User '" << details.user->user()->username() << "'");
135  return new Id(this, details.user->user());
136 }
137 
139 {
140  debugs(77, 3, "DelayUserBucket::DelayUserBucket");
141 }
142 
144 {
145  authUser = NULL;
146  debugs(77, 3, "DelayUserBucket::~DelayUserBucket");
147 }
148 
149 void
151 {
152  storeAppendPrintf(entry, " %s:", authUser->username());
153  theBucket.stats(entry);
154 }
155 
156 DelayUser::Id::Id(DelayUser::Pointer aDelayUser, Auth::User::Pointer aUser) : theUser(aDelayUser)
157 {
158  theBucket = new DelayUserBucket(aUser);
159  DelayUserBucket::Pointer const *existing = theUser->buckets.find(theBucket, DelayUserCmp);
160 
161  if (existing) {
162  theBucket = *existing;
163  return;
164  }
165 
167  theUser->buckets.insert (theBucket, DelayUserCmp);
168 }
169 
171 {
172  debugs(77, 3, "DelayUser::Id::~Id");
173 }
174 
175 int
177 {
178  return theBucket->theBucket.bytesWanted(min,max);
179 }
180 
181 void
183 {
184  theBucket->theBucket.bytesIn(qty);
185 }
186 
187 #endif /* USE_DELAY_POOLS && USE_AUTH */
188 
#define assert(EX)
Definition: assert.h:17
virtual void parse()
Definition: DelayUser.cc:123
DelayUserUpdateVisitor(DelayUserUpdater *updater)
Definition: DelayUser.cc:108
RefCount< DelayUser > theUser
Definition: DelayUser.h:69
DelaySpec spec
Definition: DelayUser.cc:92
static void deregisterForUpdates(Updateable *)
Definition: delay_pools.cc:515
DelayUserStatsVisitor(StoreEntry *s)
Definition: DelayUser.cc:59
void DelayUserUpdateWalkee(DelayUserBucket::Pointer const &current, void *state)
Definition: DelayUser.cc:99
Splay< DelayUserBucket::Pointer > buckets
Definition: DelayUser.h:76
Definition: splay.h:56
void DelayUserStatsWalkee(DelayUserBucket::Pointer const &current, void *state)
Definition: DelayUser.cc:52
void parse()
Definition: DelaySpec.cc:42
A const & max(A const &lhs, A const &rhs)
virtual void stats(StoreEntry *sentry)
Definition: DelayUser.cc:66
DelayBucket theBucket
Definition: DelayUser.h:35
virtual void update(int incr)
Definition: DelayUser.cc:115
static Splay< DelayUserBucket::Pointer >::SPLAYCMP DelayUserCmp
Definition: DelayUser.cc:34
virtual DelayIdComposite::Pointer id(CompositeSelectionDetails &)
Definition: DelayUser.cc:129
DelaySpec spec
Definition: DelayUser.h:75
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
int restore_bps
Definition: DelaySpec.h:23
virtual ~DelayUser()
Definition: DelayUser.cc:28
void stats(StoreEntry *sentry, char const *) const
Definition: DelaySpec.cc:23
DelayUserBucket::Pointer theBucket
Definition: DelayUser.h:70
StoreEntry * se
Definition: DelayUser.cc:58
Id(RefCount< DelayUser >, Auth::User::Pointer)
Definition: DelayUser.cc:156
void init(DelaySpec const &)
Definition: DelayBucket.cc:47
void stats(StoreEntry *) const
Definition: DelayBucket.cc:20
std::ostream & HERE(std::ostream &s)
Definition: Debug.h:147
void dump(StoreEntry *) const
Definition: DelaySpec.cc:36
Auth::User::Pointer authUser
Definition: DelayUser.h:36
void stats(StoreEntry *) const
Definition: DelayUser.cc:150
virtual User::Pointer user()
Definition: UserRequest.h:143
static Splay< DelayUserBucket::Pointer >::SPLAYFREE DelayUserFree
Definition: DelayUser.cc:26
virtual int bytesWanted(int min, int max) const
Definition: DelayUser.cc:176
void operator()(DelayUserBucket::Pointer const &current)
Definition: DelayUser.cc:109
virtual void bytesIn(int qty)
Definition: DelayUser.cc:182
DelayUserBucket(Auth::User::Pointer)
Definition: DelayUser.cc:138
void operator()(DelayUserBucket::Pointer const &current)
Definition: DelayUser.cc:60
DelayUserUpdater * t
Definition: DelayUser.cc:107
DelayUserUpdater(DelaySpec &_spec, int _incr)
Definition: DelayUser.cc:92
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:904
friend class Id
Definition: DelayUser.h:73
C * getRaw() const
Definition: RefCount.h:74
#define NULL
Definition: types.h:166
A const & min(A const &lhs, A const &rhs)
virtual void dump(StoreEntry *entry) const
Definition: DelayUser.cc:86
static void registerForUpdates(Updateable *)
Definition: delay_pools.cc:508

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors