]> git.ipfire.org Git - thirdparty/squid.git/blob - src/CachePeers.cc
Bug 5428: Warn if pkg-config is not found (#1902)
[thirdparty/squid.git] / src / CachePeers.cc
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
33 CachePeers::remove(CachePeer * const peer)
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 &
43 CurrentCachePeers()
44 {
45 if (Config.peers)
46 return *Config.peers;
47
48 static const CachePeers empty;
49 return empty;
50 }
51
52 void
53 DeleteConfigured(CachePeer * const peer)
54 {
55 Assure(Config.peers);
56 Config.peers->remove(peer);
57 }
58