CachePeers.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 #include "squid.h"
10 #include "CachePeers.h"
11 #include "SquidConfig.h"
12 
13 #include <algorithm>
14 
15 CachePeer &
16 CachePeers::nextPeerToPing(const size_t pollIndex)
17 {
18  Assure(size());
19 
20  // Remember the number of polls to keep shifting each poll starting point,
21  // to avoid always polling the same group of peers before other peers and
22  // risk overloading that first group with requests.
23  if (!pollIndex)
24  ++peerPolls_;
25 
26  // subtract 1 to set the very first pos to zero
27  const auto pos = (peerPolls_ - 1 + pollIndex) % size();
28 
29  return *storage[pos];
30 }
31 
32 void
34 {
35  const auto pos = std::find_if(storage.begin(), storage.end(), [&](const auto &storePeer) {
36  return storePeer.get() == peer;
37  });
38  Assure(pos != storage.end());
39  storage.erase(pos);
40 }
41 
42 const CachePeers &
44 {
45  if (Config.peers)
46  return *Config.peers;
47 
48  static const CachePeers empty;
49  return empty;
50 }
51 
52 void
54 {
56  Config.peers->remove(peer);
57 }
58 
uint64_t peerPolls_
total number of completed peer scans by nextPeerToPing()-calling code
Definition: CachePeers.h:50
Storage storage
cache_peers in configuration/parsing order
Definition: CachePeers.h:47
void remove(CachePeer *)
deletes a previously add()ed CachePeer object
Definition: CachePeers.cc:33
CachePeer & nextPeerToPing(size_t iteration)
Definition: CachePeers.cc:16
CachePeers * peers
Definition: SquidConfig.h:247
#define Assure(condition)
Definition: Assure.h:35
cache_peer configuration storage
Definition: CachePeers.h:20
auto size() const
the number of currently stored (i.e. added and not removed) cache_peers
Definition: CachePeers.h:33
const CachePeers & CurrentCachePeers()
Definition: CachePeers.cc:43
void DeleteConfigured(CachePeer *const peer)
destroys the given peer after removing it from the set of configured peers
Definition: CachePeers.cc:53
class SquidConfig Config
Definition: SquidConfig.cc:12

 

Introduction

Documentation

Support

Miscellaneous