]>
Commit | Line | Data |
---|---|---|
719815a0 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 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" | |
97269a72 | 16 | #include "PeerDigest.h" |
719815a0 | 17 | #include "PeerPoolMgr.h" |
5f5d319e | 18 | #include "SquidConfig.h" |
a555a85b | 19 | #include "util.h" |
719815a0 AJ |
20 | |
21 | CBDATA_CLASS_INIT(CachePeer); | |
22 | ||
a555a85b AR |
23 | CachePeer::CachePeer(const char * const hostname): |
24 | name(xstrdup(hostname)), | |
25 | host(xstrdup(hostname)) | |
26 | { | |
27 | Tolower(host); // but .name preserves original spelling | |
28 | } | |
29 | ||
719815a0 AJ |
30 | CachePeer::~CachePeer() |
31 | { | |
32 | xfree(name); | |
33 | xfree(host); | |
34 | ||
719815a0 AJ |
35 | while (NeighborTypeDomainList *l = typelist) { |
36 | typelist = l->next; | |
37 | xfree(l->domain); | |
38 | xfree(l); | |
39 | } | |
40 | ||
41 | aclDestroyAccessList(&access); | |
42 | ||
43 | #if USE_CACHE_DIGESTS | |
97269a72 EB |
44 | void *digestTmp = nullptr; |
45 | if (cbdataReferenceValidDone(digest, &digestTmp)) | |
46 | peerDigestNotePeerGone(static_cast<PeerDigest *>(digestTmp)); | |
719815a0 AJ |
47 | xfree(digest_url); |
48 | #endif | |
49 | ||
50 | delete next; | |
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); | |
719815a0 | 60 | } |
7dfc5092 | 61 | |
022dbabd EB |
62 | void |
63 | CachePeer::noteSuccess() | |
64 | { | |
65 | if (!tcp_up) { | |
66 | debugs(15, 2, "connection to " << *this << " succeeded"); | |
67 | tcp_up = connect_fail_limit; // NP: so peerAlive() works properly. | |
68 | peerAlive(this); | |
69 | } else { | |
70 | tcp_up = connect_fail_limit; | |
71 | } | |
72 | } | |
73 | ||
74 | void | |
75 | CachePeer::noteFailure(const Http::StatusCode code) | |
76 | { | |
77 | if (Http::Is4xx(code)) | |
78 | return; // this failure is not our fault | |
79 | ||
80 | countFailure(); | |
81 | } | |
82 | ||
83 | // TODO: Require callers to detail failures instead of using one (and often | |
84 | // misleading!) "connection failed" phrase for all of them. | |
85 | /// noteFailure() helper for handling failures attributed to this peer | |
86 | void | |
87 | CachePeer::countFailure() | |
88 | { | |
89 | stats.last_connect_failure = squid_curtime; | |
90 | if (tcp_up > 0) | |
91 | --tcp_up; | |
92 | ||
93 | const auto consideredAliveByAdmin = (stats.logged_state == PEER_ALIVE); | |
94 | const auto level = consideredAliveByAdmin ? DBG_IMPORTANT : 2; | |
95 | debugs(15, level, "ERROR: Connection to " << *this << " failed"); | |
96 | ||
97 | if (consideredAliveByAdmin) { | |
98 | if (!tcp_up) { | |
99 | debugs(15, DBG_IMPORTANT, "Detected DEAD " << neighborTypeStr(this) << ": " << name); | |
100 | stats.logged_state = PEER_DEAD; | |
101 | } else { | |
102 | debugs(15, 2, "additional failures needed to mark this cache_peer DEAD: " << tcp_up); | |
103 | } | |
104 | } else { | |
105 | assert(!tcp_up); | |
106 | debugs(15, 2, "cache_peer " << *this << " is still DEAD"); | |
107 | } | |
108 | } | |
109 | ||
a555a85b AR |
110 | void |
111 | CachePeer::rename(const char * const newName) | |
112 | { | |
113 | if (!newName || !*newName) | |
114 | throw TextException("cache_peer name=value cannot be empty", Here()); | |
115 | ||
116 | xfree(name); | |
117 | name = xstrdup(newName); | |
118 | } | |
119 | ||
5f5d319e FC |
120 | time_t |
121 | CachePeer::connectTimeout() const | |
122 | { | |
123 | if (connect_timeout_raw > 0) | |
124 | return connect_timeout_raw; | |
125 | return Config.Timeout.peer_connect; | |
126 | } | |
127 | ||
a555a85b AR |
128 | std::ostream & |
129 | operator <<(std::ostream &os, const CachePeer &p) | |
130 | { | |
131 | return os << p.name; | |
132 | } | |
133 |