]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/CachePeer.cc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
10 #include "acl/Gadgets.h"
11 #include "CachePeer.h"
13 #include "neighbors.h"
14 #include "NeighborTypeDomainList.h"
16 #include "PeerDigest.h"
17 #include "PeerPoolMgr.h"
18 #include "SquidConfig.h"
21 CBDATA_CLASS_INIT(CachePeer
);
23 CachePeer::CachePeer(const char * const hostname
):
24 name(xstrdup(hostname
)),
25 host(xstrdup(hostname
))
27 Tolower(host
); // but .name preserves original spelling
30 CachePeer::~CachePeer()
35 while (NeighborTypeDomainList
*l
= typelist
) {
41 aclDestroyAccessList(&access
);
44 void *digestTmp
= nullptr;
45 if (cbdataReferenceValidDone(digest
, &digestTmp
))
46 peerDigestNotePeerGone(static_cast<PeerDigest
*>(digestTmp
));
54 // the mgr job will notice that its owner is gone and stop
55 PeerPoolMgr::Checkpoint(standby
.mgr
, "peer gone");
61 CachePeer::noteSuccess()
64 debugs(15, 2, "connection to " << *this << " succeeded");
65 tcp_up
= connect_fail_limit
; // NP: so peerAlive() works properly.
68 tcp_up
= connect_fail_limit
;
73 CachePeer::noteFailure(const Http::StatusCode code
)
75 if (Http::Is4xx(code
))
76 return; // this failure is not our fault
81 // TODO: Require callers to detail failures instead of using one (and often
82 // misleading!) "connection failed" phrase for all of them.
83 /// noteFailure() helper for handling failures attributed to this peer
85 CachePeer::countFailure()
87 stats
.last_connect_failure
= squid_curtime
;
91 const auto consideredAliveByAdmin
= (stats
.logged_state
== PEER_ALIVE
);
92 const auto level
= consideredAliveByAdmin
? DBG_IMPORTANT
: 2;
93 debugs(15, level
, "ERROR: Connection to " << *this << " failed");
95 if (consideredAliveByAdmin
) {
97 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(this) << ": " << name
);
98 stats
.logged_state
= PEER_DEAD
;
100 debugs(15, 2, "additional failures needed to mark this cache_peer DEAD: " << tcp_up
);
104 debugs(15, 2, "cache_peer " << *this << " is still DEAD");
109 CachePeer::rename(const char * const newName
)
111 if (!newName
|| !*newName
)
112 throw TextException("cache_peer name=value cannot be empty", Here());
115 name
= xstrdup(newName
);
119 CachePeer::connectTimeout() const
121 if (connect_timeout_raw
> 0)
122 return connect_timeout_raw
;
123 return Config
.Timeout
.peer_connect
;
127 operator <<(std::ostream
&os
, const CachePeer
&p
)