2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 15 Neighbor Routines */
12 #include "acl/FilledChecklist.h"
13 #include "anyp/PortCfg.h"
14 #include "CacheDigest.h"
15 #include "CachePeer.h"
16 #include "CachePeerDomainList.h"
17 #include "comm/Connection.h"
18 #include "comm/ConnOpener.h"
23 #include "HttpRequest.h"
24 #include "icmp/net_db.h"
27 #include "ip/Address.h"
30 #include "MemObject.h"
31 #include "mgr/Registration.h"
32 #include "multicast.h"
33 #include "neighbors.h"
34 #include "NeighborTypeDomainList.h"
36 #include "PeerDigest.h"
37 #include "PeerPoolMgr.h"
38 #include "PeerSelectState.h"
39 #include "RequestFlags.h"
40 #include "SquidConfig.h"
41 #include "SquidMath.h"
42 #include "SquidTime.h"
45 #include "store_key_md5.h"
49 /* count mcast group peers every 15 minutes */
50 #define MCAST_COUNT_RATE 900
52 bool peerAllowedToUse(const CachePeer
*, HttpRequest
*);
53 static int peerWouldBePinged(const CachePeer
*, HttpRequest
*);
54 static void neighborRemove(CachePeer
*);
55 static void neighborAlive(CachePeer
*, const MemObject
*, const icp_common_t
*);
57 static void neighborAliveHtcp(CachePeer
*, const MemObject
*, const HtcpReplyData
*);
59 static void neighborCountIgnored(CachePeer
*);
60 static void peerRefreshDNS(void *);
61 static IPH peerDNSConfigure
;
62 static bool peerProbeConnect(CachePeer
*);
63 static CNCB peerProbeConnectDone
;
64 static void peerCountMcastPeersDone(void *data
);
65 static void peerCountMcastPeersStart(void *data
);
66 static void peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
);
67 static IRCB peerCountHandleIcpReply
;
69 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
70 static OBJH neighborDumpPeers
;
71 static OBJH neighborDumpNonPeers
;
72 static void dump_peers(StoreEntry
* sentry
, CachePeer
* peers
);
74 static unsigned short echo_port
;
76 static int NLateReplies
= 0;
77 static CachePeer
*first_ping
= NULL
;
80 neighborTypeStr(const CachePeer
* p
)
82 if (p
->type
== PEER_NONE
)
85 if (p
->type
== PEER_SIBLING
)
88 if (p
->type
== PEER_MULTICAST
)
89 return "Multicast Group";
95 whichPeer(const Ip::Address
&from
)
100 debugs(15, 3, "whichPeer: from " << from
);
102 for (p
= Config
.peers
; p
; p
= p
->next
) {
103 for (j
= 0; j
< p
->n_addresses
; ++j
) {
104 if (from
== p
->addresses
[j
] && from
.port() == p
->icp
.port
) {
114 neighborType(const CachePeer
* p
, const HttpRequest
* request
)
117 const NeighborTypeDomainList
*d
= NULL
;
119 for (d
= p
->typelist
; d
; d
= d
->next
) {
120 if (0 == matchDomainName(request
->GetHost(), d
->domain
))
121 if (d
->type
!= PEER_NONE
)
124 #if PEER_MULTICAST_SIBLINGS
125 if (p
->type
== PEER_MULTICAST
)
126 if (p
->options
.mcast_siblings
)
134 * \return Whether it is appropriate to fetch REQUEST from PEER.
137 peerAllowedToUse(const CachePeer
* p
, HttpRequest
* request
)
140 const CachePeerDomainList
*d
= NULL
;
141 assert(request
!= NULL
);
143 if (neighborType(p
, request
) == PEER_SIBLING
) {
144 #if PEER_MULTICAST_SIBLINGS
145 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
146 (request
->flags
.noCache
|| request
->flags
.refresh
|| request
->flags
.loopDetected
|| request
->flags
.needValidation
))
147 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->GetHost() << ") : multicast-siblings optimization match");
149 if (request
->flags
.noCache
)
152 if (request
->flags
.refresh
)
155 if (request
->flags
.loopDetected
)
158 if (request
->flags
.needValidation
)
162 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
163 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
164 if (p
->options
.originserver
&& request
->method
== Http::METHOD_CONNECT
&& request
->port
!= p
->in_addr
.port())
167 if (p
->peer_domain
== NULL
&& p
->access
== NULL
)
170 bool do_ping
= false;
171 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
172 if (0 == matchDomainName(request
->GetHost(), d
->domain
)) {
173 do_ping
= d
->do_ping
;
177 do_ping
= !d
->do_ping
;
180 if (p
->peer_domain
&& !do_ping
)
183 if (p
->access
== NULL
)
186 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
188 return (checklist
.fastCheck() == ACCESS_ALLOWED
);
191 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
193 peerWouldBePinged(const CachePeer
* p
, HttpRequest
* request
)
195 if (p
->icp
.port
== 0)
198 if (p
->options
.no_query
)
201 if (p
->options
.mcast_responder
)
204 if (p
->n_addresses
== 0)
207 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
210 /* the case below seems strange, but can happen if the
211 * URL host is on the other side of a firewall */
212 if (p
->type
== PEER_SIBLING
)
213 if (!request
->flags
.hierarchical
)
216 if (!peerAllowedToUse(p
, request
))
219 /* Ping dead peers every timeout interval */
220 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
230 peerCanOpenMore(const CachePeer
*p
)
232 const int effectiveLimit
= p
->max_conn
<= 0 ? Squid_MaxFD
: p
->max_conn
;
233 const int remaining
= effectiveLimit
- p
->stats
.conn_open
;
234 debugs(15, 7, remaining
<< '=' << effectiveLimit
<< '-' << p
->stats
.conn_open
);
235 return remaining
> 0;
239 peerHasConnAvailable(const CachePeer
*p
)
241 // Standby connections can be used without opening new connections.
242 const int standbys
= p
->standby
.pool
? p
->standby
.pool
->count() : 0;
244 // XXX: Some idle pconns can be used without opening new connections.
245 // Complication: Idle pconns cannot be reused for some requests.
246 const int usableIdles
= 0;
248 const int available
= standbys
+ usableIdles
;
249 debugs(15, 7, available
<< '=' << standbys
<< '+' << usableIdles
);
250 return available
> 0;
254 peerConnClosed(CachePeer
*p
)
256 --p
->stats
.conn_open
;
257 if (p
->standby
.waitingForClose
&& peerCanOpenMore(p
)) {
258 p
->standby
.waitingForClose
= false;
259 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "conn closed");
263 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
265 peerHTTPOkay(const CachePeer
* p
, HttpRequest
* request
)
267 if (!peerCanOpenMore(p
) && !peerHasConnAvailable(p
))
270 if (!peerAllowedToUse(p
, request
))
280 neighborsCount(HttpRequest
* request
)
285 for (p
= Config
.peers
; p
; p
= p
->next
)
286 if (peerWouldBePinged(p
, request
))
289 debugs(15, 3, "neighborsCount: " << count
);
295 getFirstUpParent(HttpRequest
* request
)
299 for (p
= Config
.peers
; p
; p
= p
->next
) {
303 if (neighborType(p
, request
) != PEER_PARENT
)
306 if (!peerHTTPOkay(p
, request
))
312 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
317 getRoundRobinParent(HttpRequest
* request
)
322 for (p
= Config
.peers
; p
; p
= p
->next
) {
323 if (!p
->options
.roundrobin
)
326 if (neighborType(p
, request
) != PEER_PARENT
)
329 if (!peerHTTPOkay(p
, request
))
336 if (p
->weight
== q
->weight
) {
337 if (q
->rr_count
< p
->rr_count
)
339 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
350 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
356 getWeightedRoundRobinParent(HttpRequest
* request
)
362 for (p
= Config
.peers
; p
; p
= p
->next
) {
363 if (!p
->options
.weighted_roundrobin
)
366 if (neighborType(p
, request
) != PEER_PARENT
)
369 if (!peerHTTPOkay(p
, request
))
372 if (q
&& q
->rr_count
< p
->rr_count
)
378 if (q
&& q
->rr_count
> 1000000)
379 for (p
= Config
.peers
; p
; p
= p
->next
) {
380 if (!p
->options
.weighted_roundrobin
)
383 if (neighborType(p
, request
) != PEER_PARENT
)
390 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
392 if (weighted_rtt
< 1)
395 q
->rr_count
+= weighted_rtt
;
397 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
400 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
405 * This gets called every 5 minutes to clear the round-robin counter.
406 * The exact timing is an arbitrary default, set on estimate timing of a
407 * large number of requests in a high-performance environment during the
408 * period. The larger the number of requests between cycled resets the
409 * more balanced the operations.
412 \todo Make the reset timing a selectable parameter in squid.conf
415 peerClearRRLoop(void *data
)
418 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
422 * This gets called on startup and restart to kick off the CachePeer round-robin
423 * maintenance event. It ensures that no matter how many times its called
424 * no more than one event is scheduled.
427 peerClearRRStart(void)
429 static bool event_added
= false;
431 peerClearRRLoop(NULL
);
437 * Called whenever the round-robin counters need to be reset to a sane state.
438 * So far those times are:
439 * - On startup and reconfigure - to set the counters to sane initial settings.
440 * - When a CachePeer has revived from dead, to prevent the revived CachePeer being
441 * flooded with requests which it has 'missed' during the down period.
447 for (p
= Config
.peers
; p
; p
= p
->next
) {
453 * Perform all actions when a CachePeer is detected revived.
456 peerAlive(CachePeer
*p
)
458 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
459 debugs(15, DBG_IMPORTANT
, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
460 p
->stats
.logged_state
= PEER_ALIVE
;
462 if (p
->standby
.mgr
.valid())
463 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "revived peer");
466 p
->stats
.last_reply
= squid_curtime
;
467 p
->stats
.probe_start
= 0;
471 getDefaultParent(HttpRequest
* request
)
475 for (p
= Config
.peers
; p
; p
= p
->next
) {
476 if (neighborType(p
, request
) != PEER_PARENT
)
479 if (!p
->options
.default_parent
)
482 if (!peerHTTPOkay(p
, request
))
485 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
490 debugs(15, 3, "getDefaultParent: returning NULL");
495 getNextPeer(CachePeer
* p
)
507 neighborRemove(CachePeer
* target
)
510 CachePeer
**P
= NULL
;
530 first_ping
= Config
.peers
;
534 neighborsRegisterWithCacheManager()
536 Mgr::RegisterAction("server_list",
537 "Peer Cache Statistics",
538 neighborDumpPeers
, 0, 1);
540 if (Comm::IsConnOpen(icpIncomingConn
)) {
541 Mgr::RegisterAction("non_peers",
542 "List of Unknown sites sending ICP messages",
543 neighborDumpNonPeers
, 0, 1);
550 struct servent
*sep
= NULL
;
551 const char *me
= getMyHostname();
552 CachePeer
*thisPeer
= NULL
;
553 CachePeer
*next
= NULL
;
555 neighborsRegisterWithCacheManager();
557 if (Comm::IsConnOpen(icpIncomingConn
)) {
559 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
560 next
= thisPeer
->next
;
562 if (0 != strcmp(thisPeer
->host
, me
))
565 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
566 if (thisPeer
->http_port
!= s
->s
.port())
569 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
571 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
572 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
573 "/" << thisPeer
->http_port
<< "/" <<
576 neighborRemove(thisPeer
);
581 peerRefreshDNS((void *) 1);
583 sep
= getservbyname("echo", "udp");
584 echo_port
= sep
? ntohs((unsigned short) sep
->s_port
) : 7;
586 first_ping
= Config
.peers
;
590 neighborsUdpPing(HttpRequest
* request
,
597 const char *url
= entry
->url();
598 MemObject
*mem
= entry
->mem_obj
;
604 int queries_sent
= 0;
605 int peers_pinged
= 0;
606 int parent_timeout
= 0, parent_exprep
= 0;
607 int sibling_timeout
= 0, sibling_exprep
= 0;
608 int mcast_timeout
= 0, mcast_exprep
= 0;
610 if (Config
.peers
== NULL
)
613 assert(entry
->swap_status
== SWAPOUT_NONE
);
615 mem
->start_ping
= current_time
;
617 mem
->ping_reply_callback
= callback
;
619 mem
->ircb_data
= callback_data
;
621 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
623 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
627 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
629 if (!peerWouldBePinged(p
, request
))
630 continue; /* next CachePeer */
634 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
636 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
638 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
641 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
642 if (Config
.Port
.htcp
<= 0) {
643 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
647 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
648 if (htcpQuery(entry
, request
, p
) <= 0)
649 continue; // unable to send.
653 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
654 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
658 if (p
->type
== PEER_MULTICAST
)
659 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
661 if (p
->icp
.port
== echo_port
) {
662 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
663 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
664 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
668 if (Config
.onoff
.query_icmp
)
669 if (p
->icp
.version
== ICP_VERSION_2
)
670 flags
|= ICP_FLAG_SRC_RTT
;
672 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
674 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0.0);
681 ++ p
->stats
.pings_sent
;
683 if (p
->type
== PEER_MULTICAST
) {
684 mcast_exprep
+= p
->mcast
.n_replies_expected
;
685 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
686 } else if (neighborUp(p
)) {
687 /* its alive, expect a reply from it */
689 if (neighborType(p
, request
) == PEER_PARENT
) {
691 parent_timeout
+= p
->stats
.rtt
;
694 sibling_timeout
+= p
->stats
.rtt
;
697 /* Neighbor is dead; ping it anyway, but don't expect a reply */
698 /* log it once at the threshold */
700 if (p
->stats
.logged_state
== PEER_ALIVE
) {
701 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
702 p
->stats
.logged_state
= PEER_DEAD
;
706 p
->stats
.last_query
= squid_curtime
;
709 * keep probe_start == 0 for a multicast CachePeer,
710 * so neighborUp() never says this CachePeer is dead.
713 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
714 p
->stats
.probe_start
= squid_curtime
;
717 if ((first_ping
= first_ping
->next
) == NULL
)
718 first_ping
= Config
.peers
;
721 * How many replies to expect?
723 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
726 * If there is a configured timeout, use it
728 if (Config
.Timeout
.icp_query
)
729 *timeout
= Config
.Timeout
.icp_query
;
733 *timeout
= 2 * parent_timeout
/ parent_exprep
;
734 else if (mcast_exprep
)
735 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
737 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
739 *timeout
= 2000; /* 2 seconds */
741 if (Config
.Timeout
.icp_query_max
)
742 if (*timeout
> Config
.Timeout
.icp_query_max
)
743 *timeout
= Config
.Timeout
.icp_query_max
;
745 if (*timeout
< Config
.Timeout
.icp_query_min
)
746 *timeout
= Config
.Timeout
.icp_query_min
;
752 /* lookup the digest of a given CachePeer */
754 peerDigestLookup(CachePeer
* p
, HttpRequest
* request
)
756 #if USE_CACHE_DIGESTS
757 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
760 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
761 /* does the peeer have a valid digest? */
764 debugs(15, 5, "peerDigestLookup: gone!");
766 } else if (!peerHTTPOkay(p
, request
)) {
767 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
769 } else if (!p
->digest
->flags
.needed
) {
770 debugs(15, 5, "peerDigestLookup: note need");
771 peerDigestNeeded(p
->digest
);
773 } else if (!p
->digest
->flags
.usable
) {
774 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
778 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
779 assert(p
->digest
->cd
);
780 /* does digest predict a hit? */
782 if (!cacheDigestTest(p
->digest
->cd
, key
))
785 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
794 /* select best CachePeer based on cache digests */
796 neighborsDigestSelect(HttpRequest
* request
)
798 CachePeer
*best_p
= NULL
;
799 #if USE_CACHE_DIGESTS
802 int choice_count
= 0;
803 int ichoice_count
= 0;
808 if (!request
->flags
.hierarchical
)
811 storeKeyPublicByRequest(request
);
813 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
822 lookup
= peerDigestLookup(p
, request
);
824 if (lookup
== LOOKUP_NONE
)
829 if (lookup
== LOOKUP_MISS
)
832 p_rtt
= netdbHostRtt(p
->host
);
834 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
836 /* is this CachePeer better than others in terms of rtt ? */
837 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
841 if (p_rtt
) /* informative choice (aka educated guess) */
844 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
848 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
849 peerNoteDigestLookup(request
, best_p
,
850 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
851 request
->hier
.n_choices
= choice_count
;
852 request
->hier
.n_ichoices
= ichoice_count
;
859 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
861 #if USE_CACHE_DIGESTS
863 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
865 *request
->hier
.cd_host
= '\0';
867 request
->hier
.cd_lookup
= lookup
;
868 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
873 neighborAlive(CachePeer
* p
, const MemObject
*, const icp_common_t
* header
)
876 ++ p
->stats
.pings_acked
;
878 if ((icp_opcode
) header
->opcode
<= ICP_END
)
879 ++ p
->icp
.counts
[header
->opcode
];
881 p
->icp
.version
= (int) header
->version
;
885 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
887 int rtt
, rtt_av_factor
;
892 if (!mem
->start_ping
.tv_sec
)
895 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
897 if (rtt
< 1 || rtt
> 10000)
900 rtt_av_factor
= RTT_AV_FACTOR
;
902 if (p
->options
.weighted_roundrobin
)
903 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
905 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
910 neighborAliveHtcp(CachePeer
* p
, const MemObject
*, const HtcpReplyData
* htcp
)
913 ++ p
->stats
.pings_acked
;
914 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
915 p
->htcp
.version
= htcp
->version
;
921 neighborCountIgnored(CachePeer
* p
)
926 ++ p
->stats
.ignored_replies
;
931 static CachePeer
*non_peers
= NULL
;
934 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
938 for (np
= non_peers
; np
; np
= np
->next
) {
939 if (np
->in_addr
!= from
)
942 if (np
->in_addr
.port() != from
.port())
951 np
->icp
.port
= from
.port();
952 np
->type
= PEER_NONE
;
953 np
->host
= new char[MAX_IPSTRLEN
];
954 from
.toStr(np
->host
,MAX_IPSTRLEN
);
955 np
->next
= non_peers
;
959 ++ np
->icp
.counts
[opcode
];
961 if (isPowTen(++np
->stats
.ignored_replies
))
962 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
965 /* ignoreMulticastReply
967 * * We want to ignore replies from multicast peers if the
968 * * cache_host_domain rules would normally prevent the CachePeer
972 ignoreMulticastReply(CachePeer
* p
, MemObject
* mem
)
977 if (!p
->options
.mcast_responder
)
980 if (peerHTTPOkay(p
, mem
->request
))
987 * I should attach these records to the entry. We take the first
988 * hit we get our wait until everyone misses. The timeout handler
989 * call needs to nip this shopping list or call one of the misses.
991 * If a hit process is already started, then sobeit
994 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
998 MemObject
*mem
= NULL
;
999 peer_t ntype
= PEER_NONE
;
1000 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1002 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1004 if (NULL
!= (entry
= Store::Root().get(key
)))
1005 mem
= entry
->mem_obj
;
1007 if ((p
= whichPeer(from
)))
1008 neighborAlive(p
, mem
, header
);
1010 if (opcode
> ICP_END
)
1013 const char *opcode_d
= icp_opcode_str
[opcode
];
1016 neighborUpdateRtt(p
, mem
);
1018 /* Does the entry exist? */
1019 if (NULL
== entry
) {
1020 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1021 neighborCountIgnored(p
);
1025 /* check if someone is already fetching it */
1026 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1027 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1028 neighborCountIgnored(p
);
1033 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1034 neighborCountIgnored(p
);
1038 if (entry
->ping_status
!= PING_WAITING
) {
1039 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1040 neighborCountIgnored(p
);
1044 if (!entry
->locked()) {
1045 // TODO: many entries are unlocked; why is this reported at level 1?
1046 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1047 neighborCountIgnored(p
);
1051 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1054 ntype
= neighborType(p
, mem
->request
);
1057 if (ignoreMulticastReply(p
, mem
)) {
1058 neighborCountIgnored(p
);
1059 } else if (opcode
== ICP_MISS
) {
1061 neighborIgnoreNonPeer(from
, opcode
);
1063 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1065 } else if (opcode
== ICP_HIT
) {
1067 neighborIgnoreNonPeer(from
, opcode
);
1069 header
->opcode
= ICP_HIT
;
1070 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1072 } else if (opcode
== ICP_DECHO
) {
1074 neighborIgnoreNonPeer(from
, opcode
);
1075 } else if (ntype
== PEER_SIBLING
) {
1076 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1077 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1079 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1081 } else if (opcode
== ICP_SECHO
) {
1083 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << p
->host
);
1084 neighborCountIgnored(p
);
1086 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1088 } else if (opcode
== ICP_DENIED
) {
1090 neighborIgnoreNonPeer(from
, opcode
);
1091 } else if (p
->stats
.pings_acked
> 100) {
1092 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1093 debugs(15, DBG_CRITICAL
, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1094 debugs(15, DBG_CRITICAL
, "Disabling '" << p
->host
<< "', please check your configuration.");
1098 neighborCountIgnored(p
);
1101 } else if (opcode
== ICP_MISS_NOFETCH
) {
1102 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1104 debugs(15, DBG_CRITICAL
, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1109 peerFindByName(const char *name
)
1111 CachePeer
*p
= NULL
;
1113 for (p
= Config
.peers
; p
; p
= p
->next
) {
1114 if (!strcasecmp(name
, p
->name
))
1122 peerFindByNameAndPort(const char *name
, unsigned short port
)
1124 CachePeer
*p
= NULL
;
1126 for (p
= Config
.peers
; p
; p
= p
->next
) {
1127 if (strcasecmp(name
, p
->name
))
1130 if (port
!= p
->http_port
)
1140 neighborUp(const CachePeer
* p
)
1143 if (!peerProbeConnect((CachePeer
*) p
)) {
1144 debugs(15, 8, "neighborUp: DOWN (probed): " << p
->host
<< " (" << p
->in_addr
<< ")");
1150 * The CachePeer can not be UP if we don't have any IP addresses
1153 if (0 == p
->n_addresses
) {
1154 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1158 if (p
->options
.no_query
) {
1159 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1163 if (p
->stats
.probe_start
!= 0 &&
1164 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1165 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1169 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1174 peerNoteDigestGone(CachePeer
* p
)
1176 #if USE_CACHE_DIGESTS
1177 cbdataReferenceDone(p
->digest
);
1182 peerDNSConfigure(const ipcache_addrs
*ia
, const Dns::LookupDetails
&, void *data
)
1184 // TODO: connections to no-longer valid IP addresses should be
1185 // closed when we can detect such IP addresses.
1187 CachePeer
*p
= (CachePeer
*)data
;
1191 if (p
->n_addresses
== 0) {
1192 debugs(15, DBG_IMPORTANT
, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1194 if (p
->type
== PEER_MULTICAST
)
1195 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1201 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1205 if ((int) ia
->count
< 1) {
1206 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << p
->host
<< "'!");
1210 p
->tcp_up
= p
->connect_fail_limit
;
1212 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; ++j
) {
1213 p
->addresses
[j
] = ia
->in_addrs
[j
];
1214 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1218 p
->in_addr
.setEmpty();
1219 p
->in_addr
= p
->addresses
[0];
1220 p
->in_addr
.port(p
->icp
.port
);
1222 if (p
->type
== PEER_MULTICAST
)
1223 peerCountMcastPeersSchedule(p
, 10);
1226 if (p
->type
!= PEER_MULTICAST
&& IamWorkerProcess())
1227 if (!p
->options
.no_netdb_exchange
)
1228 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1231 if (p
->standby
.mgr
.valid())
1232 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "resolved peer");
1236 peerRefreshDNS(void *data
)
1238 CachePeer
*p
= NULL
;
1240 if (eventFind(peerRefreshDNS
, NULL
))
1241 eventDelete(peerRefreshDNS
, NULL
);
1243 if (!data
&& 0 == stat5minClientRequests()) {
1244 /* no recent client traffic, wait a bit */
1245 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1249 for (p
= Config
.peers
; p
; p
= p
->next
)
1250 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1252 /* Reconfigure the peers every hour */
1253 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1257 peerConnectFailedSilent(CachePeer
* p
)
1259 p
->stats
.last_connect_failure
= squid_curtime
;
1262 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1270 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1271 p
->stats
.logged_state
= PEER_DEAD
;
1276 peerConnectFailed(CachePeer
*p
)
1278 debugs(15, DBG_IMPORTANT
, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1279 peerConnectFailedSilent(p
);
1283 peerConnectSucceded(CachePeer
* p
)
1286 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1287 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1289 if (!p
->n_addresses
)
1290 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1292 p
->tcp_up
= p
->connect_fail_limit
;
1296 * peerProbeConnect will be called on dead peers by neighborUp
1299 peerProbeConnect(CachePeer
* p
)
1301 time_t ctimeout
= p
->connect_timeout
> 0 ? p
->connect_timeout
: Config
.Timeout
.peer_connect
;
1302 bool ret
= (squid_curtime
- p
->stats
.last_connect_failure
) > (ctimeout
* 10);
1304 if (p
->testing_now
> 0)
1305 return ret
;/* probe already running */
1307 if (squid_curtime
- p
->stats
.last_connect_probe
== 0)
1308 return ret
;/* don't probe to often */
1310 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1311 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1312 Comm::ConnectionPointer conn
= new Comm::Connection
;
1313 conn
->remote
= p
->addresses
[i
];
1314 conn
->remote
.port(p
->http_port
);
1316 getOutgoingAddress(NULL
, conn
);
1320 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1321 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1322 cs
->setHost(p
->host
);
1323 AsyncJob::Start(cs
);
1326 p
->stats
.last_connect_probe
= squid_curtime
;
1332 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, Comm::Flag status
, int, void *data
)
1334 CachePeer
*p
= (CachePeer
*)data
;
1336 if (status
== Comm::OK
) {
1337 peerConnectSucceded(p
);
1339 peerConnectFailedSilent(p
);
1344 // TODO: log this traffic.
1348 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1350 if (p
->mcast
.flags
.count_event_pending
)
1353 eventAdd("peerCountMcastPeersStart",
1354 peerCountMcastPeersStart
,
1358 p
->mcast
.flags
.count_event_pending
= true;
1362 peerCountMcastPeersStart(void *data
)
1364 CachePeer
*p
= (CachePeer
*)data
;
1368 icp_common_t
*query
;
1370 LOCAL_ARRAY(char, url
, MAX_URL
);
1371 assert(p
->type
== PEER_MULTICAST
);
1372 p
->mcast
.flags
.count_event_pending
= false;
1373 snprintf(url
, MAX_URL
, "http://");
1374 p
->in_addr
.toUrl(url
+7, MAX_URL
-8 );
1376 fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1377 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1378 psstate
= new ps_state
;
1379 psstate
->request
= req
;
1380 HTTPMSGLOCK(psstate
->request
);
1381 psstate
->entry
= fake
;
1382 psstate
->callback
= NULL
;
1383 psstate
->callback_data
= cbdataReference(p
);
1384 psstate
->ping
.start
= current_time
;
1385 mem
= fake
->mem_obj
;
1386 mem
->request
= psstate
->request
;
1387 HTTPMSGLOCK(mem
->request
);
1388 mem
->start_ping
= current_time
;
1389 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1390 mem
->ircb_data
= psstate
;
1391 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1392 p
->mcast
.id
= mem
->id
;
1393 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1394 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1395 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
1396 fake
->ping_status
= PING_WAITING
;
1397 eventAdd("peerCountMcastPeersDone",
1398 peerCountMcastPeersDone
,
1400 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1401 p
->mcast
.flags
.counting
= true;
1402 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1406 peerCountMcastPeersDone(void *data
)
1408 ps_state
*psstate
= (ps_state
*)data
;
1409 StoreEntry
*fake
= psstate
->entry
;
1411 if (cbdataReferenceValid(psstate
->callback_data
)) {
1412 CachePeer
*p
= (CachePeer
*)psstate
->callback_data
;
1413 p
->mcast
.flags
.counting
= false;
1414 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1415 debugs(15, DBG_IMPORTANT
, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1416 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1417 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1418 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1421 cbdataReferenceDone(psstate
->callback_data
);
1423 fake
->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
1424 HTTPMSGUNLOCK(fake
->mem_obj
->request
);
1425 fake
->unlock("peerCountMcastPeersDone");
1430 peerCountHandleIcpReply(CachePeer
* p
, peer_t
, AnyP::ProtocolType proto
, void *, void *data
)
1432 ps_state
*psstate
= (ps_state
*)data
;
1433 StoreEntry
*fake
= psstate
->entry
;
1435 MemObject
*mem
= fake
->mem_obj
;
1437 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1438 assert(proto
== AnyP::PROTO_ICP
);
1439 ++ psstate
->ping
.n_recv
;
1440 int rtt_av_factor
= RTT_AV_FACTOR
;
1442 if (p
->options
.weighted_roundrobin
)
1443 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1445 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1449 neighborDumpPeers(StoreEntry
* sentry
)
1451 dump_peers(sentry
, Config
.peers
);
1455 neighborDumpNonPeers(StoreEntry
* sentry
)
1457 dump_peers(sentry
, non_peers
);
1461 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1463 if (p
->options
.proxy_only
)
1464 storeAppendPrintf(sentry
, " proxy-only");
1466 if (p
->options
.no_query
)
1467 storeAppendPrintf(sentry
, " no-query");
1469 if (p
->options
.background_ping
)
1470 storeAppendPrintf(sentry
, " background-ping");
1472 if (p
->options
.no_digest
)
1473 storeAppendPrintf(sentry
, " no-digest");
1475 if (p
->options
.default_parent
)
1476 storeAppendPrintf(sentry
, " default");
1478 if (p
->options
.roundrobin
)
1479 storeAppendPrintf(sentry
, " round-robin");
1481 if (p
->options
.carp
)
1482 storeAppendPrintf(sentry
, " carp");
1485 if (p
->options
.userhash
)
1486 storeAppendPrintf(sentry
, " userhash");
1489 if (p
->options
.sourcehash
)
1490 storeAppendPrintf(sentry
, " sourcehash");
1492 if (p
->options
.weighted_roundrobin
)
1493 storeAppendPrintf(sentry
, " weighted-round-robin");
1495 if (p
->options
.mcast_responder
)
1496 storeAppendPrintf(sentry
, " multicast-responder");
1498 #if PEER_MULTICAST_SIBLINGS
1499 if (p
->options
.mcast_siblings
)
1500 storeAppendPrintf(sentry
, " multicast-siblings");
1504 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1506 if (p
->options
.closest_only
)
1507 storeAppendPrintf(sentry
, " closest-only");
1510 if (p
->options
.htcp
) {
1511 storeAppendPrintf(sentry
, " htcp");
1512 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1514 if (p
->options
.htcp_oldsquid
)
1515 storeAppendPrintf(sentry
, "%soldsquid",(doneopts
++>0?",":"="));
1516 if (p
->options
.htcp_no_clr
)
1517 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
++>0?",":"="));
1518 if (p
->options
.htcp_no_purge_clr
)
1519 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
++>0?",":"="));
1520 if (p
->options
.htcp_only_clr
)
1521 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
++>0?",":"="));
1526 if (p
->options
.no_netdb_exchange
)
1527 storeAppendPrintf(sentry
, " no-netdb-exchange");
1530 if (p
->options
.no_delay
)
1531 storeAppendPrintf(sentry
, " no-delay");
1535 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1537 if (p
->mcast
.ttl
> 0)
1538 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1540 if (p
->connect_timeout
> 0)
1541 storeAppendPrintf(sentry
, " connect-timeout=%d", (int) p
->connect_timeout
);
1543 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1544 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1546 #if USE_CACHE_DIGESTS
1549 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1553 if (p
->options
.allow_miss
)
1554 storeAppendPrintf(sentry
, " allow-miss");
1556 if (p
->options
.no_tproxy
)
1557 storeAppendPrintf(sentry
, " no-tproxy");
1559 if (p
->max_conn
> 0)
1560 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1561 if (p
->standby
.limit
> 0)
1562 storeAppendPrintf(sentry
, " standby=%d", p
->standby
.limit
);
1564 if (p
->options
.originserver
)
1565 storeAppendPrintf(sentry
, " originserver");
1568 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1570 if (p
->connection_auth
== 0)
1571 storeAppendPrintf(sentry
, " connection-auth=off");
1572 else if (p
->connection_auth
== 1)
1573 storeAppendPrintf(sentry
, " connection-auth=on");
1574 else if (p
->connection_auth
== 2)
1575 storeAppendPrintf(sentry
, " connection-auth=auto");
1577 storeAppendPrintf(sentry
, "\n");
1581 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1583 CachePeer
*e
= NULL
;
1584 char ntoabuf
[MAX_IPSTRLEN
];
1585 CachePeerDomainList
*d
= NULL
;
1590 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1592 for (e
= peers
; e
; e
= e
->next
) {
1593 assert(e
->host
!= NULL
);
1594 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1597 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1601 storeAppendPrintf(sentry
, "Flags :");
1602 dump_peer_options(sentry
, e
);
1604 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1605 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1606 e
->addresses
[i
].toStr(ntoabuf
,MAX_IPSTRLEN
) );
1609 storeAppendPrintf(sentry
, "Status : %s\n",
1610 neighborUp(e
) ? "Up" : "Down");
1611 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1612 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1613 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1615 if (!e
->options
.no_query
) {
1616 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1617 (int) (squid_curtime
- e
->stats
.last_query
));
1619 if (e
->stats
.last_reply
> 0)
1620 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1621 (int) (squid_curtime
- e
->stats
.last_reply
));
1623 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1625 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1627 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1628 e
->stats
.pings_acked
,
1629 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1632 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1634 if (!e
->options
.no_query
) {
1635 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1638 if (e
->options
.htcp
) {
1639 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1641 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1642 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1644 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1648 for (op
= ICP_INVALID
; op
< ICP_END
; ++op
) {
1649 if (e
->icp
.counts
[op
] == 0)
1652 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1655 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1666 if (e
->stats
.last_connect_failure
) {
1667 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1668 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1671 if (e
->peer_domain
!= NULL
) {
1672 storeAppendPrintf(sentry
, "DOMAIN LIST: ");
1674 for (d
= e
->peer_domain
; d
; d
= d
->next
) {
1675 storeAppendPrintf(sentry
, "%s%s ",
1676 d
->do_ping
? null_string
: "!", d
->domain
);
1679 storeAppendPrintf(sentry
, "\n");
1682 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1688 neighborsHtcpReply(const cache_key
* key
, HtcpReplyData
* htcp
, const Ip::Address
&from
)
1690 StoreEntry
*e
= Store::Root().get(key
);
1691 MemObject
*mem
= NULL
;
1693 peer_t ntype
= PEER_NONE
;
1694 debugs(15, 6, "neighborsHtcpReply: " <<
1695 (htcp
->hit
? "HIT" : "MISS") << " " <<
1696 storeKeyText(key
) );
1701 if ((p
= whichPeer(from
)))
1702 neighborAliveHtcp(p
, mem
, htcp
);
1704 /* Does the entry exist? */
1706 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1707 neighborCountIgnored(p
);
1711 /* check if someone is already fetching it */
1712 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1713 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1714 neighborCountIgnored(p
);
1719 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1720 neighborCountIgnored(p
);
1724 if (e
->ping_status
!= PING_WAITING
) {
1725 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1726 neighborCountIgnored(p
);
1731 // TODO: many entries are unlocked; why is this reported at level 1?
1732 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1733 neighborCountIgnored(p
);
1738 ntype
= neighborType(p
, mem
->request
);
1739 neighborUpdateRtt(p
, mem
);
1742 if (ignoreMulticastReply(p
, mem
)) {
1743 neighborCountIgnored(p
);
1747 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1748 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1752 * Send HTCP CLR messages to all peers configured to receive them.
1755 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1760 for (p
= Config
.peers
; p
; p
= p
->next
) {
1761 if (!p
->options
.htcp
) {
1764 if (p
->options
.htcp_no_clr
) {
1767 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1770 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.toUrl(buf
, 128));
1771 htcpClear(e
, uri
, req
, method
, p
, reason
);