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.
9 /* DEBUG: section 15 Neighbor Routines */
12 #include "acl/FilledChecklist.h"
13 #include "anyp/PortCfg.h"
14 #include "base/EnumIterator.h"
15 #include "base/IoManip.h"
16 #include "CacheDigest.h"
17 #include "CachePeer.h"
18 #include "comm/Connection.h"
19 #include "comm/ConnOpener.h"
20 #include "debug/Messages.h"
25 #include "HttpRequest.h"
26 #include "icmp/net_db.h"
29 #include "ip/Address.h"
32 #include "MemObject.h"
33 #include "mgr/Registration.h"
34 #include "multicast.h"
35 #include "neighbors.h"
36 #include "NeighborTypeDomainList.h"
38 #include "PeerDigest.h"
39 #include "PeerPoolMgr.h"
40 #include "PeerSelectState.h"
41 #include "RequestFlags.h"
42 #include "SquidConfig.h"
43 #include "SquidMath.h"
46 #include "store_key_md5.h"
49 /* count mcast group peers every 15 minutes */
50 #define MCAST_COUNT_RATE 900
52 bool peerAllowedToUse(const CachePeer
*, PeerSelector
*);
53 static int peerWouldBePinged(const CachePeer
*, PeerSelector
*);
54 static void neighborRemove(CachePeer
*);
55 static void neighborAlive(CachePeer
*, const MemObject
*, const icp_common_t
*);
57 static void neighborAliveHtcp(CachePeer
*, const MemObject
*, const HtcpReplyData
*);
59 static void neighborCountIgnored(CachePeer
*);
60 static void peerRefreshDNS(void *);
61 static IPH peerDNSConfigure
;
62 static void peerProbeConnect(CachePeer
*, const bool reprobeIfBusy
= false);
63 static CNCB peerProbeConnectDone
;
64 static void peerCountMcastPeersDone(void *data
);
65 static void peerCountMcastPeersStart(void *data
);
66 static void peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
);
67 static void peerCountMcastPeersAbort(PeerSelector
*);
68 static void peerCountMcastPeersCreateAndSend(CachePeer
*p
);
69 static IRCB peerCountHandleIcpReply
;
71 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
72 static OBJH neighborDumpPeers
;
73 static OBJH neighborDumpNonPeers
;
74 static void dump_peers(StoreEntry
* sentry
, CachePeer
* peers
);
76 static unsigned short echo_port
;
78 static int NLateReplies
= 0;
79 static CachePeer
*first_ping
= nullptr;
82 neighborTypeStr(const CachePeer
* p
)
84 if (p
->type
== PEER_NONE
)
87 if (p
->type
== PEER_SIBLING
)
90 if (p
->type
== PEER_MULTICAST
)
91 return "Multicast Group";
97 whichPeer(const Ip::Address
&from
)
101 CachePeer
*p
= nullptr;
102 debugs(15, 3, "whichPeer: from " << from
);
104 for (p
= Config
.peers
; p
; p
= p
->next
) {
105 for (j
= 0; j
< p
->n_addresses
; ++j
) {
106 if (from
== p
->addresses
[j
] && from
.port() == p
->icp
.port
) {
116 neighborType(const CachePeer
* p
, const AnyP::Uri
&url
)
119 const NeighborTypeDomainList
*d
= nullptr;
121 for (d
= p
->typelist
; d
; d
= d
->next
) {
122 if (0 == matchDomainName(url
.host(), d
->domain
))
123 if (d
->type
!= PEER_NONE
)
126 #if PEER_MULTICAST_SIBLINGS
127 if (p
->type
== PEER_MULTICAST
)
128 if (p
->options
.mcast_siblings
)
136 * \return Whether it is appropriate to fetch REQUEST from PEER.
139 peerAllowedToUse(const CachePeer
* p
, PeerSelector
* ps
)
142 HttpRequest
*request
= ps
->request
;
143 assert(request
!= nullptr);
145 if (neighborType(p
, request
->url
) == PEER_SIBLING
) {
146 #if PEER_MULTICAST_SIBLINGS
147 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
148 (request
->flags
.noCache
|| request
->flags
.refresh
|| request
->flags
.loopDetected
|| request
->flags
.needValidation
))
149 debugs(15, 2, "multicast-siblings optimization match for " << *p
<< ", " << request
->url
.authority());
151 if (request
->flags
.noCache
)
154 if (request
->flags
.refresh
)
157 if (request
->flags
.loopDetected
)
160 if (request
->flags
.needValidation
)
164 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
165 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
166 if (p
->options
.originserver
&& request
->method
== Http::METHOD_CONNECT
&& request
->url
.port() != p
->http_port
)
169 if (p
->access
== nullptr)
172 ACLFilledChecklist
checklist(p
->access
, request
, nullptr);
173 checklist
.al
= ps
->al
;
174 if (ps
->al
&& ps
->al
->reply
) {
175 checklist
.reply
= ps
->al
->reply
.getRaw();
176 HTTPMSGLOCK(checklist
.reply
);
178 checklist
.syncAle(request
, nullptr);
179 return checklist
.fastCheck().allowed();
182 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
184 peerWouldBePinged(const CachePeer
* p
, PeerSelector
* ps
)
187 HttpRequest
*request
= ps
->request
;
189 if (p
->icp
.port
== 0)
192 if (p
->options
.no_query
)
195 if (p
->options
.mcast_responder
)
198 if (p
->n_addresses
== 0)
201 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
204 /* the case below seems strange, but can happen if the
205 * URL host is on the other side of a firewall */
206 if (p
->type
== PEER_SIBLING
)
207 if (!request
->flags
.hierarchical
)
210 if (!peerAllowedToUse(p
, ps
))
213 /* Ping dead peers every timeout interval */
214 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
224 peerCanOpenMore(const CachePeer
*p
)
226 const int effectiveLimit
= p
->max_conn
<= 0 ? Squid_MaxFD
: p
->max_conn
;
227 const int remaining
= effectiveLimit
- p
->stats
.conn_open
;
228 debugs(15, 7, remaining
<< '=' << effectiveLimit
<< '-' << p
->stats
.conn_open
);
229 return remaining
> 0;
233 peerHasConnAvailable(const CachePeer
*p
)
235 // Standby connections can be used without opening new connections.
236 const int standbys
= p
->standby
.pool
? p
->standby
.pool
->count() : 0;
238 // XXX: Some idle pconns can be used without opening new connections.
239 // Complication: Idle pconns cannot be reused for some requests.
240 const int usableIdles
= 0;
242 const int available
= standbys
+ usableIdles
;
243 debugs(15, 7, available
<< '=' << standbys
<< '+' << usableIdles
);
244 return available
> 0;
248 peerConnClosed(CachePeer
*p
)
250 --p
->stats
.conn_open
;
251 if (p
->standby
.waitingForClose
&& peerCanOpenMore(p
)) {
252 p
->standby
.waitingForClose
= false;
253 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "conn closed");
257 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
259 peerHTTPOkay(const CachePeer
* p
, PeerSelector
* ps
)
261 if (!peerCanOpenMore(p
) && !peerHasConnAvailable(p
))
264 if (!peerAllowedToUse(p
, ps
))
274 neighborsCount(PeerSelector
*ps
)
276 CachePeer
*p
= nullptr;
279 for (p
= Config
.peers
; p
; p
= p
->next
)
280 if (peerWouldBePinged(p
, ps
))
283 debugs(15, 3, "neighborsCount: " << count
);
289 getFirstUpParent(PeerSelector
*ps
)
292 HttpRequest
*request
= ps
->request
;
294 CachePeer
*p
= nullptr;
296 for (p
= Config
.peers
; p
; p
= p
->next
) {
300 if (neighborType(p
, request
->url
) != PEER_PARENT
)
303 if (!peerHTTPOkay(p
, ps
))
309 debugs(15, 3, "returning " << RawPointer(p
).orNil());
314 getRoundRobinParent(PeerSelector
*ps
)
317 HttpRequest
*request
= ps
->request
;
320 CachePeer
*q
= nullptr;
322 for (p
= Config
.peers
; p
; p
= p
->next
) {
323 if (!p
->options
.roundrobin
)
326 if (neighborType(p
, request
->url
) != PEER_PARENT
)
329 if (!peerHTTPOkay(p
, ps
))
336 if (p
->weight
== q
->weight
) {
337 if (q
->rr_count
< p
->rr_count
)
339 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
350 debugs(15, 3, "returning " << RawPointer(q
).orNil());
356 getWeightedRoundRobinParent(PeerSelector
*ps
)
359 HttpRequest
*request
= ps
->request
;
362 CachePeer
*q
= nullptr;
365 for (p
= Config
.peers
; p
; p
= p
->next
) {
366 if (!p
->options
.weighted_roundrobin
)
369 if (neighborType(p
, request
->url
) != PEER_PARENT
)
372 if (!peerHTTPOkay(p
, ps
))
375 if (q
&& q
->rr_count
< p
->rr_count
)
381 if (q
&& q
->rr_count
> 1000000)
382 for (p
= Config
.peers
; p
; p
= p
->next
) {
383 if (!p
->options
.weighted_roundrobin
)
386 if (neighborType(p
, request
->url
) != PEER_PARENT
)
393 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
395 if (weighted_rtt
< 1)
398 q
->rr_count
+= weighted_rtt
;
400 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
403 debugs(15, 3, "returning " << RawPointer(q
).orNil());
408 * This gets called every 5 minutes to clear the round-robin counter.
409 * The exact timing is an arbitrary default, set on estimate timing of a
410 * large number of requests in a high-performance environment during the
411 * period. The larger the number of requests between cycled resets the
412 * more balanced the operations.
416 * TODO: Make the reset timing a selectable parameter in squid.conf
419 peerClearRRLoop(void *data
)
422 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
426 * This gets called on startup and restart to kick off the CachePeer round-robin
427 * maintenance event. It ensures that no matter how many times its called
428 * no more than one event is scheduled.
431 peerClearRRStart(void)
433 static bool event_added
= false;
435 peerClearRRLoop(nullptr);
441 * Called whenever the round-robin counters need to be reset to a sane state.
442 * So far those times are:
443 * - On startup and reconfigure - to set the counters to sane initial settings.
444 * - When a CachePeer has revived from dead, to prevent the revived CachePeer being
445 * flooded with requests which it has 'missed' during the down period.
450 CachePeer
*p
= nullptr;
451 for (p
= Config
.peers
; p
; p
= p
->next
) {
457 peerAlive(CachePeer
*p
)
459 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
460 debugs(15, DBG_IMPORTANT
, "Detected REVIVED " << neighborTypeStr(p
) << ": " << *p
);
461 p
->stats
.logged_state
= PEER_ALIVE
;
463 if (p
->standby
.mgr
.valid())
464 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "revived peer");
467 p
->stats
.last_reply
= squid_curtime
;
468 p
->stats
.probe_start
= 0;
470 // TODO: Remove or explain how we could detect an alive peer without IP addresses
472 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
476 getDefaultParent(PeerSelector
*ps
)
479 HttpRequest
*request
= ps
->request
;
481 CachePeer
*p
= nullptr;
483 for (p
= Config
.peers
; p
; p
= p
->next
) {
484 if (neighborType(p
, request
->url
) != PEER_PARENT
)
487 if (!p
->options
.default_parent
)
490 if (!peerHTTPOkay(p
, ps
))
493 debugs(15, 3, "returning " << *p
);
498 // TODO: Refactor similar get*() functions to use our return/reporting style
499 debugs(15, 3, "none found");
504 getNextPeer(CachePeer
* p
)
516 neighborRemove(CachePeer
* target
)
518 CachePeer
*p
= nullptr;
519 CachePeer
**P
= nullptr;
539 first_ping
= Config
.peers
;
543 neighborsRegisterWithCacheManager()
545 Mgr::RegisterAction("server_list",
546 "Peer Cache Statistics",
547 neighborDumpPeers
, 0, 1);
549 if (Comm::IsConnOpen(icpIncomingConn
)) {
550 Mgr::RegisterAction("non_peers",
551 "List of Unknown sites sending ICP messages",
552 neighborDumpNonPeers
, 0, 1);
559 struct servent
*sep
= nullptr;
560 const char *me
= getMyHostname();
561 CachePeer
*thisPeer
= nullptr;
562 CachePeer
*next
= nullptr;
564 neighborsRegisterWithCacheManager();
566 if (Comm::IsConnOpen(icpIncomingConn
)) {
568 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
569 next
= thisPeer
->next
;
571 if (0 != strcmp(thisPeer
->host
, me
))
574 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= nullptr; s
= s
->next
) {
575 if (thisPeer
->http_port
!= s
->s
.port())
578 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host." <<
579 Debug::Extra
<< "Ignoring cache_peer " << *thisPeer
);
581 neighborRemove(thisPeer
);
586 peerRefreshDNS((void *) 1);
588 sep
= getservbyname("echo", "udp");
589 echo_port
= sep
? ntohs((unsigned short) sep
->s_port
) : 7;
591 first_ping
= Config
.peers
;
595 neighborsUdpPing(HttpRequest
* request
,
602 const char *url
= entry
->url();
603 MemObject
*mem
= entry
->mem_obj
;
604 CachePeer
*p
= nullptr;
608 int queries_sent
= 0;
609 int peers_pinged
= 0;
610 int parent_timeout
= 0, parent_exprep
= 0;
611 int sibling_timeout
= 0, sibling_exprep
= 0;
612 int mcast_timeout
= 0, mcast_exprep
= 0;
614 if (Config
.peers
== nullptr)
617 assert(!entry
->hasDisk());
619 mem
->start_ping
= current_time
;
621 mem
->ping_reply_callback
= callback
;
625 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
627 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
631 debugs(15, 5, "candidate: " << *p
);
633 if (!peerWouldBePinged(p
, ps
))
634 continue; /* next CachePeer */
638 debugs(15, 4, "pinging cache_peer " << *p
<< " for '" << url
<< "'");
640 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
642 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
645 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
646 if (Config
.Port
.htcp
<= 0) {
647 debugs(15, DBG_CRITICAL
, "ERROR: HTCP is disabled! Cannot send HTCP request to peer.");
651 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
652 if (htcpQuery(entry
, request
, p
) <= 0)
653 continue; // unable to send.
657 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
658 debugs(15, DBG_CRITICAL
, "ERROR: ICP is disabled! Cannot send ICP request to peer.");
662 if (p
->type
== PEER_MULTICAST
)
663 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
665 if (p
->icp
.port
== echo_port
) {
666 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
667 // TODO: Get ALE from callback_data if possible.
668 icpCreateAndSend(ICP_DECHO
, 0, url
, reqnum
, 0,
669 icpOutgoingConn
->fd
, p
->in_addr
, nullptr);
673 if (Config
.onoff
.query_icmp
)
674 if (p
->icp
.version
== ICP_VERSION_2
)
675 flags
|= ICP_FLAG_SRC_RTT
;
677 // TODO: Get ALE from callback_data if possible.
678 icpCreateAndSend(ICP_QUERY
, flags
, url
, reqnum
, 0,
679 icpOutgoingConn
->fd
, p
->in_addr
, nullptr);
686 ++ p
->stats
.pings_sent
;
688 if (p
->type
== PEER_MULTICAST
) {
689 mcast_exprep
+= p
->mcast
.n_replies_expected
;
690 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
691 } else if (neighborUp(p
)) {
692 /* its alive, expect a reply from it */
694 if (neighborType(p
, request
->url
) == PEER_PARENT
) {
696 parent_timeout
+= p
->stats
.rtt
;
699 sibling_timeout
+= p
->stats
.rtt
;
702 /* Neighbor is dead; ping it anyway, but don't expect a reply */
703 /* log it once at the threshold */
705 if (p
->stats
.logged_state
== PEER_ALIVE
) {
706 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << *p
);
707 p
->stats
.logged_state
= PEER_DEAD
;
711 p
->stats
.last_query
= squid_curtime
;
714 * keep probe_start == 0 for a multicast CachePeer,
715 * so neighborUp() never says this CachePeer is dead.
718 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
719 p
->stats
.probe_start
= squid_curtime
;
722 if ((first_ping
= first_ping
->next
) == nullptr)
723 first_ping
= Config
.peers
;
726 * How many replies to expect?
728 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
731 * If there is a configured timeout, use it
733 if (Config
.Timeout
.icp_query
)
734 *timeout
= Config
.Timeout
.icp_query
;
738 *timeout
= 2 * parent_timeout
/ parent_exprep
;
739 else if (mcast_exprep
)
740 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
742 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
744 *timeout
= 2000; /* 2 seconds */
746 if (Config
.Timeout
.icp_query_max
)
747 if (*timeout
> Config
.Timeout
.icp_query_max
)
748 *timeout
= Config
.Timeout
.icp_query_max
;
750 if (*timeout
< Config
.Timeout
.icp_query_min
)
751 *timeout
= Config
.Timeout
.icp_query_min
;
757 /* lookup the digest of a given CachePeer */
759 peerDigestLookup(CachePeer
* p
, PeerSelector
* ps
)
761 #if USE_CACHE_DIGESTS
763 HttpRequest
*request
= ps
->request
;
764 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : nullptr;
767 debugs(15, 5, "cache_peer " << *p
);
768 /* does the peeer have a valid digest? */
771 debugs(15, 5, "peerDigestLookup: gone!");
773 } else if (!peerHTTPOkay(p
, ps
)) {
774 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
776 } else if (!p
->digest
->flags
.needed
) {
777 debugs(15, 5, "peerDigestLookup: note need");
778 peerDigestNeeded(p
->digest
);
780 } else if (!p
->digest
->flags
.usable
) {
781 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
785 debugs(15, 5, "OK to lookup cache_peer " << *p
);
786 assert(p
->digest
->cd
);
787 /* does digest predict a hit? */
789 if (!p
->digest
->cd
->contains(key
))
792 debugs(15, 5, "HIT for cache_peer " << *p
);
803 /* select best CachePeer based on cache digests */
805 neighborsDigestSelect(PeerSelector
*ps
)
807 CachePeer
*best_p
= nullptr;
808 #if USE_CACHE_DIGESTS
810 HttpRequest
*request
= ps
->request
;
813 int choice_count
= 0;
814 int ichoice_count
= 0;
819 if (!request
->flags
.hierarchical
)
822 storeKeyPublicByRequest(request
);
824 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
833 lookup
= peerDigestLookup(p
, ps
);
835 if (lookup
== LOOKUP_NONE
)
840 if (lookup
== LOOKUP_MISS
)
843 p_rtt
= netdbHostRtt(p
->host
);
845 debugs(15, 5, "cache_peer " << *p
<< " rtt: " << p_rtt
);
847 /* is this CachePeer better than others in terms of rtt ? */
848 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
852 if (p_rtt
) /* informative choice (aka educated guess) */
855 debugs(15, 4, "cache_peer " << *p
<< " leads with rtt " << best_rtt
);
859 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
860 peerNoteDigestLookup(request
, best_p
,
861 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
862 request
->hier
.n_choices
= choice_count
;
863 request
->hier
.n_ichoices
= ichoice_count
;
872 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
874 #if USE_CACHE_DIGESTS
876 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
878 *request
->hier
.cd_host
= '\0';
880 request
->hier
.cd_lookup
= lookup
;
881 debugs(15, 4, "cache_peer " << RawPointer(p
).orNil() << ", lookup: " << lookup_t_str
[lookup
]);
890 neighborAlive(CachePeer
* p
, const MemObject
*, const icp_common_t
* header
)
893 ++ p
->stats
.pings_acked
;
895 if ((icp_opcode
) header
->opcode
<= ICP_END
)
896 ++ p
->icp
.counts
[header
->opcode
];
898 p
->icp
.version
= (int) header
->version
;
902 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
904 int rtt
, rtt_av_factor
;
909 if (!mem
->start_ping
.tv_sec
)
912 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
914 if (rtt
< 1 || rtt
> 10000)
917 rtt_av_factor
= RTT_AV_FACTOR
;
919 if (p
->options
.weighted_roundrobin
)
920 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
922 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
927 neighborAliveHtcp(CachePeer
* p
, const MemObject
*, const HtcpReplyData
* htcp
)
930 ++ p
->stats
.pings_acked
;
931 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
932 p
->htcp
.version
= htcp
->version
;
938 neighborCountIgnored(CachePeer
* p
)
943 ++ p
->stats
.ignored_replies
;
948 static CachePeer
*non_peers
= nullptr;
951 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
955 for (np
= non_peers
; np
; np
= np
->next
) {
956 if (np
->in_addr
!= from
)
959 if (np
->in_addr
.port() != from
.port())
966 char fromStr
[MAX_IPSTRLEN
];
967 from
.toStr(fromStr
, sizeof(fromStr
));
968 np
= new CachePeer(fromStr
);
970 np
->icp
.port
= from
.port();
971 np
->type
= PEER_NONE
;
972 np
->next
= non_peers
;
976 ++ np
->icp
.counts
[opcode
];
978 if (isPowTen(++np
->stats
.ignored_replies
))
979 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << *np
);
982 /* ignoreMulticastReply
984 * * We want to ignore replies from multicast peers if the
985 * * cache_host_domain rules would normally prevent the CachePeer
989 ignoreMulticastReply(CachePeer
* p
, PeerSelector
* ps
)
994 if (!p
->options
.mcast_responder
)
997 if (peerHTTPOkay(p
, ps
))
1004 * I should attach these records to the entry. We take the first
1005 * hit we get our wait until everyone misses. The timeout handler
1006 * call needs to nip this shopping list or call one of the misses.
1008 * If a hit process is already started, then sobeit
1011 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
1013 CachePeer
*p
= nullptr;
1015 MemObject
*mem
= nullptr;
1016 peer_t ntype
= PEER_NONE
;
1017 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1019 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1021 if ((entry
= Store::Root().findCallbackXXX(key
)))
1022 mem
= entry
->mem_obj
;
1024 if ((p
= whichPeer(from
)))
1025 neighborAlive(p
, mem
, header
);
1027 if (opcode
> ICP_END
)
1030 const char *opcode_d
= icp_opcode_str
[opcode
];
1033 neighborUpdateRtt(p
, mem
);
1035 /* Does the entry exist? */
1036 if (nullptr == entry
) {
1037 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1038 neighborCountIgnored(p
);
1042 /* check if someone is already fetching it */
1043 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1044 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1045 neighborCountIgnored(p
);
1049 if (mem
== nullptr) {
1050 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1051 neighborCountIgnored(p
);
1055 if (entry
->ping_status
!= PING_WAITING
) {
1056 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1057 neighborCountIgnored(p
);
1061 if (!entry
->locked()) {
1062 // TODO: many entries are unlocked; why is this reported at level 1?
1063 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1064 neighborCountIgnored(p
);
1068 if (!mem
->ircb_data
) {
1069 debugs(12, DBG_IMPORTANT
, "ERROR: Squid BUG: missing ICP callback data for " << *entry
);
1070 neighborCountIgnored(p
);
1074 debugs(15, 3, opcode_d
<< " for " << storeKeyText(key
) << " from " << RawPointer(p
).orNil("source"));
1077 ntype
= neighborType(p
, mem
->request
->url
);
1080 if (ignoreMulticastReply(p
, mem
->ircb_data
)) {
1081 neighborCountIgnored(p
);
1082 } else if (opcode
== ICP_MISS
) {
1084 neighborIgnoreNonPeer(from
, opcode
);
1086 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1088 } else if (opcode
== ICP_HIT
) {
1090 neighborIgnoreNonPeer(from
, opcode
);
1092 header
->opcode
= ICP_HIT
;
1093 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1095 } else if (opcode
== ICP_DECHO
) {
1097 neighborIgnoreNonPeer(from
, opcode
);
1098 } else if (ntype
== PEER_SIBLING
) {
1099 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1100 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1102 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1104 } else if (opcode
== ICP_SECHO
) {
1106 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << *p
);
1107 neighborCountIgnored(p
);
1109 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1111 } else if (opcode
== ICP_DENIED
) {
1113 neighborIgnoreNonPeer(from
, opcode
);
1114 } else if (p
->stats
.pings_acked
> 100) {
1115 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1116 debugs(15, DBG_CRITICAL
, "Disabling cache_peer " << *p
<<
1117 " because over 95% of its replies are UDP_DENIED");
1121 neighborCountIgnored(p
);
1124 } else if (opcode
== ICP_MISS_NOFETCH
) {
1125 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1127 debugs(15, DBG_CRITICAL
, "ERROR: neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1132 findCachePeerByName(const char * const name
)
1134 CachePeer
*p
= nullptr;
1136 for (p
= Config
.peers
; p
; p
= p
->next
) {
1137 if (!strcasecmp(name
, p
->name
))
1145 neighborUp(const CachePeer
* p
)
1148 // TODO: When CachePeer gets its own CodeContext, pass that context instead of nullptr
1149 CallService(nullptr, [&] {
1150 peerProbeConnect(const_cast<CachePeer
*>(p
));
1156 * The CachePeer can not be UP if we don't have any IP addresses
1159 if (0 == p
->n_addresses
) {
1160 debugs(15, 8, "DOWN (no-ip): " << *p
);
1164 if (p
->options
.no_query
) {
1165 debugs(15, 8, "UP (no-query): " << *p
);
1169 if (p
->stats
.probe_start
!= 0 &&
1170 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1171 debugs(15, 8, "DOWN (dead): " << *p
);
1175 debugs(15, 8, "UP: " << *p
);
1180 positiveTimeout(const time_t timeout
)
1182 return max(static_cast<time_t>(1), timeout
);
1186 peerDNSConfigure(const ipcache_addrs
*ia
, const Dns::LookupDetails
&, void *data
)
1188 // TODO: connections to no-longer valid IP addresses should be
1189 // closed when we can detect such IP addresses.
1191 CachePeer
*p
= (CachePeer
*)data
;
1193 if (p
->n_addresses
== 0) {
1194 debugs(15, Important(29), "Configuring " << neighborTypeStr(p
) << " " << *p
);
1196 if (p
->type
== PEER_MULTICAST
)
1197 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1202 if (ia
== nullptr) {
1203 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << *p
<< "' failed!");
1208 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << *p
<< "'!");
1212 for (const auto &ip
: ia
->goodAndBad()) { // TODO: Consider using just good().
1213 if (p
->n_addresses
< PEER_MAX_ADDRESSES
) {
1214 const auto idx
= p
->n_addresses
++;
1215 p
->addresses
[idx
] = ip
;
1216 debugs(15, 2, "--> IP address #" << idx
<< ": " << p
->addresses
[idx
]);
1218 debugs(15, 3, "ignoring remaining " << (ia
->size() - p
->n_addresses
) << " ips");
1223 p
->in_addr
.setEmpty();
1224 p
->in_addr
= p
->addresses
[0];
1225 p
->in_addr
.port(p
->icp
.port
);
1227 peerProbeConnect(p
, true); // detect any died or revived peers ASAP
1229 if (p
->type
== PEER_MULTICAST
)
1230 peerCountMcastPeersSchedule(p
, 10);
1233 if (p
->type
!= PEER_MULTICAST
&& IamWorkerProcess())
1234 if (!p
->options
.no_netdb_exchange
)
1235 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1238 if (p
->standby
.mgr
.valid())
1239 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "resolved peer");
1243 peerRefreshDNS(void *data
)
1245 CachePeer
*p
= nullptr;
1247 if (eventFind(peerRefreshDNS
, nullptr))
1248 eventDelete(peerRefreshDNS
, nullptr);
1250 if (!data
&& 0 == stat5minClientRequests()) {
1251 /* no recent client traffic, wait a bit */
1252 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, nullptr, 180.0, 1);
1256 for (p
= Config
.peers
; p
; p
= p
->next
)
1257 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1259 /* Reconfigure the peers every hour */
1260 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, nullptr, 3600.0, 1);
1263 /// whether new TCP probes are currently banned
1265 peerProbeIsBusy(const CachePeer
*p
)
1267 if (p
->testing_now
> 0) {
1268 debugs(15, 8, "yes, probing " << p
);
1271 if (squid_curtime
- p
->stats
.last_connect_probe
== 0) {
1272 debugs(15, 8, "yes, just probed " << p
);
1278 * peerProbeConnect will be called on dead peers by neighborUp
1281 peerProbeConnect(CachePeer
*p
, const bool reprobeIfBusy
)
1283 if (peerProbeIsBusy(p
)) {
1284 p
->reprobe
= reprobeIfBusy
;
1289 const auto ctimeout
= p
->connectTimeout();
1290 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1291 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1292 Comm::ConnectionPointer conn
= new Comm::Connection
;
1293 conn
->remote
= p
->addresses
[i
];
1294 conn
->remote
.port(p
->http_port
);
1296 getOutgoingAddress(nullptr, conn
);
1300 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1301 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1302 cs
->setHost(p
->host
);
1303 AsyncJob::Start(cs
);
1306 p
->stats
.last_connect_probe
= squid_curtime
;
1310 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, Comm::Flag status
, int, void *data
)
1312 CachePeer
*p
= (CachePeer
*)data
;
1314 if (status
== Comm::OK
)
1317 p
->noteFailure(Http::scNone
);
1321 // TODO: log this traffic.
1324 peerProbeConnect(p
);
1328 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1330 if (p
->mcast
.flags
.count_event_pending
)
1333 eventAdd("peerCountMcastPeersStart",
1334 peerCountMcastPeersStart
,
1338 p
->mcast
.flags
.count_event_pending
= true;
1342 peerCountMcastPeersStart(void *data
)
1344 const auto peer
= static_cast<CachePeer
*>(data
);
1345 CallContextCreator([peer
] {
1346 peerCountMcastPeersCreateAndSend(peer
);
1348 peerCountMcastPeersSchedule(peer
, MCAST_COUNT_RATE
);
1351 /// initiates an ICP transaction to a multicast peer
1353 peerCountMcastPeersCreateAndSend(CachePeer
* const p
)
1355 // XXX: Do not create lots of complex fake objects (while abusing their
1356 // APIs) to pass around a few basic data points like start_ping and ping!
1359 // TODO: use class AnyP::Uri instead of constructing and re-parsing a string
1360 LOCAL_ARRAY(char, url
, MAX_URL
);
1361 assert(p
->type
== PEER_MULTICAST
);
1362 p
->mcast
.flags
.count_event_pending
= false;
1363 snprintf(url
, MAX_URL
, "http://");
1364 p
->in_addr
.toUrl(url
+7, MAX_URL
-8 );
1366 const auto mx
= MasterXaction::MakePortless
<XactionInitiator::initPeerMcast
>();
1367 auto *req
= HttpRequest::FromUrlXXX(url
, mx
);
1368 assert(req
!= nullptr);
1369 const AccessLogEntry::Pointer ale
= new AccessLogEntry
;
1371 CodeContext::Reset(ale
);
1372 StoreEntry
*fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1373 const auto psstate
= new PeerSelector(nullptr);
1374 psstate
->request
= req
;
1375 HTTPMSGLOCK(psstate
->request
);
1376 psstate
->entry
= fake
;
1377 psstate
->peerCountMcastPeerXXX
= cbdataReference(p
);
1378 psstate
->ping
.start
= current_time
;
1380 mem
= fake
->mem_obj
;
1381 mem
->request
= psstate
->request
;
1382 mem
->start_ping
= current_time
;
1383 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1384 mem
->ircb_data
= psstate
;
1385 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1386 p
->mcast
.id
= mem
->id
;
1387 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1388 icpCreateAndSend(ICP_QUERY
, 0, url
, reqnum
, 0,
1389 icpOutgoingConn
->fd
, p
->in_addr
, psstate
->al
);
1390 fake
->ping_status
= PING_WAITING
; // TODO: refactor to use PeerSelector::startPingWaiting()
1391 eventAdd("peerCountMcastPeersDone",
1392 peerCountMcastPeersDone
,
1394 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1395 p
->mcast
.flags
.counting
= true;
1399 peerCountMcastPeersDone(void *data
)
1401 const auto psstate
= static_cast<PeerSelector
*>(data
);
1402 CallBack(psstate
->al
, [psstate
] {
1403 peerCountMcastPeersAbort(psstate
);
1408 /// ends counting of multicast ICP replies
1409 /// to the ICP query initiated by peerCountMcastPeersCreateAndSend()
1411 peerCountMcastPeersAbort(PeerSelector
* const psstate
)
1413 StoreEntry
*fake
= psstate
->entry
;
1415 if (cbdataReferenceValid(psstate
->peerCountMcastPeerXXX
)) {
1416 CachePeer
*p
= (CachePeer
*)psstate
->peerCountMcastPeerXXX
;
1417 p
->mcast
.flags
.counting
= false;
1418 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1419 debugs(15, DBG_IMPORTANT
, "Group " << *p
<< ": " << psstate
->ping
.n_recv
<<
1420 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1421 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1422 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1425 cbdataReferenceDone(psstate
->peerCountMcastPeerXXX
);
1427 fake
->abort(); // sets ENTRY_ABORTED and initiates related cleanup
1428 fake
->mem_obj
->request
= nullptr;
1429 fake
->unlock("peerCountMcastPeersDone");
1433 peerCountHandleIcpReply(CachePeer
* p
, peer_t
, AnyP::ProtocolType proto
, void *, void *data
)
1435 const auto psstate
= static_cast<PeerSelector
*>(data
);
1436 StoreEntry
*fake
= psstate
->entry
;
1438 MemObject
*mem
= fake
->mem_obj
;
1440 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1441 assert(proto
== AnyP::PROTO_ICP
);
1442 ++ psstate
->ping
.n_recv
;
1443 int rtt_av_factor
= RTT_AV_FACTOR
;
1445 if (p
->options
.weighted_roundrobin
)
1446 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1448 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1452 neighborDumpPeers(StoreEntry
* sentry
)
1454 dump_peers(sentry
, Config
.peers
);
1458 neighborDumpNonPeers(StoreEntry
* sentry
)
1460 dump_peers(sentry
, non_peers
);
1464 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1466 if (p
->options
.proxy_only
)
1467 storeAppendPrintf(sentry
, " proxy-only");
1469 if (p
->options
.no_query
)
1470 storeAppendPrintf(sentry
, " no-query");
1472 if (p
->options
.background_ping
)
1473 storeAppendPrintf(sentry
, " background-ping");
1475 if (p
->options
.no_digest
)
1476 storeAppendPrintf(sentry
, " no-digest");
1478 if (p
->options
.default_parent
)
1479 storeAppendPrintf(sentry
, " default");
1481 if (p
->options
.roundrobin
)
1482 storeAppendPrintf(sentry
, " round-robin");
1484 if (p
->options
.carp
)
1485 storeAppendPrintf(sentry
, " carp");
1488 if (p
->options
.userhash
)
1489 storeAppendPrintf(sentry
, " userhash");
1492 if (p
->options
.sourcehash
)
1493 storeAppendPrintf(sentry
, " sourcehash");
1495 if (p
->options
.weighted_roundrobin
)
1496 storeAppendPrintf(sentry
, " weighted-round-robin");
1498 if (p
->options
.mcast_responder
)
1499 storeAppendPrintf(sentry
, " multicast-responder");
1501 #if PEER_MULTICAST_SIBLINGS
1502 if (p
->options
.mcast_siblings
)
1503 storeAppendPrintf(sentry
, " multicast-siblings");
1507 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1509 if (p
->options
.closest_only
)
1510 storeAppendPrintf(sentry
, " closest-only");
1513 if (p
->options
.htcp
) {
1514 storeAppendPrintf(sentry
, " htcp");
1515 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1516 bool doneopts
= false;
1517 if (p
->options
.htcp_oldsquid
) {
1518 storeAppendPrintf(sentry
, "oldsquid");
1521 if (p
->options
.htcp_no_clr
) {
1522 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
?",":"="));
1525 if (p
->options
.htcp_no_purge_clr
) {
1526 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
?",":"="));
1529 if (p
->options
.htcp_only_clr
) {
1530 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
?",":"="));
1531 //doneopts = true; // uncomment if more opts are added
1537 if (p
->options
.no_netdb_exchange
)
1538 storeAppendPrintf(sentry
, " no-netdb-exchange");
1541 if (p
->options
.no_delay
)
1542 storeAppendPrintf(sentry
, " no-delay");
1546 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1548 if (p
->mcast
.ttl
> 0)
1549 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1551 if (p
->connect_timeout_raw
> 0)
1552 storeAppendPrintf(sentry
, " connect-timeout=%d", (int)p
->connect_timeout_raw
);
1554 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1555 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1557 #if USE_CACHE_DIGESTS
1560 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1564 if (p
->options
.allow_miss
)
1565 storeAppendPrintf(sentry
, " allow-miss");
1567 if (p
->options
.no_tproxy
)
1568 storeAppendPrintf(sentry
, " no-tproxy");
1570 if (p
->max_conn
> 0)
1571 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1572 if (p
->standby
.limit
> 0)
1573 storeAppendPrintf(sentry
, " standby=%d", p
->standby
.limit
);
1575 if (p
->options
.originserver
)
1576 storeAppendPrintf(sentry
, " originserver");
1579 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1581 if (p
->connection_auth
== 0)
1582 storeAppendPrintf(sentry
, " connection-auth=off");
1583 else if (p
->connection_auth
== 1)
1584 storeAppendPrintf(sentry
, " connection-auth=on");
1585 else if (p
->connection_auth
== 2)
1586 storeAppendPrintf(sentry
, " connection-auth=auto");
1588 p
->secure
.dumpCfg(sentry
,"tls-");
1589 storeAppendPrintf(sentry
, "\n");
1593 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1595 char ntoabuf
[MAX_IPSTRLEN
];
1598 if (peers
== nullptr)
1599 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1601 for (CachePeer
*e
= peers
; e
; e
= e
->next
) {
1602 assert(e
->host
!= nullptr);
1603 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1606 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1610 storeAppendPrintf(sentry
, "Flags :");
1611 dump_peer_options(sentry
, e
);
1613 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1614 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1615 e
->addresses
[i
].toStr(ntoabuf
,MAX_IPSTRLEN
) );
1618 storeAppendPrintf(sentry
, "Status : %s\n",
1619 neighborUp(e
) ? "Up" : "Down");
1620 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1621 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1622 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1624 if (!e
->options
.no_query
) {
1625 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1626 (int) (squid_curtime
- e
->stats
.last_query
));
1628 if (e
->stats
.last_reply
> 0)
1629 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1630 (int) (squid_curtime
- e
->stats
.last_reply
));
1632 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1634 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1636 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1637 e
->stats
.pings_acked
,
1638 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1641 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1643 if (!e
->options
.no_query
) {
1644 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1647 if (e
->options
.htcp
) {
1648 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1650 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1651 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1653 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1657 for (auto op
: WholeEnum
<icp_opcode
>()) {
1658 if (e
->icp
.counts
[op
] == 0)
1661 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1664 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1675 if (e
->stats
.last_connect_failure
) {
1676 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1677 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1680 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1686 neighborsHtcpReply(const cache_key
* key
, HtcpReplyData
* htcp
, const Ip::Address
&from
)
1688 StoreEntry
*e
= Store::Root().findCallbackXXX(key
);
1689 MemObject
*mem
= nullptr;
1691 peer_t ntype
= PEER_NONE
;
1692 debugs(15, 6, "neighborsHtcpReply: " <<
1693 (htcp
->hit
? "HIT" : "MISS") << " " <<
1694 storeKeyText(key
) );
1699 if ((p
= whichPeer(from
)))
1700 neighborAliveHtcp(p
, mem
, htcp
);
1702 /* Does the entry exist? */
1704 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1705 neighborCountIgnored(p
);
1709 /* check if someone is already fetching it */
1710 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1711 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1712 neighborCountIgnored(p
);
1716 if (mem
== nullptr) {
1717 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1718 neighborCountIgnored(p
);
1722 if (e
->ping_status
!= PING_WAITING
) {
1723 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1724 neighborCountIgnored(p
);
1729 // TODO: many entries are unlocked; why is this reported at level 1?
1730 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1731 neighborCountIgnored(p
);
1735 if (!mem
->ircb_data
) {
1736 debugs(12, DBG_IMPORTANT
, "ERROR: Squid BUG: missing HTCP callback data for " << *e
);
1737 neighborCountIgnored(p
);
1742 ntype
= neighborType(p
, mem
->request
->url
);
1743 neighborUpdateRtt(p
, mem
);
1746 if (ignoreMulticastReply(p
, mem
->ircb_data
)) {
1747 neighborCountIgnored(p
);
1751 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1752 // TODO: Refactor (ping_reply_callback,ircb_data) to add CodeContext.
1753 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1757 * Send HTCP CLR messages to all peers configured to receive them.
1760 neighborsHtcpClear(StoreEntry
* e
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1765 for (p
= Config
.peers
; p
; p
= p
->next
) {
1766 if (!p
->options
.htcp
) {
1769 if (p
->options
.htcp_no_clr
) {
1772 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1775 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.toUrl(buf
, 128));
1776 htcpClear(e
, req
, method
, p
, reason
);