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"
38 #include "HttpRequest.h"
41 #include "MemObject.h"
42 #include "PeerDigest.h"
43 #include "PeerSelectState.h"
44 #include "SquidMath.h"
45 #include "SquidTime.h"
47 #include "icmp/net_db.h"
48 #include "ip/Address.h"
50 #include "mgr/Registration.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 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
172 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this peer.
173 if (p
->options
.originserver
&& request
->method
== METHOD_CONNECT
&& request
->port
!= p
->in_addr
.GetPort())
176 if (p
->peer_domain
== NULL
&& p
->access
== NULL
)
181 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
182 if (0 == matchDomainName(request
->GetHost(), d
->domain
)) {
183 do_ping
= d
->do_ping
;
187 do_ping
= !d
->do_ping
;
190 if (p
->peer_domain
&& 0 == do_ping
)
193 if (p
->access
== NULL
)
196 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
197 checklist
.src_addr
= request
->client_addr
;
198 checklist
.my_addr
= request
->my_addr
;
202 * this is currently broken because 'request->user_ident' has been
203 * moved to conn->rfc931 and we don't have access to the parent
204 * ConnStateData here.
206 if (request
->user_ident
[0])
207 xstrncpy(checklist
.rfc931
, request
->user_ident
, USER_IDENT_SZ
);
211 return checklist
.fastCheck();
214 /* Return TRUE if it is okay to send an ICP request to this peer. */
216 peerWouldBePinged(const peer
* p
, HttpRequest
* request
)
218 if (!peerAllowedToUse(p
, request
))
221 if (p
->options
.no_query
)
224 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
227 if (p
->options
.mcast_responder
)
230 if (p
->n_addresses
== 0)
233 if (p
->icp
.port
== 0)
236 /* the case below seems strange, but can happen if the
237 * URL host is on the other side of a firewall */
238 if (p
->type
== PEER_SIBLING
)
239 if (!request
->flags
.hierarchical
)
242 /* Ping dead peers every timeout interval */
243 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
252 /* Return TRUE if it is okay to send an HTTP request to this peer. */
254 peerHTTPOkay(const peer
* p
, HttpRequest
* request
)
256 if (!peerAllowedToUse(p
, request
))
263 if (p
->stats
.conn_open
>= p
->max_conn
)
270 neighborsCount(HttpRequest
* request
)
275 for (p
= Config
.peers
; p
; p
= p
->next
)
276 if (peerWouldBePinged(p
, request
))
279 debugs(15, 3, "neighborsCount: " << count
);
285 getFirstUpParent(HttpRequest
* request
)
289 for (p
= Config
.peers
; p
; p
= p
->next
) {
293 if (neighborType(p
, request
) != PEER_PARENT
)
296 if (!peerHTTPOkay(p
, request
))
302 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
307 getRoundRobinParent(HttpRequest
* request
)
312 for (p
= Config
.peers
; p
; p
= p
->next
) {
313 if (!p
->options
.roundrobin
)
316 if (neighborType(p
, request
) != PEER_PARENT
)
319 if (!peerHTTPOkay(p
, request
))
326 if (p
->weight
== q
->weight
) {
327 if (q
->rr_count
< p
->rr_count
)
329 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
340 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
346 getWeightedRoundRobinParent(HttpRequest
* request
)
352 for (p
= Config
.peers
; p
; p
= p
->next
) {
353 if (!p
->options
.weighted_roundrobin
)
356 if (neighborType(p
, request
) != PEER_PARENT
)
359 if (!peerHTTPOkay(p
, request
))
362 if (q
&& q
->rr_count
< p
->rr_count
)
368 if (q
&& q
->rr_count
> 1000000)
369 for (p
= Config
.peers
; p
; p
= p
->next
) {
370 if (!p
->options
.weighted_roundrobin
)
373 if (neighborType(p
, request
) != PEER_PARENT
)
380 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
382 if (weighted_rtt
< 1)
385 q
->rr_count
+= weighted_rtt
;
387 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
390 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
395 * This gets called every 5 minutes to clear the round-robin counter.
396 * The exact timing is an arbitrary default, set on estimate timing of a
397 * large number of requests in a high-performance environment during the
398 * period. The larger the number of requests between cycled resets the
399 * more balanced the operations.
402 \todo Make the reset timing a selectable parameter in squid.conf
405 peerClearRRLoop(void *data
)
408 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
412 * This gets called on startup and restart to kick off the peer round-robin
413 * maintenance event. It ensures that no matter how many times its called
414 * no more than one event is scheduled.
417 peerClearRRStart(void)
419 static int event_added
= 0;
421 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 peer has revived from dead, to prevent the revived peer 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 peer is detected revived.
447 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
448 debugs(15, 1, "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 * XXX DW thinks this function is equivalent to/redundant with
483 * getFirstUpParent(). peerHTTPOkay() only returns true if the
484 * peer is UP anyway, so this function would not return a
488 getAnyParent(HttpRequest
* request
)
492 for (p
= Config
.peers
; p
; p
= p
->next
) {
493 if (neighborType(p
, request
) != PEER_PARENT
)
496 if (!peerHTTPOkay(p
, request
))
499 debugs(15, 3, "getAnyParent: returning " << p
->host
);
504 debugs(15, 3, "getAnyParent: returning NULL");
509 getNextPeer(peer
* p
)
521 neighborRemove(peer
* target
)
543 first_ping
= Config
.peers
;
547 neighborsRegisterWithCacheManager()
549 Mgr::RegisterAction("server_list",
550 "Peer Cache Statistics",
551 neighborDumpPeers
, 0, 1);
553 if (theInIcpConnection
>= 0) {
554 Mgr::RegisterAction("non_peers",
555 "List of Unknown sites sending ICP messages",
556 neighborDumpNonPeers
, 0, 1);
564 struct addrinfo
*AI
= NULL
;
565 struct servent
*sep
= NULL
;
566 const char *me
= getMyHostname();
567 peer
*thisPeer
= NULL
;
569 int fd
= theInIcpConnection
;
571 neighborsRegisterWithCacheManager();
573 /* setup addrinfo for use */
574 nul
.InitAddrInfo(AI
);
578 if (getsockname(fd
, AI
->ai_addr
, &AI
->ai_addrlen
) < 0)
579 debugs(15, 1, "getsockname(" << fd
<< "," << AI
->ai_addr
<< "," << &AI
->ai_addrlen
<< ") failed.");
581 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
582 http_port_list
*s
= NULL
;
583 next
= thisPeer
->next
;
585 if (0 != strcmp(thisPeer
->host
, me
))
588 for (s
= Config
.Sockaddr
.http
; s
; s
= s
->next
) {
589 if (thisPeer
->http_port
!= s
->s
.GetPort())
592 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
594 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
595 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
596 "/" << thisPeer
->http_port
<< "/" <<
599 neighborRemove(thisPeer
);
604 peerRefreshDNS((void *) 1);
606 if (echo_hdr
.opcode
== ICP_INVALID
) {
607 echo_hdr
.opcode
= ICP_SECHO
;
608 echo_hdr
.version
= ICP_VERSION_CURRENT
;
614 nul
.GetInAddr( *((struct in_addr
*)&echo_hdr
.shostid
) );
615 sep
= getservbyname("echo", "udp");
616 echo_port
= sep
? ntohs((u_short
) sep
->s_port
) : 7;
619 first_ping
= Config
.peers
;
620 nul
.FreeAddrInfo(AI
);
624 neighborsUdpPing(HttpRequest
* request
,
631 const char *url
= entry
->url();
632 MemObject
*mem
= entry
->mem_obj
;
638 int queries_sent
= 0;
639 int peers_pinged
= 0;
640 int parent_timeout
= 0, parent_exprep
= 0;
641 int sibling_timeout
= 0, sibling_exprep
= 0;
642 int mcast_timeout
= 0, mcast_exprep
= 0;
644 if (Config
.peers
== NULL
)
647 assert(entry
->swap_status
== SWAPOUT_NONE
);
649 mem
->start_ping
= current_time
;
651 mem
->ping_reply_callback
= callback
;
653 mem
->ircb_data
= callback_data
;
655 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
657 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
661 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
663 if (!peerWouldBePinged(p
, request
))
664 continue; /* next peer */
668 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
670 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
672 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
675 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
676 if (Config
.Port
.htcp
<= 0) {
677 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
681 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
682 if (htcpQuery(entry
, request
, p
) <= 0) continue; // unable to send.
686 if (Config
.Port
.icp
<= 0 || theOutIcpConnection
<= 0) {
687 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
691 if (p
->type
== PEER_MULTICAST
)
692 mcastSetTtl(theOutIcpConnection
, p
->mcast
.ttl
);
694 if (p
->icp
.port
== echo_port
) {
695 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
696 echo_hdr
.reqnum
= reqnum
;
697 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
698 icpUdpSend(theOutIcpConnection
,p
->in_addr
,query
,LOG_ICP_QUERY
,0);
702 if (Config
.onoff
.query_icmp
)
703 if (p
->icp
.version
== ICP_VERSION_2
)
704 flags
|= ICP_FLAG_SRC_RTT
;
706 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
708 icpUdpSend(theOutIcpConnection
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
715 p
->stats
.pings_sent
++;
717 if (p
->type
== PEER_MULTICAST
) {
718 mcast_exprep
+= p
->mcast
.n_replies_expected
;
719 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
720 } else if (neighborUp(p
)) {
721 /* its alive, expect a reply from it */
723 if (neighborType(p
, request
) == PEER_PARENT
) {
725 parent_timeout
+= p
->stats
.rtt
;
728 sibling_timeout
+= p
->stats
.rtt
;
731 /* Neighbor is dead; ping it anyway, but don't expect a reply */
732 /* log it once at the threshold */
734 if (p
->stats
.logged_state
== PEER_ALIVE
) {
735 debugs(15, 1, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
736 p
->stats
.logged_state
= PEER_DEAD
;
740 p
->stats
.last_query
= squid_curtime
;
743 * keep probe_start == 0 for a multicast peer,
744 * so neighborUp() never says this peer is dead.
747 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
748 p
->stats
.probe_start
= squid_curtime
;
751 if ((first_ping
= first_ping
->next
) == NULL
)
752 first_ping
= Config
.peers
;
755 * How many replies to expect?
757 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
760 * If there is a configured timeout, use it
762 if (Config
.Timeout
.icp_query
)
763 *timeout
= Config
.Timeout
.icp_query
;
767 *timeout
= 2 * parent_timeout
/ parent_exprep
;
768 else if (mcast_exprep
)
769 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
771 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
773 *timeout
= 2000; /* 2 seconds */
775 if (Config
.Timeout
.icp_query_max
)
776 if (*timeout
> Config
.Timeout
.icp_query_max
)
777 *timeout
= Config
.Timeout
.icp_query_max
;
779 if (*timeout
< Config
.Timeout
.icp_query_min
)
780 *timeout
= Config
.Timeout
.icp_query_min
;
786 /* lookup the digest of a given peer */
788 peerDigestLookup(peer
* p
, HttpRequest
* request
)
790 #if USE_CACHE_DIGESTS
791 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
794 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
795 /* does the peeer have a valid digest? */
798 debugs(15, 5, "peerDigestLookup: gone!");
800 } else if (!peerHTTPOkay(p
, request
)) {
801 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
803 } else if (!p
->digest
->flags
.needed
) {
804 debugs(15, 5, "peerDigestLookup: note need");
805 peerDigestNeeded(p
->digest
);
807 } else if (!p
->digest
->flags
.usable
) {
808 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
812 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
813 assert(p
->digest
->cd
);
814 /* does digest predict a hit? */
816 if (!cacheDigestTest(p
->digest
->cd
, key
))
819 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
828 /* select best peer based on cache digests */
830 neighborsDigestSelect(HttpRequest
* request
)
833 #if USE_CACHE_DIGESTS
836 int choice_count
= 0;
837 int ichoice_count
= 0;
842 if (!request
->flags
.hierarchical
)
845 storeKeyPublicByRequest(request
);
847 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
856 lookup
= peerDigestLookup(p
, request
);
858 if (lookup
== LOOKUP_NONE
)
863 if (lookup
== LOOKUP_MISS
)
866 p_rtt
= netdbHostRtt(p
->host
);
868 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
870 /* is this peer better than others in terms of rtt ? */
871 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
875 if (p_rtt
) /* informative choice (aka educated guess) */
878 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
882 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
883 peerNoteDigestLookup(request
, best_p
,
884 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
885 request
->hier
.n_choices
= choice_count
;
886 request
->hier
.n_ichoices
= ichoice_count
;
893 peerNoteDigestLookup(HttpRequest
* request
, peer
* p
, lookup_t lookup
)
895 #if USE_CACHE_DIGESTS
897 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
));
899 *request
->hier
.cd_host
= '\0';
901 request
->hier
.cd_lookup
= lookup
;
902 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
907 neighborAlive(peer
* p
, const MemObject
* mem
, const icp_common_t
* header
)
910 p
->stats
.pings_acked
++;
912 if ((icp_opcode
) header
->opcode
<= ICP_END
)
913 p
->icp
.counts
[header
->opcode
]++;
915 p
->icp
.version
= (int) header
->version
;
919 neighborUpdateRtt(peer
* p
, MemObject
* mem
)
921 int rtt
, rtt_av_factor
;
926 if (!mem
->start_ping
.tv_sec
)
929 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
931 if (rtt
< 1 || rtt
> 10000)
934 rtt_av_factor
= RTT_AV_FACTOR
;
936 if (p
->options
.weighted_roundrobin
)
937 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
939 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
944 neighborAliveHtcp(peer
* p
, const MemObject
* mem
, const htcpReplyData
* htcp
)
947 p
->stats
.pings_acked
++;
948 p
->htcp
.counts
[htcp
->hit
? 1 : 0]++;
949 p
->htcp
.version
= htcp
->version
;
955 neighborCountIgnored(peer
* p
)
960 p
->stats
.ignored_replies
++;
965 static peer
*non_peers
= NULL
;
968 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
972 for (np
= non_peers
; np
; np
= np
->next
) {
973 if (np
->in_addr
!= from
)
976 if (np
->in_addr
.GetPort() != from
.GetPort())
983 np
= (peer
*)xcalloc(1, sizeof(peer
));
985 np
->icp
.port
= from
.GetPort();
986 np
->type
= PEER_NONE
;
987 np
->host
= new char[MAX_IPSTRLEN
];
988 from
.NtoA(np
->host
,MAX_IPSTRLEN
);
989 np
->next
= non_peers
;
993 np
->icp
.counts
[opcode
]++;
995 if (isPowTen(++np
->stats
.ignored_replies
))
996 debugs(15, 1, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
999 /* ignoreMulticastReply
1001 * * We want to ignore replies from multicast peers if the
1002 * * cache_host_domain rules would normally prevent the peer
1006 ignoreMulticastReply(peer
* p
, MemObject
* mem
)
1011 if (!p
->options
.mcast_responder
)
1014 if (peerHTTPOkay(p
, mem
->request
))
1021 * I should attach these records to the entry. We take the first
1022 * hit we get our wait until everyone misses. The timeout handler
1023 * call needs to nip this shopping list or call one of the misses.
1025 * If a hit process is already started, then sobeit
1028 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
1032 MemObject
*mem
= NULL
;
1033 peer_t ntype
= PEER_NONE
;
1034 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1036 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1038 if (NULL
!= (entry
= Store::Root().get(key
)))
1039 mem
= entry
->mem_obj
;
1041 if ((p
= whichPeer(from
)))
1042 neighborAlive(p
, mem
, header
);
1044 if (opcode
> ICP_END
)
1047 const char *opcode_d
= icp_opcode_str
[opcode
];
1050 neighborUpdateRtt(p
, mem
);
1052 /* Does the entry exist? */
1053 if (NULL
== entry
) {
1054 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1055 neighborCountIgnored(p
);
1059 /* check if someone is already fetching it */
1060 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1061 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1062 neighborCountIgnored(p
);
1067 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1068 neighborCountIgnored(p
);
1072 if (entry
->ping_status
!= PING_WAITING
) {
1073 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1074 neighborCountIgnored(p
);
1078 if (entry
->lock_count
== 0) {
1079 debugs(12, 1, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1080 neighborCountIgnored(p
);
1084 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1087 ntype
= neighborType(p
, mem
->request
);
1090 if (ignoreMulticastReply(p
, mem
)) {
1091 neighborCountIgnored(p
);
1092 } else if (opcode
== ICP_MISS
) {
1094 neighborIgnoreNonPeer(from
, opcode
);
1096 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1098 } else if (opcode
== ICP_HIT
) {
1100 neighborIgnoreNonPeer(from
, opcode
);
1102 header
->opcode
= ICP_HIT
;
1103 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1105 } else if (opcode
== ICP_DECHO
) {
1107 neighborIgnoreNonPeer(from
, opcode
);
1108 } else if (ntype
== PEER_SIBLING
) {
1109 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1110 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1112 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1114 } else if (opcode
== ICP_SECHO
) {
1116 debugs(15, 1, "Ignoring SECHO from neighbor " << p
->host
);
1117 neighborCountIgnored(p
);
1119 debugs(15, 1, "Unsolicited SECHO from " << from
);
1121 } else if (opcode
== ICP_DENIED
) {
1123 neighborIgnoreNonPeer(from
, opcode
);
1124 } else if (p
->stats
.pings_acked
> 100) {
1125 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1126 debugs(15, 0, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1127 debugs(15, 0, "Disabling '" << p
->host
<< "', please check your configuration.");
1131 neighborCountIgnored(p
);
1134 } else if (opcode
== ICP_MISS_NOFETCH
) {
1135 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1137 debugs(15, 0, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1142 peerFindByName(const char *name
)
1146 for (p
= Config
.peers
; p
; p
= p
->next
) {
1147 if (!strcasecmp(name
, p
->name
))
1155 peerFindByNameAndPort(const char *name
, unsigned short port
)
1159 for (p
= Config
.peers
; p
; p
= p
->next
) {
1160 if (strcasecmp(name
, p
->name
))
1163 if (port
!= p
->http_port
)
1173 neighborUp(const peer
* p
)
1176 if (!peerProbeConnect((peer
*) p
)) {
1177 debugs(15, 8, "neighborUp: DOWN (probed): " << p
->host
<< " (" << p
->in_addr
<< ")");
1183 * The peer can not be UP if we don't have any IP addresses
1186 if (0 == p
->n_addresses
) {
1187 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1191 if (p
->options
.no_query
) {
1192 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1196 if (p
->stats
.probe_start
!= 0 &&
1197 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1198 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1202 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1207 peerDestroy(void *data
)
1209 peer
*p
= (peer
*)data
;
1214 struct _domain_ping
*nl
= NULL
;
1216 for (struct _domain_ping
*l
= p
->peer_domain
; l
; l
= nl
) {
1218 safe_free(l
->domain
);
1224 safe_free(p
->domain
);
1225 #if USE_CACHE_DIGESTS
1227 cbdataReferenceDone(p
->digest
);
1232 peerNoteDigestGone(peer
* p
)
1234 #if USE_CACHE_DIGESTS
1235 cbdataReferenceDone(p
->digest
);
1240 peerDNSConfigure(const ipcache_addrs
*ia
, const DnsLookupDetails
&, void *data
)
1242 peer
*p
= (peer
*)data
;
1246 if (p
->n_addresses
== 0) {
1247 debugs(15, 1, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1249 if (p
->type
== PEER_MULTICAST
)
1250 debugs(15, 1, " Multicast TTL = " << p
->mcast
.ttl
);
1256 debugs(0, 0, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1260 if ((int) ia
->count
< 1) {
1261 debugs(0, 0, "WARNING: No IP address found for '" << p
->host
<< "'!");
1265 p
->tcp_up
= p
->connect_fail_limit
;
1267 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; j
++) {
1268 p
->addresses
[j
] = ia
->in_addrs
[j
];
1269 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1273 p
->in_addr
.SetEmpty();
1274 p
->in_addr
= p
->addresses
[0];
1275 p
->in_addr
.SetPort(p
->icp
.port
);
1277 if (p
->type
== PEER_MULTICAST
)
1278 peerCountMcastPeersSchedule(p
, 10);
1281 if (p
->type
!= PEER_MULTICAST
)
1282 if (!p
->options
.no_netdb_exchange
)
1283 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1289 peerRefreshDNS(void *data
)
1293 if (eventFind(peerRefreshDNS
, NULL
))
1294 eventDelete(peerRefreshDNS
, NULL
);
1296 if (!data
&& 0 == stat5minClientRequests()) {
1297 /* no recent client traffic, wait a bit */
1298 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1302 for (p
= Config
.peers
; p
; p
= p
->next
)
1303 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1305 /* Reconfigure the peers every hour */
1306 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1310 peerConnectFailedSilent(peer
* p
)
1312 p
->stats
.last_connect_failure
= squid_curtime
;
1315 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1323 debugs(15, 1, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1324 p
->stats
.logged_state
= PEER_DEAD
;
1329 peerConnectFailed(peer
*p
)
1331 debugs(15, 1, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1332 peerConnectFailedSilent(p
);
1336 peerConnectSucceded(peer
* p
)
1339 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1340 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1342 if (!p
->n_addresses
)
1343 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1345 p
->tcp_up
= p
->connect_fail_limit
;
1348 /// called by Comm when test_fd is closed while connect is in progress
1350 peerProbeClosed(int fd
, void *data
)
1352 peer
*p
= (peer
*)data
;
1354 // it is a failure because we failed to connect
1355 peerConnectFailedSilent(p
);
1359 peerProbeConnectTimeout(int fd
, void *data
)
1361 peer
* p
= (peer
*)data
;
1362 comm_remove_close_handler(fd
, &peerProbeClosed
, p
);
1365 peerConnectFailedSilent(p
);
1369 * peerProbeConnect will be called on dead peers by neighborUp
1372 peerProbeConnect(peer
* p
)
1375 time_t ctimeout
= p
->connect_timeout
> 0 ? p
->connect_timeout
1376 : Config
.Timeout
.peer_connect
;
1377 int ret
= squid_curtime
- p
->stats
.last_connect_failure
> ctimeout
* 10;
1379 if (p
->test_fd
!= -1)
1380 return ret
;/* probe already running */
1382 if (squid_curtime
- p
->stats
.last_connect_probe
== 0)
1383 return ret
;/* don't probe to often */
1385 Ip::Address
temp(getOutgoingAddr(NULL
,p
));
1387 // if IPv6 is disabled try to force IPv4-only outgoing.
1388 if (!Ip::EnableIpv6
&& !temp
.SetIPv4()) {
1389 debugs(50, DBG_IMPORTANT
, "WARNING: IPv6 is disabled. Failed to use " << temp
<< " to probe " << p
->host
);
1393 // if IPv6 is split-stack, prefer IPv4
1394 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
) {
1395 // NP: This is not a great choice of default,
1396 // but with the current Internet being IPv4-majority has a higher success rate.
1397 // if setting to IPv4 fails we dont care, that just means to use IPv6 outgoing.
1401 fd
= comm_open(SOCK_STREAM
, IPPROTO_TCP
, temp
, COMM_NONBLOCKING
, p
->host
);
1406 comm_add_close_handler(fd
, &peerProbeClosed
, p
);
1407 commSetTimeout(fd
, ctimeout
, peerProbeConnectTimeout
, p
);
1411 p
->stats
.last_connect_probe
= squid_curtime
;
1413 commConnectStart(p
->test_fd
,
1416 peerProbeConnectDone
,
1423 peerProbeConnectDone(int fd
, const DnsLookupDetails
&, comm_err_t status
, int xerrno
, void *data
)
1425 peer
*p
= (peer
*)data
;
1427 if (status
== COMM_OK
) {
1428 peerConnectSucceded(p
);
1430 peerConnectFailedSilent(p
);
1433 comm_remove_close_handler(fd
, &peerProbeClosed
, p
);
1440 peerCountMcastPeersSchedule(peer
* p
, time_t when
)
1442 if (p
->mcast
.flags
.count_event_pending
)
1445 eventAdd("peerCountMcastPeersStart",
1446 peerCountMcastPeersStart
,
1450 p
->mcast
.flags
.count_event_pending
= 1;
1454 peerCountMcastPeersStart(void *data
)
1456 peer
*p
= (peer
*)data
;
1460 icp_common_t
*query
;
1462 LOCAL_ARRAY(char, url
, MAX_URL
);
1463 assert(p
->type
== PEER_MULTICAST
);
1464 p
->mcast
.flags
.count_event_pending
= 0;
1465 snprintf(url
, MAX_URL
, "http://");
1466 p
->in_addr
.ToURL(url
+7, MAX_URL
-8 );
1468 fake
= storeCreateEntry(url
, url
, request_flags(), METHOD_GET
);
1469 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1470 psstate
= new ps_state
;
1471 psstate
->request
= HTTPMSGLOCK(req
);
1472 psstate
->entry
= fake
;
1473 psstate
->callback
= NULL
;
1474 psstate
->callback_data
= cbdataReference(p
);
1475 psstate
->ping
.start
= current_time
;
1476 mem
= fake
->mem_obj
;
1477 mem
->request
= HTTPMSGLOCK(psstate
->request
);
1478 mem
->start_ping
= current_time
;
1479 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1480 mem
->ircb_data
= psstate
;
1481 mcastSetTtl(theOutIcpConnection
, p
->mcast
.ttl
);
1482 p
->mcast
.id
= mem
->id
;
1483 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1484 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1485 icpUdpSend(theOutIcpConnection
,
1490 fake
->ping_status
= PING_WAITING
;
1491 eventAdd("peerCountMcastPeersDone",
1492 peerCountMcastPeersDone
,
1494 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1495 p
->mcast
.flags
.counting
= 1;
1496 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1500 peerCountMcastPeersDone(void *data
)
1502 ps_state
*psstate
= (ps_state
*)data
;
1503 StoreEntry
*fake
= psstate
->entry
;
1505 if (cbdataReferenceValid(psstate
->callback_data
)) {
1506 peer
*p
= (peer
*)psstate
->callback_data
;
1507 p
->mcast
.flags
.counting
= 0;
1508 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1509 debugs(15, 1, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1510 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1511 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1512 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1515 cbdataReferenceDone(psstate
->callback_data
);
1517 EBIT_SET(fake
->flags
, ENTRY_ABORTED
);
1518 HTTPMSGUNLOCK(fake
->mem_obj
->request
);
1519 fake
->releaseRequest();
1521 HTTPMSGUNLOCK(psstate
->request
);
1522 cbdataFree(psstate
);
1526 peerCountHandleIcpReply(peer
* p
, peer_t type
, AnyP::ProtocolType proto
, void *hdrnotused
, void *data
)
1530 ps_state
*psstate
= (ps_state
*)data
;
1531 StoreEntry
*fake
= psstate
->entry
;
1532 MemObject
*mem
= fake
->mem_obj
;
1533 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1534 assert(proto
== AnyP::PROTO_ICP
);
1537 psstate
->ping
.n_recv
++;
1538 rtt_av_factor
= RTT_AV_FACTOR
;
1540 if (p
->options
.weighted_roundrobin
)
1541 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1543 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1547 neighborDumpPeers(StoreEntry
* sentry
)
1549 dump_peers(sentry
, Config
.peers
);
1553 neighborDumpNonPeers(StoreEntry
* sentry
)
1555 dump_peers(sentry
, non_peers
);
1559 dump_peer_options(StoreEntry
* sentry
, peer
* p
)
1561 if (p
->options
.proxy_only
)
1562 storeAppendPrintf(sentry
, " proxy-only");
1564 if (p
->options
.no_query
)
1565 storeAppendPrintf(sentry
, " no-query");
1567 if (p
->options
.background_ping
)
1568 storeAppendPrintf(sentry
, " background-ping");
1570 if (p
->options
.no_digest
)
1571 storeAppendPrintf(sentry
, " no-digest");
1573 if (p
->options
.default_parent
)
1574 storeAppendPrintf(sentry
, " default");
1576 if (p
->options
.roundrobin
)
1577 storeAppendPrintf(sentry
, " round-robin");
1579 if (p
->options
.carp
)
1580 storeAppendPrintf(sentry
, " carp");
1583 if (p
->options
.userhash
)
1584 storeAppendPrintf(sentry
, " userhash");
1587 if (p
->options
.sourcehash
)
1588 storeAppendPrintf(sentry
, " sourcehash");
1590 if (p
->options
.weighted_roundrobin
)
1591 storeAppendPrintf(sentry
, " weighted-round-robin");
1593 if (p
->options
.mcast_responder
)
1594 storeAppendPrintf(sentry
, " multicast-responder");
1596 #if PEER_MULTICAST_SIBLINGS
1597 if (p
->options
.mcast_siblings
)
1598 storeAppendPrintf(sentry
, " multicast-siblings");
1602 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1604 if (p
->options
.closest_only
)
1605 storeAppendPrintf(sentry
, " closest-only");
1608 if (p
->options
.htcp
) {
1609 storeAppendPrintf(sentry
, " htcp");
1610 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1612 if (p
->options
.htcp_oldsquid
)
1613 storeAppendPrintf(sentry
, "%soldsquid",(doneopts
++>0?",":"="));
1614 if (p
->options
.htcp_no_clr
)
1615 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
++>0?",":"="));
1616 if (p
->options
.htcp_no_purge_clr
)
1617 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
++>0?",":"="));
1618 if (p
->options
.htcp_only_clr
)
1619 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
++>0?",":"="));
1624 if (p
->options
.no_netdb_exchange
)
1625 storeAppendPrintf(sentry
, " no-netdb-exchange");
1628 if (p
->options
.no_delay
)
1629 storeAppendPrintf(sentry
, " no-delay");
1633 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1635 if (p
->mcast
.ttl
> 0)
1636 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1638 if (p
->connect_timeout
> 0)
1639 storeAppendPrintf(sentry
, " connect-timeout=%d", (int) p
->connect_timeout
);
1641 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1642 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1644 #if USE_CACHE_DIGESTS
1647 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1651 if (p
->options
.allow_miss
)
1652 storeAppendPrintf(sentry
, " allow-miss");
1654 if (p
->options
.no_tproxy
)
1655 storeAppendPrintf(sentry
, " no-tproxy");
1657 if (p
->max_conn
> 0)
1658 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1660 if (p
->options
.originserver
)
1661 storeAppendPrintf(sentry
, " originserver");
1664 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1666 if (p
->connection_auth
== 0)
1667 storeAppendPrintf(sentry
, " connection-auth=off");
1668 else if (p
->connection_auth
== 1)
1669 storeAppendPrintf(sentry
, " connection-auth=on");
1670 else if (p
->connection_auth
== 2)
1671 storeAppendPrintf(sentry
, " connection-auth=auto");
1673 storeAppendPrintf(sentry
, "\n");
1677 dump_peers(StoreEntry
* sentry
, peer
* peers
)
1680 char ntoabuf
[MAX_IPSTRLEN
];
1681 struct _domain_ping
*d
= NULL
;
1686 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1688 for (e
= peers
; e
; e
= e
->next
) {
1689 assert(e
->host
!= NULL
);
1690 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1693 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1697 storeAppendPrintf(sentry
, "Flags :");
1698 dump_peer_options(sentry
, e
);
1700 for (i
= 0; i
< e
->n_addresses
; i
++) {
1701 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1702 e
->addresses
[i
].NtoA(ntoabuf
,MAX_IPSTRLEN
) );
1705 storeAppendPrintf(sentry
, "Status : %s\n",
1706 neighborUp(e
) ? "Up" : "Down");
1707 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1708 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1709 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1711 if (!e
->options
.no_query
) {
1712 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1713 (int) (squid_curtime
- e
->stats
.last_query
));
1715 if (e
->stats
.last_reply
> 0)
1716 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1717 (int) (squid_curtime
- e
->stats
.last_reply
));
1719 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1721 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1723 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1724 e
->stats
.pings_acked
,
1725 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1728 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1730 if (!e
->options
.no_query
) {
1731 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1734 if (e
->options
.htcp
) {
1735 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1737 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1738 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1740 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1744 for (op
= ICP_INVALID
; op
< ICP_END
; ++op
) {
1745 if (e
->icp
.counts
[op
] == 0)
1748 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1751 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1762 if (e
->stats
.last_connect_failure
) {
1763 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1764 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1767 if (e
->peer_domain
!= NULL
) {
1768 storeAppendPrintf(sentry
, "DOMAIN LIST: ");
1770 for (d
= e
->peer_domain
; d
; d
= d
->next
) {
1771 storeAppendPrintf(sentry
, "%s%s ",
1772 d
->do_ping
? null_string
: "!", d
->domain
);
1775 storeAppendPrintf(sentry
, "\n");
1778 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1784 neighborsHtcpReply(const cache_key
* key
, htcpReplyData
* htcp
, const Ip::Address
&from
)
1786 StoreEntry
*e
= Store::Root().get(key
);
1787 MemObject
*mem
= NULL
;
1789 peer_t ntype
= PEER_NONE
;
1790 debugs(15, 6, "neighborsHtcpReply: " <<
1791 (htcp
->hit
? "HIT" : "MISS") << " " <<
1792 storeKeyText(key
) );
1797 if ((p
= whichPeer(from
)))
1798 neighborAliveHtcp(p
, mem
, htcp
);
1800 /* Does the entry exist? */
1802 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1803 neighborCountIgnored(p
);
1807 /* check if someone is already fetching it */
1808 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1809 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1810 neighborCountIgnored(p
);
1815 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1816 neighborCountIgnored(p
);
1820 if (e
->ping_status
!= PING_WAITING
) {
1821 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1822 neighborCountIgnored(p
);
1826 if (e
->lock_count
== 0) {
1827 debugs(12, 1, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1828 neighborCountIgnored(p
);
1833 ntype
= neighborType(p
, mem
->request
);
1834 neighborUpdateRtt(p
, mem
);
1837 if (ignoreMulticastReply(p
, mem
)) {
1838 neighborCountIgnored(p
);
1842 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1843 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1847 * Send HTCP CLR messages to all peers configured to receive them.
1850 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1855 for (p
= Config
.peers
; p
; p
= p
->next
) {
1856 if (!p
->options
.htcp
) {
1859 if (p
->options
.htcp_no_clr
) {
1862 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1865 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.ToURL(buf
, 128));
1866 htcpClear(e
, uri
, req
, method
, p
, reason
);