CachePeer.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 "acl/Gadgets.h"
12 #include "CachePeer.h"
13 #include "defines.h"
14 #include "neighbors.h"
15 #include "NeighborTypeDomainList.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 
25 CachePeer::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 
59  xfree(domain);
60 }
61 
64 {
66  return &tlsContext;
67  return nullptr;
68 }
69 
70 void
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.
85 void
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 
109 void
110 CachePeer::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 
119 time_t
121 {
122  if (connect_timeout_raw > 0)
123  return connect_timeout_raw;
124  return Config.Timeout.peer_connect;
125 }
126 
127 std::ostream &
128 operator <<(std::ostream &os, const CachePeer &p)
129 {
130  return os << p.name;
131 }
132 
#define Here()
source code location of the caller
Definition: Here.h:15
PeerDigest * digest
Definition: CachePeer.h:167
acl_access * access
Definition: CachePeer.h:106
void noteSuccess()
reacts to a successful establishment of a connection to this cache_peer
Definition: CachePeer.cc:71
char * login
Definition: CachePeer.h:202
#define PEER_ALIVE
Definition: defines.h:84
#define xstrdup
struct CachePeer::@25 stats
int connect_fail_limit
Definition: CachePeer.h:204
A combination of PeerOptions and the corresponding Context.
Definition: PeerOptions.h:154
time_t connectTimeout() const
Definition: CachePeer.cc:120
char * name
Definition: CachePeer.h:61
char * domain
Forced domain.
Definition: CachePeer.h:215
Security::FuturePeerContext tlsContext
Definition: CachePeer.h:221
NeighborTypeDomainList * typelist
Definition: CachePeer.h:105
void Tolower(char *)
Definition: util.cc:28
void noteFailure()
reacts to a failed attempt to establish a connection to this cache_peer
Definition: CachePeer.cc:86
~CachePeer()
Definition: CachePeer.cc:34
void rename(const char *)
(re)configure cache_peer name=value
Definition: CachePeer.cc:110
struct CachePeer::@32 standby
optional "cache_peer standby=limit" feature
representation of a neighbor_type_domain configuration directive. A POD
time_t peer_connect
Definition: SquidConfig.h:117
#define assert(EX)
Definition: assert.h:17
CachePeer(const char *hostname)
Definition: CachePeer.cc:25
#define CBDATA_CLASS_INIT(type)
Definition: cbdata.h:325
time_t squid_curtime
Definition: stub_libtime.cc:20
#define xfree
CodeContext with constant details known at construction time.
void aclDestroyAccessList(acl_access **list)
Definition: Gadgets.cc:223
NeighborTypeDomainList * next
int tcp_up
Definition: CachePeer.h:174
#define PEER_DEAD
Definition: defines.h:83
char * host
Definition: CachePeer.h:66
std::ostream & operator<<(std::ostream &os, const CachePeer &p)
identify the given cache peer in cache.log messages and such
Definition: CachePeer.cc:128
struct SquidConfig::@84 Timeout
an std::runtime_error with thrower location info
Definition: TextException.h:20
void peerAlive(CachePeer *p)
Definition: neighbors.cc:449
time_t connect_timeout_raw
connect_timeout; use connectTimeout() instead!
Definition: CachePeer.h:203
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:63
#define DBG_IMPORTANT
Definition: Stream.h:38
const char * neighborTypeStr(const CachePeer *p)
Definition: neighbors.cc:83
bool encryptTransport
whether transport encryption (TLS/SSL) is to be used on connections to the peer
Definition: PeerOptions.h:147
Security::FuturePeerContext * securityContext()
Definition: CachePeer.cc:63
static void Checkpoint(const Pointer &mgr, const char *reason)
Definition: PeerPoolMgr.cc:232
Security::PeerOptions secure
security settings for peer connection
Definition: CachePeer.h:219
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
class SquidConfig Config
Definition: SquidConfig.cc:12
char * digest_url
Definition: CachePeer.h:168

 

Introduction

Documentation

Support

Miscellaneous