2 * DEBUG: section 15 Neighbor Routines
3 * AUTHOR: Harvest Derived
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 #include "acl/FilledChecklist.h"
35 #include "anyp/PortCfg.h"
36 #include "CacheDigest.h"
37 #include "CachePeer.h"
38 #include "CachePeerDomainList.h"
39 #include "comm/Connection.h"
40 #include "comm/ConnOpener.h"
45 #include "HttpRequest.h"
46 #include "icmp/net_db.h"
49 #include "ip/Address.h"
52 #include "MemObject.h"
53 #include "mgr/Registration.h"
54 #include "multicast.h"
55 #include "NeighborTypeDomainList.h"
56 #include "neighbors.h"
57 #include "PeerDigest.h"
58 #include "PeerSelectState.h"
59 #include "RequestFlags.h"
60 #include "SquidConfig.h"
61 #include "SquidMath.h"
62 #include "SquidTime.h"
65 #include "store_key_md5.h"
69 /* count mcast group peers every 15 minutes */
70 #define MCAST_COUNT_RATE 900
72 bool peerAllowedToUse(const CachePeer
*, HttpRequest
*);
73 static int peerWouldBePinged(const CachePeer
*, HttpRequest
*);
74 static void neighborRemove(CachePeer
*);
75 static void neighborAlive(CachePeer
*, const MemObject
*, const icp_common_t
*);
77 static void neighborAliveHtcp(CachePeer
*, const MemObject
*, const htcpReplyData
*);
79 static void neighborCountIgnored(CachePeer
*);
80 static void peerRefreshDNS(void *);
81 static IPH peerDNSConfigure
;
82 static bool peerProbeConnect(CachePeer
*);
83 static CNCB peerProbeConnectDone
;
84 static void peerCountMcastPeersDone(void *data
);
85 static void peerCountMcastPeersStart(void *data
);
86 static void peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
);
87 static IRCB peerCountHandleIcpReply
;
89 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
90 static OBJH neighborDumpPeers
;
91 static OBJH neighborDumpNonPeers
;
92 static void dump_peers(StoreEntry
* sentry
, CachePeer
* peers
);
94 static unsigned short echo_port
;
96 static int NLateReplies
= 0;
97 static CachePeer
*first_ping
= NULL
;
100 neighborTypeStr(const CachePeer
* p
)
102 if (p
->type
== PEER_NONE
)
105 if (p
->type
== PEER_SIBLING
)
108 if (p
->type
== PEER_MULTICAST
)
109 return "Multicast Group";
115 whichPeer(const Ip::Address
&from
)
120 debugs(15, 3, "whichPeer: from " << from
);
122 for (p
= Config
.peers
; p
; p
= p
->next
) {
123 for (j
= 0; j
< p
->n_addresses
; ++j
) {
124 if (from
== p
->addresses
[j
] && from
.GetPort() == p
->icp
.port
) {
134 neighborType(const CachePeer
* p
, const HttpRequest
* request
)
137 const NeighborTypeDomainList
*d
= NULL
;
139 for (d
= p
->typelist
; d
; d
= d
->next
) {
140 if (0 == matchDomainName(request
->GetHost(), d
->domain
))
141 if (d
->type
!= PEER_NONE
)
144 #if PEER_MULTICAST_SIBLINGS
145 if (p
->type
== PEER_MULTICAST
)
146 if (p
->options
.mcast_siblings
)
154 * \return Whether it is appropriate to fetch REQUEST from PEER.
157 peerAllowedToUse(const CachePeer
* p
, HttpRequest
* request
)
160 const CachePeerDomainList
*d
= NULL
;
161 assert(request
!= NULL
);
163 if (neighborType(p
, request
) == PEER_SIBLING
) {
164 #if PEER_MULTICAST_SIBLINGS
165 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
166 (request
->flags
.noCache
|| request
->flags
.refresh
|| request
->flags
.loopDetected
|| request
->flags
.needValidation
))
167 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->GetHost() << ") : multicast-siblings optimization match");
169 if (request
->flags
.noCache
)
172 if (request
->flags
.refresh
)
175 if (request
->flags
.loopDetected
)
178 if (request
->flags
.needValidation
)
182 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
183 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
184 if (p
->options
.originserver
&& request
->method
== Http::METHOD_CONNECT
&& request
->port
!= p
->in_addr
.GetPort())
187 if (p
->peer_domain
== NULL
&& p
->access
== NULL
)
190 bool do_ping
= false;
191 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
192 if (0 == matchDomainName(request
->GetHost(), d
->domain
)) {
193 do_ping
= d
->do_ping
;
197 do_ping
= !d
->do_ping
;
200 if (p
->peer_domain
&& !do_ping
)
203 if (p
->access
== NULL
)
206 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
207 checklist
.src_addr
= request
->client_addr
;
208 checklist
.my_addr
= request
->my_addr
;
210 return (checklist
.fastCheck() == ACCESS_ALLOWED
);
213 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
215 peerWouldBePinged(const CachePeer
* p
, HttpRequest
* request
)
217 if (p
->icp
.port
== 0)
220 if (p
->options
.no_query
)
223 if (p
->options
.mcast_responder
)
226 if (p
->n_addresses
== 0)
229 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
232 /* the case below seems strange, but can happen if the
233 * URL host is on the other side of a firewall */
234 if (p
->type
== PEER_SIBLING
)
235 if (!request
->flags
.hierarchical
)
238 if (!peerAllowedToUse(p
, request
))
241 /* Ping dead peers every timeout interval */
242 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
251 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
253 peerHTTPOkay(const CachePeer
* p
, HttpRequest
* request
)
256 if (p
->stats
.conn_open
>= p
->max_conn
)
259 if (!peerAllowedToUse(p
, request
))
269 neighborsCount(HttpRequest
* request
)
274 for (p
= Config
.peers
; p
; p
= p
->next
)
275 if (peerWouldBePinged(p
, request
))
278 debugs(15, 3, "neighborsCount: " << count
);
284 getFirstUpParent(HttpRequest
* request
)
288 for (p
= Config
.peers
; p
; p
= p
->next
) {
292 if (neighborType(p
, request
) != PEER_PARENT
)
295 if (!peerHTTPOkay(p
, request
))
301 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
306 getRoundRobinParent(HttpRequest
* request
)
311 for (p
= Config
.peers
; p
; p
= p
->next
) {
312 if (!p
->options
.roundrobin
)
315 if (neighborType(p
, request
) != PEER_PARENT
)
318 if (!peerHTTPOkay(p
, request
))
325 if (p
->weight
== q
->weight
) {
326 if (q
->rr_count
< p
->rr_count
)
328 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
339 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
345 getWeightedRoundRobinParent(HttpRequest
* request
)
351 for (p
= Config
.peers
; p
; p
= p
->next
) {
352 if (!p
->options
.weighted_roundrobin
)
355 if (neighborType(p
, request
) != PEER_PARENT
)
358 if (!peerHTTPOkay(p
, request
))
361 if (q
&& q
->rr_count
< p
->rr_count
)
367 if (q
&& q
->rr_count
> 1000000)
368 for (p
= Config
.peers
; p
; p
= p
->next
) {
369 if (!p
->options
.weighted_roundrobin
)
372 if (neighborType(p
, request
) != PEER_PARENT
)
379 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
381 if (weighted_rtt
< 1)
384 q
->rr_count
+= weighted_rtt
;
386 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
389 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
394 * This gets called every 5 minutes to clear the round-robin counter.
395 * The exact timing is an arbitrary default, set on estimate timing of a
396 * large number of requests in a high-performance environment during the
397 * period. The larger the number of requests between cycled resets the
398 * more balanced the operations.
401 \todo Make the reset timing a selectable parameter in squid.conf
404 peerClearRRLoop(void *data
)
407 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
411 * This gets called on startup and restart to kick off the CachePeer round-robin
412 * maintenance event. It ensures that no matter how many times its called
413 * no more than one event is scheduled.
416 peerClearRRStart(void)
418 static bool event_added
= false;
420 peerClearRRLoop(NULL
);
426 * Called whenever the round-robin counters need to be reset to a sane state.
427 * So far those times are:
428 * - On startup and reconfigure - to set the counters to sane initial settings.
429 * - When a CachePeer has revived from dead, to prevent the revived CachePeer being
430 * flooded with requests which it has 'missed' during the down period.
436 for (p
= Config
.peers
; p
; p
= p
->next
) {
442 * Perform all actions when a CachePeer is detected revived.
445 peerAlive(CachePeer
*p
)
447 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
448 debugs(15, DBG_IMPORTANT
, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
449 p
->stats
.logged_state
= PEER_ALIVE
;
453 p
->stats
.last_reply
= squid_curtime
;
454 p
->stats
.probe_start
= 0;
458 getDefaultParent(HttpRequest
* request
)
462 for (p
= Config
.peers
; p
; p
= p
->next
) {
463 if (neighborType(p
, request
) != PEER_PARENT
)
466 if (!p
->options
.default_parent
)
469 if (!peerHTTPOkay(p
, request
))
472 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
477 debugs(15, 3, "getDefaultParent: returning NULL");
482 getNextPeer(CachePeer
* p
)
494 neighborRemove(CachePeer
* target
)
497 CachePeer
**P
= NULL
;
516 first_ping
= Config
.peers
;
520 neighborsRegisterWithCacheManager()
522 Mgr::RegisterAction("server_list",
523 "Peer Cache Statistics",
524 neighborDumpPeers
, 0, 1);
526 if (Comm::IsConnOpen(icpIncomingConn
)) {
527 Mgr::RegisterAction("non_peers",
528 "List of Unknown sites sending ICP messages",
529 neighborDumpNonPeers
, 0, 1);
536 struct servent
*sep
= NULL
;
537 const char *me
= getMyHostname();
538 CachePeer
*thisPeer
= NULL
;
539 CachePeer
*next
= NULL
;
541 neighborsRegisterWithCacheManager();
543 if (Comm::IsConnOpen(icpIncomingConn
)) {
545 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
546 next
= thisPeer
->next
;
548 if (0 != strcmp(thisPeer
->host
, me
))
551 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
; s
= s
->next
) {
552 if (thisPeer
->http_port
!= s
->s
.GetPort())
555 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
557 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
558 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
559 "/" << thisPeer
->http_port
<< "/" <<
562 neighborRemove(thisPeer
);
567 peerRefreshDNS((void *) 1);
569 sep
= getservbyname("echo", "udp");
570 echo_port
= sep
? ntohs((unsigned short) sep
->s_port
) : 7;
572 first_ping
= Config
.peers
;
576 neighborsUdpPing(HttpRequest
* request
,
583 const char *url
= entry
->url();
584 MemObject
*mem
= entry
->mem_obj
;
590 int queries_sent
= 0;
591 int peers_pinged
= 0;
592 int parent_timeout
= 0, parent_exprep
= 0;
593 int sibling_timeout
= 0, sibling_exprep
= 0;
594 int mcast_timeout
= 0, mcast_exprep
= 0;
596 if (Config
.peers
== NULL
)
599 assert(entry
->swap_status
== SWAPOUT_NONE
);
601 mem
->start_ping
= current_time
;
603 mem
->ping_reply_callback
= callback
;
605 mem
->ircb_data
= callback_data
;
607 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
609 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
613 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
615 if (!peerWouldBePinged(p
, request
))
616 continue; /* next CachePeer */
620 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
622 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
624 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
627 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
628 if (Config
.Port
.htcp
<= 0) {
629 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
633 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
634 if (htcpQuery(entry
, request
, p
) <= 0)
635 continue; // unable to send.
639 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
640 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
644 if (p
->type
== PEER_MULTICAST
)
645 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
647 if (p
->icp
.port
== echo_port
) {
648 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
649 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
650 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
654 if (Config
.onoff
.query_icmp
)
655 if (p
->icp
.version
== ICP_VERSION_2
)
656 flags
|= ICP_FLAG_SRC_RTT
;
658 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
660 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
667 ++ p
->stats
.pings_sent
;
669 if (p
->type
== PEER_MULTICAST
) {
670 mcast_exprep
+= p
->mcast
.n_replies_expected
;
671 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
672 } else if (neighborUp(p
)) {
673 /* its alive, expect a reply from it */
675 if (neighborType(p
, request
) == PEER_PARENT
) {
677 parent_timeout
+= p
->stats
.rtt
;
680 sibling_timeout
+= p
->stats
.rtt
;
683 /* Neighbor is dead; ping it anyway, but don't expect a reply */
684 /* log it once at the threshold */
686 if (p
->stats
.logged_state
== PEER_ALIVE
) {
687 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
688 p
->stats
.logged_state
= PEER_DEAD
;
692 p
->stats
.last_query
= squid_curtime
;
695 * keep probe_start == 0 for a multicast CachePeer,
696 * so neighborUp() never says this CachePeer is dead.
699 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
700 p
->stats
.probe_start
= squid_curtime
;
703 if ((first_ping
= first_ping
->next
) == NULL
)
704 first_ping
= Config
.peers
;
707 * How many replies to expect?
709 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
712 * If there is a configured timeout, use it
714 if (Config
.Timeout
.icp_query
)
715 *timeout
= Config
.Timeout
.icp_query
;
719 *timeout
= 2 * parent_timeout
/ parent_exprep
;
720 else if (mcast_exprep
)
721 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
723 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
725 *timeout
= 2000; /* 2 seconds */
727 if (Config
.Timeout
.icp_query_max
)
728 if (*timeout
> Config
.Timeout
.icp_query_max
)
729 *timeout
= Config
.Timeout
.icp_query_max
;
731 if (*timeout
< Config
.Timeout
.icp_query_min
)
732 *timeout
= Config
.Timeout
.icp_query_min
;
738 /* lookup the digest of a given CachePeer */
740 peerDigestLookup(CachePeer
* p
, HttpRequest
* request
)
742 #if USE_CACHE_DIGESTS
743 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
746 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
747 /* does the peeer have a valid digest? */
750 debugs(15, 5, "peerDigestLookup: gone!");
752 } else if (!peerHTTPOkay(p
, request
)) {
753 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
755 } else if (!p
->digest
->flags
.needed
) {
756 debugs(15, 5, "peerDigestLookup: note need");
757 peerDigestNeeded(p
->digest
);
759 } else if (!p
->digest
->flags
.usable
) {
760 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
764 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
765 assert(p
->digest
->cd
);
766 /* does digest predict a hit? */
768 if (!cacheDigestTest(p
->digest
->cd
, key
))
771 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
780 /* select best CachePeer based on cache digests */
782 neighborsDigestSelect(HttpRequest
* request
)
784 CachePeer
*best_p
= NULL
;
785 #if USE_CACHE_DIGESTS
788 int choice_count
= 0;
789 int ichoice_count
= 0;
794 if (!request
->flags
.hierarchical
)
797 storeKeyPublicByRequest(request
);
799 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
808 lookup
= peerDigestLookup(p
, request
);
810 if (lookup
== LOOKUP_NONE
)
815 if (lookup
== LOOKUP_MISS
)
818 p_rtt
= netdbHostRtt(p
->host
);
820 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
822 /* is this CachePeer better than others in terms of rtt ? */
823 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
827 if (p_rtt
) /* informative choice (aka educated guess) */
830 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
834 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
835 peerNoteDigestLookup(request
, best_p
,
836 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
837 request
->hier
.n_choices
= choice_count
;
838 request
->hier
.n_ichoices
= ichoice_count
;
845 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
847 #if USE_CACHE_DIGESTS
849 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
851 *request
->hier
.cd_host
= '\0';
853 request
->hier
.cd_lookup
= lookup
;
854 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
859 neighborAlive(CachePeer
* p
, const MemObject
* mem
, const icp_common_t
* header
)
862 ++ p
->stats
.pings_acked
;
864 if ((icp_opcode
) header
->opcode
<= ICP_END
)
865 ++ p
->icp
.counts
[header
->opcode
];
867 p
->icp
.version
= (int) header
->version
;
871 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
873 int rtt
, rtt_av_factor
;
878 if (!mem
->start_ping
.tv_sec
)
881 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
883 if (rtt
< 1 || rtt
> 10000)
886 rtt_av_factor
= RTT_AV_FACTOR
;
888 if (p
->options
.weighted_roundrobin
)
889 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
891 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
896 neighborAliveHtcp(CachePeer
* p
, const MemObject
* mem
, const htcpReplyData
* htcp
)
899 ++ p
->stats
.pings_acked
;
900 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
901 p
->htcp
.version
= htcp
->version
;
907 neighborCountIgnored(CachePeer
* p
)
912 ++ p
->stats
.ignored_replies
;
917 static CachePeer
*non_peers
= NULL
;
920 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
924 for (np
= non_peers
; np
; np
= np
->next
) {
925 if (np
->in_addr
!= from
)
928 if (np
->in_addr
.GetPort() != from
.GetPort())
935 np
= (CachePeer
*)xcalloc(1, sizeof(CachePeer
));
937 np
->icp
.port
= from
.GetPort();
938 np
->type
= PEER_NONE
;
939 np
->host
= new char[MAX_IPSTRLEN
];
940 from
.NtoA(np
->host
,MAX_IPSTRLEN
);
941 np
->next
= non_peers
;
945 ++ np
->icp
.counts
[opcode
];
947 if (isPowTen(++np
->stats
.ignored_replies
))
948 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
951 /* ignoreMulticastReply
953 * * We want to ignore replies from multicast peers if the
954 * * cache_host_domain rules would normally prevent the CachePeer
958 ignoreMulticastReply(CachePeer
* p
, MemObject
* mem
)
963 if (!p
->options
.mcast_responder
)
966 if (peerHTTPOkay(p
, mem
->request
))
973 * I should attach these records to the entry. We take the first
974 * hit we get our wait until everyone misses. The timeout handler
975 * call needs to nip this shopping list or call one of the misses.
977 * If a hit process is already started, then sobeit
980 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
984 MemObject
*mem
= NULL
;
985 peer_t ntype
= PEER_NONE
;
986 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
988 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
990 if (NULL
!= (entry
= Store::Root().get(key
)))
991 mem
= entry
->mem_obj
;
993 if ((p
= whichPeer(from
)))
994 neighborAlive(p
, mem
, header
);
996 if (opcode
> ICP_END
)
999 const char *opcode_d
= icp_opcode_str
[opcode
];
1002 neighborUpdateRtt(p
, mem
);
1004 /* Does the entry exist? */
1005 if (NULL
== entry
) {
1006 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1007 neighborCountIgnored(p
);
1011 /* check if someone is already fetching it */
1012 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1013 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1014 neighborCountIgnored(p
);
1019 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1020 neighborCountIgnored(p
);
1024 if (entry
->ping_status
!= PING_WAITING
) {
1025 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1026 neighborCountIgnored(p
);
1030 if (entry
->lock_count
== 0) {
1031 // TODO: many entries are unlocked; why is this reported at level 1?
1032 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1033 neighborCountIgnored(p
);
1037 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1040 ntype
= neighborType(p
, mem
->request
);
1043 if (ignoreMulticastReply(p
, mem
)) {
1044 neighborCountIgnored(p
);
1045 } else if (opcode
== ICP_MISS
) {
1047 neighborIgnoreNonPeer(from
, opcode
);
1049 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1051 } else if (opcode
== ICP_HIT
) {
1053 neighborIgnoreNonPeer(from
, opcode
);
1055 header
->opcode
= ICP_HIT
;
1056 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1058 } else if (opcode
== ICP_DECHO
) {
1060 neighborIgnoreNonPeer(from
, opcode
);
1061 } else if (ntype
== PEER_SIBLING
) {
1062 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1063 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1065 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1067 } else if (opcode
== ICP_SECHO
) {
1069 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << p
->host
);
1070 neighborCountIgnored(p
);
1072 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1074 } else if (opcode
== ICP_DENIED
) {
1076 neighborIgnoreNonPeer(from
, opcode
);
1077 } else if (p
->stats
.pings_acked
> 100) {
1078 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1079 debugs(15, DBG_CRITICAL
, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1080 debugs(15, DBG_CRITICAL
, "Disabling '" << p
->host
<< "', please check your configuration.");
1084 neighborCountIgnored(p
);
1087 } else if (opcode
== ICP_MISS_NOFETCH
) {
1088 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1090 debugs(15, DBG_CRITICAL
, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1095 peerFindByName(const char *name
)
1097 CachePeer
*p
= NULL
;
1099 for (p
= Config
.peers
; p
; p
= p
->next
) {
1100 if (!strcasecmp(name
, p
->name
))
1108 peerFindByNameAndPort(const char *name
, unsigned short port
)
1110 CachePeer
*p
= NULL
;
1112 for (p
= Config
.peers
; p
; p
= p
->next
) {
1113 if (strcasecmp(name
, p
->name
))
1116 if (port
!= p
->http_port
)
1126 neighborUp(const CachePeer
* p
)
1129 if (!peerProbeConnect((CachePeer
*) p
)) {
1130 debugs(15, 8, "neighborUp: DOWN (probed): " << p
->host
<< " (" << p
->in_addr
<< ")");
1136 * The CachePeer can not be UP if we don't have any IP addresses
1139 if (0 == p
->n_addresses
) {
1140 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1144 if (p
->options
.no_query
) {
1145 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1149 if (p
->stats
.probe_start
!= 0 &&
1150 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1151 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1155 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1160 peerDestroy(void *data
)
1162 CachePeer
*p
= (CachePeer
*)data
;
1167 CachePeerDomainList
*nl
= NULL
;
1169 for (CachePeerDomainList
*l
= p
->peer_domain
; l
; l
= nl
) {
1171 safe_free(l
->domain
);
1177 safe_free(p
->domain
);
1178 #if USE_CACHE_DIGESTS
1180 cbdataReferenceDone(p
->digest
);
1185 peerNoteDigestGone(CachePeer
* p
)
1187 #if USE_CACHE_DIGESTS
1188 cbdataReferenceDone(p
->digest
);
1193 peerDNSConfigure(const ipcache_addrs
*ia
, const DnsLookupDetails
&, void *data
)
1195 CachePeer
*p
= (CachePeer
*)data
;
1199 if (p
->n_addresses
== 0) {
1200 debugs(15, DBG_IMPORTANT
, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1202 if (p
->type
== PEER_MULTICAST
)
1203 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1209 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1213 if ((int) ia
->count
< 1) {
1214 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << p
->host
<< "'!");
1218 p
->tcp_up
= p
->connect_fail_limit
;
1220 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; ++j
) {
1221 p
->addresses
[j
] = ia
->in_addrs
[j
];
1222 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1226 p
->in_addr
.SetEmpty();
1227 p
->in_addr
= p
->addresses
[0];
1228 p
->in_addr
.SetPort(p
->icp
.port
);
1230 if (p
->type
== PEER_MULTICAST
)
1231 peerCountMcastPeersSchedule(p
, 10);
1234 if (p
->type
!= PEER_MULTICAST
)
1235 if (!p
->options
.no_netdb_exchange
)
1236 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1242 peerRefreshDNS(void *data
)
1244 CachePeer
*p
= NULL
;
1246 if (eventFind(peerRefreshDNS
, NULL
))
1247 eventDelete(peerRefreshDNS
, NULL
);
1249 if (!data
&& 0 == stat5minClientRequests()) {
1250 /* no recent client traffic, wait a bit */
1251 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1255 for (p
= Config
.peers
; p
; p
= p
->next
)
1256 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1258 /* Reconfigure the peers every hour */
1259 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1263 peerConnectFailedSilent(CachePeer
* p
)
1265 p
->stats
.last_connect_failure
= squid_curtime
;
1268 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1276 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1277 p
->stats
.logged_state
= PEER_DEAD
;
1282 peerConnectFailed(CachePeer
*p
)
1284 debugs(15, DBG_IMPORTANT
, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1285 peerConnectFailedSilent(p
);
1289 peerConnectSucceded(CachePeer
* p
)
1292 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1293 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1295 if (!p
->n_addresses
)
1296 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1298 p
->tcp_up
= p
->connect_fail_limit
;
1302 * peerProbeConnect will be called on dead peers by neighborUp
1305 peerProbeConnect(CachePeer
* p
)
1307 time_t ctimeout
= p
->connect_timeout
> 0 ? p
->connect_timeout
: Config
.Timeout
.peer_connect
;
1308 bool ret
= (squid_curtime
- p
->stats
.last_connect_failure
) > (ctimeout
* 10);
1310 if (p
->testing_now
> 0)
1311 return ret
;/* probe already running */
1313 if (squid_curtime
- p
->stats
.last_connect_probe
== 0)
1314 return ret
;/* don't probe to often */
1316 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1317 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1318 Comm::ConnectionPointer conn
= new Comm::Connection
;
1319 conn
->remote
= p
->addresses
[i
];
1320 conn
->remote
.SetPort(p
->http_port
);
1321 getOutgoingAddress(NULL
, conn
);
1325 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1326 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1327 cs
->setHost(p
->host
);
1328 AsyncJob::Start(cs
);
1331 p
->stats
.last_connect_probe
= squid_curtime
;
1337 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, comm_err_t status
, int xerrno
, void *data
)
1339 CachePeer
*p
= (CachePeer
*)data
;
1341 if (status
== COMM_OK
) {
1342 peerConnectSucceded(p
);
1344 peerConnectFailedSilent(p
);
1349 // TODO: log this traffic.
1353 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1355 if (p
->mcast
.flags
.count_event_pending
)
1358 eventAdd("peerCountMcastPeersStart",
1359 peerCountMcastPeersStart
,
1363 p
->mcast
.flags
.count_event_pending
= 1;
1367 peerCountMcastPeersStart(void *data
)
1369 CachePeer
*p
= (CachePeer
*)data
;
1373 icp_common_t
*query
;
1375 LOCAL_ARRAY(char, url
, MAX_URL
);
1376 assert(p
->type
== PEER_MULTICAST
);
1377 p
->mcast
.flags
.count_event_pending
= 0;
1378 snprintf(url
, MAX_URL
, "http://");
1379 p
->in_addr
.ToURL(url
+7, MAX_URL
-8 );
1381 fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1382 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1383 psstate
= new ps_state
;
1384 psstate
->request
= HTTPMSGLOCK(req
);
1385 psstate
->entry
= fake
;
1386 psstate
->callback
= NULL
;
1387 psstate
->callback_data
= cbdataReference(p
);
1388 psstate
->ping
.start
= current_time
;
1389 mem
= fake
->mem_obj
;
1390 mem
->request
= HTTPMSGLOCK(psstate
->request
);
1391 mem
->start_ping
= current_time
;
1392 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1393 mem
->ircb_data
= psstate
;
1394 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1395 p
->mcast
.id
= mem
->id
;
1396 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1397 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1398 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
1399 fake
->ping_status
= PING_WAITING
;
1400 eventAdd("peerCountMcastPeersDone",
1401 peerCountMcastPeersDone
,
1403 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1404 p
->mcast
.flags
.counting
= 1;
1405 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1409 peerCountMcastPeersDone(void *data
)
1411 ps_state
*psstate
= (ps_state
*)data
;
1412 StoreEntry
*fake
= psstate
->entry
;
1414 if (cbdataReferenceValid(psstate
->callback_data
)) {
1415 CachePeer
*p
= (CachePeer
*)psstate
->callback_data
;
1416 p
->mcast
.flags
.counting
= 0;
1417 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1418 debugs(15, DBG_IMPORTANT
, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1419 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1420 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1421 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1424 cbdataReferenceDone(psstate
->callback_data
);
1426 fake
->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
1427 HTTPMSGUNLOCK(fake
->mem_obj
->request
);
1429 HTTPMSGUNLOCK(psstate
->request
);
1430 cbdataFree(psstate
);
1434 peerCountHandleIcpReply(CachePeer
* p
, peer_t type
, AnyP::ProtocolType proto
, void *hdrnotused
, void *data
)
1438 ps_state
*psstate
= (ps_state
*)data
;
1439 StoreEntry
*fake
= psstate
->entry
;
1440 MemObject
*mem
= fake
->mem_obj
;
1441 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1442 assert(proto
== AnyP::PROTO_ICP
);
1445 ++ psstate
->ping
.n_recv
;
1446 rtt_av_factor
= RTT_AV_FACTOR
;
1448 if (p
->options
.weighted_roundrobin
)
1449 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1451 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1455 neighborDumpPeers(StoreEntry
* sentry
)
1457 dump_peers(sentry
, Config
.peers
);
1461 neighborDumpNonPeers(StoreEntry
* sentry
)
1463 dump_peers(sentry
, non_peers
);
1467 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1469 if (p
->options
.proxy_only
)
1470 storeAppendPrintf(sentry
, " proxy-only");
1472 if (p
->options
.no_query
)
1473 storeAppendPrintf(sentry
, " no-query");
1475 if (p
->options
.background_ping
)
1476 storeAppendPrintf(sentry
, " background-ping");
1478 if (p
->options
.no_digest
)
1479 storeAppendPrintf(sentry
, " no-digest");
1481 if (p
->options
.default_parent
)
1482 storeAppendPrintf(sentry
, " default");
1484 if (p
->options
.roundrobin
)
1485 storeAppendPrintf(sentry
, " round-robin");
1487 if (p
->options
.carp
)
1488 storeAppendPrintf(sentry
, " carp");
1491 if (p
->options
.userhash
)
1492 storeAppendPrintf(sentry
, " userhash");
1495 if (p
->options
.sourcehash
)
1496 storeAppendPrintf(sentry
, " sourcehash");
1498 if (p
->options
.weighted_roundrobin
)
1499 storeAppendPrintf(sentry
, " weighted-round-robin");
1501 if (p
->options
.mcast_responder
)
1502 storeAppendPrintf(sentry
, " multicast-responder");
1504 #if PEER_MULTICAST_SIBLINGS
1505 if (p
->options
.mcast_siblings
)
1506 storeAppendPrintf(sentry
, " multicast-siblings");
1510 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1512 if (p
->options
.closest_only
)
1513 storeAppendPrintf(sentry
, " closest-only");
1516 if (p
->options
.htcp
) {
1517 storeAppendPrintf(sentry
, " htcp");
1518 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1520 if (p
->options
.htcp_oldsquid
)
1521 storeAppendPrintf(sentry
, "%soldsquid",(doneopts
++>0?",":"="));
1522 if (p
->options
.htcp_no_clr
)
1523 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
++>0?",":"="));
1524 if (p
->options
.htcp_no_purge_clr
)
1525 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
++>0?",":"="));
1526 if (p
->options
.htcp_only_clr
)
1527 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
++>0?",":"="));
1532 if (p
->options
.no_netdb_exchange
)
1533 storeAppendPrintf(sentry
, " no-netdb-exchange");
1536 if (p
->options
.no_delay
)
1537 storeAppendPrintf(sentry
, " no-delay");
1541 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1543 if (p
->mcast
.ttl
> 0)
1544 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1546 if (p
->connect_timeout
> 0)
1547 storeAppendPrintf(sentry
, " connect-timeout=%d", (int) p
->connect_timeout
);
1549 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1550 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1552 #if USE_CACHE_DIGESTS
1555 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1559 if (p
->options
.allow_miss
)
1560 storeAppendPrintf(sentry
, " allow-miss");
1562 if (p
->options
.no_tproxy
)
1563 storeAppendPrintf(sentry
, " no-tproxy");
1565 if (p
->max_conn
> 0)
1566 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1568 if (p
->options
.originserver
)
1569 storeAppendPrintf(sentry
, " originserver");
1572 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1574 if (p
->connection_auth
== 0)
1575 storeAppendPrintf(sentry
, " connection-auth=off");
1576 else if (p
->connection_auth
== 1)
1577 storeAppendPrintf(sentry
, " connection-auth=on");
1578 else if (p
->connection_auth
== 2)
1579 storeAppendPrintf(sentry
, " connection-auth=auto");
1581 storeAppendPrintf(sentry
, "\n");
1585 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1587 CachePeer
*e
= NULL
;
1588 char ntoabuf
[MAX_IPSTRLEN
];
1589 CachePeerDomainList
*d
= NULL
;
1594 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1596 for (e
= peers
; e
; e
= e
->next
) {
1597 assert(e
->host
!= NULL
);
1598 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1601 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1605 storeAppendPrintf(sentry
, "Flags :");
1606 dump_peer_options(sentry
, e
);
1608 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1609 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1610 e
->addresses
[i
].NtoA(ntoabuf
,MAX_IPSTRLEN
) );
1613 storeAppendPrintf(sentry
, "Status : %s\n",
1614 neighborUp(e
) ? "Up" : "Down");
1615 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1616 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1617 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1619 if (!e
->options
.no_query
) {
1620 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1621 (int) (squid_curtime
- e
->stats
.last_query
));
1623 if (e
->stats
.last_reply
> 0)
1624 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1625 (int) (squid_curtime
- e
->stats
.last_reply
));
1627 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1629 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1631 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1632 e
->stats
.pings_acked
,
1633 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1636 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1638 if (!e
->options
.no_query
) {
1639 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1642 if (e
->options
.htcp
) {
1643 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1645 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1646 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1648 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1652 for (op
= ICP_INVALID
; op
< ICP_END
; ++op
) {
1653 if (e
->icp
.counts
[op
] == 0)
1656 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1659 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1670 if (e
->stats
.last_connect_failure
) {
1671 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1672 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1675 if (e
->peer_domain
!= NULL
) {
1676 storeAppendPrintf(sentry
, "DOMAIN LIST: ");
1678 for (d
= e
->peer_domain
; d
; d
= d
->next
) {
1679 storeAppendPrintf(sentry
, "%s%s ",
1680 d
->do_ping
? null_string
: "!", d
->domain
);
1683 storeAppendPrintf(sentry
, "\n");
1686 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1692 neighborsHtcpReply(const cache_key
* key
, htcpReplyData
* htcp
, const Ip::Address
&from
)
1694 StoreEntry
*e
= Store::Root().get(key
);
1695 MemObject
*mem
= NULL
;
1697 peer_t ntype
= PEER_NONE
;
1698 debugs(15, 6, "neighborsHtcpReply: " <<
1699 (htcp
->hit
? "HIT" : "MISS") << " " <<
1700 storeKeyText(key
) );
1705 if ((p
= whichPeer(from
)))
1706 neighborAliveHtcp(p
, mem
, htcp
);
1708 /* Does the entry exist? */
1710 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1711 neighborCountIgnored(p
);
1715 /* check if someone is already fetching it */
1716 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1717 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1718 neighborCountIgnored(p
);
1723 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1724 neighborCountIgnored(p
);
1728 if (e
->ping_status
!= PING_WAITING
) {
1729 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1730 neighborCountIgnored(p
);
1734 if (e
->lock_count
== 0) {
1735 // TODO: many entries are unlocked; why is this reported at level 1?
1736 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1737 neighborCountIgnored(p
);
1742 ntype
= neighborType(p
, mem
->request
);
1743 neighborUpdateRtt(p
, mem
);
1746 if (ignoreMulticastReply(p
, mem
)) {
1747 neighborCountIgnored(p
);
1751 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1752 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1756 * Send HTCP CLR messages to all peers configured to receive them.
1759 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1764 for (p
= Config
.peers
; p
; p
= p
->next
) {
1765 if (!p
->options
.htcp
) {
1768 if (p
->options
.htcp_no_clr
) {
1771 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1774 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.ToURL(buf
, 128));
1775 htcpClear(e
, uri
, req
, method
, p
, reason
);