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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors