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"
36 #include "comm/Connection.h"
37 #include "comm/ConnOpener.h"
40 #include "HttpRequest.h"
43 #include "MemObject.h"
44 #include "PeerDigest.h"
45 #include "PeerSelectState.h"
46 #include "SquidMath.h"
47 #include "SquidTime.h"
49 #include "icmp/net_db.h"
50 #include "ip/Address.h"
52 #include "mgr/Registration.h"
54 /* count mcast group peers every 15 minutes */
55 #define MCAST_COUNT_RATE 900
57 int peerAllowedToUse(const peer
*, HttpRequest
*);
58 static int peerWouldBePinged(const peer
*, HttpRequest
*);
59 static void neighborRemove(peer
*);
60 static void neighborAlive(peer
*, const MemObject
*, const icp_common_t
*);
62 static void neighborAliveHtcp(peer
*, const MemObject
*, const htcpReplyData
*);
64 static void neighborCountIgnored(peer
*);
65 static void peerRefreshDNS(void *);
66 static IPH peerDNSConfigure
;
67 static bool peerProbeConnect(peer
*);
68 static CNCB peerProbeConnectDone
;
69 static void peerCountMcastPeersDone(void *data
);
70 static void peerCountMcastPeersStart(void *data
);
71 static void peerCountMcastPeersSchedule(peer
* p
, time_t when
);
72 static IRCB peerCountHandleIcpReply
;
74 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
75 static OBJH neighborDumpPeers
;
76 static OBJH neighborDumpNonPeers
;
77 static void dump_peers(StoreEntry
* sentry
, peer
* peers
);
79 static icp_common_t echo_hdr
;
80 static u_short echo_port
;
82 static int NLateReplies
= 0;
83 static peer
*first_ping
= NULL
;
86 neighborTypeStr(const peer
* p
)
88 if (p
->type
== PEER_NONE
)
91 if (p
->type
== PEER_SIBLING
)
94 if (p
->type
== PEER_MULTICAST
)
95 return "Multicast Group";
102 whichPeer(const Ip::Address
&from
)
107 debugs(15, 3, "whichPeer: from " << from
);
109 for (p
= Config
.peers
; p
; p
= p
->next
) {
110 for (j
= 0; j
< p
->n_addresses
; j
++) {
111 if (from
== p
->addresses
[j
] && from
.GetPort() == p
->icp
.port
) {
121 neighborType(const peer
* p
, const HttpRequest
* request
)
124 const struct _domain_type
*d
= NULL
;
126 for (d
= p
->typelist
; d
; d
= d
->next
) {
127 if (0 == matchDomainName(request
->GetHost(), d
->domain
))
128 if (d
->type
!= PEER_NONE
)
131 #if PEER_MULTICAST_SIBLINGS
132 if (p
->type
== PEER_MULTICAST
)
133 if (p
->options
.mcast_siblings
)
143 * this function figures out if it is appropriate to fetch REQUEST
147 peerAllowedToUse(const peer
* p
, HttpRequest
* request
)
150 const struct _domain_ping
*d
= NULL
;
152 assert(request
!= NULL
);
154 if (neighborType(p
, request
) == PEER_SIBLING
) {
155 #if PEER_MULTICAST_SIBLINGS
156 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
157 (request
->flags
.nocache
|| request
->flags
.refresh
|| request
->flags
.loopdetect
|| request
->flags
.need_validation
))
158 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->GetHost() << ") : multicast-siblings optimization match");
160 if (request
->flags
.nocache
)
163 if (request
->flags
.refresh
)
166 if (request
->flags
.loopdetect
)
169 if (request
->flags
.need_validation
)
173 if (p
->peer_domain
== NULL
&& p
->access
== NULL
)
178 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
179 if (0 == matchDomainName(request
->GetHost(), d
->domain
)) {
180 do_ping
= d
->do_ping
;
184 do_ping
= !d
->do_ping
;
187 if (p
->peer_domain
&& 0 == do_ping
)
190 if (p
->access
== NULL
)
193 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
194 checklist
.src_addr
= request
->client_addr
;
195 checklist
.my_addr
= request
->my_addr
;
199 * this is currently broken because 'request->user_ident' has been
200 * moved to conn->rfc931 and we don't have access to the parent
201 * ConnStateData here.
203 if (request
->user_ident
[0])
204 xstrncpy(checklist
.rfc931
, request
->user_ident
, USER_IDENT_SZ
);
208 return checklist
.fastCheck();
211 /* Return TRUE if it is okay to send an ICP request to this peer. */
213 peerWouldBePinged(const peer
* p
, HttpRequest
* request
)
215 if (!peerAllowedToUse(p
, request
))
218 if (p
->options
.no_query
)
221 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
224 if (p
->options
.mcast_responder
)
227 if (p
->n_addresses
== 0)
230 if (p
->icp
.port
== 0)
233 /* the case below seems strange, but can happen if the
234 * URL host is on the other side of a firewall */
235 if (p
->type
== PEER_SIBLING
)
236 if (!request
->flags
.hierarchical
)
239 /* Ping dead peers every timeout interval */
240 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
249 /* Return TRUE if it is okay to send an HTTP request to this peer. */
251 peerHTTPOkay(const peer
* p
, HttpRequest
* request
)
253 if (!peerAllowedToUse(p
, request
))
260 if (p
->stats
.conn_open
>= p
->max_conn
)
267 neighborsCount(HttpRequest
* request
)
272 for (p
= Config
.peers
; p
; p
= p
->next
)
273 if (peerWouldBePinged(p
, request
))
276 debugs(15, 3, "neighborsCount: " << count
);
282 getFirstUpParent(HttpRequest
* request
)
286 for (p
= Config
.peers
; p
; p
= p
->next
) {
290 if (neighborType(p
, request
) != PEER_PARENT
)
293 if (!peerHTTPOkay(p
, request
))
299 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
304 getRoundRobinParent(HttpRequest
* request
)
309 for (p
= Config
.peers
; p
; p
= p
->next
) {
310 if (!p
->options
.roundrobin
)
313 if (neighborType(p
, request
) != PEER_PARENT
)
316 if (!peerHTTPOkay(p
, request
))
323 if (p
->weight
== q
->weight
) {
324 if (q
->rr_count
< p
->rr_count
)
326 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
337 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
343 getWeightedRoundRobinParent(HttpRequest
* request
)
349 for (p
= Config
.peers
; p
; p
= p
->next
) {
350 if (!p
->options
.weighted_roundrobin
)
353 if (neighborType(p
, request
) != PEER_PARENT
)
356 if (!peerHTTPOkay(p
, request
))
359 if (q
&& q
->rr_count
< p
->rr_count
)
365 if (q
&& q
->rr_count
> 1000000)
366 for (p
= Config
.peers
; p
; p
= p
->next
) {
367 if (!p
->options
.weighted_roundrobin
)
370 if (neighborType(p
, request
) != PEER_PARENT
)
377 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
379 if (weighted_rtt
< 1)
382 q
->rr_count
+= weighted_rtt
;
384 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
387 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
392 * This gets called every 5 minutes to clear the round-robin counter.
393 * The exact timing is an arbitrary default, set on estimate timing of a
394 * large number of requests in a high-performance environment during the
395 * period. The larger the number of requests between cycled resets the
396 * more balanced the operations.
399 \todo Make the reset timing a selectable parameter in squid.conf
402 peerClearRRLoop(void *data
)
405 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
409 * This gets called on startup and restart to kick off the peer round-robin
410 * maintenance event. It ensures that no matter how many times its called
411 * no more than one event is scheduled.
414 peerClearRRStart(void)
416 static int event_added
= 0;
418 peerClearRRLoop(NULL
);
423 * Called whenever the round-robin counters need to be reset to a sane state.
424 * So far those times are:
425 * - On startup and reconfigure - to set the counters to sane initial settings.
426 * - When a peer has revived from dead, to prevent the revived peer being
427 * flooded with requests which it has 'missed' during the down period.
433 for (p
= Config
.peers
; p
; p
= p
->next
) {
439 * Perform all actions when a peer is detected revived.
444 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
445 debugs(15, 1, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
446 p
->stats
.logged_state
= PEER_ALIVE
;
450 p
->stats
.last_reply
= squid_curtime
;
451 p
->stats
.probe_start
= 0;
455 getDefaultParent(HttpRequest
* request
)
459 for (p
= Config
.peers
; p
; p
= p
->next
) {
460 if (neighborType(p
, request
) != PEER_PARENT
)
463 if (!p
->options
.default_parent
)
466 if (!peerHTTPOkay(p
, request
))
469 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
474 debugs(15, 3, "getDefaultParent: returning NULL");
479 * XXX DW thinks this function is equivalent to/redundant with
480 * getFirstUpParent(). peerHTTPOkay() only returns true if the
481 * peer is UP anyway, so this function would not return a
485 getAnyParent(HttpRequest
* request
)
489 for (p
= Config
.peers
; p
; p
= p
->next
) {
490 if (neighborType(p
, request
) != PEER_PARENT
)
493 if (!peerHTTPOkay(p
, request
))
496 debugs(15, 3, "getAnyParent: returning " << p
->host
);
501 debugs(15, 3, "getAnyParent: returning NULL");
506 getNextPeer(peer
* p
)
518 neighborRemove(peer
* target
)
540 first_ping
= Config
.peers
;
544 neighborsRegisterWithCacheManager()
546 Mgr::RegisterAction("server_list",
547 "Peer Cache Statistics",
548 neighborDumpPeers
, 0, 1);
550 if (Comm::IsConnOpen(icpIncomingConn
)) {
551 Mgr::RegisterAction("non_peers",
552 "List of Unknown sites sending ICP messages",
553 neighborDumpNonPeers
, 0, 1);
560 struct servent
*sep
= NULL
;
561 const char *me
= getMyHostname();
562 peer
*thisPeer
= NULL
;
565 neighborsRegisterWithCacheManager();
567 if (Comm::IsConnOpen(icpIncomingConn
)) {
569 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
570 http_port_list
*s
= NULL
;
571 next
= thisPeer
->next
;
573 if (0 != strcmp(thisPeer
->host
, me
))
576 for (s
= Config
.Sockaddr
.http
; s
; s
= s
->next
) {
577 if (thisPeer
->http_port
!= s
->s
.GetPort())
580 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
582 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
583 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
584 "/" << thisPeer
->http_port
<< "/" <<
587 neighborRemove(thisPeer
);
592 peerRefreshDNS((void *) 1);
594 if (echo_hdr
.opcode
== ICP_INVALID
) {
595 echo_hdr
.opcode
= ICP_SECHO
;
596 echo_hdr
.version
= ICP_VERSION_CURRENT
;
601 theIcpPublicHostID
.GetInAddr( *((struct in_addr
*)&echo_hdr
.shostid
) );
602 sep
= getservbyname("echo", "udp");
603 echo_port
= sep
? ntohs((u_short
) sep
->s_port
) : 7;
606 first_ping
= Config
.peers
;
610 neighborsUdpPing(HttpRequest
* request
,
617 const char *url
= entry
->url();
618 MemObject
*mem
= entry
->mem_obj
;
624 int queries_sent
= 0;
625 int peers_pinged
= 0;
626 int parent_timeout
= 0, parent_exprep
= 0;
627 int sibling_timeout
= 0, sibling_exprep
= 0;
628 int mcast_timeout
= 0, mcast_exprep
= 0;
630 if (Config
.peers
== NULL
)
633 assert(entry
->swap_status
== SWAPOUT_NONE
);
635 mem
->start_ping
= current_time
;
637 mem
->ping_reply_callback
= callback
;
639 mem
->ircb_data
= callback_data
;
641 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
643 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
647 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
649 if (!peerWouldBePinged(p
, request
))
650 continue; /* next peer */
654 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
656 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
658 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
661 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
662 if (Config
.Port
.htcp
<= 0) {
663 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
667 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
668 if (htcpQuery(entry
, request
, p
) <= 0) continue; // unable to send.
672 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
673 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
677 if (p
->type
== PEER_MULTICAST
)
678 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
680 if (p
->icp
.port
== echo_port
) {
681 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
682 echo_hdr
.reqnum
= reqnum
;
683 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
684 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
688 if (Config
.onoff
.query_icmp
)
689 if (p
->icp
.version
== ICP_VERSION_2
)
690 flags
|= ICP_FLAG_SRC_RTT
;
692 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
694 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
701 p
->stats
.pings_sent
++;
703 if (p
->type
== PEER_MULTICAST
) {
704 mcast_exprep
+= p
->mcast
.n_replies_expected
;
705 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
706 } else if (neighborUp(p
)) {
707 /* its alive, expect a reply from it */
709 if (neighborType(p
, request
) == PEER_PARENT
) {
711 parent_timeout
+= p
->stats
.rtt
;
714 sibling_timeout
+= p
->stats
.rtt
;
717 /* Neighbor is dead; ping it anyway, but don't expect a reply */
718 /* log it once at the threshold */
720 if (p
->stats
.logged_state
== PEER_ALIVE
) {
721 debugs(15, 1, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
722 p
->stats
.logged_state
= PEER_DEAD
;
726 p
->stats
.last_query
= squid_curtime
;
729 * keep probe_start == 0 for a multicast peer,
730 * so neighborUp() never says this peer is dead.
733 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
734 p
->stats
.probe_start
= squid_curtime
;
737 if ((first_ping
= first_ping
->next
) == NULL
)
738 first_ping
= Config
.peers
;
741 * How many replies to expect?
743 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
746 * If there is a configured timeout, use it
748 if (Config
.Timeout
.icp_query
)
749 *timeout
= Config
.Timeout
.icp_query
;
753 *timeout
= 2 * parent_timeout
/ parent_exprep
;
754 else if (mcast_exprep
)
755 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
757 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
759 *timeout
= 2000; /* 2 seconds */
761 if (Config
.Timeout
.icp_query_max
)
762 if (*timeout
> Config
.Timeout
.icp_query_max
)
763 *timeout
= Config
.Timeout
.icp_query_max
;
765 if (*timeout
< Config
.Timeout
.icp_query_min
)
766 *timeout
= Config
.Timeout
.icp_query_min
;
772 /* lookup the digest of a given peer */
774 peerDigestLookup(peer
* p
, HttpRequest
* request
)
776 #if USE_CACHE_DIGESTS
777 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
780 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
781 /* does the peeer have a valid digest? */
784 debugs(15, 5, "peerDigestLookup: gone!");
786 } else if (!peerHTTPOkay(p
, request
)) {
787 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
789 } else if (!p
->digest
->flags
.needed
) {
790 debugs(15, 5, "peerDigestLookup: note need");
791 peerDigestNeeded(p
->digest
);
793 } else if (!p
->digest
->flags
.usable
) {
794 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
798 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
799 assert(p
->digest
->cd
);
800 /* does digest predict a hit? */
802 if (!cacheDigestTest(p
->digest
->cd
, key
))
805 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
814 /* select best peer based on cache digests */
816 neighborsDigestSelect(HttpRequest
* request
)
819 #if USE_CACHE_DIGESTS
821 const cache_key
*key
;
823 int choice_count
= 0;
824 int ichoice_count
= 0;
829 if (!request
->flags
.hierarchical
)
832 key
= storeKeyPublicByRequest(request
);
834 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
843 lookup
= peerDigestLookup(p
, request
);
845 if (lookup
== LOOKUP_NONE
)
850 if (lookup
== LOOKUP_MISS
)
853 p_rtt
= netdbHostRtt(p
->host
);
855 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
857 /* is this peer better than others in terms of rtt ? */
858 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
862 if (p_rtt
) /* informative choice (aka educated guess) */
865 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
869 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
870 peerNoteDigestLookup(request
, best_p
,
871 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
872 request
->hier
.n_choices
= choice_count
;
873 request
->hier
.n_ichoices
= ichoice_count
;
880 peerNoteDigestLookup(HttpRequest
* request
, peer
* p
, lookup_t lookup
)
882 #if USE_CACHE_DIGESTS
884 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
));
886 *request
->hier
.cd_host
= '\0';
888 request
->hier
.cd_lookup
= lookup
;
889 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
894 neighborAlive(peer
* p
, const MemObject
* mem
, const icp_common_t
* header
)
897 p
->stats
.pings_acked
++;
899 if ((icp_opcode
) header
->opcode
<= ICP_END
)
900 p
->icp
.counts
[header
->opcode
]++;
902 p
->icp
.version
= (int) header
->version
;
906 neighborUpdateRtt(peer
* p
, MemObject
* mem
)
908 int rtt
, rtt_av_factor
;
913 if (!mem
->start_ping
.tv_sec
)
916 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
918 if (rtt
< 1 || rtt
> 10000)
921 rtt_av_factor
= RTT_AV_FACTOR
;
923 if (p
->options
.weighted_roundrobin
)
924 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
926 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
931 neighborAliveHtcp(peer
* p
, const MemObject
* mem
, const htcpReplyData
* htcp
)
934 p
->stats
.pings_acked
++;
935 p
->htcp
.counts
[htcp
->hit
? 1 : 0]++;
936 p
->htcp
.version
= htcp
->version
;
942 neighborCountIgnored(peer
* p
)
947 p
->stats
.ignored_replies
++;
952 static peer
*non_peers
= NULL
;
955 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
959 for (np
= non_peers
; np
; np
= np
->next
) {
960 if (np
->in_addr
!= from
)
963 if (np
->in_addr
.GetPort() != from
.GetPort())
970 np
= (peer
*)xcalloc(1, sizeof(peer
));
972 np
->icp
.port
= from
.GetPort();
973 np
->type
= PEER_NONE
;
974 np
->host
= new char[MAX_IPSTRLEN
];
975 from
.NtoA(np
->host
,MAX_IPSTRLEN
);
976 np
->next
= non_peers
;
980 np
->icp
.counts
[opcode
]++;
982 if (isPowTen(++np
->stats
.ignored_replies
))
983 debugs(15, 1, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
986 /* ignoreMulticastReply
988 * * We want to ignore replies from multicast peers if the
989 * * cache_host_domain rules would normally prevent the peer
993 ignoreMulticastReply(peer
* p
, MemObject
* mem
)
998 if (!p
->options
.mcast_responder
)
1001 if (peerHTTPOkay(p
, mem
->request
))
1008 * I should attach these records to the entry. We take the first
1009 * hit we get our wait until everyone misses. The timeout handler
1010 * call needs to nip this shopping list or call one of the misses.
1012 * If a hit process is already started, then sobeit
1015 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
1019 MemObject
*mem
= NULL
;
1020 peer_t ntype
= PEER_NONE
;
1021 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1023 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1025 if (NULL
!= (entry
= Store::Root().get(key
)))
1026 mem
= entry
->mem_obj
;
1028 if ((p
= whichPeer(from
)))
1029 neighborAlive(p
, mem
, header
);
1031 if (opcode
> ICP_END
)
1034 const char *opcode_d
= icp_opcode_str
[opcode
];
1037 neighborUpdateRtt(p
, mem
);
1039 /* Does the entry exist? */
1040 if (NULL
== entry
) {
1041 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1042 neighborCountIgnored(p
);
1046 /* check if someone is already fetching it */
1047 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1048 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1049 neighborCountIgnored(p
);
1054 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1055 neighborCountIgnored(p
);
1059 if (entry
->ping_status
!= PING_WAITING
) {
1060 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1061 neighborCountIgnored(p
);
1065 if (entry
->lock_count
== 0) {
1066 debugs(12, 1, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1067 neighborCountIgnored(p
);
1071 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1074 ntype
= neighborType(p
, mem
->request
);
1077 if (ignoreMulticastReply(p
, mem
)) {
1078 neighborCountIgnored(p
);
1079 } else if (opcode
== ICP_MISS
) {
1081 neighborIgnoreNonPeer(from
, opcode
);
1083 mem
->ping_reply_callback(p
, ntype
, PROTO_ICP
, header
, mem
->ircb_data
);
1085 } else if (opcode
== ICP_HIT
) {
1087 neighborIgnoreNonPeer(from
, opcode
);
1089 header
->opcode
= ICP_HIT
;
1090 mem
->ping_reply_callback(p
, ntype
, PROTO_ICP
, header
, mem
->ircb_data
);
1092 } else if (opcode
== ICP_DECHO
) {
1094 neighborIgnoreNonPeer(from
, opcode
);
1095 } else if (ntype
== PEER_SIBLING
) {
1096 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1097 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1099 mem
->ping_reply_callback(p
, ntype
, PROTO_ICP
, header
, mem
->ircb_data
);
1101 } else if (opcode
== ICP_SECHO
) {
1103 debugs(15, 1, "Ignoring SECHO from neighbor " << p
->host
);
1104 neighborCountIgnored(p
);
1106 debugs(15, 1, "Unsolicited SECHO from " << from
);
1108 } else if (opcode
== ICP_DENIED
) {
1110 neighborIgnoreNonPeer(from
, opcode
);
1111 } else if (p
->stats
.pings_acked
> 100) {
1112 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1113 debugs(15, 0, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1114 debugs(15, 0, "Disabling '" << p
->host
<< "', please check your configuration.");
1118 neighborCountIgnored(p
);
1121 } else if (opcode
== ICP_MISS_NOFETCH
) {
1122 mem
->ping_reply_callback(p
, ntype
, PROTO_ICP
, header
, mem
->ircb_data
);
1124 debugs(15, 0, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1129 peerFindByName(const char *name
)
1133 for (p
= Config
.peers
; p
; p
= p
->next
) {
1134 if (!strcasecmp(name
, p
->name
))
1142 peerFindByNameAndPort(const char *name
, unsigned short port
)
1146 for (p
= Config
.peers
; p
; p
= p
->next
) {
1147 if (strcasecmp(name
, p
->name
))
1150 if (port
!= p
->http_port
)
1160 neighborUp(const peer
* p
)
1163 if (!peerProbeConnect((peer
*) p
)) {
1164 debugs(15, 8, "neighborUp: DOWN (probed): " << p
->host
<< " (" << p
->in_addr
<< ")");
1170 * The peer can not be UP if we don't have any IP addresses
1173 if (0 == p
->n_addresses
) {
1174 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1178 if (p
->options
.no_query
) {
1179 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1183 if (p
->stats
.probe_start
!= 0 &&
1184 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1185 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1189 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1194 peerDestroy(void *data
)
1196 peer
*p
= (peer
*)data
;
1201 struct _domain_ping
*nl
= NULL
;
1203 for (struct _domain_ping
*l
= p
->peer_domain
; l
; l
= nl
) {
1205 safe_free(l
->domain
);
1211 safe_free(p
->domain
);
1212 #if USE_CACHE_DIGESTS
1214 cbdataReferenceDone(p
->digest
);
1219 peerNoteDigestGone(peer
* p
)
1221 #if USE_CACHE_DIGESTS
1222 cbdataReferenceDone(p
->digest
);
1227 peerDNSConfigure(const ipcache_addrs
*ia
, const DnsLookupDetails
&, void *data
)
1229 peer
*p
= (peer
*)data
;
1233 if (p
->n_addresses
== 0) {
1234 debugs(15, 1, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1236 if (p
->type
== PEER_MULTICAST
)
1237 debugs(15, 1, " Multicast TTL = " << p
->mcast
.ttl
);
1243 debugs(0, 0, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1247 if ((int) ia
->count
< 1) {
1248 debugs(0, 0, "WARNING: No IP address found for '" << p
->host
<< "'!");
1252 p
->tcp_up
= p
->connect_fail_limit
;
1254 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; j
++) {
1255 p
->addresses
[j
] = ia
->in_addrs
[j
];
1256 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1260 p
->in_addr
.SetEmpty();
1261 p
->in_addr
= p
->addresses
[0];
1262 p
->in_addr
.SetPort(p
->icp
.port
);
1264 if (p
->type
== PEER_MULTICAST
)
1265 peerCountMcastPeersSchedule(p
, 10);
1268 if (p
->type
!= PEER_MULTICAST
)
1269 if (!p
->options
.no_netdb_exchange
)
1270 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1276 peerRefreshDNS(void *data
)
1280 if (eventFind(peerRefreshDNS
, NULL
))
1281 eventDelete(peerRefreshDNS
, NULL
);
1283 if (!data
&& 0 == stat5minClientRequests()) {
1284 /* no recent client traffic, wait a bit */
1285 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1289 for (p
= Config
.peers
; p
; p
= p
->next
)
1290 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1292 /* Reconfigure the peers every hour */
1293 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1297 peerConnectFailedSilent(peer
* p
)
1299 p
->stats
.last_connect_failure
= squid_curtime
;
1302 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1310 debugs(15, 1, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1311 p
->stats
.logged_state
= PEER_DEAD
;
1316 peerConnectFailed(peer
*p
)
1318 debugs(15, 1, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1319 peerConnectFailedSilent(p
);
1323 peerConnectSucceded(peer
* p
)
1326 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1327 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1329 if (!p
->n_addresses
)
1330 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1332 p
->tcp_up
= p
->connect_fail_limit
;
1336 * peerProbeConnect will be called on dead peers by neighborUp
1339 peerProbeConnect(peer
* p
)
1341 time_t ctimeout
= p
->connect_timeout
> 0 ? p
->connect_timeout
: Config
.Timeout
.peer_connect
;
1342 bool ret
= (squid_curtime
- p
->stats
.last_connect_failure
) > (ctimeout
* 10);
1344 if (p
->testing_now
> 0)
1345 return ret
;/* probe already running */
1347 if (squid_curtime
- p
->stats
.last_connect_probe
== 0)
1348 return ret
;/* don't probe to often */
1350 /* for each IP address of this peer. find one that we can connect to and probe it. */
1351 for (int i
= 0; i
< p
->n_addresses
; i
++) {
1352 Comm::ConnectionPointer conn
= new Comm::Connection
;
1353 conn
->remote
= p
->addresses
[i
];
1354 conn
->remote
.SetPort(p
->http_port
);
1355 getOutgoingAddress(NULL
, conn
);
1359 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1360 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1361 cs
->setHost(p
->host
);
1362 AsyncJob::Start(cs
);
1365 p
->stats
.last_connect_probe
= squid_curtime
;
1371 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, comm_err_t status
, int xerrno
, void *data
)
1373 peer
*p
= (peer
*)data
;
1375 if (status
== COMM_OK
) {
1376 peerConnectSucceded(p
);
1378 peerConnectFailedSilent(p
);
1386 peerCountMcastPeersSchedule(peer
* p
, time_t when
)
1388 if (p
->mcast
.flags
.count_event_pending
)
1391 eventAdd("peerCountMcastPeersStart",
1392 peerCountMcastPeersStart
,
1396 p
->mcast
.flags
.count_event_pending
= 1;
1400 peerCountMcastPeersStart(void *data
)
1402 peer
*p
= (peer
*)data
;
1406 icp_common_t
*query
;
1408 LOCAL_ARRAY(char, url
, MAX_URL
);
1409 assert(p
->type
== PEER_MULTICAST
);
1410 p
->mcast
.flags
.count_event_pending
= 0;
1411 snprintf(url
, MAX_URL
, "http://");
1412 p
->in_addr
.ToURL(url
+7, MAX_URL
-8 );
1414 fake
= storeCreateEntry(url
, url
, request_flags(), METHOD_GET
);
1415 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1416 psstate
= new ps_state
;
1417 psstate
->request
= HTTPMSGLOCK(req
);
1418 psstate
->entry
= fake
;
1419 psstate
->callback
= NULL
;
1420 psstate
->callback_data
= cbdataReference(p
);
1421 psstate
->ping
.start
= current_time
;
1422 mem
= fake
->mem_obj
;
1423 mem
->request
= HTTPMSGLOCK(psstate
->request
);
1424 mem
->start_ping
= current_time
;
1425 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1426 mem
->ircb_data
= psstate
;
1427 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1428 p
->mcast
.id
= mem
->id
;
1429 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1430 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1431 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
1432 fake
->ping_status
= PING_WAITING
;
1433 eventAdd("peerCountMcastPeersDone",
1434 peerCountMcastPeersDone
,
1436 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1437 p
->mcast
.flags
.counting
= 1;
1438 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1442 peerCountMcastPeersDone(void *data
)
1444 ps_state
*psstate
= (ps_state
*)data
;
1445 StoreEntry
*fake
= psstate
->entry
;
1447 if (cbdataReferenceValid(psstate
->callback_data
)) {
1448 peer
*p
= (peer
*)psstate
->callback_data
;
1449 p
->mcast
.flags
.counting
= 0;
1450 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1451 debugs(15, 1, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1452 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1453 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1454 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1457 cbdataReferenceDone(psstate
->callback_data
);
1459 EBIT_SET(fake
->flags
, ENTRY_ABORTED
);
1460 HTTPMSGUNLOCK(fake
->mem_obj
->request
);
1461 fake
->releaseRequest();
1463 HTTPMSGUNLOCK(psstate
->request
);
1464 cbdataFree(psstate
);
1468 peerCountHandleIcpReply(peer
* p
, peer_t type
, protocol_t proto
, void *hdrnotused
, void *data
)
1472 ps_state
*psstate
= (ps_state
*)data
;
1473 StoreEntry
*fake
= psstate
->entry
;
1474 MemObject
*mem
= fake
->mem_obj
;
1475 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1476 assert(proto
== PROTO_ICP
);
1479 psstate
->ping
.n_recv
++;
1480 rtt_av_factor
= RTT_AV_FACTOR
;
1482 if (p
->options
.weighted_roundrobin
)
1483 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1485 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1489 neighborDumpPeers(StoreEntry
* sentry
)
1491 dump_peers(sentry
, Config
.peers
);
1495 neighborDumpNonPeers(StoreEntry
* sentry
)
1497 dump_peers(sentry
, non_peers
);
1501 dump_peer_options(StoreEntry
* sentry
, peer
* p
)
1503 if (p
->options
.proxy_only
)
1504 storeAppendPrintf(sentry
, " proxy-only");
1506 if (p
->options
.no_query
)
1507 storeAppendPrintf(sentry
, " no-query");
1509 if (p
->options
.background_ping
)
1510 storeAppendPrintf(sentry
, " background-ping");
1512 if (p
->options
.no_digest
)
1513 storeAppendPrintf(sentry
, " no-digest");
1515 if (p
->options
.default_parent
)
1516 storeAppendPrintf(sentry
, " default");
1518 if (p
->options
.roundrobin
)
1519 storeAppendPrintf(sentry
, " round-robin");
1521 if (p
->options
.carp
)
1522 storeAppendPrintf(sentry
, " carp");
1524 if (p
->options
.userhash
)
1525 storeAppendPrintf(sentry
, " userhash");
1527 if (p
->options
.userhash
)
1528 storeAppendPrintf(sentry
, " sourcehash");
1530 if (p
->options
.weighted_roundrobin
)
1531 storeAppendPrintf(sentry
, " weighted-round-robin");
1533 if (p
->options
.mcast_responder
)
1534 storeAppendPrintf(sentry
, " multicast-responder");
1536 #if PEER_MULTICAST_SIBLINGS
1537 if (p
->options
.mcast_siblings
)
1538 storeAppendPrintf(sentry
, " multicast-siblings");
1542 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1544 if (p
->options
.closest_only
)
1545 storeAppendPrintf(sentry
, " closest-only");
1548 if (p
->options
.htcp
) {
1549 storeAppendPrintf(sentry
, " htcp");
1550 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1552 if (p
->options
.htcp_oldsquid
)
1553 storeAppendPrintf(sentry
, "%soldsquid",(doneopts
++>0?",":"="));
1554 if (p
->options
.htcp_no_clr
)
1555 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
++>0?",":"="));
1556 if (p
->options
.htcp_no_purge_clr
)
1557 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
++>0?",":"="));
1558 if (p
->options
.htcp_only_clr
)
1559 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
++>0?",":"="));
1564 if (p
->options
.no_netdb_exchange
)
1565 storeAppendPrintf(sentry
, " no-netdb-exchange");
1569 if (p
->options
.no_delay
)
1570 storeAppendPrintf(sentry
, " no-delay");
1575 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1577 if (p
->mcast
.ttl
> 0)
1578 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1580 if (p
->connect_timeout
> 0)
1581 storeAppendPrintf(sentry
, " connect-timeout=%d", (int) p
->connect_timeout
);
1583 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1584 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1586 #if USE_CACHE_DIGESTS
1589 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1593 if (p
->options
.allow_miss
)
1594 storeAppendPrintf(sentry
, " allow-miss");
1596 if (p
->options
.no_tproxy
)
1597 storeAppendPrintf(sentry
, " no-tproxy");
1599 if (p
->max_conn
> 0)
1600 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1602 if (p
->options
.originserver
)
1603 storeAppendPrintf(sentry
, " originserver");
1606 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1608 if (p
->connection_auth
== 0)
1609 storeAppendPrintf(sentry
, " connection-auth=off");
1610 else if (p
->connection_auth
== 1)
1611 storeAppendPrintf(sentry
, " connection-auth=on");
1612 else if (p
->connection_auth
== 2)
1613 storeAppendPrintf(sentry
, " connection-auth=auto");
1615 storeAppendPrintf(sentry
, "\n");
1619 dump_peers(StoreEntry
* sentry
, peer
* peers
)
1622 char ntoabuf
[MAX_IPSTRLEN
];
1623 struct _domain_ping
*d
= NULL
;
1628 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1630 for (e
= peers
; e
; e
= e
->next
) {
1631 assert(e
->host
!= NULL
);
1632 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1635 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1639 storeAppendPrintf(sentry
, "Flags :");
1640 dump_peer_options(sentry
, e
);
1642 for (i
= 0; i
< e
->n_addresses
; i
++) {
1643 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1644 e
->addresses
[i
].NtoA(ntoabuf
,MAX_IPSTRLEN
) );
1647 storeAppendPrintf(sentry
, "Status : %s\n",
1648 neighborUp(e
) ? "Up" : "Down");
1649 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1650 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1651 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1653 if (!e
->options
.no_query
) {
1654 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1655 (int) (squid_curtime
- e
->stats
.last_query
));
1657 if (e
->stats
.last_reply
> 0)
1658 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1659 (int) (squid_curtime
- e
->stats
.last_reply
));
1661 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1663 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1665 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1666 e
->stats
.pings_acked
,
1667 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1670 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1672 if (!e
->options
.no_query
) {
1673 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1676 if (e
->options
.htcp
) {
1677 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1679 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1680 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1682 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1686 for (op
= ICP_INVALID
; op
< ICP_END
; ++op
) {
1687 if (e
->icp
.counts
[op
] == 0)
1690 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1693 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1704 if (e
->stats
.last_connect_failure
) {
1705 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1706 mkhttpdlogtime(&(e
->stats
.last_connect_failure
)));
1709 if (e
->peer_domain
!= NULL
) {
1710 storeAppendPrintf(sentry
, "DOMAIN LIST: ");
1712 for (d
= e
->peer_domain
; d
; d
= d
->next
) {
1713 storeAppendPrintf(sentry
, "%s%s ",
1714 d
->do_ping
? null_string
: "!", d
->domain
);
1717 storeAppendPrintf(sentry
, "\n");
1720 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1726 neighborsHtcpReply(const cache_key
* key
, htcpReplyData
* htcp
, const Ip::Address
&from
)
1728 StoreEntry
*e
= Store::Root().get(key
);
1729 MemObject
*mem
= NULL
;
1731 peer_t ntype
= PEER_NONE
;
1732 debugs(15, 6, "neighborsHtcpReply: " <<
1733 (htcp
->hit
? "HIT" : "MISS") << " " <<
1734 storeKeyText(key
) );
1739 if ((p
= whichPeer(from
)))
1740 neighborAliveHtcp(p
, mem
, htcp
);
1742 /* Does the entry exist? */
1744 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1745 neighborCountIgnored(p
);
1749 /* check if someone is already fetching it */
1750 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1751 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1752 neighborCountIgnored(p
);
1757 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1758 neighborCountIgnored(p
);
1762 if (e
->ping_status
!= PING_WAITING
) {
1763 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1764 neighborCountIgnored(p
);
1768 if (e
->lock_count
== 0) {
1769 debugs(12, 1, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1770 neighborCountIgnored(p
);
1775 ntype
= neighborType(p
, mem
->request
);
1776 neighborUpdateRtt(p
, mem
);
1779 if (ignoreMulticastReply(p
, mem
)) {
1780 neighborCountIgnored(p
);
1784 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1785 mem
->ping_reply_callback(p
, ntype
, PROTO_HTCP
, htcp
, mem
->ircb_data
);
1789 * Send HTCP CLR messages to all peers configured to receive them.
1792 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1797 for (p
= Config
.peers
; p
; p
= p
->next
) {
1798 if (!p
->options
.htcp
) {
1801 if (p
->options
.htcp_no_clr
) {
1804 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1807 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.ToURL(buf
, 128));
1808 htcpClear(e
, uri
, req
, method
, p
, reason
);