]> git.ipfire.org Git - thirdparty/squid.git/blame - src/CachePeer.cc
Removed tcp-banger* and pconn-banger tools (#1236)
[thirdparty/squid.git] / src / CachePeer.cc
CommitLineData
719815a0 1/*
bf95c10a 2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
719815a0
AJ
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"
11#include "CachePeer.h"
719815a0 12#include "defines.h"
022dbabd 13#include "neighbors.h"
719815a0
AJ
14#include "NeighborTypeDomainList.h"
15#include "pconn.h"
16#include "PeerPoolMgr.h"
5f5d319e 17#include "SquidConfig.h"
a555a85b 18#include "util.h"
719815a0
AJ
19
20CBDATA_CLASS_INIT(CachePeer);
21
a555a85b
AR
22CachePeer::CachePeer(const char * const hostname):
23 name(xstrdup(hostname)),
24 host(xstrdup(hostname))
25{
26 Tolower(host); // but .name preserves original spelling
27}
28
719815a0
AJ
29CachePeer::~CachePeer()
30{
31 xfree(name);
32 xfree(host);
33
719815a0
AJ
34 while (NeighborTypeDomainList *l = typelist) {
35 typelist = l->next;
36 xfree(l->domain);
37 xfree(l);
38 }
39
40 aclDestroyAccessList(&access);
41
42#if USE_CACHE_DIGESTS
43 cbdataReferenceDone(digest);
44 xfree(digest_url);
45#endif
46
47 delete next;
48
49 xfree(login);
50
51 delete standby.pool;
52
53 // the mgr job will notice that its owner is gone and stop
54 PeerPoolMgr::Checkpoint(standby.mgr, "peer gone");
55
56 xfree(domain);
719815a0 57}
7dfc5092 58
022dbabd
EB
59void
60CachePeer::noteSuccess()
61{
62 if (!tcp_up) {
63 debugs(15, 2, "connection to " << *this << " succeeded");
64 tcp_up = connect_fail_limit; // NP: so peerAlive() works properly.
65 peerAlive(this);
66 } else {
67 tcp_up = connect_fail_limit;
68 }
69}
70
71void
72CachePeer::noteFailure(const Http::StatusCode code)
73{
74 if (Http::Is4xx(code))
75 return; // this failure is not our fault
76
77 countFailure();
78}
79
80// TODO: Require callers to detail failures instead of using one (and often
81// misleading!) "connection failed" phrase for all of them.
82/// noteFailure() helper for handling failures attributed to this peer
83void
84CachePeer::countFailure()
85{
86 stats.last_connect_failure = squid_curtime;
87 if (tcp_up > 0)
88 --tcp_up;
89
90 const auto consideredAliveByAdmin = (stats.logged_state == PEER_ALIVE);
91 const auto level = consideredAliveByAdmin ? DBG_IMPORTANT : 2;
92 debugs(15, level, "ERROR: Connection to " << *this << " failed");
93
94 if (consideredAliveByAdmin) {
95 if (!tcp_up) {
96 debugs(15, DBG_IMPORTANT, "Detected DEAD " << neighborTypeStr(this) << ": " << name);
97 stats.logged_state = PEER_DEAD;
98 } else {
99 debugs(15, 2, "additional failures needed to mark this cache_peer DEAD: " << tcp_up);
100 }
101 } else {
102 assert(!tcp_up);
103 debugs(15, 2, "cache_peer " << *this << " is still DEAD");
104 }
105}
106
a555a85b
AR
107void
108CachePeer::rename(const char * const newName)
109{
110 if (!newName || !*newName)
111 throw TextException("cache_peer name=value cannot be empty", Here());
112
113 xfree(name);
114 name = xstrdup(newName);
115}
116
5f5d319e
FC
117time_t
118CachePeer::connectTimeout() const
119{
120 if (connect_timeout_raw > 0)
121 return connect_timeout_raw;
122 return Config.Timeout.peer_connect;
123}
124
a555a85b
AR
125std::ostream &
126operator <<(std::ostream &os, const CachePeer &p)
127{
128 return os << p.name;
129}
130