Squid Web Cache master
Loading...
Searching...
No Matches
CachePeer.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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 "acl/Gadgets.h"
12#include "CachePeer.h"
13#include "defines.h"
14#include "neighbors.h"
16#include "pconn.h"
17#include "PeerDigest.h"
18#include "PeerPoolMgr.h"
19#include "sbuf/Stream.h"
20#include "SquidConfig.h"
21#include "util.h"
22
24
25CachePeer::CachePeer(const char * const hostname):
26 name(xstrdup(hostname)),
27 host(xstrdup(hostname)),
28 tlsContext(secure, sslContext),
29 probeCodeContext(new PrecomputedCodeContext("cache_peer probe", ToSBuf("current cache_peer probe: ", *this)))
30{
31 Tolower(host); // but .name preserves original spelling
32}
33
35{
36 xfree(name);
37 xfree(host);
38
39 while (NeighborTypeDomainList *l = typelist) {
40 typelist = l->next;
41 xfree(l->domain);
42 xfree(l);
43 }
44
46
47#if USE_CACHE_DIGESTS
48 delete digest;
50#endif
51
52 xfree(login);
53
54 delete standby.pool;
55
56 // the mgr job will notice that its owner is gone and stop
57 PeerPoolMgr::Checkpoint(standby.mgr, "peer gone");
58
60}
61
64{
66 return &tlsContext;
67 return nullptr;
68}
69
70void
72{
73 if (!tcp_up) {
74 debugs(15, 2, "connection to " << *this << " succeeded");
75 tcp_up = connect_fail_limit; // NP: so peerAlive() works properly.
76 peerAlive(this);
77 } else {
79 }
80}
81
82// TODO: Require callers to detail failures instead of using one (and often
83// misleading!) "connection failed" phrase for all of them.
85void
87{
88 stats.last_connect_failure = squid_curtime;
89 if (tcp_up > 0)
90 --tcp_up;
91
92 const auto consideredAliveByAdmin = (stats.logged_state == PEER_ALIVE);
93 const auto level = consideredAliveByAdmin ? DBG_IMPORTANT : 2;
94 debugs(15, level, "ERROR: Connection to " << *this << " failed");
95
96 if (consideredAliveByAdmin) {
97 if (!tcp_up) {
98 debugs(15, DBG_IMPORTANT, "Detected DEAD " << neighborTypeStr(this) << ": " << name);
99 stats.logged_state = PEER_DEAD;
100 } else {
101 debugs(15, 2, "additional failures needed to mark this cache_peer DEAD: " << tcp_up);
102 }
103 } else {
104 assert(!tcp_up);
105 debugs(15, 2, "cache_peer " << *this << " is still DEAD");
106 }
107}
108
109void
110CachePeer::rename(const char * const newName)
111{
112 if (!newName || !*newName)
113 throw TextException("cache_peer name=value cannot be empty", Here());
114
115 xfree(name);
116 name = xstrdup(newName);
117}
118
119time_t
126
127std::ostream &
128operator <<(std::ostream &os, const CachePeer &p)
129{
130 return os << p.name;
131}
132
std::ostream & operator<<(std::ostream &os, const CachePeer &p)
identify the given cache peer in cache.log messages and such
Definition CachePeer.cc:128
#define Here()
source code location of the caller
Definition Here.h:15
time_t squid_curtime
class SquidConfig Config
#define assert(EX)
Definition assert.h:17
#define CBDATA_CLASS_INIT(type)
Definition cbdata.h:325
acl_access * access
Definition CachePeer.h:106
CachePeer(const char *hostname)
Definition CachePeer.cc:25
void noteSuccess()
reacts to a successful establishment of a connection to this cache_peer
Definition CachePeer.cc:71
Security::FuturePeerContext * securityContext()
Definition CachePeer.cc:63
NeighborTypeDomainList * typelist
Definition CachePeer.h:105
char * login
Definition CachePeer.h:202
char * host
Definition CachePeer.h:66
Security::PeerOptions secure
security settings for peer connection
Definition CachePeer.h:219
time_t connect_timeout_raw
connect_timeout; use connectTimeout() instead!
Definition CachePeer.h:203
struct CachePeer::@18 stats
char * domain
Forced domain.
Definition CachePeer.h:215
Security::FuturePeerContext tlsContext
Definition CachePeer.h:221
PeerDigest * digest
Definition CachePeer.h:167
struct CachePeer::@25 standby
optional "cache_peer standby=limit" feature
int connect_fail_limit
Definition CachePeer.h:204
time_t connectTimeout() const
Definition CachePeer.cc:120
void noteFailure()
reacts to a failed attempt to establish a connection to this cache_peer
Definition CachePeer.cc:86
void rename(const char *)
(re)configure cache_peer name=value
Definition CachePeer.cc:110
char * name
Definition CachePeer.h:61
char * digest_url
Definition CachePeer.h:168
representation of a neighbor_type_domain configuration directive. A POD
NeighborTypeDomainList * next
static void Checkpoint(const Pointer &mgr, const char *reason)
CodeContext with constant details known at construction time.
A combination of PeerOptions and the corresponding Context.
bool encryptTransport
whether transport encryption (TLS/SSL) is to be used on connections to the peer
time_t peer_connect
struct SquidConfig::@77 Timeout
an std::runtime_error with thrower location info
#define DBG_IMPORTANT
Definition Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define PEER_ALIVE
Definition defines.h:84
#define PEER_DEAD
Definition defines.h:83
void aclDestroyAccessList(acl_access **list)
Definition Gadgets.cc:223
#define xfree
#define xstrdup
void peerAlive(CachePeer *p)
Definition neighbors.cc:450
const char * neighborTypeStr(const CachePeer *p)
Definition neighbors.cc:84
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition Stream.h:63
void Tolower(char *)
Definition util.cc:28