2 * Copyright (C) 1996-2017 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"
49 /* count mcast group peers every 15 minutes */
50 #define MCAST_COUNT_RATE 900
52 bool peerAllowedToUse(const CachePeer
*, HttpRequest
*);
53 static int peerWouldBePinged(const CachePeer
*, HttpRequest
*);
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 IRCB peerCountHandleIcpReply
;
69 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
70 static OBJH neighborDumpPeers
;
71 static OBJH neighborDumpNonPeers
;
72 static void dump_peers(StoreEntry
* sentry
, CachePeer
* peers
);
74 static unsigned short echo_port
;
76 static int NLateReplies
= 0;
77 static CachePeer
*first_ping
= NULL
;
80 neighborTypeStr(const CachePeer
* p
)
82 if (p
->type
== PEER_NONE
)
85 if (p
->type
== PEER_SIBLING
)
88 if (p
->type
== PEER_MULTICAST
)
89 return "Multicast Group";
95 whichPeer(const Ip::Address
&from
)
100 debugs(15, 3, "whichPeer: from " << from
);
102 for (p
= Config
.peers
; p
; p
= p
->next
) {
103 for (j
= 0; j
< p
->n_addresses
; ++j
) {
104 if (from
== p
->addresses
[j
] && from
.port() == p
->icp
.port
) {
114 neighborType(const CachePeer
* p
, const URL
&url
)
117 const NeighborTypeDomainList
*d
= NULL
;
119 for (d
= p
->typelist
; d
; d
= d
->next
) {
120 if (0 == matchDomainName(url
.host(), d
->domain
))
121 if (d
->type
!= PEER_NONE
)
124 #if PEER_MULTICAST_SIBLINGS
125 if (p
->type
== PEER_MULTICAST
)
126 if (p
->options
.mcast_siblings
)
134 * \return Whether it is appropriate to fetch REQUEST from PEER.
137 peerAllowedToUse(const CachePeer
* p
, HttpRequest
* 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
);
171 return (checklist
.fastCheck() == ACCESS_ALLOWED
);
174 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
176 peerWouldBePinged(const CachePeer
* p
, HttpRequest
* request
)
178 if (p
->icp
.port
== 0)
181 if (p
->options
.no_query
)
184 if (p
->options
.mcast_responder
)
187 if (p
->n_addresses
== 0)
190 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
193 /* the case below seems strange, but can happen if the
194 * URL host is on the other side of a firewall */
195 if (p
->type
== PEER_SIBLING
)
196 if (!request
->flags
.hierarchical
)
199 if (!peerAllowedToUse(p
, request
))
202 /* Ping dead peers every timeout interval */
203 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
213 peerCanOpenMore(const CachePeer
*p
)
215 const int effectiveLimit
= p
->max_conn
<= 0 ? Squid_MaxFD
: p
->max_conn
;
216 const int remaining
= effectiveLimit
- p
->stats
.conn_open
;
217 debugs(15, 7, remaining
<< '=' << effectiveLimit
<< '-' << p
->stats
.conn_open
);
218 return remaining
> 0;
222 peerHasConnAvailable(const CachePeer
*p
)
224 // Standby connections can be used without opening new connections.
225 const int standbys
= p
->standby
.pool
? p
->standby
.pool
->count() : 0;
227 // XXX: Some idle pconns can be used without opening new connections.
228 // Complication: Idle pconns cannot be reused for some requests.
229 const int usableIdles
= 0;
231 const int available
= standbys
+ usableIdles
;
232 debugs(15, 7, available
<< '=' << standbys
<< '+' << usableIdles
);
233 return available
> 0;
237 peerConnClosed(CachePeer
*p
)
239 --p
->stats
.conn_open
;
240 if (p
->standby
.waitingForClose
&& peerCanOpenMore(p
)) {
241 p
->standby
.waitingForClose
= false;
242 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "conn closed");
246 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
248 peerHTTPOkay(const CachePeer
* p
, HttpRequest
* request
)
250 if (!peerCanOpenMore(p
) && !peerHasConnAvailable(p
))
253 if (!peerAllowedToUse(p
, request
))
263 neighborsCount(HttpRequest
* request
)
268 for (p
= Config
.peers
; p
; p
= p
->next
)
269 if (peerWouldBePinged(p
, request
))
272 debugs(15, 3, "neighborsCount: " << count
);
278 getFirstUpParent(HttpRequest
* request
)
282 for (p
= Config
.peers
; p
; p
= p
->next
) {
286 if (neighborType(p
, request
->url
) != PEER_PARENT
)
289 if (!peerHTTPOkay(p
, request
))
295 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
300 getRoundRobinParent(HttpRequest
* request
)
305 for (p
= Config
.peers
; p
; p
= p
->next
) {
306 if (!p
->options
.roundrobin
)
309 if (neighborType(p
, request
->url
) != PEER_PARENT
)
312 if (!peerHTTPOkay(p
, request
))
319 if (p
->weight
== q
->weight
) {
320 if (q
->rr_count
< p
->rr_count
)
322 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
333 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
339 getWeightedRoundRobinParent(HttpRequest
* request
)
345 for (p
= Config
.peers
; p
; p
= p
->next
) {
346 if (!p
->options
.weighted_roundrobin
)
349 if (neighborType(p
, request
->url
) != PEER_PARENT
)
352 if (!peerHTTPOkay(p
, request
))
355 if (q
&& q
->rr_count
< p
->rr_count
)
361 if (q
&& q
->rr_count
> 1000000)
362 for (p
= Config
.peers
; p
; p
= p
->next
) {
363 if (!p
->options
.weighted_roundrobin
)
366 if (neighborType(p
, request
->url
) != PEER_PARENT
)
373 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
375 if (weighted_rtt
< 1)
378 q
->rr_count
+= weighted_rtt
;
380 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
383 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
388 * This gets called every 5 minutes to clear the round-robin counter.
389 * The exact timing is an arbitrary default, set on estimate timing of a
390 * large number of requests in a high-performance environment during the
391 * period. The larger the number of requests between cycled resets the
392 * more balanced the operations.
395 \todo Make the reset timing a selectable parameter in squid.conf
398 peerClearRRLoop(void *data
)
401 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
405 * This gets called on startup and restart to kick off the CachePeer round-robin
406 * maintenance event. It ensures that no matter how many times its called
407 * no more than one event is scheduled.
410 peerClearRRStart(void)
412 static bool event_added
= false;
414 peerClearRRLoop(NULL
);
420 * Called whenever the round-robin counters need to be reset to a sane state.
421 * So far those times are:
422 * - On startup and reconfigure - to set the counters to sane initial settings.
423 * - When a CachePeer has revived from dead, to prevent the revived CachePeer being
424 * flooded with requests which it has 'missed' during the down period.
430 for (p
= Config
.peers
; p
; p
= p
->next
) {
436 * Perform all actions when a CachePeer is detected revived.
439 peerAlive(CachePeer
*p
)
441 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
442 debugs(15, DBG_IMPORTANT
, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
443 p
->stats
.logged_state
= PEER_ALIVE
;
445 if (p
->standby
.mgr
.valid())
446 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "revived peer");
449 p
->stats
.last_reply
= squid_curtime
;
450 p
->stats
.probe_start
= 0;
454 getDefaultParent(HttpRequest
* request
)
458 for (p
= Config
.peers
; p
; p
= p
->next
) {
459 if (neighborType(p
, request
->url
) != PEER_PARENT
)
462 if (!p
->options
.default_parent
)
465 if (!peerHTTPOkay(p
, request
))
468 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
473 debugs(15, 3, "getDefaultParent: returning NULL");
478 getNextPeer(CachePeer
* p
)
490 neighborRemove(CachePeer
* target
)
493 CachePeer
**P
= NULL
;
513 first_ping
= Config
.peers
;
517 neighborsRegisterWithCacheManager()
519 Mgr::RegisterAction("server_list",
520 "Peer Cache Statistics",
521 neighborDumpPeers
, 0, 1);
523 if (Comm::IsConnOpen(icpIncomingConn
)) {
524 Mgr::RegisterAction("non_peers",
525 "List of Unknown sites sending ICP messages",
526 neighborDumpNonPeers
, 0, 1);
533 struct servent
*sep
= NULL
;
534 const char *me
= getMyHostname();
535 CachePeer
*thisPeer
= NULL
;
536 CachePeer
*next
= NULL
;
538 neighborsRegisterWithCacheManager();
540 if (Comm::IsConnOpen(icpIncomingConn
)) {
542 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
543 next
= thisPeer
->next
;
545 if (0 != strcmp(thisPeer
->host
, me
))
548 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
549 if (thisPeer
->http_port
!= s
->s
.port())
552 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
554 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
555 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
556 "/" << thisPeer
->http_port
<< "/" <<
559 neighborRemove(thisPeer
);
564 peerRefreshDNS((void *) 1);
566 sep
= getservbyname("echo", "udp");
567 echo_port
= sep
? ntohs((unsigned short) sep
->s_port
) : 7;
569 first_ping
= Config
.peers
;
573 neighborsUdpPing(HttpRequest
* request
,
580 const char *url
= entry
->url();
581 MemObject
*mem
= entry
->mem_obj
;
587 int queries_sent
= 0;
588 int peers_pinged
= 0;
589 int parent_timeout
= 0, parent_exprep
= 0;
590 int sibling_timeout
= 0, sibling_exprep
= 0;
591 int mcast_timeout
= 0, mcast_exprep
= 0;
593 if (Config
.peers
== NULL
)
596 assert(entry
->swap_status
== SWAPOUT_NONE
);
598 mem
->start_ping
= current_time
;
600 mem
->ping_reply_callback
= callback
;
602 mem
->ircb_data
= callback_data
;
604 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
606 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
610 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
612 if (!peerWouldBePinged(p
, request
))
613 continue; /* next CachePeer */
617 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
619 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
621 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
624 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
625 if (Config
.Port
.htcp
<= 0) {
626 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
630 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
631 if (htcpQuery(entry
, request
, p
) <= 0)
632 continue; // unable to send.
636 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
637 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
641 if (p
->type
== PEER_MULTICAST
)
642 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
644 if (p
->icp
.port
== echo_port
) {
645 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
646 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
647 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
651 if (Config
.onoff
.query_icmp
)
652 if (p
->icp
.version
== ICP_VERSION_2
)
653 flags
|= ICP_FLAG_SRC_RTT
;
655 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
657 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0.0);
664 ++ p
->stats
.pings_sent
;
666 if (p
->type
== PEER_MULTICAST
) {
667 mcast_exprep
+= p
->mcast
.n_replies_expected
;
668 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
669 } else if (neighborUp(p
)) {
670 /* its alive, expect a reply from it */
672 if (neighborType(p
, request
->url
) == PEER_PARENT
) {
674 parent_timeout
+= p
->stats
.rtt
;
677 sibling_timeout
+= p
->stats
.rtt
;
680 /* Neighbor is dead; ping it anyway, but don't expect a reply */
681 /* log it once at the threshold */
683 if (p
->stats
.logged_state
== PEER_ALIVE
) {
684 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
685 p
->stats
.logged_state
= PEER_DEAD
;
689 p
->stats
.last_query
= squid_curtime
;
692 * keep probe_start == 0 for a multicast CachePeer,
693 * so neighborUp() never says this CachePeer is dead.
696 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
697 p
->stats
.probe_start
= squid_curtime
;
700 if ((first_ping
= first_ping
->next
) == NULL
)
701 first_ping
= Config
.peers
;
704 * How many replies to expect?
706 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
709 * If there is a configured timeout, use it
711 if (Config
.Timeout
.icp_query
)
712 *timeout
= Config
.Timeout
.icp_query
;
716 *timeout
= 2 * parent_timeout
/ parent_exprep
;
717 else if (mcast_exprep
)
718 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
720 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
722 *timeout
= 2000; /* 2 seconds */
724 if (Config
.Timeout
.icp_query_max
)
725 if (*timeout
> Config
.Timeout
.icp_query_max
)
726 *timeout
= Config
.Timeout
.icp_query_max
;
728 if (*timeout
< Config
.Timeout
.icp_query_min
)
729 *timeout
= Config
.Timeout
.icp_query_min
;
735 /* lookup the digest of a given CachePeer */
737 peerDigestLookup(CachePeer
* p
, HttpRequest
* request
)
739 #if USE_CACHE_DIGESTS
740 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
743 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
744 /* does the peeer have a valid digest? */
747 debugs(15, 5, "peerDigestLookup: gone!");
749 } else if (!peerHTTPOkay(p
, request
)) {
750 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
752 } else if (!p
->digest
->flags
.needed
) {
753 debugs(15, 5, "peerDigestLookup: note need");
754 peerDigestNeeded(p
->digest
);
756 } else if (!p
->digest
->flags
.usable
) {
757 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
761 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
762 assert(p
->digest
->cd
);
763 /* does digest predict a hit? */
765 if (!p
->digest
->cd
->contains(key
))
768 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
777 /* select best CachePeer based on cache digests */
779 neighborsDigestSelect(HttpRequest
* request
)
781 CachePeer
*best_p
= NULL
;
782 #if USE_CACHE_DIGESTS
785 int choice_count
= 0;
786 int ichoice_count
= 0;
791 if (!request
->flags
.hierarchical
)
794 storeKeyPublicByRequest(request
);
796 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
805 lookup
= peerDigestLookup(p
, request
);
807 if (lookup
== LOOKUP_NONE
)
812 if (lookup
== LOOKUP_MISS
)
815 p_rtt
= netdbHostRtt(p
->host
);
817 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
819 /* is this CachePeer better than others in terms of rtt ? */
820 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
824 if (p_rtt
) /* informative choice (aka educated guess) */
827 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
831 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
832 peerNoteDigestLookup(request
, best_p
,
833 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
834 request
->hier
.n_choices
= choice_count
;
835 request
->hier
.n_ichoices
= ichoice_count
;
842 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
844 #if USE_CACHE_DIGESTS
846 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
848 *request
->hier
.cd_host
= '\0';
850 request
->hier
.cd_lookup
= lookup
;
851 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
856 neighborAlive(CachePeer
* p
, const MemObject
*, const icp_common_t
* header
)
859 ++ p
->stats
.pings_acked
;
861 if ((icp_opcode
) header
->opcode
<= ICP_END
)
862 ++ p
->icp
.counts
[header
->opcode
];
864 p
->icp
.version
= (int) header
->version
;
868 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
870 int rtt
, rtt_av_factor
;
875 if (!mem
->start_ping
.tv_sec
)
878 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
880 if (rtt
< 1 || rtt
> 10000)
883 rtt_av_factor
= RTT_AV_FACTOR
;
885 if (p
->options
.weighted_roundrobin
)
886 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
888 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
893 neighborAliveHtcp(CachePeer
* p
, const MemObject
*, const HtcpReplyData
* htcp
)
896 ++ p
->stats
.pings_acked
;
897 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
898 p
->htcp
.version
= htcp
->version
;
904 neighborCountIgnored(CachePeer
* p
)
909 ++ p
->stats
.ignored_replies
;
914 static CachePeer
*non_peers
= NULL
;
917 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
921 for (np
= non_peers
; np
; np
= np
->next
) {
922 if (np
->in_addr
!= from
)
925 if (np
->in_addr
.port() != from
.port())
934 np
->icp
.port
= from
.port();
935 np
->type
= PEER_NONE
;
936 np
->host
= new char[MAX_IPSTRLEN
];
937 from
.toStr(np
->host
,MAX_IPSTRLEN
);
938 np
->next
= non_peers
;
942 ++ np
->icp
.counts
[opcode
];
944 if (isPowTen(++np
->stats
.ignored_replies
))
945 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
948 /* ignoreMulticastReply
950 * * We want to ignore replies from multicast peers if the
951 * * cache_host_domain rules would normally prevent the CachePeer
955 ignoreMulticastReply(CachePeer
* p
, MemObject
* mem
)
960 if (!p
->options
.mcast_responder
)
963 if (peerHTTPOkay(p
, mem
->request
.getRaw()))
970 * I should attach these records to the entry. We take the first
971 * hit we get our wait until everyone misses. The timeout handler
972 * call needs to nip this shopping list or call one of the misses.
974 * If a hit process is already started, then sobeit
977 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
981 MemObject
*mem
= NULL
;
982 peer_t ntype
= PEER_NONE
;
983 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
985 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
987 if (NULL
!= (entry
= Store::Root().get(key
)))
988 mem
= entry
->mem_obj
;
990 if ((p
= whichPeer(from
)))
991 neighborAlive(p
, mem
, header
);
993 if (opcode
> ICP_END
)
996 const char *opcode_d
= icp_opcode_str
[opcode
];
999 neighborUpdateRtt(p
, mem
);
1001 /* Does the entry exist? */
1002 if (NULL
== entry
) {
1003 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1004 neighborCountIgnored(p
);
1008 /* check if someone is already fetching it */
1009 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1010 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1011 neighborCountIgnored(p
);
1016 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1017 neighborCountIgnored(p
);
1021 if (entry
->ping_status
!= PING_WAITING
) {
1022 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1023 neighborCountIgnored(p
);
1027 if (!entry
->locked()) {
1028 // TODO: many entries are unlocked; why is this reported at level 1?
1029 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1030 neighborCountIgnored(p
);
1034 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1037 ntype
= neighborType(p
, mem
->request
->url
);
1040 if (ignoreMulticastReply(p
, mem
)) {
1041 neighborCountIgnored(p
);
1042 } else if (opcode
== ICP_MISS
) {
1044 neighborIgnoreNonPeer(from
, opcode
);
1046 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1048 } else if (opcode
== ICP_HIT
) {
1050 neighborIgnoreNonPeer(from
, opcode
);
1052 header
->opcode
= ICP_HIT
;
1053 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1055 } else if (opcode
== ICP_DECHO
) {
1057 neighborIgnoreNonPeer(from
, opcode
);
1058 } else if (ntype
== PEER_SIBLING
) {
1059 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1060 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1062 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1064 } else if (opcode
== ICP_SECHO
) {
1066 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << p
->host
);
1067 neighborCountIgnored(p
);
1069 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1071 } else if (opcode
== ICP_DENIED
) {
1073 neighborIgnoreNonPeer(from
, opcode
);
1074 } else if (p
->stats
.pings_acked
> 100) {
1075 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1076 debugs(15, DBG_CRITICAL
, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1077 debugs(15, DBG_CRITICAL
, "Disabling '" << p
->host
<< "', please check your configuration.");
1081 neighborCountIgnored(p
);
1084 } else if (opcode
== ICP_MISS_NOFETCH
) {
1085 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1087 debugs(15, DBG_CRITICAL
, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1092 peerFindByName(const char *name
)
1094 CachePeer
*p
= NULL
;
1096 for (p
= Config
.peers
; p
; p
= p
->next
) {
1097 if (!strcasecmp(name
, p
->name
))
1105 peerFindByNameAndPort(const char *name
, unsigned short port
)
1107 CachePeer
*p
= NULL
;
1109 for (p
= Config
.peers
; p
; p
= p
->next
) {
1110 if (strcasecmp(name
, p
->name
))
1113 if (port
!= p
->http_port
)
1123 neighborUp(const CachePeer
* p
)
1126 peerProbeConnect(const_cast<CachePeer
*>(p
));
1131 * The CachePeer can not be UP if we don't have any IP addresses
1134 if (0 == p
->n_addresses
) {
1135 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1139 if (p
->options
.no_query
) {
1140 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1144 if (p
->stats
.probe_start
!= 0 &&
1145 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1146 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1150 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1155 peerNoteDigestGone(CachePeer
* p
)
1157 #if USE_CACHE_DIGESTS
1158 cbdataReferenceDone(p
->digest
);
1162 /// \returns the effective connect timeout for this peer
1164 peerConnectTimeout(const CachePeer
*peer
)
1166 return peer
->connect_timeout_raw
> 0 ?
1167 peer
->connect_timeout_raw
: Config
.Timeout
.peer_connect
;
1171 positiveTimeout(const time_t timeout
)
1173 return max(static_cast<time_t>(1), timeout
);
1177 peerDNSConfigure(const ipcache_addrs
*ia
, const Dns::LookupDetails
&, void *data
)
1179 // TODO: connections to no-longer valid IP addresses should be
1180 // closed when we can detect such IP addresses.
1182 CachePeer
*p
= (CachePeer
*)data
;
1186 if (p
->n_addresses
== 0) {
1187 debugs(15, DBG_IMPORTANT
, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1189 if (p
->type
== PEER_MULTICAST
)
1190 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1196 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1200 if ((int) ia
->count
< 1) {
1201 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << p
->host
<< "'!");
1205 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; ++j
) {
1206 p
->addresses
[j
] = ia
->in_addrs
[j
];
1207 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1211 p
->in_addr
.setEmpty();
1212 p
->in_addr
= p
->addresses
[0];
1213 p
->in_addr
.port(p
->icp
.port
);
1215 peerProbeConnect(p
, true); // detect any died or revived peers ASAP
1217 if (p
->type
== PEER_MULTICAST
)
1218 peerCountMcastPeersSchedule(p
, 10);
1221 if (p
->type
!= PEER_MULTICAST
&& IamWorkerProcess())
1222 if (!p
->options
.no_netdb_exchange
)
1223 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1226 if (p
->standby
.mgr
.valid())
1227 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "resolved peer");
1231 peerRefreshDNS(void *data
)
1233 CachePeer
*p
= NULL
;
1235 if (eventFind(peerRefreshDNS
, NULL
))
1236 eventDelete(peerRefreshDNS
, NULL
);
1238 if (!data
&& 0 == stat5minClientRequests()) {
1239 /* no recent client traffic, wait a bit */
1240 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1244 for (p
= Config
.peers
; p
; p
= p
->next
)
1245 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1247 /* Reconfigure the peers every hour */
1248 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1252 peerConnectFailedSilent(CachePeer
* p
)
1254 p
->stats
.last_connect_failure
= squid_curtime
;
1257 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1265 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1266 p
->stats
.logged_state
= PEER_DEAD
;
1271 peerConnectFailed(CachePeer
*p
)
1273 debugs(15, DBG_IMPORTANT
, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1274 peerConnectFailedSilent(p
);
1278 peerConnectSucceded(CachePeer
* p
)
1281 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1282 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1284 if (!p
->n_addresses
)
1285 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1287 p
->tcp_up
= p
->connect_fail_limit
;
1290 /// whether new TCP probes are currently banned
1292 peerProbeIsBusy(const CachePeer
*p
)
1294 if (p
->testing_now
> 0) {
1295 debugs(15, 8, "yes, probing " << p
);
1298 if (squid_curtime
- p
->stats
.last_connect_probe
== 0) {
1299 debugs(15, 8, "yes, just probed " << p
);
1305 * peerProbeConnect will be called on dead peers by neighborUp
1308 peerProbeConnect(CachePeer
*p
, const bool reprobeIfBusy
)
1310 if (peerProbeIsBusy(p
)) {
1311 p
->reprobe
= reprobeIfBusy
;
1316 const time_t ctimeout
= peerConnectTimeout(p
);
1317 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1318 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1319 Comm::ConnectionPointer conn
= new Comm::Connection
;
1320 conn
->remote
= p
->addresses
[i
];
1321 conn
->remote
.port(p
->http_port
);
1323 getOutgoingAddress(NULL
, conn
);
1327 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1328 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1329 cs
->setHost(p
->host
);
1330 AsyncJob::Start(cs
);
1333 p
->stats
.last_connect_probe
= squid_curtime
;
1337 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, Comm::Flag status
, int, void *data
)
1339 CachePeer
*p
= (CachePeer
*)data
;
1341 if (status
== Comm::OK
) {
1342 peerConnectSucceded(p
);
1344 peerConnectFailedSilent(p
);
1349 // TODO: log this traffic.
1352 peerProbeConnect(p
);
1356 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1358 if (p
->mcast
.flags
.count_event_pending
)
1361 eventAdd("peerCountMcastPeersStart",
1362 peerCountMcastPeersStart
,
1366 p
->mcast
.flags
.count_event_pending
= true;
1370 peerCountMcastPeersStart(void *data
)
1372 // XXX: Do not create lots of complex fake objects (while abusing their
1373 // APIs) to pass around a few basic data points like start_ping and ping!
1374 CachePeer
*p
= (CachePeer
*)data
;
1378 icp_common_t
*query
;
1380 LOCAL_ARRAY(char, url
, MAX_URL
);
1381 assert(p
->type
== PEER_MULTICAST
);
1382 p
->mcast
.flags
.count_event_pending
= false;
1383 snprintf(url
, MAX_URL
, "http://");
1384 p
->in_addr
.toUrl(url
+7, MAX_URL
-8 );
1386 fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1387 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1388 psstate
= new ps_state(nullptr);
1389 psstate
->request
= req
;
1390 HTTPMSGLOCK(psstate
->request
);
1391 psstate
->entry
= fake
;
1392 psstate
->peerCountMcastPeerXXX
= cbdataReference(p
);
1393 psstate
->ping
.start
= current_time
;
1394 mem
= fake
->mem_obj
;
1395 mem
->request
= psstate
->request
;
1396 mem
->start_ping
= current_time
;
1397 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1398 mem
->ircb_data
= psstate
;
1399 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1400 p
->mcast
.id
= mem
->id
;
1401 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1402 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1403 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
1404 fake
->ping_status
= PING_WAITING
;
1405 eventAdd("peerCountMcastPeersDone",
1406 peerCountMcastPeersDone
,
1408 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1409 p
->mcast
.flags
.counting
= true;
1410 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1414 peerCountMcastPeersDone(void *data
)
1416 ps_state
*psstate
= (ps_state
*)data
;
1417 StoreEntry
*fake
= psstate
->entry
;
1419 if (cbdataReferenceValid(psstate
->peerCountMcastPeerXXX
)) {
1420 CachePeer
*p
= (CachePeer
*)psstate
->peerCountMcastPeerXXX
;
1421 p
->mcast
.flags
.counting
= false;
1422 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1423 debugs(15, DBG_IMPORTANT
, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1424 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1425 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1426 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1429 cbdataReferenceDone(psstate
->peerCountMcastPeerXXX
);
1431 fake
->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
1432 fake
->mem_obj
->request
= nullptr;
1433 fake
->unlock("peerCountMcastPeersDone");
1438 peerCountHandleIcpReply(CachePeer
* p
, peer_t
, AnyP::ProtocolType proto
, void *, void *data
)
1440 ps_state
*psstate
= (ps_state
*)data
;
1441 StoreEntry
*fake
= psstate
->entry
;
1443 MemObject
*mem
= fake
->mem_obj
;
1445 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1446 assert(proto
== AnyP::PROTO_ICP
);
1447 ++ psstate
->ping
.n_recv
;
1448 int rtt_av_factor
= RTT_AV_FACTOR
;
1450 if (p
->options
.weighted_roundrobin
)
1451 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1453 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1457 neighborDumpPeers(StoreEntry
* sentry
)
1459 dump_peers(sentry
, Config
.peers
);
1463 neighborDumpNonPeers(StoreEntry
* sentry
)
1465 dump_peers(sentry
, non_peers
);
1469 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1471 if (p
->options
.proxy_only
)
1472 storeAppendPrintf(sentry
, " proxy-only");
1474 if (p
->options
.no_query
)
1475 storeAppendPrintf(sentry
, " no-query");
1477 if (p
->options
.background_ping
)
1478 storeAppendPrintf(sentry
, " background-ping");
1480 if (p
->options
.no_digest
)
1481 storeAppendPrintf(sentry
, " no-digest");
1483 if (p
->options
.default_parent
)
1484 storeAppendPrintf(sentry
, " default");
1486 if (p
->options
.roundrobin
)
1487 storeAppendPrintf(sentry
, " round-robin");
1489 if (p
->options
.carp
)
1490 storeAppendPrintf(sentry
, " carp");
1493 if (p
->options
.userhash
)
1494 storeAppendPrintf(sentry
, " userhash");
1497 if (p
->options
.sourcehash
)
1498 storeAppendPrintf(sentry
, " sourcehash");
1500 if (p
->options
.weighted_roundrobin
)
1501 storeAppendPrintf(sentry
, " weighted-round-robin");
1503 if (p
->options
.mcast_responder
)
1504 storeAppendPrintf(sentry
, " multicast-responder");
1506 #if PEER_MULTICAST_SIBLINGS
1507 if (p
->options
.mcast_siblings
)
1508 storeAppendPrintf(sentry
, " multicast-siblings");
1512 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1514 if (p
->options
.closest_only
)
1515 storeAppendPrintf(sentry
, " closest-only");
1518 if (p
->options
.htcp
) {
1519 storeAppendPrintf(sentry
, " htcp");
1520 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1521 bool doneopts
= false;
1522 if (p
->options
.htcp_oldsquid
) {
1523 storeAppendPrintf(sentry
, "oldsquid");
1526 if (p
->options
.htcp_no_clr
) {
1527 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
?",":"="));
1530 if (p
->options
.htcp_no_purge_clr
) {
1531 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
?",":"="));
1534 if (p
->options
.htcp_only_clr
) {
1535 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
?",":"="));
1536 //doneopts = true; // uncomment if more opts are added
1542 if (p
->options
.no_netdb_exchange
)
1543 storeAppendPrintf(sentry
, " no-netdb-exchange");
1546 if (p
->options
.no_delay
)
1547 storeAppendPrintf(sentry
, " no-delay");
1551 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1553 if (p
->mcast
.ttl
> 0)
1554 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1556 if (p
->connect_timeout_raw
> 0)
1557 storeAppendPrintf(sentry
, " connect-timeout=%d", (int)p
->connect_timeout_raw
);
1559 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1560 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1562 #if USE_CACHE_DIGESTS
1565 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1569 if (p
->options
.allow_miss
)
1570 storeAppendPrintf(sentry
, " allow-miss");
1572 if (p
->options
.no_tproxy
)
1573 storeAppendPrintf(sentry
, " no-tproxy");
1575 if (p
->max_conn
> 0)
1576 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1577 if (p
->standby
.limit
> 0)
1578 storeAppendPrintf(sentry
, " standby=%d", p
->standby
.limit
);
1580 if (p
->options
.originserver
)
1581 storeAppendPrintf(sentry
, " originserver");
1584 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1586 if (p
->connection_auth
== 0)
1587 storeAppendPrintf(sentry
, " connection-auth=off");
1588 else if (p
->connection_auth
== 1)
1589 storeAppendPrintf(sentry
, " connection-auth=on");
1590 else if (p
->connection_auth
== 2)
1591 storeAppendPrintf(sentry
, " connection-auth=auto");
1593 p
->secure
.dumpCfg(sentry
,"tls-");
1594 storeAppendPrintf(sentry
, "\n");
1598 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1600 char ntoabuf
[MAX_IPSTRLEN
];
1604 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1606 for (CachePeer
*e
= peers
; e
; e
= e
->next
) {
1607 assert(e
->host
!= NULL
);
1608 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1611 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1615 storeAppendPrintf(sentry
, "Flags :");
1616 dump_peer_options(sentry
, e
);
1618 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1619 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1620 e
->addresses
[i
].toStr(ntoabuf
,MAX_IPSTRLEN
) );
1623 storeAppendPrintf(sentry
, "Status : %s\n",
1624 neighborUp(e
) ? "Up" : "Down");
1625 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1626 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1627 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1629 if (!e
->options
.no_query
) {
1630 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1631 (int) (squid_curtime
- e
->stats
.last_query
));
1633 if (e
->stats
.last_reply
> 0)
1634 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1635 (int) (squid_curtime
- e
->stats
.last_reply
));
1637 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1639 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1641 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1642 e
->stats
.pings_acked
,
1643 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1646 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1648 if (!e
->options
.no_query
) {
1649 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1652 if (e
->options
.htcp
) {
1653 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1655 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1656 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1658 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1662 for (auto op
: WholeEnum
<icp_opcode
>()) {
1663 if (e
->icp
.counts
[op
] == 0)
1666 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1669 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1680 if (e
->stats
.last_connect_failure
) {
1681 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1682 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1685 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1691 neighborsHtcpReply(const cache_key
* key
, HtcpReplyData
* htcp
, const Ip::Address
&from
)
1693 StoreEntry
*e
= Store::Root().get(key
);
1694 MemObject
*mem
= NULL
;
1696 peer_t ntype
= PEER_NONE
;
1697 debugs(15, 6, "neighborsHtcpReply: " <<
1698 (htcp
->hit
? "HIT" : "MISS") << " " <<
1699 storeKeyText(key
) );
1704 if ((p
= whichPeer(from
)))
1705 neighborAliveHtcp(p
, mem
, htcp
);
1707 /* Does the entry exist? */
1709 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1710 neighborCountIgnored(p
);
1714 /* check if someone is already fetching it */
1715 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1716 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1717 neighborCountIgnored(p
);
1722 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1723 neighborCountIgnored(p
);
1727 if (e
->ping_status
!= PING_WAITING
) {
1728 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1729 neighborCountIgnored(p
);
1734 // TODO: many entries are unlocked; why is this reported at level 1?
1735 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1736 neighborCountIgnored(p
);
1741 ntype
= neighborType(p
, mem
->request
->url
);
1742 neighborUpdateRtt(p
, mem
);
1745 if (ignoreMulticastReply(p
, mem
)) {
1746 neighborCountIgnored(p
);
1750 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1751 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1755 * Send HTCP CLR messages to all peers configured to receive them.
1758 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1763 for (p
= Config
.peers
; p
; p
= p
->next
) {
1764 if (!p
->options
.htcp
) {
1767 if (p
->options
.htcp_no_clr
) {
1770 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1773 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.toUrl(buf
, 128));
1774 htcpClear(e
, uri
, req
, method
, p
, reason
);