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 "ProtoPort.h"
35 #include "acl/FilledChecklist.h"
37 #include "CacheManager.h"
39 #include "HttpRequest.h"
42 #include "MemObject.h"
43 #include "PeerDigest.h"
44 #include "PeerSelectState.h"
45 #include "SquidMath.h"
46 #include "SquidTime.h"
48 #include "icmp/net_db.h"
49 #include "ip/Address.h"
52 /* count mcast group peers every 15 minutes */
53 #define MCAST_COUNT_RATE 900
55 int peerAllowedToUse(const peer
*, HttpRequest
*);
56 static int peerWouldBePinged(const peer
*, HttpRequest
*);
57 static void neighborRemove(peer
*);
58 static void neighborAlive(peer
*, const MemObject
*, const icp_common_t
*);
60 static void neighborAliveHtcp(peer
*, const MemObject
*, const htcpReplyData
*);
62 static void neighborCountIgnored(peer
*);
63 static void peerRefreshDNS(void *);
64 static IPH peerDNSConfigure
;
65 static int peerProbeConnect(peer
*);
66 static CNCB peerProbeConnectDone
;
67 static void peerCountMcastPeersDone(void *data
);
68 static void peerCountMcastPeersStart(void *data
);
69 static void peerCountMcastPeersSchedule(peer
* p
, time_t when
);
70 static IRCB peerCountHandleIcpReply
;
72 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
73 static OBJH neighborDumpPeers
;
74 static OBJH neighborDumpNonPeers
;
75 static void dump_peers(StoreEntry
* sentry
, peer
* peers
);
77 static icp_common_t echo_hdr
;
78 static u_short echo_port
;
80 static int NLateReplies
= 0;
81 static peer
*first_ping
= NULL
;
84 neighborTypeStr(const peer
* p
)
86 if (p
->type
== PEER_NONE
)
89 if (p
->type
== PEER_SIBLING
)
92 if (p
->type
== PEER_MULTICAST
)
93 return "Multicast Group";
100 whichPeer(const Ip::Address
&from
)
105 debugs(15, 3, "whichPeer: from " << from
);
107 for (p
= Config
.peers
; p
; p
= p
->next
) {
108 for (j
= 0; j
< p
->n_addresses
; j
++) {
109 if (from
== p
->addresses
[j
] && from
.GetPort() == p
->icp
.port
) {
119 neighborType(const peer
* p
, const HttpRequest
* request
)
122 const struct _domain_type
*d
= NULL
;
124 for (d
= p
->typelist
; d
; d
= d
->next
) {
125 if (0 == matchDomainName(request
->GetHost(), d
->domain
))
126 if (d
->type
!= PEER_NONE
)
129 #if PEER_MULTICAST_SIBLINGS
130 if (p
->type
== PEER_MULTICAST
)
131 if (p
->options
.mcast_siblings
)
141 * this function figures out if it is appropriate to fetch REQUEST
145 peerAllowedToUse(const peer
* p
, HttpRequest
* request
)
148 const struct _domain_ping
*d
= NULL
;
150 assert(request
!= NULL
);
152 if (neighborType(p
, request
) == PEER_SIBLING
) {
153 #if PEER_MULTICAST_SIBLINGS
154 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
155 (request
->flags
.nocache
|| request
->flags
.refresh
|| request
->flags
.loopdetect
|| request
->flags
.need_validation
))
156 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->GetHost() << ") : multicast-siblings optimization match");
158 if (request
->flags
.nocache
)
161 if (request
->flags
.refresh
)
164 if (request
->flags
.loopdetect
)
167 if (request
->flags
.need_validation
)
171 if (p
->peer_domain
== NULL
&& p
->access
== NULL
)
176 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
177 if (0 == matchDomainName(request
->GetHost(), d
->domain
)) {
178 do_ping
= d
->do_ping
;
182 do_ping
= !d
->do_ping
;
185 if (p
->peer_domain
&& 0 == do_ping
)
188 if (p
->access
== NULL
)
191 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
192 checklist
.src_addr
= request
->client_addr
;
193 checklist
.my_addr
= request
->my_addr
;
197 * this is currently broken because 'request->user_ident' has been
198 * moved to conn->rfc931 and we don't have access to the parent
199 * ConnStateData here.
201 if (request
->user_ident
[0])
202 xstrncpy(checklist
.rfc931
, request
->user_ident
, USER_IDENT_SZ
);
206 return checklist
.fastCheck();
209 /* Return TRUE if it is okay to send an ICP request to this peer. */
211 peerWouldBePinged(const peer
* p
, HttpRequest
* request
)
213 if (!peerAllowedToUse(p
, request
))
216 if (p
->options
.no_query
)
219 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
222 if (p
->options
.mcast_responder
)
225 if (p
->n_addresses
== 0)
228 if (p
->icp
.port
== 0)
231 /* the case below seems strange, but can happen if the
232 * URL host is on the other side of a firewall */
233 if (p
->type
== PEER_SIBLING
)
234 if (!request
->flags
.hierarchical
)
237 /* Ping dead peers every timeout interval */
238 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
247 /* Return TRUE if it is okay to send an HTTP request to this peer. */
249 peerHTTPOkay(const peer
* p
, HttpRequest
* request
)
251 if (!peerAllowedToUse(p
, request
))
258 if (p
->stats
.conn_open
>= p
->max_conn
)
265 neighborsCount(HttpRequest
* request
)
270 for (p
= Config
.peers
; p
; p
= p
->next
)
271 if (peerWouldBePinged(p
, request
))
274 debugs(15, 3, "neighborsCount: " << count
);
280 getFirstUpParent(HttpRequest
* request
)
284 for (p
= Config
.peers
; p
; p
= p
->next
) {
288 if (neighborType(p
, request
) != PEER_PARENT
)
291 if (!peerHTTPOkay(p
, request
))
297 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
302 getRoundRobinParent(HttpRequest
* request
)
307 for (p
= Config
.peers
; p
; p
= p
->next
) {
308 if (!p
->options
.roundrobin
)
311 if (neighborType(p
, request
) != PEER_PARENT
)
314 if (!peerHTTPOkay(p
, request
))
321 if (p
->weight
== q
->weight
) {
322 if (q
->rr_count
< p
->rr_count
)
324 } else if ( (double) q
->rr_count
/ q
->weight
< (double) p
->rr_count
/ p
->weight
) {
335 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
341 getWeightedRoundRobinParent(HttpRequest
* request
)
347 for (p
= Config
.peers
; p
; p
= p
->next
) {
348 if (!p
->options
.weighted_roundrobin
)
351 if (neighborType(p
, request
) != PEER_PARENT
)
354 if (!peerHTTPOkay(p
, request
))
357 if (q
&& q
->rr_count
< p
->rr_count
)
363 if (q
&& q
->rr_count
> 1000000)
364 for (p
= Config
.peers
; p
; p
= p
->next
) {
365 if (!p
->options
.weighted_roundrobin
)
368 if (neighborType(p
, request
) != PEER_PARENT
)
375 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
377 if (weighted_rtt
< 1)
380 q
->rr_count
+= weighted_rtt
;
382 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
385 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
390 * This gets called every 5 minutes to clear the round-robin counter.
391 * The exact timing is an arbitrary default, set on estimate timing of a
392 * large number of requests in a high-performance environment during the
393 * period. The larger the number of requests between cycled resets the
394 * more balanced the operations.
397 \todo Make the reset timing a selectable parameter in squid.conf
400 peerClearRRLoop(void *data
)
403 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
407 * This gets called on startup and restart to kick off the peer round-robin
408 * maintenance event. It ensures that no matter how many times its called
409 * no more than one event is scheduled.
412 peerClearRRStart(void)
414 static int event_added
= 0;
416 peerClearRRLoop(NULL
);
421 * Called whenever the round-robin counters need to be reset to a sane state.
422 * So far those times are:
423 * - On startup and reconfigure - to set the counters to sane initial settings.
424 * - When a peer has revived from dead, to prevent the revived peer being
425 * flooded with requests which it has 'missed' during the down period.
431 for (p
= Config
.peers
; p
; p
= p
->next
) {
437 * Perform all actions when a peer is detected revived.
442 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
443 debugs(15, 1, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
444 p
->stats
.logged_state
= PEER_ALIVE
;
448 p
->stats
.last_reply
= squid_curtime
;
449 p
->stats
.probe_start
= 0;
453 getDefaultParent(HttpRequest
* request
)
457 for (p
= Config
.peers
; p
; p
= p
->next
) {
458 if (neighborType(p
, request
) != PEER_PARENT
)
461 if (!p
->options
.default_parent
)
464 if (!peerHTTPOkay(p
, request
))
467 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
472 debugs(15, 3, "getDefaultParent: returning NULL");
477 * XXX DW thinks this function is equivalent to/redundant with
478 * getFirstUpParent(). peerHTTPOkay() only returns true if the
479 * peer is UP anyway, so this function would not return a
483 getAnyParent(HttpRequest
* request
)
487 for (p
= Config
.peers
; p
; p
= p
->next
) {
488 if (neighborType(p
, request
) != PEER_PARENT
)
491 if (!peerHTTPOkay(p
, request
))
494 debugs(15, 3, "getAnyParent: returning " << p
->host
);
499 debugs(15, 3, "getAnyParent: returning NULL");
504 getNextPeer(peer
* p
)
516 neighborRemove(peer
* target
)
538 first_ping
= Config
.peers
;
542 neighborsRegisterWithCacheManager()
544 CacheManager
*manager
= CacheManager::GetInstance();
545 manager
->registerAction("server_list",
546 "Peer Cache Statistics",
547 neighborDumpPeers
, 0, 1);
549 if (theInIcpConnection
>= 0) {
550 manager
->registerAction("non_peers",
551 "List of Unknown sites sending ICP messages",
552 neighborDumpNonPeers
, 0, 1);
560 struct addrinfo
*AI
= NULL
;
561 struct servent
*sep
= NULL
;
562 const char *me
= getMyHostname();
563 peer
*thisPeer
= NULL
;
565 int fd
= theInIcpConnection
;
567 neighborsRegisterWithCacheManager();
569 /* setup addrinfo for use */
570 nul
.InitAddrInfo(AI
);
574 if (getsockname(fd
, AI
->ai_addr
, &AI
->ai_addrlen
) < 0)
575 debugs(15, 1, "getsockname(" << fd
<< "," << AI
->ai_addr
<< "," << &AI
->ai_addrlen
<< ") failed.");
577 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
578 http_port_list
*s
= NULL
;
579 next
= thisPeer
->next
;
581 if (0 != strcmp(thisPeer
->host
, me
))
584 for (s
= Config
.Sockaddr
.http
; s
; s
= s
->next
) {
585 if (thisPeer
->http_port
!= s
->s
.GetPort())
588 debugs(15, 1, "WARNING: Peer looks like this host");
590 debugs(15, 1, " Ignoring " <<
591 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
592 "/" << thisPeer
->http_port
<< "/" <<
595 neighborRemove(thisPeer
);
600 peerRefreshDNS((void *) 1);
602 if (ICP_INVALID
== echo_hdr
.opcode
) {
603 echo_hdr
.opcode
= ICP_SECHO
;
604 echo_hdr
.version
= ICP_VERSION_CURRENT
;
610 nul
.GetInAddr( *((struct in_addr
*)&echo_hdr
.shostid
) );
611 sep
= getservbyname("echo", "udp");
612 echo_port
= sep
? ntohs((u_short
) sep
->s_port
) : 7;
615 first_ping
= Config
.peers
;
616 nul
.FreeAddrInfo(AI
);
620 neighborsUdpPing(HttpRequest
* request
,
627 const char *url
= entry
->url();
628 MemObject
*mem
= entry
->mem_obj
;
634 int queries_sent
= 0;
635 int peers_pinged
= 0;
636 int parent_timeout
= 0, parent_exprep
= 0;
637 int sibling_timeout
= 0, sibling_exprep
= 0;
638 int mcast_timeout
= 0, mcast_exprep
= 0;
640 if (Config
.peers
== NULL
)
643 assert(entry
->swap_status
== SWAPOUT_NONE
);
645 mem
->start_ping
= current_time
;
647 mem
->ping_reply_callback
= callback
;
649 mem
->ircb_data
= callback_data
;
651 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
653 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
657 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
659 if (!peerWouldBePinged(p
, request
))
660 continue; /* next peer */
664 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
666 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
668 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
671 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
672 if (Config
.Port
.htcp
<= 0) {
673 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
677 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
678 if (htcpQuery(entry
, request
, p
) <= 0) continue; // unable to send.
682 if (Config
.Port
.icp
<= 0 || theOutIcpConnection
<= 0) {
683 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
687 if (p
->type
== PEER_MULTICAST
)
688 mcastSetTtl(theOutIcpConnection
, p
->mcast
.ttl
);
690 if (p
->icp
.port
== echo_port
) {
691 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
692 echo_hdr
.reqnum
= reqnum
;
693 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
694 icpUdpSend(theOutIcpConnection
,p
->in_addr
,query
,LOG_ICP_QUERY
,0);
698 if (Config
.onoff
.query_icmp
)
699 if (p
->icp
.version
== ICP_VERSION_2
)
700 flags
|= ICP_FLAG_SRC_RTT
;
702 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
704 icpUdpSend(theOutIcpConnection
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
711 p
->stats
.pings_sent
++;
713 if (p
->type
== PEER_MULTICAST
) {
714 mcast_exprep
+= p
->mcast
.n_replies_expected
;
715 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
716 } else if (neighborUp(p
)) {
717 /* its alive, expect a reply from it */
719 if (neighborType(p
, request
) == PEER_PARENT
) {
721 parent_timeout
+= p
->stats
.rtt
;
724 sibling_timeout
+= p
->stats
.rtt
;
727 /* Neighbor is dead; ping it anyway, but don't expect a reply */
728 /* log it once at the threshold */
730 if (p
->stats
.logged_state
== PEER_ALIVE
) {
731 debugs(15, 1, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
732 p
->stats
.logged_state
= PEER_DEAD
;
736 p
->stats
.last_query
= squid_curtime
;
739 * keep probe_start == 0 for a multicast peer,
740 * so neighborUp() never says this peer is dead.
743 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
744 p
->stats
.probe_start
= squid_curtime
;
747 if ((first_ping
= first_ping
->next
) == NULL
)
748 first_ping
= Config
.peers
;
751 * How many replies to expect?
753 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
756 * If there is a configured timeout, use it
758 if (Config
.Timeout
.icp_query
)
759 *timeout
= Config
.Timeout
.icp_query
;
763 *timeout
= 2 * parent_timeout
/ parent_exprep
;
764 else if (mcast_exprep
)
765 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
767 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
769 *timeout
= 2000; /* 2 seconds */
771 if (Config
.Timeout
.icp_query_max
)
772 if (*timeout
> Config
.Timeout
.icp_query_max
)
773 *timeout
= Config
.Timeout
.icp_query_max
;
775 if (*timeout
< Config
.Timeout
.icp_query_min
)
776 *timeout
= Config
.Timeout
.icp_query_min
;
782 /* lookup the digest of a given peer */
784 peerDigestLookup(peer
* p
, HttpRequest
* request
)
786 #if USE_CACHE_DIGESTS
787 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
790 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
791 /* does the peeer have a valid digest? */
794 debugs(15, 5, "peerDigestLookup: gone!");
796 } else if (!peerHTTPOkay(p
, request
)) {
797 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
799 } else if (!p
->digest
->flags
.needed
) {
800 debugs(15, 5, "peerDigestLookup: note need");
801 peerDigestNeeded(p
->digest
);
803 } else if (!p
->digest
->flags
.usable
) {
804 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
808 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
809 assert(p
->digest
->cd
);
810 /* does digest predict a hit? */
812 if (!cacheDigestTest(p
->digest
->cd
, key
))
815 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
824 /* select best peer based on cache digests */
826 neighborsDigestSelect(HttpRequest
* request
)
829 #if USE_CACHE_DIGESTS
831 const cache_key
*key
;
833 int choice_count
= 0;
834 int ichoice_count
= 0;
839 if (!request
->flags
.hierarchical
)
842 key
= storeKeyPublicByRequest(request
);
844 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
853 lookup
= peerDigestLookup(p
, request
);
855 if (lookup
== LOOKUP_NONE
)
860 if (lookup
== LOOKUP_MISS
)
863 p_rtt
= netdbHostRtt(p
->host
);
865 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
867 /* is this peer better than others in terms of rtt ? */
868 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
872 if (p_rtt
) /* informative choice (aka educated guess) */
875 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
879 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
880 peerNoteDigestLookup(request
, best_p
,
881 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
882 request
->hier
.n_choices
= choice_count
;
883 request
->hier
.n_ichoices
= ichoice_count
;
890 peerNoteDigestLookup(HttpRequest
* request
, peer
* p
, lookup_t lookup
)
892 #if USE_CACHE_DIGESTS
894 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
));
896 *request
->hier
.cd_host
= '\0';
898 request
->hier
.cd_lookup
= lookup
;
899 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
904 neighborAlive(peer
* p
, const MemObject
* mem
, const icp_common_t
* header
)
907 p
->stats
.pings_acked
++;
909 if ((icp_opcode
) header
->opcode
<= ICP_END
)
910 p
->icp
.counts
[header
->opcode
]++;
912 p
->icp
.version
= (int) header
->version
;
916 neighborUpdateRtt(peer
* p
, MemObject
* mem
)
918 int rtt
, rtt_av_factor
;
923 if (!mem
->start_ping
.tv_sec
)
926 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
928 if (rtt
< 1 || rtt
> 10000)
931 rtt_av_factor
= RTT_AV_FACTOR
;
933 if (p
->options
.weighted_roundrobin
)
934 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
936 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
941 neighborAliveHtcp(peer
* p
, const MemObject
* mem
, const htcpReplyData
* htcp
)
944 p
->stats
.pings_acked
++;
945 p
->htcp
.counts
[htcp
->hit
? 1 : 0]++;
946 p
->htcp
.version
= htcp
->version
;
952 neighborCountIgnored(peer
* p
)
957 p
->stats
.ignored_replies
++;
962 static peer
*non_peers
= NULL
;
965 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
969 for (np
= non_peers
; np
; np
= np
->next
) {
970 if (np
->in_addr
!= from
)
973 if (np
->in_addr
.GetPort() != from
.GetPort())
980 np
= (peer
*)xcalloc(1, sizeof(peer
));
982 np
->icp
.port
= from
.GetPort();
983 np
->type
= PEER_NONE
;
984 np
->host
= new char[MAX_IPSTRLEN
];
985 from
.NtoA(np
->host
,MAX_IPSTRLEN
);
986 np
->next
= non_peers
;
990 np
->icp
.counts
[opcode
]++;
992 if (isPowTen(++np
->stats
.ignored_replies
))
993 debugs(15, 1, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
996 /* ignoreMulticastReply
998 * * We want to ignore replies from multicast peers if the
999 * * cache_host_domain rules would normally prevent the peer
1003 ignoreMulticastReply(peer
* p
, MemObject
* mem
)
1008 if (!p
->options
.mcast_responder
)
1011 if (peerHTTPOkay(p
, mem
->request
))
1018 * I should attach these records to the entry. We take the first
1019 * hit we get our wait until everyone misses. The timeout handler
1020 * call needs to nip this shopping list or call one of the misses.
1022 * If a hit process is already started, then sobeit
1025 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
1029 MemObject
*mem
= NULL
;
1030 peer_t ntype
= PEER_NONE
;
1031 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1033 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1035 if (NULL
!= (entry
= Store::Root().get(key
)))
1036 mem
= entry
->mem_obj
;
1038 if ((p
= whichPeer(from
)))
1039 neighborAlive(p
, mem
, header
);
1041 if (opcode
> ICP_END
)
1044 const char *opcode_d
= icp_opcode_str
[opcode
];
1047 neighborUpdateRtt(p
, mem
);
1049 /* Does the entry exist? */
1050 if (NULL
== entry
) {
1051 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1052 neighborCountIgnored(p
);
1056 /* check if someone is already fetching it */
1057 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1058 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1059 neighborCountIgnored(p
);
1064 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1065 neighborCountIgnored(p
);
1069 if (entry
->ping_status
!= PING_WAITING
) {
1070 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1071 neighborCountIgnored(p
);
1075 if (entry
->lock_count
== 0) {
1076 debugs(12, 1, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1077 neighborCountIgnored(p
);
1081 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1084 ntype
= neighborType(p
, mem
->request
);
1087 if (ignoreMulticastReply(p
, mem
)) {
1088 neighborCountIgnored(p
);
1089 } else if (opcode
== ICP_MISS
) {
1091 neighborIgnoreNonPeer(from
, opcode
);
1093 mem
->ping_reply_callback(p
, ntype
, PROTO_ICP
, header
, mem
->ircb_data
);
1095 } else if (opcode
== ICP_HIT
) {
1097 neighborIgnoreNonPeer(from
, opcode
);
1099 header
->opcode
= ICP_HIT
;
1100 mem
->ping_reply_callback(p
, ntype
, PROTO_ICP
, header
, mem
->ircb_data
);
1102 } else if (opcode
== ICP_DECHO
) {
1104 neighborIgnoreNonPeer(from
, opcode
);
1105 } else if (ntype
== PEER_SIBLING
) {
1106 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1107 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1109 mem
->ping_reply_callback(p
, ntype
, PROTO_ICP
, header
, mem
->ircb_data
);
1111 } else if (opcode
== ICP_SECHO
) {
1113 debugs(15, 1, "Ignoring SECHO from neighbor " << p
->host
);
1114 neighborCountIgnored(p
);
1116 debugs(15, 1, "Unsolicited SECHO from " << from
);
1118 } else if (opcode
== ICP_DENIED
) {
1120 neighborIgnoreNonPeer(from
, opcode
);
1121 } else if (p
->stats
.pings_acked
> 100) {
1122 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1123 debugs(15, 0, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1124 debugs(15, 0, "Disabling '" << p
->host
<< "', please check your configuration.");
1128 neighborCountIgnored(p
);
1131 } else if (opcode
== ICP_MISS_NOFETCH
) {
1132 mem
->ping_reply_callback(p
, ntype
, PROTO_ICP
, header
, mem
->ircb_data
);
1134 debugs(15, 0, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1139 peerFindByName(const char *name
)
1143 for (p
= Config
.peers
; p
; p
= p
->next
) {
1144 if (!strcasecmp(name
, p
->name
))
1152 peerFindByNameAndPort(const char *name
, unsigned short port
)
1156 for (p
= Config
.peers
; p
; p
= p
->next
) {
1157 if (strcasecmp(name
, p
->name
))
1160 if (port
!= p
->http_port
)
1170 neighborUp(const peer
* p
)
1173 if (!peerProbeConnect((peer
*) p
)) {
1174 debugs(15, 8, "neighborUp: DOWN (probed): " << p
->host
<< " (" << p
->in_addr
<< ")");
1180 * The peer can not be UP if we don't have any IP addresses
1183 if (0 == p
->n_addresses
) {
1184 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1188 if (p
->options
.no_query
) {
1189 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1193 if (p
->stats
.probe_start
!= 0 &&
1194 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1195 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1199 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1204 peerDestroy(void *data
)
1206 peer
*p
= (peer
*)data
;
1208 struct _domain_ping
*l
= NULL
;
1210 struct _domain_ping
*nl
= NULL
;
1215 for (l
= p
->peer_domain
; l
; l
= nl
) {
1217 safe_free(l
->domain
);
1223 safe_free(p
->domain
);
1224 #if USE_CACHE_DIGESTS
1226 cbdataReferenceDone(p
->digest
);
1231 peerNoteDigestGone(peer
* p
)
1233 #if USE_CACHE_DIGESTS
1234 cbdataReferenceDone(p
->digest
);
1239 peerDNSConfigure(const ipcache_addrs
*ia
, const DnsLookupDetails
&, void *data
)
1241 peer
*p
= (peer
*)data
;
1245 if (p
->n_addresses
== 0) {
1246 debugs(15, 1, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1248 if (p
->type
== PEER_MULTICAST
)
1249 debugs(15, 1, " Multicast TTL = " << p
->mcast
.ttl
);
1255 debugs(0, 0, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1259 if ((int) ia
->count
< 1) {
1260 debugs(0, 0, "WARNING: No IP address found for '" << p
->host
<< "'!");
1264 p
->tcp_up
= p
->connect_fail_limit
;
1266 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; j
++) {
1267 p
->addresses
[j
] = ia
->in_addrs
[j
];
1268 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1272 p
->in_addr
.SetEmpty();
1273 p
->in_addr
= p
->addresses
[0];
1274 p
->in_addr
.SetPort(p
->icp
.port
);
1276 if (p
->type
== PEER_MULTICAST
)
1277 peerCountMcastPeersSchedule(p
, 10);
1280 if (p
->type
!= PEER_MULTICAST
)
1281 if (!p
->options
.no_netdb_exchange
)
1282 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1288 peerRefreshDNS(void *data
)
1292 if (eventFind(peerRefreshDNS
, NULL
))
1293 eventDelete(peerRefreshDNS
, NULL
);
1295 if (!data
&& 0 == stat5minClientRequests()) {
1296 /* no recent client traffic, wait a bit */
1297 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1301 for (p
= Config
.peers
; p
; p
= p
->next
)
1302 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1304 /* Reconfigure the peers every hour */
1305 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1309 peerConnectFailedSilent(peer
* p
)
1311 p
->stats
.last_connect_failure
= squid_curtime
;
1314 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1322 debugs(15, 1, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1323 p
->stats
.logged_state
= PEER_DEAD
;
1328 peerConnectFailed(peer
*p
)
1330 debugs(15, 1, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1331 peerConnectFailedSilent(p
);
1335 peerConnectSucceded(peer
* p
)
1338 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1339 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1341 if (!p
->n_addresses
)
1342 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1344 p
->tcp_up
= p
->connect_fail_limit
;
1347 /// called by Comm when test_fd is closed while connect is in progress
1349 peerProbeClosed(int fd
, void *data
)
1351 peer
*p
= (peer
*)data
;
1353 // it is a failure because we failed to connect
1354 peerConnectFailedSilent(p
);
1358 peerProbeConnectTimeout(int fd
, void *data
)
1360 peer
* p
= (peer
*)data
;
1361 comm_remove_close_handler(fd
, &peerProbeClosed
, p
);
1364 peerConnectFailedSilent(p
);
1368 * peerProbeConnect will be called on dead peers by neighborUp
1371 peerProbeConnect(peer
* p
)
1374 time_t ctimeout
= p
->connect_timeout
> 0 ? p
->connect_timeout
1375 : Config
.Timeout
.peer_connect
;
1376 int ret
= squid_curtime
- p
->stats
.last_connect_failure
> ctimeout
* 10;
1378 if (p
->test_fd
!= -1)
1379 return ret
;/* probe already running */
1381 if (squid_curtime
- p
->stats
.last_connect_probe
== 0)
1382 return ret
;/* don't probe to often */
1384 Ip::Address
temp(getOutgoingAddr(NULL
,p
));
1386 // if IPv6 is disabled try to force IPv4-only outgoing.
1387 if (!Ip::EnableIpv6
&& !temp
.SetIPv4()) {
1388 debugs(50, DBG_IMPORTANT
, "WARNING: IPv6 is disabled. Failed to use " << temp
<< " to probe " << p
->host
);
1392 // if IPv6 is split-stack, prefer IPv4
1393 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
) {
1394 // NP: This is not a great choice of default,
1395 // but with the current Internet being IPv4-majority has a higher success rate.
1396 // if setting to IPv4 fails we dont care, that just means to use IPv6 outgoing.
1400 fd
= comm_open(SOCK_STREAM
, IPPROTO_TCP
, temp
, COMM_NONBLOCKING
, p
->host
);
1405 comm_add_close_handler(fd
, &peerProbeClosed
, p
);
1406 commSetTimeout(fd
, ctimeout
, peerProbeConnectTimeout
, p
);
1410 p
->stats
.last_connect_probe
= squid_curtime
;
1412 commConnectStart(p
->test_fd
,
1415 peerProbeConnectDone
,
1422 peerProbeConnectDone(int fd
, const DnsLookupDetails
&, comm_err_t status
, int xerrno
, void *data
)
1424 peer
*p
= (peer
*)data
;
1426 if (status
== COMM_OK
) {
1427 peerConnectSucceded(p
);
1429 peerConnectFailedSilent(p
);
1432 comm_remove_close_handler(fd
, &peerProbeClosed
, p
);
1439 peerCountMcastPeersSchedule(peer
* p
, time_t when
)
1441 if (p
->mcast
.flags
.count_event_pending
)
1444 eventAdd("peerCountMcastPeersStart",
1445 peerCountMcastPeersStart
,
1449 p
->mcast
.flags
.count_event_pending
= 1;
1453 peerCountMcastPeersStart(void *data
)
1455 peer
*p
= (peer
*)data
;
1459 icp_common_t
*query
;
1461 LOCAL_ARRAY(char, url
, MAX_URL
);
1462 assert(p
->type
== PEER_MULTICAST
);
1463 p
->mcast
.flags
.count_event_pending
= 0;
1464 snprintf(url
, MAX_URL
, "http://");
1465 p
->in_addr
.ToURL(url
+7, MAX_URL
-8 );
1467 fake
= storeCreateEntry(url
, url
, request_flags(), METHOD_GET
);
1468 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1469 psstate
= new ps_state
;
1470 psstate
->request
= HTTPMSGLOCK(req
);
1471 psstate
->entry
= fake
;
1472 psstate
->callback
= NULL
;
1473 psstate
->callback_data
= cbdataReference(p
);
1474 psstate
->ping
.start
= current_time
;
1475 mem
= fake
->mem_obj
;
1476 mem
->request
= HTTPMSGLOCK(psstate
->request
);
1477 mem
->start_ping
= current_time
;
1478 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1479 mem
->ircb_data
= psstate
;
1480 mcastSetTtl(theOutIcpConnection
, p
->mcast
.ttl
);
1481 p
->mcast
.id
= mem
->id
;
1482 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1483 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1484 icpUdpSend(theOutIcpConnection
,
1489 fake
->ping_status
= PING_WAITING
;
1490 eventAdd("peerCountMcastPeersDone",
1491 peerCountMcastPeersDone
,
1493 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1494 p
->mcast
.flags
.counting
= 1;
1495 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1499 peerCountMcastPeersDone(void *data
)
1501 ps_state
*psstate
= (ps_state
*)data
;
1502 StoreEntry
*fake
= psstate
->entry
;
1504 if (cbdataReferenceValid(psstate
->callback_data
)) {
1505 peer
*p
= (peer
*)psstate
->callback_data
;
1506 p
->mcast
.flags
.counting
= 0;
1507 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1508 debugs(15, 1, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1509 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1510 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1511 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1514 cbdataReferenceDone(psstate
->callback_data
);
1516 EBIT_SET(fake
->flags
, ENTRY_ABORTED
);
1517 HTTPMSGUNLOCK(fake
->mem_obj
->request
);
1518 fake
->releaseRequest();
1520 HTTPMSGUNLOCK(psstate
->request
);
1521 cbdataFree(psstate
);
1525 peerCountHandleIcpReply(peer
* p
, peer_t type
, protocol_t proto
, void *hdrnotused
, void *data
)
1529 ps_state
*psstate
= (ps_state
*)data
;
1530 StoreEntry
*fake
= psstate
->entry
;
1531 MemObject
*mem
= fake
->mem_obj
;
1532 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1533 assert(proto
== PROTO_ICP
);
1536 psstate
->ping
.n_recv
++;
1537 rtt_av_factor
= RTT_AV_FACTOR
;
1539 if (p
->options
.weighted_roundrobin
)
1540 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1542 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1546 neighborDumpPeers(StoreEntry
* sentry
)
1548 dump_peers(sentry
, Config
.peers
);
1552 neighborDumpNonPeers(StoreEntry
* sentry
)
1554 dump_peers(sentry
, non_peers
);
1558 dump_peer_options(StoreEntry
* sentry
, peer
* p
)
1560 if (p
->options
.proxy_only
)
1561 storeAppendPrintf(sentry
, " proxy-only");
1563 if (p
->options
.no_query
)
1564 storeAppendPrintf(sentry
, " no-query");
1566 if (p
->options
.background_ping
)
1567 storeAppendPrintf(sentry
, " background-ping");
1569 if (p
->options
.no_digest
)
1570 storeAppendPrintf(sentry
, " no-digest");
1572 if (p
->options
.default_parent
)
1573 storeAppendPrintf(sentry
, " default");
1575 if (p
->options
.roundrobin
)
1576 storeAppendPrintf(sentry
, " round-robin");
1578 if (p
->options
.carp
)
1579 storeAppendPrintf(sentry
, " carp");
1581 if (p
->options
.userhash
)
1582 storeAppendPrintf(sentry
, " userhash");
1584 if (p
->options
.userhash
)
1585 storeAppendPrintf(sentry
, " sourcehash");
1587 if (p
->options
.weighted_roundrobin
)
1588 storeAppendPrintf(sentry
, " weighted-round-robin");
1590 if (p
->options
.mcast_responder
)
1591 storeAppendPrintf(sentry
, " multicast-responder");
1593 #if PEER_MULTICAST_SIBLINGS
1594 if (p
->options
.mcast_siblings
)
1595 storeAppendPrintf(sentry
, " multicast-siblings");
1599 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1601 if (p
->options
.closest_only
)
1602 storeAppendPrintf(sentry
, " closest-only");
1605 if (p
->options
.htcp
)
1606 storeAppendPrintf(sentry
, " htcp");
1607 if (p
->options
.htcp_oldsquid
)
1608 storeAppendPrintf(sentry
, " htcp-oldsquid");
1609 if (p
->options
.htcp_no_clr
)
1610 storeAppendPrintf(sentry
, " htcp-no-clr");
1611 if (p
->options
.htcp_no_purge_clr
)
1612 storeAppendPrintf(sentry
, " htcp-no-purge-clr");
1613 if (p
->options
.htcp_only_clr
)
1614 storeAppendPrintf(sentry
, " htcp-only-clr");
1617 if (p
->options
.no_netdb_exchange
)
1618 storeAppendPrintf(sentry
, " no-netdb-exchange");
1622 if (p
->options
.no_delay
)
1623 storeAppendPrintf(sentry
, " no-delay");
1628 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1630 if (p
->mcast
.ttl
> 0)
1631 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1633 if (p
->connect_timeout
> 0)
1634 storeAppendPrintf(sentry
, " connect-timeout=%d", (int) p
->connect_timeout
);
1636 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1637 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1639 #if USE_CACHE_DIGESTS
1642 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1646 if (p
->options
.allow_miss
)
1647 storeAppendPrintf(sentry
, " allow-miss");
1649 if (p
->options
.no_tproxy
)
1650 storeAppendPrintf(sentry
, " no-tproxy");
1652 if (p
->max_conn
> 0)
1653 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1655 if (p
->options
.originserver
)
1656 storeAppendPrintf(sentry
, " originserver");
1659 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1661 if (p
->connection_auth
== 0)
1662 storeAppendPrintf(sentry
, " connection-auth=off");
1663 else if (p
->connection_auth
== 1)
1664 storeAppendPrintf(sentry
, " connection-auth=on");
1665 else if (p
->connection_auth
== 2)
1666 storeAppendPrintf(sentry
, " connection-auth=auto");
1668 storeAppendPrintf(sentry
, "\n");
1672 dump_peers(StoreEntry
* sentry
, peer
* peers
)
1675 char ntoabuf
[MAX_IPSTRLEN
];
1676 struct _domain_ping
*d
= NULL
;
1681 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1683 for (e
= peers
; e
; e
= e
->next
) {
1684 assert(e
->host
!= NULL
);
1685 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1688 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1692 storeAppendPrintf(sentry
, "Flags :");
1693 dump_peer_options(sentry
, e
);
1695 for (i
= 0; i
< e
->n_addresses
; i
++) {
1696 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1697 e
->addresses
[i
].NtoA(ntoabuf
,MAX_IPSTRLEN
) );
1700 storeAppendPrintf(sentry
, "Status : %s\n",
1701 neighborUp(e
) ? "Up" : "Down");
1702 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1703 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1704 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1706 if (!e
->options
.no_query
) {
1707 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1708 (int) (squid_curtime
- e
->stats
.last_query
));
1710 if (e
->stats
.last_reply
> 0)
1711 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1712 (int) (squid_curtime
- e
->stats
.last_reply
));
1714 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1716 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1718 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1719 e
->stats
.pings_acked
,
1720 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1723 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1725 if (!e
->options
.no_query
) {
1726 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1729 if (e
->options
.htcp
) {
1730 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1732 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1733 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1735 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1739 for (op
= ICP_INVALID
; op
< ICP_END
; ++op
) {
1740 if (e
->icp
.counts
[op
] == 0)
1743 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1746 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1757 if (e
->stats
.last_connect_failure
) {
1758 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1759 mkhttpdlogtime(&(e
->stats
.last_connect_failure
)));
1762 if (e
->peer_domain
!= NULL
) {
1763 storeAppendPrintf(sentry
, "DOMAIN LIST: ");
1765 for (d
= e
->peer_domain
; d
; d
= d
->next
) {
1766 storeAppendPrintf(sentry
, "%s%s ",
1767 d
->do_ping
? null_string
: "!", d
->domain
);
1770 storeAppendPrintf(sentry
, "\n");
1773 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1779 neighborsHtcpReply(const cache_key
* key
, htcpReplyData
* htcp
, const Ip::Address
&from
)
1781 StoreEntry
*e
= Store::Root().get(key
);
1782 MemObject
*mem
= NULL
;
1784 peer_t ntype
= PEER_NONE
;
1785 debugs(15, 6, "neighborsHtcpReply: " <<
1786 (htcp
->hit
? "HIT" : "MISS") << " " <<
1787 storeKeyText(key
) );
1792 if ((p
= whichPeer(from
)))
1793 neighborAliveHtcp(p
, mem
, htcp
);
1795 /* Does the entry exist? */
1797 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1798 neighborCountIgnored(p
);
1802 /* check if someone is already fetching it */
1803 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1804 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1805 neighborCountIgnored(p
);
1810 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1811 neighborCountIgnored(p
);
1815 if (e
->ping_status
!= PING_WAITING
) {
1816 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1817 neighborCountIgnored(p
);
1821 if (e
->lock_count
== 0) {
1822 debugs(12, 1, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1823 neighborCountIgnored(p
);
1828 ntype
= neighborType(p
, mem
->request
);
1829 neighborUpdateRtt(p
, mem
);
1832 if (ignoreMulticastReply(p
, mem
)) {
1833 neighborCountIgnored(p
);
1837 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1838 mem
->ping_reply_callback(p
, ntype
, PROTO_HTCP
, htcp
, mem
->ircb_data
);
1842 * Send HTCP CLR messages to all peers configured to receive them.
1845 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1850 for (p
= Config
.peers
; p
; p
= p
->next
) {
1851 if (!p
->options
.htcp
) {
1854 if (p
->options
.htcp_no_clr
) {
1857 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1860 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.ToURL(buf
, 128));
1861 htcpClear(e
, uri
, req
, method
, p
, reason
);