/*
- * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "squid.h"
#include "CachePeer.h"
+#include "CachePeers.h"
#include "HttpRequest.h"
#include "mgr/Registration.h"
#include "neighbors.h"
#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
static int n_sourcehash_peers = 0;
-static CachePeer **sourcehash_peers = NULL;
+static CachePeer **sourcehash_peers = nullptr;
static OBJH peerSourceHashCachemgr;
static void peerSourceHashRegisterWithCacheManager(void);
int K;
int k;
double P_last, X_last, Xn;
- CachePeer *p;
- CachePeer **P;
char *t;
/* Clean up */
n_sourcehash_peers = 0;
/* find out which peers we have */
- for (p = Config.peers; p; p = p->next) {
+ for (const auto &p: CurrentCachePeers()) {
if (!p->options.sourcehash)
continue;
sourcehash_peers = (CachePeer **)xcalloc(n_sourcehash_peers, sizeof(*sourcehash_peers));
+ auto P = sourcehash_peers;
/* Build a list of the found peers and calculate hashes and load factors */
- for (P = sourcehash_peers, p = Config.peers; p; p = p->next) {
+ for (const auto &peer: CurrentCachePeers()) {
+ const auto p = peer.get();
+
if (!p->options.sourcehash)
continue;
for (k = 1; k <= K; ++k) {
double Kk1 = (double) (K - k + 1);
- p = sourcehash_peers[k - 1];
+ const auto p = sourcehash_peers[k - 1];
p->sourcehash.load_multiplier = (Kk1 * (p->sourcehash.load_factor - P_last)) / Xn;
p->sourcehash.load_multiplier += pow(X_last, Kk1);
p->sourcehash.load_multiplier = pow(p->sourcehash.load_multiplier, 1.0 / Kk1);
{
int k;
const char *c;
- CachePeer *p = NULL;
+ CachePeer *p = nullptr;
CachePeer *tp;
unsigned int user_hash = 0;
unsigned int combined_hash;
double score;
double high_score = 0;
- const char *key = NULL;
+ const char *key = nullptr;
char ntoabuf[MAX_IPSTRLEN];
if (n_sourcehash_peers == 0)
- return NULL;
+ return nullptr;
assert(ps);
HttpRequest *request = ps->request;
combined_hash += combined_hash * 0x62531965;
combined_hash = ROTATE_LEFT(combined_hash, 21);
score = combined_hash * tp->sourcehash.load_multiplier;
- debugs(39, 3, "peerSourceHashSelectParent: " << tp->name << " combined_hash " << combined_hash <<
+ debugs(39, 3, *tp << " combined_hash " << combined_hash <<
" score " << std::setprecision(0) << score);
if ((score > high_score) && peerHTTPOkay(tp, ps)) {
}
if (p)
- debugs(39, 2, "peerSourceHashSelectParent: selected " << p->name);
+ debugs(39, 2, "selected " << *p);
return p;
}
static void
peerSourceHashCachemgr(StoreEntry * sentry)
{
- CachePeer *p;
int sumfetches = 0;
storeAppendPrintf(sentry, "%24s %10s %10s %10s %10s\n",
"Hostname",
"Factor",
"Actual");
- for (p = Config.peers; p; p = p->next)
+ for (const auto &p: CurrentCachePeers())
sumfetches += p->stats.fetches;
- for (p = Config.peers; p; p = p->next) {
+ for (const auto &p: CurrentCachePeers()) {
storeAppendPrintf(sentry, "%24s %10x %10f %10f %10f\n",
p->name, p->sourcehash.hash,
p->sourcehash.load_multiplier,