2 * Copyright (C) 1996-2015 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 "CacheDigest.h"
15 #include "CachePeer.h"
16 #include "CachePeerDomainList.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 bool peerProbeConnect(CachePeer
*);
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 HttpRequest
* request
)
117 const NeighborTypeDomainList
*d
= NULL
;
119 for (d
= p
->typelist
; d
; d
= d
->next
) {
120 if (0 == matchDomainName(request
->GetHost(), 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 const CachePeerDomainList
*d
= NULL
;
141 assert(request
!= NULL
);
143 if (neighborType(p
, request
) == PEER_SIBLING
) {
144 #if PEER_MULTICAST_SIBLINGS
145 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
146 (request
->flags
.noCache
|| request
->flags
.refresh
|| request
->flags
.loopDetected
|| request
->flags
.needValidation
))
147 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->GetHost() << ") : multicast-siblings optimization match");
149 if (request
->flags
.noCache
)
152 if (request
->flags
.refresh
)
155 if (request
->flags
.loopDetected
)
158 if (request
->flags
.needValidation
)
162 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
163 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
164 if (p
->options
.originserver
&& request
->method
== Http::METHOD_CONNECT
&& request
->port
!= p
->in_addr
.port())
167 if (p
->peer_domain
== NULL
&& p
->access
== NULL
)
170 bool do_ping
= false;
171 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
172 if (0 == matchDomainName(request
->GetHost(), d
->domain
)) {
173 do_ping
= d
->do_ping
;
177 do_ping
= !d
->do_ping
;
180 if (p
->peer_domain
&& !do_ping
)
183 if (p
->access
== NULL
)
186 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
188 return (checklist
.fastCheck() == ACCESS_ALLOWED
);
191 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
193 peerWouldBePinged(const CachePeer
* p
, HttpRequest
* request
)
195 if (p
->icp
.port
== 0)
198 if (p
->options
.no_query
)
201 if (p
->options
.mcast_responder
)
204 if (p
->n_addresses
== 0)
207 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
210 /* the case below seems strange, but can happen if the
211 * URL host is on the other side of a firewall */
212 if (p
->type
== PEER_SIBLING
)
213 if (!request
->flags
.hierarchical
)
216 if (!peerAllowedToUse(p
, request
))
219 /* Ping dead peers every timeout interval */
220 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
230 peerCanOpenMore(const CachePeer
*p
)
232 const int effectiveLimit
= p
->max_conn
<= 0 ? Squid_MaxFD
: p
->max_conn
;
233 const int remaining
= effectiveLimit
- p
->stats
.conn_open
;
234 debugs(15, 7, remaining
<< '=' << effectiveLimit
<< '-' << p
->stats
.conn_open
);
235 return remaining
> 0;
239 peerHasConnAvailable(const CachePeer
*p
)
241 // Standby connections can be used without opening new connections.
242 const int standbys
= p
->standby
.pool
? p
->standby
.pool
->count() : 0;
244 // XXX: Some idle pconns can be used without opening new connections.
245 // Complication: Idle pconns cannot be reused for some requests.
246 const int usableIdles
= 0;
248 const int available
= standbys
+ usableIdles
;
249 debugs(15, 7, available
<< '=' << standbys
<< '+' << usableIdles
);
250 return available
> 0;
254 peerConnClosed(CachePeer
*p
)
256 --p
->stats
.conn_open
;
257 if (p
->standby
.waitingForClose
&& peerCanOpenMore(p
)) {
258 p
->standby
.waitingForClose
= false;
259 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "conn closed");
263 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
265 peerHTTPOkay(const CachePeer
* p
, HttpRequest
* request
)
267 if (!peerCanOpenMore(p
) && !peerHasConnAvailable(p
))
270 if (!peerAllowedToUse(p
, request
))
280 neighborsCount(HttpRequest
* request
)
285 for (p
= Config
.peers
; p
; p
= p
->next
)
286 if (peerWouldBePinged(p
, request
))
289 debugs(15, 3, "neighborsCount: " << count
);
295 getFirstUpParent(HttpRequest
* request
)
299 for (p
= Config
.peers
; p
; p
= p
->next
) {
303 if (neighborType(p
, request
) != PEER_PARENT
)
306 if (!peerHTTPOkay(p
, request
))
312 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
317 getRoundRobinParent(HttpRequest
* request
)
322 for (p
= Config
.peers
; p
; p
= p
->next
) {
323 if (!p
->options
.roundrobin
)
326 if (neighborType(p
, request
) != PEER_PARENT
)
329 if (!peerHTTPOkay(p
, request
))
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, HERE
<< "returning " << (q
? q
->host
: "NULL"));
356 getWeightedRoundRobinParent(HttpRequest
* request
)
362 for (p
= Config
.peers
; p
; p
= p
->next
) {
363 if (!p
->options
.weighted_roundrobin
)
366 if (neighborType(p
, request
) != PEER_PARENT
)
369 if (!peerHTTPOkay(p
, request
))
372 if (q
&& q
->rr_count
< p
->rr_count
)
378 if (q
&& q
->rr_count
> 1000000)
379 for (p
= Config
.peers
; p
; p
= p
->next
) {
380 if (!p
->options
.weighted_roundrobin
)
383 if (neighborType(p
, request
) != PEER_PARENT
)
390 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
392 if (weighted_rtt
< 1)
395 q
->rr_count
+= weighted_rtt
;
397 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
400 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
405 * This gets called every 5 minutes to clear the round-robin counter.
406 * The exact timing is an arbitrary default, set on estimate timing of a
407 * large number of requests in a high-performance environment during the
408 * period. The larger the number of requests between cycled resets the
409 * more balanced the operations.
412 \todo Make the reset timing a selectable parameter in squid.conf
415 peerClearRRLoop(void *data
)
418 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
422 * This gets called on startup and restart to kick off the CachePeer round-robin
423 * maintenance event. It ensures that no matter how many times its called
424 * no more than one event is scheduled.
427 peerClearRRStart(void)
429 static bool event_added
= false;
431 peerClearRRLoop(NULL
);
437 * Called whenever the round-robin counters need to be reset to a sane state.
438 * So far those times are:
439 * - On startup and reconfigure - to set the counters to sane initial settings.
440 * - When a CachePeer has revived from dead, to prevent the revived CachePeer being
441 * flooded with requests which it has 'missed' during the down period.
447 for (p
= Config
.peers
; p
; p
= p
->next
) {
453 * Perform all actions when a CachePeer is detected revived.
456 peerAlive(CachePeer
*p
)
458 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
459 debugs(15, DBG_IMPORTANT
, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
460 p
->stats
.logged_state
= PEER_ALIVE
;
462 if (p
->standby
.mgr
.valid())
463 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "revived peer");
466 p
->stats
.last_reply
= squid_curtime
;
467 p
->stats
.probe_start
= 0;
471 getDefaultParent(HttpRequest
* request
)
475 for (p
= Config
.peers
; p
; p
= p
->next
) {
476 if (neighborType(p
, request
) != PEER_PARENT
)
479 if (!p
->options
.default_parent
)
482 if (!peerHTTPOkay(p
, request
))
485 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
490 debugs(15, 3, "getDefaultParent: returning NULL");
495 getNextPeer(CachePeer
* p
)
507 neighborRemove(CachePeer
* target
)
510 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
;
603 int queries_sent
= 0;
604 int peers_pinged
= 0;
605 int parent_timeout
= 0, parent_exprep
= 0;
606 int sibling_timeout
= 0, sibling_exprep
= 0;
607 int mcast_timeout
= 0, mcast_exprep
= 0;
609 if (Config
.peers
== NULL
)
612 assert(entry
->swap_status
== SWAPOUT_NONE
);
614 mem
->start_ping
= current_time
;
616 mem
->ping_reply_callback
= callback
;
618 mem
->ircb_data
= callback_data
;
620 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
622 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
626 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
628 if (!peerWouldBePinged(p
, request
))
629 continue; /* next CachePeer */
633 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
635 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
637 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
640 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
641 if (Config
.Port
.htcp
<= 0) {
642 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
646 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
647 if (htcpQuery(entry
, request
, p
) <= 0)
648 continue; // unable to send.
652 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
653 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
657 if (p
->type
== PEER_MULTICAST
)
658 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
660 if (p
->icp
.port
== echo_port
) {
661 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
662 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
663 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
667 if (Config
.onoff
.query_icmp
)
668 if (p
->icp
.version
== ICP_VERSION_2
)
669 flags
|= ICP_FLAG_SRC_RTT
;
671 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
673 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0.0);
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
) == 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
, HttpRequest
* request
)
755 #if USE_CACHE_DIGESTS
756 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
759 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
760 /* does the peeer have a valid digest? */
763 debugs(15, 5, "peerDigestLookup: gone!");
765 } else if (!peerHTTPOkay(p
, request
)) {
766 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
768 } else if (!p
->digest
->flags
.needed
) {
769 debugs(15, 5, "peerDigestLookup: note need");
770 peerDigestNeeded(p
->digest
);
772 } else if (!p
->digest
->flags
.usable
) {
773 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
777 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
778 assert(p
->digest
->cd
);
779 /* does digest predict a hit? */
781 if (!cacheDigestTest(p
->digest
->cd
, key
))
784 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
793 /* select best CachePeer based on cache digests */
795 neighborsDigestSelect(HttpRequest
* request
)
797 CachePeer
*best_p
= NULL
;
798 #if USE_CACHE_DIGESTS
801 int choice_count
= 0;
802 int ichoice_count
= 0;
807 if (!request
->flags
.hierarchical
)
810 storeKeyPublicByRequest(request
);
812 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
821 lookup
= peerDigestLookup(p
, request
);
823 if (lookup
== LOOKUP_NONE
)
828 if (lookup
== LOOKUP_MISS
)
831 p_rtt
= netdbHostRtt(p
->host
);
833 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
835 /* is this CachePeer better than others in terms of rtt ? */
836 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
840 if (p_rtt
) /* informative choice (aka educated guess) */
843 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
847 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
848 peerNoteDigestLookup(request
, best_p
,
849 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
850 request
->hier
.n_choices
= choice_count
;
851 request
->hier
.n_ichoices
= ichoice_count
;
858 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
860 #if USE_CACHE_DIGESTS
862 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
864 *request
->hier
.cd_host
= '\0';
866 request
->hier
.cd_lookup
= lookup
;
867 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
872 neighborAlive(CachePeer
* p
, const MemObject
*, const icp_common_t
* header
)
875 ++ p
->stats
.pings_acked
;
877 if ((icp_opcode
) header
->opcode
<= ICP_END
)
878 ++ p
->icp
.counts
[header
->opcode
];
880 p
->icp
.version
= (int) header
->version
;
884 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
886 int rtt
, rtt_av_factor
;
891 if (!mem
->start_ping
.tv_sec
)
894 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
896 if (rtt
< 1 || rtt
> 10000)
899 rtt_av_factor
= RTT_AV_FACTOR
;
901 if (p
->options
.weighted_roundrobin
)
902 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
904 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
909 neighborAliveHtcp(CachePeer
* p
, const MemObject
*, const HtcpReplyData
* htcp
)
912 ++ p
->stats
.pings_acked
;
913 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
914 p
->htcp
.version
= htcp
->version
;
920 neighborCountIgnored(CachePeer
* p
)
925 ++ p
->stats
.ignored_replies
;
930 static CachePeer
*non_peers
= NULL
;
933 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
937 for (np
= non_peers
; np
; np
= np
->next
) {
938 if (np
->in_addr
!= from
)
941 if (np
->in_addr
.port() != from
.port())
948 np
= (CachePeer
*)xcalloc(1, sizeof(CachePeer
));
950 np
->icp
.port
= from
.port();
951 np
->type
= PEER_NONE
;
952 np
->host
= new char[MAX_IPSTRLEN
];
953 from
.toStr(np
->host
,MAX_IPSTRLEN
);
954 np
->next
= non_peers
;
958 ++ np
->icp
.counts
[opcode
];
960 if (isPowTen(++np
->stats
.ignored_replies
))
961 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
964 /* ignoreMulticastReply
966 * * We want to ignore replies from multicast peers if the
967 * * cache_host_domain rules would normally prevent the CachePeer
971 ignoreMulticastReply(CachePeer
* p
, MemObject
* mem
)
976 if (!p
->options
.mcast_responder
)
979 if (peerHTTPOkay(p
, mem
->request
))
986 * I should attach these records to the entry. We take the first
987 * hit we get our wait until everyone misses. The timeout handler
988 * call needs to nip this shopping list or call one of the misses.
990 * If a hit process is already started, then sobeit
993 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
997 MemObject
*mem
= NULL
;
998 peer_t ntype
= PEER_NONE
;
999 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1001 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1003 if (NULL
!= (entry
= Store::Root().get(key
)))
1004 mem
= entry
->mem_obj
;
1006 if ((p
= whichPeer(from
)))
1007 neighborAlive(p
, mem
, header
);
1009 if (opcode
> ICP_END
)
1012 const char *opcode_d
= icp_opcode_str
[opcode
];
1015 neighborUpdateRtt(p
, mem
);
1017 /* Does the entry exist? */
1018 if (NULL
== entry
) {
1019 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1020 neighborCountIgnored(p
);
1024 /* check if someone is already fetching it */
1025 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1026 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1027 neighborCountIgnored(p
);
1032 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1033 neighborCountIgnored(p
);
1037 if (entry
->ping_status
!= PING_WAITING
) {
1038 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1039 neighborCountIgnored(p
);
1043 if (!entry
->locked()) {
1044 // TODO: many entries are unlocked; why is this reported at level 1?
1045 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1046 neighborCountIgnored(p
);
1050 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1053 ntype
= neighborType(p
, mem
->request
);
1056 if (ignoreMulticastReply(p
, mem
)) {
1057 neighborCountIgnored(p
);
1058 } else if (opcode
== ICP_MISS
) {
1060 neighborIgnoreNonPeer(from
, opcode
);
1062 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1064 } else if (opcode
== ICP_HIT
) {
1066 neighborIgnoreNonPeer(from
, opcode
);
1068 header
->opcode
= ICP_HIT
;
1069 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1071 } else if (opcode
== ICP_DECHO
) {
1073 neighborIgnoreNonPeer(from
, opcode
);
1074 } else if (ntype
== PEER_SIBLING
) {
1075 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1076 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1078 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1080 } else if (opcode
== ICP_SECHO
) {
1082 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << p
->host
);
1083 neighborCountIgnored(p
);
1085 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1087 } else if (opcode
== ICP_DENIED
) {
1089 neighborIgnoreNonPeer(from
, opcode
);
1090 } else if (p
->stats
.pings_acked
> 100) {
1091 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1092 debugs(15, DBG_CRITICAL
, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1093 debugs(15, DBG_CRITICAL
, "Disabling '" << p
->host
<< "', please check your configuration.");
1097 neighborCountIgnored(p
);
1100 } else if (opcode
== ICP_MISS_NOFETCH
) {
1101 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1103 debugs(15, DBG_CRITICAL
, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1108 peerFindByName(const char *name
)
1110 CachePeer
*p
= NULL
;
1112 for (p
= Config
.peers
; p
; p
= p
->next
) {
1113 if (!strcasecmp(name
, p
->name
))
1121 peerFindByNameAndPort(const char *name
, unsigned short port
)
1123 CachePeer
*p
= NULL
;
1125 for (p
= Config
.peers
; p
; p
= p
->next
) {
1126 if (strcasecmp(name
, p
->name
))
1129 if (port
!= p
->http_port
)
1139 neighborUp(const CachePeer
* p
)
1142 if (!peerProbeConnect((CachePeer
*) p
)) {
1143 debugs(15, 8, "neighborUp: DOWN (probed): " << p
->host
<< " (" << p
->in_addr
<< ")");
1149 * The CachePeer can not be UP if we don't have any IP addresses
1152 if (0 == p
->n_addresses
) {
1153 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1157 if (p
->options
.no_query
) {
1158 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1162 if (p
->stats
.probe_start
!= 0 &&
1163 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1164 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1168 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1173 peerDestroy(void *data
)
1175 CachePeer
*p
= (CachePeer
*)data
;
1180 CachePeerDomainList
*nl
= NULL
;
1182 for (CachePeerDomainList
*l
= p
->peer_domain
; l
; l
= nl
) {
1184 safe_free(l
->domain
);
1190 safe_free(p
->domain
);
1191 #if USE_CACHE_DIGESTS
1193 cbdataReferenceDone(p
->digest
);
1198 peerNoteDigestGone(CachePeer
* p
)
1200 #if USE_CACHE_DIGESTS
1201 cbdataReferenceDone(p
->digest
);
1206 peerDNSConfigure(const ipcache_addrs
*ia
, const DnsLookupDetails
&, void *data
)
1208 // TODO: connections to no-longer valid IP addresses should be
1209 // closed when we can detect such IP addresses.
1211 CachePeer
*p
= (CachePeer
*)data
;
1215 if (p
->n_addresses
== 0) {
1216 debugs(15, DBG_IMPORTANT
, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1218 if (p
->type
== PEER_MULTICAST
)
1219 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1225 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1229 if ((int) ia
->count
< 1) {
1230 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << p
->host
<< "'!");
1234 p
->tcp_up
= p
->connect_fail_limit
;
1236 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; ++j
) {
1237 p
->addresses
[j
] = ia
->in_addrs
[j
];
1238 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1242 p
->in_addr
.setEmpty();
1243 p
->in_addr
= p
->addresses
[0];
1244 p
->in_addr
.port(p
->icp
.port
);
1246 if (p
->type
== PEER_MULTICAST
)
1247 peerCountMcastPeersSchedule(p
, 10);
1250 if (p
->type
!= PEER_MULTICAST
&& IamWorkerProcess())
1251 if (!p
->options
.no_netdb_exchange
)
1252 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1255 if (p
->standby
.mgr
.valid())
1256 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "resolved peer");
1260 peerRefreshDNS(void *data
)
1262 CachePeer
*p
= NULL
;
1264 if (eventFind(peerRefreshDNS
, NULL
))
1265 eventDelete(peerRefreshDNS
, NULL
);
1267 if (!data
&& 0 == stat5minClientRequests()) {
1268 /* no recent client traffic, wait a bit */
1269 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1273 for (p
= Config
.peers
; p
; p
= p
->next
)
1274 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1276 /* Reconfigure the peers every hour */
1277 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1281 peerConnectFailedSilent(CachePeer
* p
)
1283 p
->stats
.last_connect_failure
= squid_curtime
;
1286 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1294 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1295 p
->stats
.logged_state
= PEER_DEAD
;
1300 peerConnectFailed(CachePeer
*p
)
1302 debugs(15, DBG_IMPORTANT
, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1303 peerConnectFailedSilent(p
);
1307 peerConnectSucceded(CachePeer
* p
)
1310 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1311 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1313 if (!p
->n_addresses
)
1314 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1316 p
->tcp_up
= p
->connect_fail_limit
;
1320 * peerProbeConnect will be called on dead peers by neighborUp
1323 peerProbeConnect(CachePeer
* p
)
1325 time_t ctimeout
= p
->connect_timeout
> 0 ? p
->connect_timeout
: Config
.Timeout
.peer_connect
;
1326 bool ret
= (squid_curtime
- p
->stats
.last_connect_failure
) > (ctimeout
* 10);
1328 if (p
->testing_now
> 0)
1329 return ret
;/* probe already running */
1331 if (squid_curtime
- p
->stats
.last_connect_probe
== 0)
1332 return ret
;/* don't probe to often */
1334 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1335 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1336 Comm::ConnectionPointer conn
= new Comm::Connection
;
1337 conn
->remote
= p
->addresses
[i
];
1338 conn
->remote
.port(p
->http_port
);
1340 getOutgoingAddress(NULL
, conn
);
1344 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1345 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1346 cs
->setHost(p
->host
);
1347 AsyncJob::Start(cs
);
1350 p
->stats
.last_connect_probe
= squid_curtime
;
1356 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, Comm::Flag status
, int, void *data
)
1358 CachePeer
*p
= (CachePeer
*)data
;
1360 if (status
== Comm::OK
) {
1361 peerConnectSucceded(p
);
1363 peerConnectFailedSilent(p
);
1368 // TODO: log this traffic.
1372 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1374 if (p
->mcast
.flags
.count_event_pending
)
1377 eventAdd("peerCountMcastPeersStart",
1378 peerCountMcastPeersStart
,
1382 p
->mcast
.flags
.count_event_pending
= true;
1386 peerCountMcastPeersStart(void *data
)
1388 CachePeer
*p
= (CachePeer
*)data
;
1392 icp_common_t
*query
;
1394 LOCAL_ARRAY(char, url
, MAX_URL
);
1395 assert(p
->type
== PEER_MULTICAST
);
1396 p
->mcast
.flags
.count_event_pending
= false;
1397 snprintf(url
, MAX_URL
, "http://");
1398 p
->in_addr
.toUrl(url
+7, MAX_URL
-8 );
1400 fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1401 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1402 psstate
= new ps_state
;
1403 psstate
->request
= req
;
1404 HTTPMSGLOCK(psstate
->request
);
1405 psstate
->entry
= fake
;
1406 psstate
->callback
= NULL
;
1407 psstate
->callback_data
= cbdataReference(p
);
1408 psstate
->ping
.start
= current_time
;
1409 mem
= fake
->mem_obj
;
1410 mem
->request
= psstate
->request
;
1411 HTTPMSGLOCK(mem
->request
);
1412 mem
->start_ping
= current_time
;
1413 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1414 mem
->ircb_data
= psstate
;
1415 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1416 p
->mcast
.id
= mem
->id
;
1417 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1418 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1419 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
1420 fake
->ping_status
= PING_WAITING
;
1421 eventAdd("peerCountMcastPeersDone",
1422 peerCountMcastPeersDone
,
1424 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1425 p
->mcast
.flags
.counting
= true;
1426 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1430 peerCountMcastPeersDone(void *data
)
1432 ps_state
*psstate
= (ps_state
*)data
;
1433 StoreEntry
*fake
= psstate
->entry
;
1435 if (cbdataReferenceValid(psstate
->callback_data
)) {
1436 CachePeer
*p
= (CachePeer
*)psstate
->callback_data
;
1437 p
->mcast
.flags
.counting
= false;
1438 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1439 debugs(15, DBG_IMPORTANT
, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1440 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1441 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1442 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1445 cbdataReferenceDone(psstate
->callback_data
);
1447 fake
->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
1448 HTTPMSGUNLOCK(fake
->mem_obj
->request
);
1449 fake
->unlock("peerCountMcastPeersDone");
1450 HTTPMSGUNLOCK(psstate
->request
);
1451 cbdataFree(psstate
);
1455 peerCountHandleIcpReply(CachePeer
* p
, peer_t
, AnyP::ProtocolType proto
, void *, void *data
)
1457 ps_state
*psstate
= (ps_state
*)data
;
1458 StoreEntry
*fake
= psstate
->entry
;
1460 MemObject
*mem
= fake
->mem_obj
;
1462 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1463 assert(proto
== AnyP::PROTO_ICP
);
1464 ++ psstate
->ping
.n_recv
;
1465 int rtt_av_factor
= RTT_AV_FACTOR
;
1467 if (p
->options
.weighted_roundrobin
)
1468 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1470 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1474 neighborDumpPeers(StoreEntry
* sentry
)
1476 dump_peers(sentry
, Config
.peers
);
1480 neighborDumpNonPeers(StoreEntry
* sentry
)
1482 dump_peers(sentry
, non_peers
);
1486 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1488 if (p
->options
.proxy_only
)
1489 storeAppendPrintf(sentry
, " proxy-only");
1491 if (p
->options
.no_query
)
1492 storeAppendPrintf(sentry
, " no-query");
1494 if (p
->options
.background_ping
)
1495 storeAppendPrintf(sentry
, " background-ping");
1497 if (p
->options
.no_digest
)
1498 storeAppendPrintf(sentry
, " no-digest");
1500 if (p
->options
.default_parent
)
1501 storeAppendPrintf(sentry
, " default");
1503 if (p
->options
.roundrobin
)
1504 storeAppendPrintf(sentry
, " round-robin");
1506 if (p
->options
.carp
)
1507 storeAppendPrintf(sentry
, " carp");
1510 if (p
->options
.userhash
)
1511 storeAppendPrintf(sentry
, " userhash");
1514 if (p
->options
.sourcehash
)
1515 storeAppendPrintf(sentry
, " sourcehash");
1517 if (p
->options
.weighted_roundrobin
)
1518 storeAppendPrintf(sentry
, " weighted-round-robin");
1520 if (p
->options
.mcast_responder
)
1521 storeAppendPrintf(sentry
, " multicast-responder");
1523 #if PEER_MULTICAST_SIBLINGS
1524 if (p
->options
.mcast_siblings
)
1525 storeAppendPrintf(sentry
, " multicast-siblings");
1529 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1531 if (p
->options
.closest_only
)
1532 storeAppendPrintf(sentry
, " closest-only");
1535 if (p
->options
.htcp
) {
1536 storeAppendPrintf(sentry
, " htcp");
1537 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1539 if (p
->options
.htcp_oldsquid
)
1540 storeAppendPrintf(sentry
, "%soldsquid",(doneopts
++>0?",":"="));
1541 if (p
->options
.htcp_no_clr
)
1542 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
++>0?",":"="));
1543 if (p
->options
.htcp_no_purge_clr
)
1544 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
++>0?",":"="));
1545 if (p
->options
.htcp_only_clr
)
1546 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
++>0?",":"="));
1551 if (p
->options
.no_netdb_exchange
)
1552 storeAppendPrintf(sentry
, " no-netdb-exchange");
1555 if (p
->options
.no_delay
)
1556 storeAppendPrintf(sentry
, " no-delay");
1560 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1562 if (p
->mcast
.ttl
> 0)
1563 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1565 if (p
->connect_timeout
> 0)
1566 storeAppendPrintf(sentry
, " connect-timeout=%d", (int) p
->connect_timeout
);
1568 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1569 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1571 #if USE_CACHE_DIGESTS
1574 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1578 if (p
->options
.allow_miss
)
1579 storeAppendPrintf(sentry
, " allow-miss");
1581 if (p
->options
.no_tproxy
)
1582 storeAppendPrintf(sentry
, " no-tproxy");
1584 if (p
->max_conn
> 0)
1585 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1586 if (p
->standby
.limit
> 0)
1587 storeAppendPrintf(sentry
, " standby=%d", p
->standby
.limit
);
1589 if (p
->options
.originserver
)
1590 storeAppendPrintf(sentry
, " originserver");
1593 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1595 if (p
->connection_auth
== 0)
1596 storeAppendPrintf(sentry
, " connection-auth=off");
1597 else if (p
->connection_auth
== 1)
1598 storeAppendPrintf(sentry
, " connection-auth=on");
1599 else if (p
->connection_auth
== 2)
1600 storeAppendPrintf(sentry
, " connection-auth=auto");
1602 storeAppendPrintf(sentry
, "\n");
1606 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1608 CachePeer
*e
= NULL
;
1609 char ntoabuf
[MAX_IPSTRLEN
];
1610 CachePeerDomainList
*d
= NULL
;
1615 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1617 for (e
= peers
; e
; e
= e
->next
) {
1618 assert(e
->host
!= NULL
);
1619 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1622 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1626 storeAppendPrintf(sentry
, "Flags :");
1627 dump_peer_options(sentry
, e
);
1629 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1630 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1631 e
->addresses
[i
].toStr(ntoabuf
,MAX_IPSTRLEN
) );
1634 storeAppendPrintf(sentry
, "Status : %s\n",
1635 neighborUp(e
) ? "Up" : "Down");
1636 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1637 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1638 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1640 if (!e
->options
.no_query
) {
1641 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1642 (int) (squid_curtime
- e
->stats
.last_query
));
1644 if (e
->stats
.last_reply
> 0)
1645 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1646 (int) (squid_curtime
- e
->stats
.last_reply
));
1648 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1650 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1652 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1653 e
->stats
.pings_acked
,
1654 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1657 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1659 if (!e
->options
.no_query
) {
1660 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1663 if (e
->options
.htcp
) {
1664 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1666 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1667 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1669 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1673 for (op
= ICP_INVALID
; op
< ICP_END
; ++op
) {
1674 if (e
->icp
.counts
[op
] == 0)
1677 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1680 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1691 if (e
->stats
.last_connect_failure
) {
1692 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1693 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1696 if (e
->peer_domain
!= NULL
) {
1697 storeAppendPrintf(sentry
, "DOMAIN LIST: ");
1699 for (d
= e
->peer_domain
; d
; d
= d
->next
) {
1700 storeAppendPrintf(sentry
, "%s%s ",
1701 d
->do_ping
? null_string
: "!", d
->domain
);
1704 storeAppendPrintf(sentry
, "\n");
1707 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1713 neighborsHtcpReply(const cache_key
* key
, HtcpReplyData
* htcp
, const Ip::Address
&from
)
1715 StoreEntry
*e
= Store::Root().get(key
);
1716 MemObject
*mem
= NULL
;
1718 peer_t ntype
= PEER_NONE
;
1719 debugs(15, 6, "neighborsHtcpReply: " <<
1720 (htcp
->hit
? "HIT" : "MISS") << " " <<
1721 storeKeyText(key
) );
1726 if ((p
= whichPeer(from
)))
1727 neighborAliveHtcp(p
, mem
, htcp
);
1729 /* Does the entry exist? */
1731 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1732 neighborCountIgnored(p
);
1736 /* check if someone is already fetching it */
1737 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1738 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1739 neighborCountIgnored(p
);
1744 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1745 neighborCountIgnored(p
);
1749 if (e
->ping_status
!= PING_WAITING
) {
1750 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1751 neighborCountIgnored(p
);
1756 // TODO: many entries are unlocked; why is this reported at level 1?
1757 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1758 neighborCountIgnored(p
);
1763 ntype
= neighborType(p
, mem
->request
);
1764 neighborUpdateRtt(p
, mem
);
1767 if (ignoreMulticastReply(p
, mem
)) {
1768 neighborCountIgnored(p
);
1772 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1773 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1777 * Send HTCP CLR messages to all peers configured to receive them.
1780 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1785 for (p
= Config
.peers
; p
; p
= p
->next
) {
1786 if (!p
->options
.htcp
) {
1789 if (p
->options
.htcp_no_clr
) {
1792 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1795 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.toUrl(buf
, 128));
1796 htcpClear(e
, uri
, req
, method
, p
, reason
);