/*
- * Copyright (C) 1996-2022 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 "base/InstanceId.h"
#include "base/TypeTraits.h"
#include "CachePeer.h"
+#include "CachePeers.h"
#include "carp.h"
#include "client_side.h"
#include "dns/LookupDetails.h"
os << hier_code_str[fsd.code];
if (fsd.peer)
- os << '/' << fsd.peer->host;
+ os << '/' << *fsd.peer;
else if (fsd.selector) // useful for DIRECT and gone PINNED destinations
os << '#' << fsd.selector->request->url.host();
if (entry) {
assert(entry->ping_status != PING_WAITING);
entry->unlock("peerSelect");
- entry = NULL;
+ entry = nullptr;
}
delete lastError;
Comm::ConnectionPointer p = new Comm::Connection();
p->remote = ip;
- p->remote.port(peer ? peer->http_port : request->url.port());
+ // XXX: We return a (non-peer) destination with a zero port if the selection
+ // initiator supplied a request target without a port. If there are no valid
+ // use cases for this behavior, stop _selecting_ such destinations.
+ p->remote.port(peer ? peer->http_port : request->url.port().value_or(0));
handlePath(p, *servers);
}
debugs(44, 3, "Unknown host: " << (fs->_peer.valid() ? fs->_peer->host : request->url.host()));
// discard any previous error.
delete lastError;
- lastError = NULL;
+ lastError = nullptr;
if (fs->code == HIER_DIRECT) {
lastError = new ErrorState(ERR_DNS_FAIL, Http::scServiceUnavailable, request, al);
lastError->dnsError = details.error;
p = whichPeer(closest_parent_miss);
- if (p == NULL)
+ if (p == nullptr)
return 0;
debugs(44, 3, "closest_parent_miss RTT = " << ping.p_rtt << " msec");
if (always_direct == ACCESS_DUNNO) {
debugs(44, 3, "direct = " << DirectStr[direct] << " (always_direct to be checked)");
/** check always_direct; */
- ACLFilledChecklist *ch = new ACLFilledChecklist(Config.accessList.AlwaysDirect, request, NULL);
+ ACLFilledChecklist *ch = new ACLFilledChecklist(Config.accessList.AlwaysDirect, request, nullptr);
ch->al = al;
acl_checklist = ch;
acl_checklist->syncAle(request, nullptr);
} else if (never_direct == ACCESS_DUNNO) {
debugs(44, 3, "direct = " << DirectStr[direct] << " (never_direct to be checked)");
/** check never_direct; */
- ACLFilledChecklist *ch = new ACLFilledChecklist(Config.accessList.NeverDirect, request, NULL);
+ ACLFilledChecklist *ch = new ACLFilledChecklist(Config.accessList.NeverDirect, request, nullptr);
ch->al = al;
acl_checklist = ch;
acl_checklist->syncAle(request, nullptr);
if (!entry || entry->ping_status == PING_NONE)
selectPinned();
- if (entry == NULL) {
+ if (entry == nullptr) {
(void) 0;
} else if (entry->ping_status == PING_NONE) {
selectSomeNeighbor();
void
PeerSelector::selectSomeNeighborReplies()
{
- CachePeer *p = NULL;
+ CachePeer *p = nullptr;
hier_code code = HIER_NONE;
assert(entry->ping_status == PING_WAITING);
assert(direct != DIRECT_YES);
void
PeerSelector::selectAllParents()
{
- CachePeer *p;
/* Add all alive parents */
- for (p = Config.peers; p; p = p->next) {
+ for (const auto &peer: CurrentCachePeers()) {
+ const auto p = peer.get();
/* XXX: neighbors.c lacks a public interface for enumerating
* parents to a request so we have to dig some here..
*/
* simply are not configured to handle the request.
*/
/* Add default parent as a last resort */
- if ((p = getDefaultParent(this))) {
+ if (const auto p = getDefaultParent(this)) {
addSelection(p, DEFAULT_PARENT);
}
}
PeerSelector::PeerSelector(PeerSelectionInitiator *initiator):
request(nullptr),
- entry (NULL),
+ entry (nullptr),
always_direct(Config.accessList.AlwaysDirect?ACCESS_DUNNO:ACCESS_DENIED),
never_direct(Config.accessList.NeverDirect?ACCESS_DUNNO:ACCESS_DENIED),
direct(DIRECT_UNKNOWN),
- lastError(NULL),
- servers (NULL),
+ lastError(nullptr),
+ servers (nullptr),
first_parent_miss(),
closest_parent_miss(),
- hit(NULL),
+ hit(nullptr),
hit_type(PEER_NONE),
- acl_checklist (NULL),
+ acl_checklist (nullptr),
initiator_(initiator)
{
; // no local defaults.