2 * Copyright (C) 1996-2019 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 "CacheDigest.h"
16 #include "CachePeer.h"
17 #include "comm/Connection.h"
18 #include "comm/ConnOpener.h"
23 #include "HttpRequest.h"
24 #include "icmp/net_db.h"
27 #include "ip/Address.h"
30 #include "MemObject.h"
31 #include "mgr/Registration.h"
32 #include "multicast.h"
33 #include "neighbors.h"
34 #include "NeighborTypeDomainList.h"
36 #include "PeerDigest.h"
37 #include "PeerPoolMgr.h"
38 #include "PeerSelectState.h"
39 #include "RequestFlags.h"
40 #include "SquidConfig.h"
41 #include "SquidMath.h"
42 #include "SquidTime.h"
45 #include "store_key_md5.h"
48 /* count mcast group peers every 15 minutes */
49 #define MCAST_COUNT_RATE 900
51 bool peerAllowedToUse(const CachePeer
*, PeerSelector
*);
52 static int peerWouldBePinged(const CachePeer
*, PeerSelector
*);
53 static void neighborRemove(CachePeer
*);
54 static void neighborAlive(CachePeer
*, const MemObject
*, const icp_common_t
*);
56 static void neighborAliveHtcp(CachePeer
*, const MemObject
*, const HtcpReplyData
*);
58 static void neighborCountIgnored(CachePeer
*);
59 static void peerRefreshDNS(void *);
60 static IPH peerDNSConfigure
;
61 static void peerProbeConnect(CachePeer
*, const bool reprobeIfBusy
= false);
62 static CNCB peerProbeConnectDone
;
63 static void peerCountMcastPeersDone(void *data
);
64 static void peerCountMcastPeersStart(void *data
);
65 static void peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
);
66 static IRCB peerCountHandleIcpReply
;
68 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
69 static OBJH neighborDumpPeers
;
70 static OBJH neighborDumpNonPeers
;
71 static void dump_peers(StoreEntry
* sentry
, CachePeer
* peers
);
73 static unsigned short echo_port
;
75 static int NLateReplies
= 0;
76 static CachePeer
*first_ping
= NULL
;
79 neighborTypeStr(const CachePeer
* p
)
81 if (p
->type
== PEER_NONE
)
84 if (p
->type
== PEER_SIBLING
)
87 if (p
->type
== PEER_MULTICAST
)
88 return "Multicast Group";
94 whichPeer(const Ip::Address
&from
)
99 debugs(15, 3, "whichPeer: from " << from
);
101 for (p
= Config
.peers
; p
; p
= p
->next
) {
102 for (j
= 0; j
< p
->n_addresses
; ++j
) {
103 if (from
== p
->addresses
[j
] && from
.port() == p
->icp
.port
) {
113 neighborType(const CachePeer
* p
, const AnyP::Uri
&url
)
116 const NeighborTypeDomainList
*d
= NULL
;
118 for (d
= p
->typelist
; d
; d
= d
->next
) {
119 if (0 == matchDomainName(url
.host(), d
->domain
))
120 if (d
->type
!= PEER_NONE
)
123 #if PEER_MULTICAST_SIBLINGS
124 if (p
->type
== PEER_MULTICAST
)
125 if (p
->options
.mcast_siblings
)
133 * \return Whether it is appropriate to fetch REQUEST from PEER.
136 peerAllowedToUse(const CachePeer
* p
, PeerSelector
* ps
)
139 HttpRequest
*request
= ps
->request
;
140 assert(request
!= NULL
);
142 if (neighborType(p
, request
->url
) == PEER_SIBLING
) {
143 #if PEER_MULTICAST_SIBLINGS
144 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
145 (request
->flags
.noCache
|| request
->flags
.refresh
|| request
->flags
.loopDetected
|| request
->flags
.needValidation
))
146 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->url
.authority() << ") : multicast-siblings optimization match");
148 if (request
->flags
.noCache
)
151 if (request
->flags
.refresh
)
154 if (request
->flags
.loopDetected
)
157 if (request
->flags
.needValidation
)
161 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
162 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
163 if (p
->options
.originserver
&& request
->method
== Http::METHOD_CONNECT
&& request
->url
.port() != p
->http_port
)
166 if (p
->access
== NULL
)
169 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
170 checklist
.al
= ps
->al
;
171 checklist
.syncAle(request
, nullptr);
172 return checklist
.fastCheck().allowed();
175 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
177 peerWouldBePinged(const CachePeer
* p
, PeerSelector
* ps
)
180 HttpRequest
*request
= ps
->request
;
182 if (p
->icp
.port
== 0)
185 if (p
->options
.no_query
)
188 if (p
->options
.mcast_responder
)
191 if (p
->n_addresses
== 0)
194 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
197 /* the case below seems strange, but can happen if the
198 * URL host is on the other side of a firewall */
199 if (p
->type
== PEER_SIBLING
)
200 if (!request
->flags
.hierarchical
)
203 if (!peerAllowedToUse(p
, ps
))
206 /* Ping dead peers every timeout interval */
207 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
217 peerCanOpenMore(const CachePeer
*p
)
219 const int effectiveLimit
= p
->max_conn
<= 0 ? Squid_MaxFD
: p
->max_conn
;
220 const int remaining
= effectiveLimit
- p
->stats
.conn_open
;
221 debugs(15, 7, remaining
<< '=' << effectiveLimit
<< '-' << p
->stats
.conn_open
);
222 return remaining
> 0;
226 peerHasConnAvailable(const CachePeer
*p
)
228 // Standby connections can be used without opening new connections.
229 const int standbys
= p
->standby
.pool
? p
->standby
.pool
->count() : 0;
231 // XXX: Some idle pconns can be used without opening new connections.
232 // Complication: Idle pconns cannot be reused for some requests.
233 const int usableIdles
= 0;
235 const int available
= standbys
+ usableIdles
;
236 debugs(15, 7, available
<< '=' << standbys
<< '+' << usableIdles
);
237 return available
> 0;
241 peerConnClosed(CachePeer
*p
)
243 --p
->stats
.conn_open
;
244 if (p
->standby
.waitingForClose
&& peerCanOpenMore(p
)) {
245 p
->standby
.waitingForClose
= false;
246 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "conn closed");
250 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
252 peerHTTPOkay(const CachePeer
* p
, PeerSelector
* ps
)
254 if (!peerCanOpenMore(p
) && !peerHasConnAvailable(p
))
257 if (!peerAllowedToUse(p
, ps
))
267 neighborsCount(PeerSelector
*ps
)
272 for (p
= Config
.peers
; p
; p
= p
->next
)
273 if (peerWouldBePinged(p
, ps
))
276 debugs(15, 3, "neighborsCount: " << count
);
282 getFirstUpParent(PeerSelector
*ps
)
285 HttpRequest
*request
= ps
->request
;
289 for (p
= Config
.peers
; p
; p
= p
->next
) {
293 if (neighborType(p
, request
->url
) != PEER_PARENT
)
296 if (!peerHTTPOkay(p
, ps
))
302 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
307 getRoundRobinParent(PeerSelector
*ps
)
310 HttpRequest
*request
= ps
->request
;
315 for (p
= Config
.peers
; p
; p
= p
->next
) {
316 if (!p
->options
.roundrobin
)
319 if (neighborType(p
, request
->url
) != PEER_PARENT
)
322 if (!peerHTTPOkay(p
, ps
))
329 if (p
->weight
== q
->weight
) {
330 if (q
->rr_count
< p
->rr_count
)
332 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
343 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
349 getWeightedRoundRobinParent(PeerSelector
*ps
)
352 HttpRequest
*request
= ps
->request
;
358 for (p
= Config
.peers
; p
; p
= p
->next
) {
359 if (!p
->options
.weighted_roundrobin
)
362 if (neighborType(p
, request
->url
) != PEER_PARENT
)
365 if (!peerHTTPOkay(p
, ps
))
368 if (q
&& q
->rr_count
< p
->rr_count
)
374 if (q
&& q
->rr_count
> 1000000)
375 for (p
= Config
.peers
; p
; p
= p
->next
) {
376 if (!p
->options
.weighted_roundrobin
)
379 if (neighborType(p
, request
->url
) != PEER_PARENT
)
386 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
388 if (weighted_rtt
< 1)
391 q
->rr_count
+= weighted_rtt
;
393 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
396 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
401 * This gets called every 5 minutes to clear the round-robin counter.
402 * The exact timing is an arbitrary default, set on estimate timing of a
403 * large number of requests in a high-performance environment during the
404 * period. The larger the number of requests between cycled resets the
405 * more balanced the operations.
408 \todo Make the reset timing a selectable parameter in squid.conf
411 peerClearRRLoop(void *data
)
414 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
418 * This gets called on startup and restart to kick off the CachePeer round-robin
419 * maintenance event. It ensures that no matter how many times its called
420 * no more than one event is scheduled.
423 peerClearRRStart(void)
425 static bool event_added
= false;
427 peerClearRRLoop(NULL
);
433 * Called whenever the round-robin counters need to be reset to a sane state.
434 * So far those times are:
435 * - On startup and reconfigure - to set the counters to sane initial settings.
436 * - When a CachePeer has revived from dead, to prevent the revived CachePeer being
437 * flooded with requests which it has 'missed' during the down period.
443 for (p
= Config
.peers
; p
; p
= p
->next
) {
449 * Perform all actions when a CachePeer is detected revived.
452 peerAlive(CachePeer
*p
)
454 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
455 debugs(15, DBG_IMPORTANT
, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
456 p
->stats
.logged_state
= PEER_ALIVE
;
458 if (p
->standby
.mgr
.valid())
459 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "revived peer");
462 p
->stats
.last_reply
= squid_curtime
;
463 p
->stats
.probe_start
= 0;
467 getDefaultParent(PeerSelector
*ps
)
470 HttpRequest
*request
= ps
->request
;
474 for (p
= Config
.peers
; p
; p
= p
->next
) {
475 if (neighborType(p
, request
->url
) != PEER_PARENT
)
478 if (!p
->options
.default_parent
)
481 if (!peerHTTPOkay(p
, ps
))
484 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
489 debugs(15, 3, "getDefaultParent: returning NULL");
494 getNextPeer(CachePeer
* p
)
506 neighborRemove(CachePeer
* target
)
509 CachePeer
**P
= NULL
;
529 first_ping
= Config
.peers
;
533 neighborsRegisterWithCacheManager()
535 Mgr::RegisterAction("server_list",
536 "Peer Cache Statistics",
537 neighborDumpPeers
, 0, 1);
539 if (Comm::IsConnOpen(icpIncomingConn
)) {
540 Mgr::RegisterAction("non_peers",
541 "List of Unknown sites sending ICP messages",
542 neighborDumpNonPeers
, 0, 1);
549 struct servent
*sep
= NULL
;
550 const char *me
= getMyHostname();
551 CachePeer
*thisPeer
= NULL
;
552 CachePeer
*next
= NULL
;
554 neighborsRegisterWithCacheManager();
556 if (Comm::IsConnOpen(icpIncomingConn
)) {
558 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
559 next
= thisPeer
->next
;
561 if (0 != strcmp(thisPeer
->host
, me
))
564 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
565 if (thisPeer
->http_port
!= s
->s
.port())
568 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
570 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
571 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
572 "/" << thisPeer
->http_port
<< "/" <<
575 neighborRemove(thisPeer
);
580 peerRefreshDNS((void *) 1);
582 sep
= getservbyname("echo", "udp");
583 echo_port
= sep
? ntohs((unsigned short) sep
->s_port
) : 7;
585 first_ping
= Config
.peers
;
589 neighborsUdpPing(HttpRequest
* request
,
596 const char *url
= entry
->url();
597 MemObject
*mem
= entry
->mem_obj
;
602 int queries_sent
= 0;
603 int peers_pinged
= 0;
604 int parent_timeout
= 0, parent_exprep
= 0;
605 int sibling_timeout
= 0, sibling_exprep
= 0;
606 int mcast_timeout
= 0, mcast_exprep
= 0;
608 if (Config
.peers
== NULL
)
611 assert(!entry
->hasDisk());
613 mem
->start_ping
= current_time
;
615 mem
->ping_reply_callback
= callback
;
619 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
621 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
625 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
627 if (!peerWouldBePinged(p
, ps
))
628 continue; /* next CachePeer */
632 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
634 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
636 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
639 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
640 if (Config
.Port
.htcp
<= 0) {
641 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
645 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
646 if (htcpQuery(entry
, request
, p
) <= 0)
647 continue; // unable to send.
651 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
652 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
656 if (p
->type
== PEER_MULTICAST
)
657 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
659 if (p
->icp
.port
== echo_port
) {
660 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
661 // TODO: Get ALE from callback_data if possible.
662 icpCreateAndSend(ICP_DECHO
, 0, url
, reqnum
, 0,
663 icpOutgoingConn
->fd
, p
->in_addr
, nullptr);
667 if (Config
.onoff
.query_icmp
)
668 if (p
->icp
.version
== ICP_VERSION_2
)
669 flags
|= ICP_FLAG_SRC_RTT
;
671 // TODO: Get ALE from callback_data if possible.
672 icpCreateAndSend(ICP_QUERY
, flags
, url
, reqnum
, 0,
673 icpOutgoingConn
->fd
, p
->in_addr
, nullptr);
680 ++ p
->stats
.pings_sent
;
682 if (p
->type
== PEER_MULTICAST
) {
683 mcast_exprep
+= p
->mcast
.n_replies_expected
;
684 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
685 } else if (neighborUp(p
)) {
686 /* its alive, expect a reply from it */
688 if (neighborType(p
, request
->url
) == PEER_PARENT
) {
690 parent_timeout
+= p
->stats
.rtt
;
693 sibling_timeout
+= p
->stats
.rtt
;
696 /* Neighbor is dead; ping it anyway, but don't expect a reply */
697 /* log it once at the threshold */
699 if (p
->stats
.logged_state
== PEER_ALIVE
) {
700 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
701 p
->stats
.logged_state
= PEER_DEAD
;
705 p
->stats
.last_query
= squid_curtime
;
708 * keep probe_start == 0 for a multicast CachePeer,
709 * so neighborUp() never says this CachePeer is dead.
712 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
713 p
->stats
.probe_start
= squid_curtime
;
716 if ((first_ping
= first_ping
->next
) == NULL
)
717 first_ping
= Config
.peers
;
720 * How many replies to expect?
722 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
725 * If there is a configured timeout, use it
727 if (Config
.Timeout
.icp_query
)
728 *timeout
= Config
.Timeout
.icp_query
;
732 *timeout
= 2 * parent_timeout
/ parent_exprep
;
733 else if (mcast_exprep
)
734 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
736 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
738 *timeout
= 2000; /* 2 seconds */
740 if (Config
.Timeout
.icp_query_max
)
741 if (*timeout
> Config
.Timeout
.icp_query_max
)
742 *timeout
= Config
.Timeout
.icp_query_max
;
744 if (*timeout
< Config
.Timeout
.icp_query_min
)
745 *timeout
= Config
.Timeout
.icp_query_min
;
751 /* lookup the digest of a given CachePeer */
753 peerDigestLookup(CachePeer
* p
, PeerSelector
* ps
)
755 #if USE_CACHE_DIGESTS
757 HttpRequest
*request
= ps
->request
;
758 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
761 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
762 /* does the peeer have a valid digest? */
765 debugs(15, 5, "peerDigestLookup: gone!");
767 } else if (!peerHTTPOkay(p
, ps
)) {
768 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
770 } else if (!p
->digest
->flags
.needed
) {
771 debugs(15, 5, "peerDigestLookup: note need");
772 peerDigestNeeded(p
->digest
);
774 } else if (!p
->digest
->flags
.usable
) {
775 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
779 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
780 assert(p
->digest
->cd
);
781 /* does digest predict a hit? */
783 if (!p
->digest
->cd
->contains(key
))
786 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
795 /* select best CachePeer based on cache digests */
797 neighborsDigestSelect(PeerSelector
*ps
)
799 CachePeer
*best_p
= NULL
;
800 #if USE_CACHE_DIGESTS
802 HttpRequest
*request
= ps
->request
;
805 int choice_count
= 0;
806 int ichoice_count
= 0;
811 if (!request
->flags
.hierarchical
)
814 storeKeyPublicByRequest(request
);
816 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
825 lookup
= peerDigestLookup(p
, ps
);
827 if (lookup
== LOOKUP_NONE
)
832 if (lookup
== LOOKUP_MISS
)
835 p_rtt
= netdbHostRtt(p
->host
);
837 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
839 /* is this CachePeer better than others in terms of rtt ? */
840 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
844 if (p_rtt
) /* informative choice (aka educated guess) */
847 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
851 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
852 peerNoteDigestLookup(request
, best_p
,
853 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
854 request
->hier
.n_choices
= choice_count
;
855 request
->hier
.n_ichoices
= ichoice_count
;
862 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
864 #if USE_CACHE_DIGESTS
866 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
868 *request
->hier
.cd_host
= '\0';
870 request
->hier
.cd_lookup
= lookup
;
871 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
876 neighborAlive(CachePeer
* p
, const MemObject
*, const icp_common_t
* header
)
879 ++ p
->stats
.pings_acked
;
881 if ((icp_opcode
) header
->opcode
<= ICP_END
)
882 ++ p
->icp
.counts
[header
->opcode
];
884 p
->icp
.version
= (int) header
->version
;
888 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
890 int rtt
, rtt_av_factor
;
895 if (!mem
->start_ping
.tv_sec
)
898 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
900 if (rtt
< 1 || rtt
> 10000)
903 rtt_av_factor
= RTT_AV_FACTOR
;
905 if (p
->options
.weighted_roundrobin
)
906 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
908 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
913 neighborAliveHtcp(CachePeer
* p
, const MemObject
*, const HtcpReplyData
* htcp
)
916 ++ p
->stats
.pings_acked
;
917 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
918 p
->htcp
.version
= htcp
->version
;
924 neighborCountIgnored(CachePeer
* p
)
929 ++ p
->stats
.ignored_replies
;
934 static CachePeer
*non_peers
= NULL
;
937 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
941 for (np
= non_peers
; np
; np
= np
->next
) {
942 if (np
->in_addr
!= from
)
945 if (np
->in_addr
.port() != from
.port())
954 np
->icp
.port
= from
.port();
955 np
->type
= PEER_NONE
;
956 np
->host
= new char[MAX_IPSTRLEN
];
957 from
.toStr(np
->host
,MAX_IPSTRLEN
);
958 np
->next
= non_peers
;
962 ++ np
->icp
.counts
[opcode
];
964 if (isPowTen(++np
->stats
.ignored_replies
))
965 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
968 /* ignoreMulticastReply
970 * * We want to ignore replies from multicast peers if the
971 * * cache_host_domain rules would normally prevent the CachePeer
975 ignoreMulticastReply(CachePeer
* p
, PeerSelector
* ps
)
980 if (!p
->options
.mcast_responder
)
983 if (peerHTTPOkay(p
, ps
))
990 * I should attach these records to the entry. We take the first
991 * hit we get our wait until everyone misses. The timeout handler
992 * call needs to nip this shopping list or call one of the misses.
994 * If a hit process is already started, then sobeit
997 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
1001 MemObject
*mem
= NULL
;
1002 peer_t ntype
= PEER_NONE
;
1003 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1005 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1007 if ((entry
= Store::Root().findCallbackXXX(key
)))
1008 mem
= entry
->mem_obj
;
1010 if ((p
= whichPeer(from
)))
1011 neighborAlive(p
, mem
, header
);
1013 if (opcode
> ICP_END
)
1016 const char *opcode_d
= icp_opcode_str
[opcode
];
1019 neighborUpdateRtt(p
, mem
);
1021 /* Does the entry exist? */
1022 if (NULL
== entry
) {
1023 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1024 neighborCountIgnored(p
);
1028 /* check if someone is already fetching it */
1029 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1030 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1031 neighborCountIgnored(p
);
1036 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1037 neighborCountIgnored(p
);
1041 if (entry
->ping_status
!= PING_WAITING
) {
1042 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1043 neighborCountIgnored(p
);
1047 if (!entry
->locked()) {
1048 // TODO: many entries are unlocked; why is this reported at level 1?
1049 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1050 neighborCountIgnored(p
);
1054 if (!mem
->ircb_data
) {
1055 debugs(12, DBG_IMPORTANT
, "BUG: missing ICP callback data for " << *entry
);
1056 neighborCountIgnored(p
);
1060 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1063 ntype
= neighborType(p
, mem
->request
->url
);
1066 if (ignoreMulticastReply(p
, mem
->ircb_data
)) {
1067 neighborCountIgnored(p
);
1068 } else if (opcode
== ICP_MISS
) {
1070 neighborIgnoreNonPeer(from
, opcode
);
1072 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1074 } else if (opcode
== ICP_HIT
) {
1076 neighborIgnoreNonPeer(from
, opcode
);
1078 header
->opcode
= ICP_HIT
;
1079 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1081 } else if (opcode
== ICP_DECHO
) {
1083 neighborIgnoreNonPeer(from
, opcode
);
1084 } else if (ntype
== PEER_SIBLING
) {
1085 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1086 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1088 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1090 } else if (opcode
== ICP_SECHO
) {
1092 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << p
->host
);
1093 neighborCountIgnored(p
);
1095 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1097 } else if (opcode
== ICP_DENIED
) {
1099 neighborIgnoreNonPeer(from
, opcode
);
1100 } else if (p
->stats
.pings_acked
> 100) {
1101 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1102 debugs(15, DBG_CRITICAL
, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1103 debugs(15, DBG_CRITICAL
, "Disabling '" << p
->host
<< "', please check your configuration.");
1107 neighborCountIgnored(p
);
1110 } else if (opcode
== ICP_MISS_NOFETCH
) {
1111 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1113 debugs(15, DBG_CRITICAL
, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1118 peerFindByName(const char *name
)
1120 CachePeer
*p
= NULL
;
1122 for (p
= Config
.peers
; p
; p
= p
->next
) {
1123 if (!strcasecmp(name
, p
->name
))
1131 peerFindByNameAndPort(const char *name
, unsigned short port
)
1133 CachePeer
*p
= NULL
;
1135 for (p
= Config
.peers
; p
; p
= p
->next
) {
1136 if (strcasecmp(name
, p
->name
))
1139 if (port
!= p
->http_port
)
1149 neighborUp(const CachePeer
* p
)
1152 peerProbeConnect(const_cast<CachePeer
*>(p
));
1157 * The CachePeer can not be UP if we don't have any IP addresses
1160 if (0 == p
->n_addresses
) {
1161 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1165 if (p
->options
.no_query
) {
1166 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1170 if (p
->stats
.probe_start
!= 0 &&
1171 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1172 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1176 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1180 /// \returns the effective connect timeout for this peer
1182 peerConnectTimeout(const CachePeer
*peer
)
1184 return peer
->connect_timeout_raw
> 0 ?
1185 peer
->connect_timeout_raw
: Config
.Timeout
.peer_connect
;
1189 positiveTimeout(const time_t timeout
)
1191 return max(static_cast<time_t>(1), timeout
);
1195 peerDNSConfigure(const ipcache_addrs
*ia
, const Dns::LookupDetails
&, void *data
)
1197 // TODO: connections to no-longer valid IP addresses should be
1198 // closed when we can detect such IP addresses.
1200 CachePeer
*p
= (CachePeer
*)data
;
1202 if (p
->n_addresses
== 0) {
1203 debugs(15, DBG_IMPORTANT
, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1205 if (p
->type
== PEER_MULTICAST
)
1206 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1212 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1217 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << p
->host
<< "'!");
1221 for (const auto &ip
: ia
->goodAndBad()) { // TODO: Consider using just good().
1222 if (p
->n_addresses
< PEER_MAX_ADDRESSES
) {
1223 const auto idx
= p
->n_addresses
++;
1224 p
->addresses
[idx
] = ip
;
1225 debugs(15, 2, "--> IP address #" << idx
<< ": " << p
->addresses
[idx
]);
1227 debugs(15, 3, "ignoring remaining " << (ia
->size() - p
->n_addresses
) << " ips");
1232 p
->in_addr
.setEmpty();
1233 p
->in_addr
= p
->addresses
[0];
1234 p
->in_addr
.port(p
->icp
.port
);
1236 peerProbeConnect(p
, true); // detect any died or revived peers ASAP
1238 if (p
->type
== PEER_MULTICAST
)
1239 peerCountMcastPeersSchedule(p
, 10);
1242 if (p
->type
!= PEER_MULTICAST
&& IamWorkerProcess())
1243 if (!p
->options
.no_netdb_exchange
)
1244 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1247 if (p
->standby
.mgr
.valid())
1248 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "resolved peer");
1252 peerRefreshDNS(void *data
)
1254 CachePeer
*p
= NULL
;
1256 if (eventFind(peerRefreshDNS
, NULL
))
1257 eventDelete(peerRefreshDNS
, NULL
);
1259 if (!data
&& 0 == stat5minClientRequests()) {
1260 /* no recent client traffic, wait a bit */
1261 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1265 for (p
= Config
.peers
; p
; p
= p
->next
)
1266 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1268 /* Reconfigure the peers every hour */
1269 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1273 peerConnectFailedSilent(CachePeer
* p
)
1275 p
->stats
.last_connect_failure
= squid_curtime
;
1278 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1286 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1287 p
->stats
.logged_state
= PEER_DEAD
;
1292 peerConnectFailed(CachePeer
*p
)
1294 debugs(15, DBG_IMPORTANT
, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1295 peerConnectFailedSilent(p
);
1299 peerConnectSucceded(CachePeer
* p
)
1302 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeeded");
1303 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1305 if (!p
->n_addresses
)
1306 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1308 p
->tcp_up
= p
->connect_fail_limit
;
1311 /// whether new TCP probes are currently banned
1313 peerProbeIsBusy(const CachePeer
*p
)
1315 if (p
->testing_now
> 0) {
1316 debugs(15, 8, "yes, probing " << p
);
1319 if (squid_curtime
- p
->stats
.last_connect_probe
== 0) {
1320 debugs(15, 8, "yes, just probed " << p
);
1326 * peerProbeConnect will be called on dead peers by neighborUp
1329 peerProbeConnect(CachePeer
*p
, const bool reprobeIfBusy
)
1331 if (peerProbeIsBusy(p
)) {
1332 p
->reprobe
= reprobeIfBusy
;
1337 const time_t ctimeout
= peerConnectTimeout(p
);
1338 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1339 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1340 Comm::ConnectionPointer conn
= new Comm::Connection
;
1341 conn
->remote
= p
->addresses
[i
];
1342 conn
->remote
.port(p
->http_port
);
1344 getOutgoingAddress(NULL
, conn
);
1348 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1349 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1350 cs
->setHost(p
->host
);
1351 AsyncJob::Start(cs
);
1354 p
->stats
.last_connect_probe
= squid_curtime
;
1358 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, Comm::Flag status
, int, void *data
)
1360 CachePeer
*p
= (CachePeer
*)data
;
1362 if (status
== Comm::OK
) {
1363 peerConnectSucceded(p
);
1365 peerConnectFailedSilent(p
);
1370 // TODO: log this traffic.
1373 peerProbeConnect(p
);
1377 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1379 if (p
->mcast
.flags
.count_event_pending
)
1382 eventAdd("peerCountMcastPeersStart",
1383 peerCountMcastPeersStart
,
1387 p
->mcast
.flags
.count_event_pending
= true;
1391 peerCountMcastPeersStart(void *data
)
1393 // XXX: Do not create lots of complex fake objects (while abusing their
1394 // APIs) to pass around a few basic data points like start_ping and ping!
1395 CachePeer
*p
= (CachePeer
*)data
;
1398 // TODO: use class AnyP::Uri instead of constructing and re-parsing a string
1399 LOCAL_ARRAY(char, url
, MAX_URL
);
1400 assert(p
->type
== PEER_MULTICAST
);
1401 p
->mcast
.flags
.count_event_pending
= false;
1402 snprintf(url
, MAX_URL
, "http://");
1403 p
->in_addr
.toUrl(url
+7, MAX_URL
-8 );
1405 const MasterXaction::Pointer mx
= new MasterXaction(XactionInitiator::initPeerMcast
);
1406 auto *req
= HttpRequest::FromUrlXXX(url
, mx
);
1407 assert(req
!= nullptr);
1408 StoreEntry
*fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1409 const auto psstate
= new PeerSelector(nullptr);
1410 psstate
->request
= req
;
1411 HTTPMSGLOCK(psstate
->request
);
1412 psstate
->entry
= fake
;
1413 psstate
->peerCountMcastPeerXXX
= cbdataReference(p
);
1414 psstate
->ping
.start
= current_time
;
1415 mem
= fake
->mem_obj
;
1416 mem
->request
= psstate
->request
;
1417 mem
->start_ping
= current_time
;
1418 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1419 mem
->ircb_data
= psstate
;
1420 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1421 p
->mcast
.id
= mem
->id
;
1422 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1423 icpCreateAndSend(ICP_QUERY
, 0, url
, reqnum
, 0,
1424 icpOutgoingConn
->fd
, p
->in_addr
, psstate
->al
);
1425 fake
->ping_status
= PING_WAITING
;
1426 eventAdd("peerCountMcastPeersDone",
1427 peerCountMcastPeersDone
,
1429 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1430 p
->mcast
.flags
.counting
= true;
1431 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1435 peerCountMcastPeersDone(void *data
)
1437 const auto psstate
= static_cast<PeerSelector
*>(data
);
1438 StoreEntry
*fake
= psstate
->entry
;
1440 if (cbdataReferenceValid(psstate
->peerCountMcastPeerXXX
)) {
1441 CachePeer
*p
= (CachePeer
*)psstate
->peerCountMcastPeerXXX
;
1442 p
->mcast
.flags
.counting
= false;
1443 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1444 debugs(15, DBG_IMPORTANT
, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1445 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1446 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1447 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1450 cbdataReferenceDone(psstate
->peerCountMcastPeerXXX
);
1452 fake
->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
1453 fake
->mem_obj
->request
= nullptr;
1454 fake
->unlock("peerCountMcastPeersDone");
1459 peerCountHandleIcpReply(CachePeer
* p
, peer_t
, AnyP::ProtocolType proto
, void *, void *data
)
1461 const auto psstate
= static_cast<PeerSelector
*>(data
);
1462 StoreEntry
*fake
= psstate
->entry
;
1464 MemObject
*mem
= fake
->mem_obj
;
1466 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1467 assert(proto
== AnyP::PROTO_ICP
);
1468 ++ psstate
->ping
.n_recv
;
1469 int rtt_av_factor
= RTT_AV_FACTOR
;
1471 if (p
->options
.weighted_roundrobin
)
1472 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1474 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1478 neighborDumpPeers(StoreEntry
* sentry
)
1480 dump_peers(sentry
, Config
.peers
);
1484 neighborDumpNonPeers(StoreEntry
* sentry
)
1486 dump_peers(sentry
, non_peers
);
1490 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1492 if (p
->options
.proxy_only
)
1493 storeAppendPrintf(sentry
, " proxy-only");
1495 if (p
->options
.no_query
)
1496 storeAppendPrintf(sentry
, " no-query");
1498 if (p
->options
.background_ping
)
1499 storeAppendPrintf(sentry
, " background-ping");
1501 if (p
->options
.no_digest
)
1502 storeAppendPrintf(sentry
, " no-digest");
1504 if (p
->options
.default_parent
)
1505 storeAppendPrintf(sentry
, " default");
1507 if (p
->options
.roundrobin
)
1508 storeAppendPrintf(sentry
, " round-robin");
1510 if (p
->options
.carp
)
1511 storeAppendPrintf(sentry
, " carp");
1514 if (p
->options
.userhash
)
1515 storeAppendPrintf(sentry
, " userhash");
1518 if (p
->options
.sourcehash
)
1519 storeAppendPrintf(sentry
, " sourcehash");
1521 if (p
->options
.weighted_roundrobin
)
1522 storeAppendPrintf(sentry
, " weighted-round-robin");
1524 if (p
->options
.mcast_responder
)
1525 storeAppendPrintf(sentry
, " multicast-responder");
1527 #if PEER_MULTICAST_SIBLINGS
1528 if (p
->options
.mcast_siblings
)
1529 storeAppendPrintf(sentry
, " multicast-siblings");
1533 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1535 if (p
->options
.closest_only
)
1536 storeAppendPrintf(sentry
, " closest-only");
1539 if (p
->options
.htcp
) {
1540 storeAppendPrintf(sentry
, " htcp");
1541 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1542 bool doneopts
= false;
1543 if (p
->options
.htcp_oldsquid
) {
1544 storeAppendPrintf(sentry
, "oldsquid");
1547 if (p
->options
.htcp_no_clr
) {
1548 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
?",":"="));
1551 if (p
->options
.htcp_no_purge_clr
) {
1552 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
?",":"="));
1555 if (p
->options
.htcp_only_clr
) {
1556 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
?",":"="));
1557 //doneopts = true; // uncomment if more opts are added
1563 if (p
->options
.no_netdb_exchange
)
1564 storeAppendPrintf(sentry
, " no-netdb-exchange");
1567 if (p
->options
.no_delay
)
1568 storeAppendPrintf(sentry
, " no-delay");
1572 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1574 if (p
->mcast
.ttl
> 0)
1575 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1577 if (p
->connect_timeout_raw
> 0)
1578 storeAppendPrintf(sentry
, " connect-timeout=%d", (int)p
->connect_timeout_raw
);
1580 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1581 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1583 #if USE_CACHE_DIGESTS
1586 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1590 if (p
->options
.allow_miss
)
1591 storeAppendPrintf(sentry
, " allow-miss");
1593 if (p
->options
.no_tproxy
)
1594 storeAppendPrintf(sentry
, " no-tproxy");
1596 if (p
->max_conn
> 0)
1597 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1598 if (p
->standby
.limit
> 0)
1599 storeAppendPrintf(sentry
, " standby=%d", p
->standby
.limit
);
1601 if (p
->options
.originserver
)
1602 storeAppendPrintf(sentry
, " originserver");
1605 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1607 if (p
->connection_auth
== 0)
1608 storeAppendPrintf(sentry
, " connection-auth=off");
1609 else if (p
->connection_auth
== 1)
1610 storeAppendPrintf(sentry
, " connection-auth=on");
1611 else if (p
->connection_auth
== 2)
1612 storeAppendPrintf(sentry
, " connection-auth=auto");
1614 p
->secure
.dumpCfg(sentry
,"tls-");
1615 storeAppendPrintf(sentry
, "\n");
1619 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1621 char ntoabuf
[MAX_IPSTRLEN
];
1625 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1627 for (CachePeer
*e
= peers
; e
; e
= e
->next
) {
1628 assert(e
->host
!= NULL
);
1629 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1632 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1636 storeAppendPrintf(sentry
, "Flags :");
1637 dump_peer_options(sentry
, e
);
1639 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1640 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1641 e
->addresses
[i
].toStr(ntoabuf
,MAX_IPSTRLEN
) );
1644 storeAppendPrintf(sentry
, "Status : %s\n",
1645 neighborUp(e
) ? "Up" : "Down");
1646 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1647 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1648 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1650 if (!e
->options
.no_query
) {
1651 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1652 (int) (squid_curtime
- e
->stats
.last_query
));
1654 if (e
->stats
.last_reply
> 0)
1655 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1656 (int) (squid_curtime
- e
->stats
.last_reply
));
1658 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1660 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1662 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1663 e
->stats
.pings_acked
,
1664 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1667 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1669 if (!e
->options
.no_query
) {
1670 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1673 if (e
->options
.htcp
) {
1674 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1676 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1677 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1679 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1683 for (auto op
: WholeEnum
<icp_opcode
>()) {
1684 if (e
->icp
.counts
[op
] == 0)
1687 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1690 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1701 if (e
->stats
.last_connect_failure
) {
1702 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1703 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1706 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1712 neighborsHtcpReply(const cache_key
* key
, HtcpReplyData
* htcp
, const Ip::Address
&from
)
1714 StoreEntry
*e
= Store::Root().findCallbackXXX(key
);
1715 MemObject
*mem
= NULL
;
1717 peer_t ntype
= PEER_NONE
;
1718 debugs(15, 6, "neighborsHtcpReply: " <<
1719 (htcp
->hit
? "HIT" : "MISS") << " " <<
1720 storeKeyText(key
) );
1725 if ((p
= whichPeer(from
)))
1726 neighborAliveHtcp(p
, mem
, htcp
);
1728 /* Does the entry exist? */
1730 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1731 neighborCountIgnored(p
);
1735 /* check if someone is already fetching it */
1736 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1737 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1738 neighborCountIgnored(p
);
1743 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1744 neighborCountIgnored(p
);
1748 if (e
->ping_status
!= PING_WAITING
) {
1749 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1750 neighborCountIgnored(p
);
1755 // TODO: many entries are unlocked; why is this reported at level 1?
1756 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1757 neighborCountIgnored(p
);
1761 if (!mem
->ircb_data
) {
1762 debugs(12, DBG_IMPORTANT
, "BUG: missing HTCP callback data for " << *e
);
1763 neighborCountIgnored(p
);
1768 ntype
= neighborType(p
, mem
->request
->url
);
1769 neighborUpdateRtt(p
, mem
);
1772 if (ignoreMulticastReply(p
, mem
->ircb_data
)) {
1773 neighborCountIgnored(p
);
1777 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1778 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1782 * Send HTCP CLR messages to all peers configured to receive them.
1785 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1790 for (p
= Config
.peers
; p
; p
= p
->next
) {
1791 if (!p
->options
.htcp
) {
1794 if (p
->options
.htcp_no_clr
) {
1797 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1800 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.toUrl(buf
, 128));
1801 htcpClear(e
, uri
, req
, method
, p
, reason
);