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 "comm/Connection.h"
17 #include "comm/ConnOpener.h"
22 #include "HttpRequest.h"
23 #include "icmp/net_db.h"
26 #include "ip/Address.h"
29 #include "MemObject.h"
30 #include "mgr/Registration.h"
31 #include "multicast.h"
32 #include "neighbors.h"
33 #include "NeighborTypeDomainList.h"
35 #include "PeerDigest.h"
36 #include "PeerPoolMgr.h"
37 #include "PeerSelectState.h"
38 #include "RequestFlags.h"
39 #include "SquidConfig.h"
40 #include "SquidMath.h"
41 #include "SquidTime.h"
44 #include "store_key_md5.h"
48 /* count mcast group peers every 15 minutes */
49 #define MCAST_COUNT_RATE 900
51 bool peerAllowedToUse(const CachePeer
*, HttpRequest
*);
52 static int peerWouldBePinged(const CachePeer
*, HttpRequest
*);
53 static void neighborRemove(CachePeer
*);
54 static void neighborAlive(CachePeer
*, const MemObject
*, const icp_common_t
*);
56 static void neighborAliveHtcp(CachePeer
*, const MemObject
*, const HtcpReplyData
*);
58 static void neighborCountIgnored(CachePeer
*);
59 static void peerRefreshDNS(void *);
60 static IPH peerDNSConfigure
;
61 static bool peerProbeConnect(CachePeer
*);
62 static CNCB peerProbeConnectDone
;
63 static void peerCountMcastPeersDone(void *data
);
64 static void peerCountMcastPeersStart(void *data
);
65 static void peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
);
66 static IRCB peerCountHandleIcpReply
;
68 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
69 static OBJH neighborDumpPeers
;
70 static OBJH neighborDumpNonPeers
;
71 static void dump_peers(StoreEntry
* sentry
, CachePeer
* peers
);
73 static unsigned short echo_port
;
75 static int NLateReplies
= 0;
76 static CachePeer
*first_ping
= NULL
;
79 neighborTypeStr(const CachePeer
* p
)
81 if (p
->type
== PEER_NONE
)
84 if (p
->type
== PEER_SIBLING
)
87 if (p
->type
== PEER_MULTICAST
)
88 return "Multicast Group";
94 whichPeer(const Ip::Address
&from
)
99 debugs(15, 3, "whichPeer: from " << from
);
101 for (p
= Config
.peers
; p
; p
= p
->next
) {
102 for (j
= 0; j
< p
->n_addresses
; ++j
) {
103 if (from
== p
->addresses
[j
] && from
.port() == p
->icp
.port
) {
113 neighborType(const CachePeer
* p
, const HttpRequest
* request
)
116 const NeighborTypeDomainList
*d
= NULL
;
118 for (d
= p
->typelist
; d
; d
= d
->next
) {
119 if (0 == matchDomainName(request
->GetHost(), d
->domain
))
120 if (d
->type
!= PEER_NONE
)
123 #if PEER_MULTICAST_SIBLINGS
124 if (p
->type
== PEER_MULTICAST
)
125 if (p
->options
.mcast_siblings
)
133 * \return Whether it is appropriate to fetch REQUEST from PEER.
136 peerAllowedToUse(const CachePeer
* p
, HttpRequest
* request
)
139 assert(request
!= NULL
);
141 if (neighborType(p
, request
) == PEER_SIBLING
) {
142 #if PEER_MULTICAST_SIBLINGS
143 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
144 (request
->flags
.noCache
|| request
->flags
.refresh
|| request
->flags
.loopDetected
|| request
->flags
.needValidation
))
145 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->GetHost() << ") : multicast-siblings optimization match");
147 if (request
->flags
.noCache
)
150 if (request
->flags
.refresh
)
153 if (request
->flags
.loopDetected
)
156 if (request
->flags
.needValidation
)
160 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
161 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
162 if (p
->options
.originserver
&& request
->method
== Http::METHOD_CONNECT
&& request
->port
!= p
->in_addr
.port())
165 if (p
->access
== NULL
)
168 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
170 return (checklist
.fastCheck() == ACCESS_ALLOWED
);
173 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
175 peerWouldBePinged(const CachePeer
* p
, HttpRequest
* request
)
177 if (p
->icp
.port
== 0)
180 if (p
->options
.no_query
)
183 if (p
->options
.mcast_responder
)
186 if (p
->n_addresses
== 0)
189 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
192 /* the case below seems strange, but can happen if the
193 * URL host is on the other side of a firewall */
194 if (p
->type
== PEER_SIBLING
)
195 if (!request
->flags
.hierarchical
)
198 if (!peerAllowedToUse(p
, request
))
201 /* Ping dead peers every timeout interval */
202 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
212 peerCanOpenMore(const CachePeer
*p
)
214 const int effectiveLimit
= p
->max_conn
<= 0 ? Squid_MaxFD
: p
->max_conn
;
215 const int remaining
= effectiveLimit
- p
->stats
.conn_open
;
216 debugs(15, 7, remaining
<< '=' << effectiveLimit
<< '-' << p
->stats
.conn_open
);
217 return remaining
> 0;
221 peerHasConnAvailable(const CachePeer
*p
)
223 // Standby connections can be used without opening new connections.
224 const int standbys
= p
->standby
.pool
? p
->standby
.pool
->count() : 0;
226 // XXX: Some idle pconns can be used without opening new connections.
227 // Complication: Idle pconns cannot be reused for some requests.
228 const int usableIdles
= 0;
230 const int available
= standbys
+ usableIdles
;
231 debugs(15, 7, available
<< '=' << standbys
<< '+' << usableIdles
);
232 return available
> 0;
236 peerConnClosed(CachePeer
*p
)
238 --p
->stats
.conn_open
;
239 if (p
->standby
.waitingForClose
&& peerCanOpenMore(p
)) {
240 p
->standby
.waitingForClose
= false;
241 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "conn closed");
245 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
247 peerHTTPOkay(const CachePeer
* p
, HttpRequest
* request
)
249 if (!peerCanOpenMore(p
) && !peerHasConnAvailable(p
))
252 if (!peerAllowedToUse(p
, request
))
262 neighborsCount(HttpRequest
* request
)
267 for (p
= Config
.peers
; p
; p
= p
->next
)
268 if (peerWouldBePinged(p
, request
))
271 debugs(15, 3, "neighborsCount: " << count
);
277 getFirstUpParent(HttpRequest
* request
)
281 for (p
= Config
.peers
; p
; p
= p
->next
) {
285 if (neighborType(p
, request
) != PEER_PARENT
)
288 if (!peerHTTPOkay(p
, request
))
294 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
299 getRoundRobinParent(HttpRequest
* request
)
304 for (p
= Config
.peers
; p
; p
= p
->next
) {
305 if (!p
->options
.roundrobin
)
308 if (neighborType(p
, request
) != PEER_PARENT
)
311 if (!peerHTTPOkay(p
, request
))
318 if (p
->weight
== q
->weight
) {
319 if (q
->rr_count
< p
->rr_count
)
321 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
332 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
338 getWeightedRoundRobinParent(HttpRequest
* request
)
344 for (p
= Config
.peers
; p
; p
= p
->next
) {
345 if (!p
->options
.weighted_roundrobin
)
348 if (neighborType(p
, request
) != PEER_PARENT
)
351 if (!peerHTTPOkay(p
, request
))
354 if (q
&& q
->rr_count
< p
->rr_count
)
360 if (q
&& q
->rr_count
> 1000000)
361 for (p
= Config
.peers
; p
; p
= p
->next
) {
362 if (!p
->options
.weighted_roundrobin
)
365 if (neighborType(p
, request
) != PEER_PARENT
)
372 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
374 if (weighted_rtt
< 1)
377 q
->rr_count
+= weighted_rtt
;
379 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
382 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
387 * This gets called every 5 minutes to clear the round-robin counter.
388 * The exact timing is an arbitrary default, set on estimate timing of a
389 * large number of requests in a high-performance environment during the
390 * period. The larger the number of requests between cycled resets the
391 * more balanced the operations.
394 \todo Make the reset timing a selectable parameter in squid.conf
397 peerClearRRLoop(void *data
)
400 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
404 * This gets called on startup and restart to kick off the CachePeer round-robin
405 * maintenance event. It ensures that no matter how many times its called
406 * no more than one event is scheduled.
409 peerClearRRStart(void)
411 static bool event_added
= false;
413 peerClearRRLoop(NULL
);
419 * Called whenever the round-robin counters need to be reset to a sane state.
420 * So far those times are:
421 * - On startup and reconfigure - to set the counters to sane initial settings.
422 * - When a CachePeer has revived from dead, to prevent the revived CachePeer being
423 * flooded with requests which it has 'missed' during the down period.
429 for (p
= Config
.peers
; p
; p
= p
->next
) {
435 * Perform all actions when a CachePeer is detected revived.
438 peerAlive(CachePeer
*p
)
440 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
441 debugs(15, DBG_IMPORTANT
, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
442 p
->stats
.logged_state
= PEER_ALIVE
;
444 if (p
->standby
.mgr
.valid())
445 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "revived peer");
448 p
->stats
.last_reply
= squid_curtime
;
449 p
->stats
.probe_start
= 0;
453 getDefaultParent(HttpRequest
* request
)
457 for (p
= Config
.peers
; p
; p
= p
->next
) {
458 if (neighborType(p
, request
) != PEER_PARENT
)
461 if (!p
->options
.default_parent
)
464 if (!peerHTTPOkay(p
, request
))
467 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
472 debugs(15, 3, "getDefaultParent: returning NULL");
477 getNextPeer(CachePeer
* p
)
489 neighborRemove(CachePeer
* target
)
492 CachePeer
**P
= NULL
;
512 first_ping
= Config
.peers
;
516 neighborsRegisterWithCacheManager()
518 Mgr::RegisterAction("server_list",
519 "Peer Cache Statistics",
520 neighborDumpPeers
, 0, 1);
522 if (Comm::IsConnOpen(icpIncomingConn
)) {
523 Mgr::RegisterAction("non_peers",
524 "List of Unknown sites sending ICP messages",
525 neighborDumpNonPeers
, 0, 1);
532 struct servent
*sep
= NULL
;
533 const char *me
= getMyHostname();
534 CachePeer
*thisPeer
= NULL
;
535 CachePeer
*next
= NULL
;
537 neighborsRegisterWithCacheManager();
539 if (Comm::IsConnOpen(icpIncomingConn
)) {
541 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
542 next
= thisPeer
->next
;
544 if (0 != strcmp(thisPeer
->host
, me
))
547 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
548 if (thisPeer
->http_port
!= s
->s
.port())
551 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
553 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
554 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
555 "/" << thisPeer
->http_port
<< "/" <<
558 neighborRemove(thisPeer
);
563 peerRefreshDNS((void *) 1);
565 sep
= getservbyname("echo", "udp");
566 echo_port
= sep
? ntohs((unsigned short) sep
->s_port
) : 7;
568 first_ping
= Config
.peers
;
572 neighborsUdpPing(HttpRequest
* request
,
579 const char *url
= entry
->url();
580 MemObject
*mem
= entry
->mem_obj
;
586 int queries_sent
= 0;
587 int peers_pinged
= 0;
588 int parent_timeout
= 0, parent_exprep
= 0;
589 int sibling_timeout
= 0, sibling_exprep
= 0;
590 int mcast_timeout
= 0, mcast_exprep
= 0;
592 if (Config
.peers
== NULL
)
595 assert(entry
->swap_status
== SWAPOUT_NONE
);
597 mem
->start_ping
= current_time
;
599 mem
->ping_reply_callback
= callback
;
601 mem
->ircb_data
= callback_data
;
603 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
605 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
609 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
611 if (!peerWouldBePinged(p
, request
))
612 continue; /* next CachePeer */
616 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
618 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
620 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
623 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
624 if (Config
.Port
.htcp
<= 0) {
625 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
629 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
630 if (htcpQuery(entry
, request
, p
) <= 0)
631 continue; // unable to send.
635 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
636 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
640 if (p
->type
== PEER_MULTICAST
)
641 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
643 if (p
->icp
.port
== echo_port
) {
644 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
645 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
646 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
650 if (Config
.onoff
.query_icmp
)
651 if (p
->icp
.version
== ICP_VERSION_2
)
652 flags
|= ICP_FLAG_SRC_RTT
;
654 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
656 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0.0);
663 ++ p
->stats
.pings_sent
;
665 if (p
->type
== PEER_MULTICAST
) {
666 mcast_exprep
+= p
->mcast
.n_replies_expected
;
667 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
668 } else if (neighborUp(p
)) {
669 /* its alive, expect a reply from it */
671 if (neighborType(p
, request
) == PEER_PARENT
) {
673 parent_timeout
+= p
->stats
.rtt
;
676 sibling_timeout
+= p
->stats
.rtt
;
679 /* Neighbor is dead; ping it anyway, but don't expect a reply */
680 /* log it once at the threshold */
682 if (p
->stats
.logged_state
== PEER_ALIVE
) {
683 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
684 p
->stats
.logged_state
= PEER_DEAD
;
688 p
->stats
.last_query
= squid_curtime
;
691 * keep probe_start == 0 for a multicast CachePeer,
692 * so neighborUp() never says this CachePeer is dead.
695 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
696 p
->stats
.probe_start
= squid_curtime
;
699 if ((first_ping
= first_ping
->next
) == NULL
)
700 first_ping
= Config
.peers
;
703 * How many replies to expect?
705 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
708 * If there is a configured timeout, use it
710 if (Config
.Timeout
.icp_query
)
711 *timeout
= Config
.Timeout
.icp_query
;
715 *timeout
= 2 * parent_timeout
/ parent_exprep
;
716 else if (mcast_exprep
)
717 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
719 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
721 *timeout
= 2000; /* 2 seconds */
723 if (Config
.Timeout
.icp_query_max
)
724 if (*timeout
> Config
.Timeout
.icp_query_max
)
725 *timeout
= Config
.Timeout
.icp_query_max
;
727 if (*timeout
< Config
.Timeout
.icp_query_min
)
728 *timeout
= Config
.Timeout
.icp_query_min
;
734 /* lookup the digest of a given CachePeer */
736 peerDigestLookup(CachePeer
* p
, HttpRequest
* request
)
738 #if USE_CACHE_DIGESTS
739 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
742 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
743 /* does the peeer have a valid digest? */
746 debugs(15, 5, "peerDigestLookup: gone!");
748 } else if (!peerHTTPOkay(p
, request
)) {
749 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
751 } else if (!p
->digest
->flags
.needed
) {
752 debugs(15, 5, "peerDigestLookup: note need");
753 peerDigestNeeded(p
->digest
);
755 } else if (!p
->digest
->flags
.usable
) {
756 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
760 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
761 assert(p
->digest
->cd
);
762 /* does digest predict a hit? */
764 if (!cacheDigestTest(p
->digest
->cd
, key
))
767 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
776 /* select best CachePeer based on cache digests */
778 neighborsDigestSelect(HttpRequest
* request
)
780 CachePeer
*best_p
= NULL
;
781 #if USE_CACHE_DIGESTS
784 int choice_count
= 0;
785 int ichoice_count
= 0;
790 if (!request
->flags
.hierarchical
)
793 storeKeyPublicByRequest(request
);
795 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
804 lookup
= peerDigestLookup(p
, request
);
806 if (lookup
== LOOKUP_NONE
)
811 if (lookup
== LOOKUP_MISS
)
814 p_rtt
= netdbHostRtt(p
->host
);
816 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
818 /* is this CachePeer better than others in terms of rtt ? */
819 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
823 if (p_rtt
) /* informative choice (aka educated guess) */
826 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
830 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
831 peerNoteDigestLookup(request
, best_p
,
832 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
833 request
->hier
.n_choices
= choice_count
;
834 request
->hier
.n_ichoices
= ichoice_count
;
841 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
843 #if USE_CACHE_DIGESTS
845 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
847 *request
->hier
.cd_host
= '\0';
849 request
->hier
.cd_lookup
= lookup
;
850 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
855 neighborAlive(CachePeer
* p
, const MemObject
*, const icp_common_t
* header
)
858 ++ p
->stats
.pings_acked
;
860 if ((icp_opcode
) header
->opcode
<= ICP_END
)
861 ++ p
->icp
.counts
[header
->opcode
];
863 p
->icp
.version
= (int) header
->version
;
867 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
869 int rtt
, rtt_av_factor
;
874 if (!mem
->start_ping
.tv_sec
)
877 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
879 if (rtt
< 1 || rtt
> 10000)
882 rtt_av_factor
= RTT_AV_FACTOR
;
884 if (p
->options
.weighted_roundrobin
)
885 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
887 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
892 neighborAliveHtcp(CachePeer
* p
, const MemObject
*, const HtcpReplyData
* htcp
)
895 ++ p
->stats
.pings_acked
;
896 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
897 p
->htcp
.version
= htcp
->version
;
903 neighborCountIgnored(CachePeer
* p
)
908 ++ p
->stats
.ignored_replies
;
913 static CachePeer
*non_peers
= NULL
;
916 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
920 for (np
= non_peers
; np
; np
= np
->next
) {
921 if (np
->in_addr
!= from
)
924 if (np
->in_addr
.port() != from
.port())
933 np
->icp
.port
= from
.port();
934 np
->type
= PEER_NONE
;
935 np
->host
= new char[MAX_IPSTRLEN
];
936 from
.toStr(np
->host
,MAX_IPSTRLEN
);
937 np
->next
= non_peers
;
941 ++ np
->icp
.counts
[opcode
];
943 if (isPowTen(++np
->stats
.ignored_replies
))
944 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
947 /* ignoreMulticastReply
949 * * We want to ignore replies from multicast peers if the
950 * * cache_host_domain rules would normally prevent the CachePeer
954 ignoreMulticastReply(CachePeer
* p
, MemObject
* mem
)
959 if (!p
->options
.mcast_responder
)
962 if (peerHTTPOkay(p
, mem
->request
))
969 * I should attach these records to the entry. We take the first
970 * hit we get our wait until everyone misses. The timeout handler
971 * call needs to nip this shopping list or call one of the misses.
973 * If a hit process is already started, then sobeit
976 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
980 MemObject
*mem
= NULL
;
981 peer_t ntype
= PEER_NONE
;
982 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
984 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
986 if (NULL
!= (entry
= Store::Root().get(key
)))
987 mem
= entry
->mem_obj
;
989 if ((p
= whichPeer(from
)))
990 neighborAlive(p
, mem
, header
);
992 if (opcode
> ICP_END
)
995 const char *opcode_d
= icp_opcode_str
[opcode
];
998 neighborUpdateRtt(p
, mem
);
1000 /* Does the entry exist? */
1001 if (NULL
== entry
) {
1002 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1003 neighborCountIgnored(p
);
1007 /* check if someone is already fetching it */
1008 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1009 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1010 neighborCountIgnored(p
);
1015 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1016 neighborCountIgnored(p
);
1020 if (entry
->ping_status
!= PING_WAITING
) {
1021 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1022 neighborCountIgnored(p
);
1026 if (!entry
->locked()) {
1027 // TODO: many entries are unlocked; why is this reported at level 1?
1028 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1029 neighborCountIgnored(p
);
1033 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1036 ntype
= neighborType(p
, mem
->request
);
1039 if (ignoreMulticastReply(p
, mem
)) {
1040 neighborCountIgnored(p
);
1041 } else if (opcode
== ICP_MISS
) {
1043 neighborIgnoreNonPeer(from
, opcode
);
1045 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1047 } else if (opcode
== ICP_HIT
) {
1049 neighborIgnoreNonPeer(from
, opcode
);
1051 header
->opcode
= ICP_HIT
;
1052 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1054 } else if (opcode
== ICP_DECHO
) {
1056 neighborIgnoreNonPeer(from
, opcode
);
1057 } else if (ntype
== PEER_SIBLING
) {
1058 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1059 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1061 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1063 } else if (opcode
== ICP_SECHO
) {
1065 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << p
->host
);
1066 neighborCountIgnored(p
);
1068 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1070 } else if (opcode
== ICP_DENIED
) {
1072 neighborIgnoreNonPeer(from
, opcode
);
1073 } else if (p
->stats
.pings_acked
> 100) {
1074 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1075 debugs(15, DBG_CRITICAL
, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1076 debugs(15, DBG_CRITICAL
, "Disabling '" << p
->host
<< "', please check your configuration.");
1080 neighborCountIgnored(p
);
1083 } else if (opcode
== ICP_MISS_NOFETCH
) {
1084 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1086 debugs(15, DBG_CRITICAL
, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1091 peerFindByName(const char *name
)
1093 CachePeer
*p
= NULL
;
1095 for (p
= Config
.peers
; p
; p
= p
->next
) {
1096 if (!strcasecmp(name
, p
->name
))
1104 peerFindByNameAndPort(const char *name
, unsigned short port
)
1106 CachePeer
*p
= NULL
;
1108 for (p
= Config
.peers
; p
; p
= p
->next
) {
1109 if (strcasecmp(name
, p
->name
))
1112 if (port
!= p
->http_port
)
1122 neighborUp(const CachePeer
* p
)
1125 if (!peerProbeConnect((CachePeer
*) p
)) {
1126 debugs(15, 8, "neighborUp: DOWN (probed): " << p
->host
<< " (" << p
->in_addr
<< ")");
1132 * The CachePeer can not be UP if we don't have any IP addresses
1135 if (0 == p
->n_addresses
) {
1136 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1140 if (p
->options
.no_query
) {
1141 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1145 if (p
->stats
.probe_start
!= 0 &&
1146 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1147 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1151 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1156 peerNoteDigestGone(CachePeer
* p
)
1158 #if USE_CACHE_DIGESTS
1159 cbdataReferenceDone(p
->digest
);
1164 peerDNSConfigure(const ipcache_addrs
*ia
, const Dns::LookupDetails
&, void *data
)
1166 // TODO: connections to no-longer valid IP addresses should be
1167 // closed when we can detect such IP addresses.
1169 CachePeer
*p
= (CachePeer
*)data
;
1173 if (p
->n_addresses
== 0) {
1174 debugs(15, DBG_IMPORTANT
, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1176 if (p
->type
== PEER_MULTICAST
)
1177 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1183 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1187 if ((int) ia
->count
< 1) {
1188 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << p
->host
<< "'!");
1192 p
->tcp_up
= p
->connect_fail_limit
;
1194 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; ++j
) {
1195 p
->addresses
[j
] = ia
->in_addrs
[j
];
1196 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1200 p
->in_addr
.setEmpty();
1201 p
->in_addr
= p
->addresses
[0];
1202 p
->in_addr
.port(p
->icp
.port
);
1204 if (p
->type
== PEER_MULTICAST
)
1205 peerCountMcastPeersSchedule(p
, 10);
1208 if (p
->type
!= PEER_MULTICAST
&& IamWorkerProcess())
1209 if (!p
->options
.no_netdb_exchange
)
1210 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1213 if (p
->standby
.mgr
.valid())
1214 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "resolved peer");
1218 peerRefreshDNS(void *data
)
1220 CachePeer
*p
= NULL
;
1222 if (eventFind(peerRefreshDNS
, NULL
))
1223 eventDelete(peerRefreshDNS
, NULL
);
1225 if (!data
&& 0 == stat5minClientRequests()) {
1226 /* no recent client traffic, wait a bit */
1227 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1231 for (p
= Config
.peers
; p
; p
= p
->next
)
1232 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1234 /* Reconfigure the peers every hour */
1235 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1239 peerConnectFailedSilent(CachePeer
* p
)
1241 p
->stats
.last_connect_failure
= squid_curtime
;
1244 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1252 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1253 p
->stats
.logged_state
= PEER_DEAD
;
1258 peerConnectFailed(CachePeer
*p
)
1260 debugs(15, DBG_IMPORTANT
, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1261 peerConnectFailedSilent(p
);
1265 peerConnectSucceded(CachePeer
* p
)
1268 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1269 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1271 if (!p
->n_addresses
)
1272 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1274 p
->tcp_up
= p
->connect_fail_limit
;
1278 * peerProbeConnect will be called on dead peers by neighborUp
1281 peerProbeConnect(CachePeer
* p
)
1283 time_t ctimeout
= p
->connect_timeout
> 0 ? p
->connect_timeout
: Config
.Timeout
.peer_connect
;
1284 bool ret
= (squid_curtime
- p
->stats
.last_connect_failure
) > (ctimeout
* 10);
1286 if (p
->testing_now
> 0)
1287 return ret
;/* probe already running */
1289 if (squid_curtime
- p
->stats
.last_connect_probe
== 0)
1290 return ret
;/* don't probe to often */
1292 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1293 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1294 Comm::ConnectionPointer conn
= new Comm::Connection
;
1295 conn
->remote
= p
->addresses
[i
];
1296 conn
->remote
.port(p
->http_port
);
1298 getOutgoingAddress(NULL
, conn
);
1302 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1303 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1304 cs
->setHost(p
->host
);
1305 AsyncJob::Start(cs
);
1308 p
->stats
.last_connect_probe
= squid_curtime
;
1314 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, Comm::Flag status
, int, void *data
)
1316 CachePeer
*p
= (CachePeer
*)data
;
1318 if (status
== Comm::OK
) {
1319 peerConnectSucceded(p
);
1321 peerConnectFailedSilent(p
);
1326 // TODO: log this traffic.
1330 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1332 if (p
->mcast
.flags
.count_event_pending
)
1335 eventAdd("peerCountMcastPeersStart",
1336 peerCountMcastPeersStart
,
1340 p
->mcast
.flags
.count_event_pending
= true;
1344 peerCountMcastPeersStart(void *data
)
1346 CachePeer
*p
= (CachePeer
*)data
;
1350 icp_common_t
*query
;
1352 LOCAL_ARRAY(char, url
, MAX_URL
);
1353 assert(p
->type
== PEER_MULTICAST
);
1354 p
->mcast
.flags
.count_event_pending
= false;
1355 snprintf(url
, MAX_URL
, "http://");
1356 p
->in_addr
.toUrl(url
+7, MAX_URL
-8 );
1358 fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1359 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1360 psstate
= new ps_state
;
1361 psstate
->request
= req
;
1362 HTTPMSGLOCK(psstate
->request
);
1363 psstate
->entry
= fake
;
1364 psstate
->callback
= NULL
;
1365 psstate
->callback_data
= cbdataReference(p
);
1366 psstate
->ping
.start
= current_time
;
1367 mem
= fake
->mem_obj
;
1368 mem
->request
= psstate
->request
;
1369 HTTPMSGLOCK(mem
->request
);
1370 mem
->start_ping
= current_time
;
1371 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1372 mem
->ircb_data
= psstate
;
1373 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1374 p
->mcast
.id
= mem
->id
;
1375 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1376 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1377 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
1378 fake
->ping_status
= PING_WAITING
;
1379 eventAdd("peerCountMcastPeersDone",
1380 peerCountMcastPeersDone
,
1382 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1383 p
->mcast
.flags
.counting
= true;
1384 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1388 peerCountMcastPeersDone(void *data
)
1390 ps_state
*psstate
= (ps_state
*)data
;
1391 StoreEntry
*fake
= psstate
->entry
;
1393 if (cbdataReferenceValid(psstate
->callback_data
)) {
1394 CachePeer
*p
= (CachePeer
*)psstate
->callback_data
;
1395 p
->mcast
.flags
.counting
= false;
1396 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1397 debugs(15, DBG_IMPORTANT
, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1398 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1399 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1400 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1403 cbdataReferenceDone(psstate
->callback_data
);
1405 fake
->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
1406 HTTPMSGUNLOCK(fake
->mem_obj
->request
);
1407 fake
->unlock("peerCountMcastPeersDone");
1412 peerCountHandleIcpReply(CachePeer
* p
, peer_t
, AnyP::ProtocolType proto
, void *, void *data
)
1414 ps_state
*psstate
= (ps_state
*)data
;
1415 StoreEntry
*fake
= psstate
->entry
;
1417 MemObject
*mem
= fake
->mem_obj
;
1419 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1420 assert(proto
== AnyP::PROTO_ICP
);
1421 ++ psstate
->ping
.n_recv
;
1422 int rtt_av_factor
= RTT_AV_FACTOR
;
1424 if (p
->options
.weighted_roundrobin
)
1425 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1427 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1431 neighborDumpPeers(StoreEntry
* sentry
)
1433 dump_peers(sentry
, Config
.peers
);
1437 neighborDumpNonPeers(StoreEntry
* sentry
)
1439 dump_peers(sentry
, non_peers
);
1443 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1445 if (p
->options
.proxy_only
)
1446 storeAppendPrintf(sentry
, " proxy-only");
1448 if (p
->options
.no_query
)
1449 storeAppendPrintf(sentry
, " no-query");
1451 if (p
->options
.background_ping
)
1452 storeAppendPrintf(sentry
, " background-ping");
1454 if (p
->options
.no_digest
)
1455 storeAppendPrintf(sentry
, " no-digest");
1457 if (p
->options
.default_parent
)
1458 storeAppendPrintf(sentry
, " default");
1460 if (p
->options
.roundrobin
)
1461 storeAppendPrintf(sentry
, " round-robin");
1463 if (p
->options
.carp
)
1464 storeAppendPrintf(sentry
, " carp");
1467 if (p
->options
.userhash
)
1468 storeAppendPrintf(sentry
, " userhash");
1471 if (p
->options
.sourcehash
)
1472 storeAppendPrintf(sentry
, " sourcehash");
1474 if (p
->options
.weighted_roundrobin
)
1475 storeAppendPrintf(sentry
, " weighted-round-robin");
1477 if (p
->options
.mcast_responder
)
1478 storeAppendPrintf(sentry
, " multicast-responder");
1480 #if PEER_MULTICAST_SIBLINGS
1481 if (p
->options
.mcast_siblings
)
1482 storeAppendPrintf(sentry
, " multicast-siblings");
1486 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1488 if (p
->options
.closest_only
)
1489 storeAppendPrintf(sentry
, " closest-only");
1492 if (p
->options
.htcp
) {
1493 storeAppendPrintf(sentry
, " htcp");
1494 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1496 if (p
->options
.htcp_oldsquid
)
1497 storeAppendPrintf(sentry
, "%soldsquid",(doneopts
++>0?",":"="));
1498 if (p
->options
.htcp_no_clr
)
1499 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
++>0?",":"="));
1500 if (p
->options
.htcp_no_purge_clr
)
1501 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
++>0?",":"="));
1502 if (p
->options
.htcp_only_clr
)
1503 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
++>0?",":"="));
1508 if (p
->options
.no_netdb_exchange
)
1509 storeAppendPrintf(sentry
, " no-netdb-exchange");
1512 if (p
->options
.no_delay
)
1513 storeAppendPrintf(sentry
, " no-delay");
1517 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1519 if (p
->mcast
.ttl
> 0)
1520 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1522 if (p
->connect_timeout
> 0)
1523 storeAppendPrintf(sentry
, " connect-timeout=%d", (int) p
->connect_timeout
);
1525 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1526 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1528 #if USE_CACHE_DIGESTS
1531 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1535 if (p
->options
.allow_miss
)
1536 storeAppendPrintf(sentry
, " allow-miss");
1538 if (p
->options
.no_tproxy
)
1539 storeAppendPrintf(sentry
, " no-tproxy");
1541 if (p
->max_conn
> 0)
1542 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1543 if (p
->standby
.limit
> 0)
1544 storeAppendPrintf(sentry
, " standby=%d", p
->standby
.limit
);
1546 if (p
->options
.originserver
)
1547 storeAppendPrintf(sentry
, " originserver");
1550 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1552 if (p
->connection_auth
== 0)
1553 storeAppendPrintf(sentry
, " connection-auth=off");
1554 else if (p
->connection_auth
== 1)
1555 storeAppendPrintf(sentry
, " connection-auth=on");
1556 else if (p
->connection_auth
== 2)
1557 storeAppendPrintf(sentry
, " connection-auth=auto");
1559 storeAppendPrintf(sentry
, "\n");
1563 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1565 char ntoabuf
[MAX_IPSTRLEN
];
1570 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1572 for (CachePeer
*e
= peers
; e
; e
= e
->next
) {
1573 assert(e
->host
!= NULL
);
1574 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1577 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1581 storeAppendPrintf(sentry
, "Flags :");
1582 dump_peer_options(sentry
, e
);
1584 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1585 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1586 e
->addresses
[i
].toStr(ntoabuf
,MAX_IPSTRLEN
) );
1589 storeAppendPrintf(sentry
, "Status : %s\n",
1590 neighborUp(e
) ? "Up" : "Down");
1591 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1592 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1593 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1595 if (!e
->options
.no_query
) {
1596 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1597 (int) (squid_curtime
- e
->stats
.last_query
));
1599 if (e
->stats
.last_reply
> 0)
1600 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1601 (int) (squid_curtime
- e
->stats
.last_reply
));
1603 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1605 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1607 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1608 e
->stats
.pings_acked
,
1609 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1612 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1614 if (!e
->options
.no_query
) {
1615 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1618 if (e
->options
.htcp
) {
1619 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1621 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1622 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1624 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1628 for (op
= ICP_INVALID
; op
< ICP_END
; ++op
) {
1629 if (e
->icp
.counts
[op
] == 0)
1632 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1635 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1646 if (e
->stats
.last_connect_failure
) {
1647 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1648 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1651 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1657 neighborsHtcpReply(const cache_key
* key
, HtcpReplyData
* htcp
, const Ip::Address
&from
)
1659 StoreEntry
*e
= Store::Root().get(key
);
1660 MemObject
*mem
= NULL
;
1662 peer_t ntype
= PEER_NONE
;
1663 debugs(15, 6, "neighborsHtcpReply: " <<
1664 (htcp
->hit
? "HIT" : "MISS") << " " <<
1665 storeKeyText(key
) );
1670 if ((p
= whichPeer(from
)))
1671 neighborAliveHtcp(p
, mem
, htcp
);
1673 /* Does the entry exist? */
1675 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1676 neighborCountIgnored(p
);
1680 /* check if someone is already fetching it */
1681 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1682 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1683 neighborCountIgnored(p
);
1688 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1689 neighborCountIgnored(p
);
1693 if (e
->ping_status
!= PING_WAITING
) {
1694 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1695 neighborCountIgnored(p
);
1700 // TODO: many entries are unlocked; why is this reported at level 1?
1701 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1702 neighborCountIgnored(p
);
1707 ntype
= neighborType(p
, mem
->request
);
1708 neighborUpdateRtt(p
, mem
);
1711 if (ignoreMulticastReply(p
, mem
)) {
1712 neighborCountIgnored(p
);
1716 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1717 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1721 * Send HTCP CLR messages to all peers configured to receive them.
1724 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1729 for (p
= Config
.peers
; p
; p
= p
->next
) {
1730 if (!p
->options
.htcp
) {
1733 if (p
->options
.htcp_no_clr
) {
1736 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1739 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.toUrl(buf
, 128));
1740 htcpClear(e
, uri
, req
, method
, p
, reason
);