2 * Copyright (C) 1996-2019 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 "base/EnumIterator.h"
15 #include "CacheDigest.h"
16 #include "CachePeer.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"
48 /* count mcast group peers every 15 minutes */
49 #define MCAST_COUNT_RATE 900
51 bool peerAllowedToUse(const CachePeer
*, PeerSelector
*);
52 static int peerWouldBePinged(const CachePeer
*, PeerSelector
*);
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 void peerProbeConnect(CachePeer
*, const bool reprobeIfBusy
= false);
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 AnyP::Uri
&url
)
116 const NeighborTypeDomainList
*d
= NULL
;
118 for (d
= p
->typelist
; d
; d
= d
->next
) {
119 if (0 == matchDomainName(url
.host(), 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
, PeerSelector
* ps
)
139 HttpRequest
*request
= ps
->request
;
140 assert(request
!= NULL
);
142 if (neighborType(p
, request
->url
) == PEER_SIBLING
) {
143 #if PEER_MULTICAST_SIBLINGS
144 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
145 (request
->flags
.noCache
|| request
->flags
.refresh
|| request
->flags
.loopDetected
|| request
->flags
.needValidation
))
146 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->url
.authority() << ") : multicast-siblings optimization match");
148 if (request
->flags
.noCache
)
151 if (request
->flags
.refresh
)
154 if (request
->flags
.loopDetected
)
157 if (request
->flags
.needValidation
)
161 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
162 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
163 if (p
->options
.originserver
&& request
->method
== Http::METHOD_CONNECT
&& request
->url
.port() != p
->http_port
)
166 if (p
->access
== NULL
)
169 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
170 checklist
.al
= ps
->al
;
171 if (ps
->al
&& ps
->al
->reply
) {
172 checklist
.reply
= ps
->al
->reply
.getRaw();
173 HTTPMSGLOCK(checklist
.reply
);
175 checklist
.syncAle(request
, nullptr);
176 return checklist
.fastCheck().allowed();
179 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
181 peerWouldBePinged(const CachePeer
* p
, PeerSelector
* ps
)
184 HttpRequest
*request
= ps
->request
;
186 if (p
->icp
.port
== 0)
189 if (p
->options
.no_query
)
192 if (p
->options
.mcast_responder
)
195 if (p
->n_addresses
== 0)
198 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
201 /* the case below seems strange, but can happen if the
202 * URL host is on the other side of a firewall */
203 if (p
->type
== PEER_SIBLING
)
204 if (!request
->flags
.hierarchical
)
207 if (!peerAllowedToUse(p
, ps
))
210 /* Ping dead peers every timeout interval */
211 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
221 peerCanOpenMore(const CachePeer
*p
)
223 const int effectiveLimit
= p
->max_conn
<= 0 ? Squid_MaxFD
: p
->max_conn
;
224 const int remaining
= effectiveLimit
- p
->stats
.conn_open
;
225 debugs(15, 7, remaining
<< '=' << effectiveLimit
<< '-' << p
->stats
.conn_open
);
226 return remaining
> 0;
230 peerHasConnAvailable(const CachePeer
*p
)
232 // Standby connections can be used without opening new connections.
233 const int standbys
= p
->standby
.pool
? p
->standby
.pool
->count() : 0;
235 // XXX: Some idle pconns can be used without opening new connections.
236 // Complication: Idle pconns cannot be reused for some requests.
237 const int usableIdles
= 0;
239 const int available
= standbys
+ usableIdles
;
240 debugs(15, 7, available
<< '=' << standbys
<< '+' << usableIdles
);
241 return available
> 0;
245 peerConnClosed(CachePeer
*p
)
247 --p
->stats
.conn_open
;
248 if (p
->standby
.waitingForClose
&& peerCanOpenMore(p
)) {
249 p
->standby
.waitingForClose
= false;
250 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "conn closed");
254 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
256 peerHTTPOkay(const CachePeer
* p
, PeerSelector
* ps
)
258 if (!peerCanOpenMore(p
) && !peerHasConnAvailable(p
))
261 if (!peerAllowedToUse(p
, ps
))
271 neighborsCount(PeerSelector
*ps
)
276 for (p
= Config
.peers
; p
; p
= p
->next
)
277 if (peerWouldBePinged(p
, ps
))
280 debugs(15, 3, "neighborsCount: " << count
);
286 getFirstUpParent(PeerSelector
*ps
)
289 HttpRequest
*request
= ps
->request
;
293 for (p
= Config
.peers
; p
; p
= p
->next
) {
297 if (neighborType(p
, request
->url
) != PEER_PARENT
)
300 if (!peerHTTPOkay(p
, ps
))
306 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
311 getRoundRobinParent(PeerSelector
*ps
)
314 HttpRequest
*request
= ps
->request
;
319 for (p
= Config
.peers
; p
; p
= p
->next
) {
320 if (!p
->options
.roundrobin
)
323 if (neighborType(p
, request
->url
) != PEER_PARENT
)
326 if (!peerHTTPOkay(p
, ps
))
333 if (p
->weight
== q
->weight
) {
334 if (q
->rr_count
< p
->rr_count
)
336 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
347 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
353 getWeightedRoundRobinParent(PeerSelector
*ps
)
356 HttpRequest
*request
= ps
->request
;
362 for (p
= Config
.peers
; p
; p
= p
->next
) {
363 if (!p
->options
.weighted_roundrobin
)
366 if (neighborType(p
, request
->url
) != PEER_PARENT
)
369 if (!peerHTTPOkay(p
, ps
))
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
->url
) != 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(PeerSelector
*ps
)
474 HttpRequest
*request
= ps
->request
;
478 for (p
= Config
.peers
; p
; p
= p
->next
) {
479 if (neighborType(p
, request
->url
) != PEER_PARENT
)
482 if (!p
->options
.default_parent
)
485 if (!peerHTTPOkay(p
, ps
))
488 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
493 debugs(15, 3, "getDefaultParent: returning NULL");
498 getNextPeer(CachePeer
* p
)
510 neighborRemove(CachePeer
* target
)
513 CachePeer
**P
= NULL
;
533 first_ping
= Config
.peers
;
537 neighborsRegisterWithCacheManager()
539 Mgr::RegisterAction("server_list",
540 "Peer Cache Statistics",
541 neighborDumpPeers
, 0, 1);
543 if (Comm::IsConnOpen(icpIncomingConn
)) {
544 Mgr::RegisterAction("non_peers",
545 "List of Unknown sites sending ICP messages",
546 neighborDumpNonPeers
, 0, 1);
553 struct servent
*sep
= NULL
;
554 const char *me
= getMyHostname();
555 CachePeer
*thisPeer
= NULL
;
556 CachePeer
*next
= NULL
;
558 neighborsRegisterWithCacheManager();
560 if (Comm::IsConnOpen(icpIncomingConn
)) {
562 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
563 next
= thisPeer
->next
;
565 if (0 != strcmp(thisPeer
->host
, me
))
568 for (AnyP::PortCfgPointer s
= HttpPortList
; s
!= NULL
; s
= s
->next
) {
569 if (thisPeer
->http_port
!= s
->s
.port())
572 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
574 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
575 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
576 "/" << thisPeer
->http_port
<< "/" <<
579 neighborRemove(thisPeer
);
584 peerRefreshDNS((void *) 1);
586 sep
= getservbyname("echo", "udp");
587 echo_port
= sep
? ntohs((unsigned short) sep
->s_port
) : 7;
589 first_ping
= Config
.peers
;
593 neighborsUdpPing(HttpRequest
* request
,
600 const char *url
= entry
->url();
601 MemObject
*mem
= entry
->mem_obj
;
606 int queries_sent
= 0;
607 int peers_pinged
= 0;
608 int parent_timeout
= 0, parent_exprep
= 0;
609 int sibling_timeout
= 0, sibling_exprep
= 0;
610 int mcast_timeout
= 0, mcast_exprep
= 0;
612 if (Config
.peers
== NULL
)
615 assert(!entry
->hasDisk());
617 mem
->start_ping
= current_time
;
619 mem
->ping_reply_callback
= callback
;
623 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
625 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
629 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
631 if (!peerWouldBePinged(p
, ps
))
632 continue; /* next CachePeer */
636 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
638 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
640 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
643 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
644 if (Config
.Port
.htcp
<= 0) {
645 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
649 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
650 if (htcpQuery(entry
, request
, p
) <= 0)
651 continue; // unable to send.
655 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
656 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
660 if (p
->type
== PEER_MULTICAST
)
661 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
663 if (p
->icp
.port
== echo_port
) {
664 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
665 // TODO: Get ALE from callback_data if possible.
666 icpCreateAndSend(ICP_DECHO
, 0, url
, reqnum
, 0,
667 icpOutgoingConn
->fd
, p
->in_addr
, nullptr);
671 if (Config
.onoff
.query_icmp
)
672 if (p
->icp
.version
== ICP_VERSION_2
)
673 flags
|= ICP_FLAG_SRC_RTT
;
675 // TODO: Get ALE from callback_data if possible.
676 icpCreateAndSend(ICP_QUERY
, flags
, url
, reqnum
, 0,
677 icpOutgoingConn
->fd
, p
->in_addr
, nullptr);
684 ++ p
->stats
.pings_sent
;
686 if (p
->type
== PEER_MULTICAST
) {
687 mcast_exprep
+= p
->mcast
.n_replies_expected
;
688 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
689 } else if (neighborUp(p
)) {
690 /* its alive, expect a reply from it */
692 if (neighborType(p
, request
->url
) == PEER_PARENT
) {
694 parent_timeout
+= p
->stats
.rtt
;
697 sibling_timeout
+= p
->stats
.rtt
;
700 /* Neighbor is dead; ping it anyway, but don't expect a reply */
701 /* log it once at the threshold */
703 if (p
->stats
.logged_state
== PEER_ALIVE
) {
704 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
705 p
->stats
.logged_state
= PEER_DEAD
;
709 p
->stats
.last_query
= squid_curtime
;
712 * keep probe_start == 0 for a multicast CachePeer,
713 * so neighborUp() never says this CachePeer is dead.
716 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
717 p
->stats
.probe_start
= squid_curtime
;
720 if ((first_ping
= first_ping
->next
) == NULL
)
721 first_ping
= Config
.peers
;
724 * How many replies to expect?
726 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
729 * If there is a configured timeout, use it
731 if (Config
.Timeout
.icp_query
)
732 *timeout
= Config
.Timeout
.icp_query
;
736 *timeout
= 2 * parent_timeout
/ parent_exprep
;
737 else if (mcast_exprep
)
738 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
740 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
742 *timeout
= 2000; /* 2 seconds */
744 if (Config
.Timeout
.icp_query_max
)
745 if (*timeout
> Config
.Timeout
.icp_query_max
)
746 *timeout
= Config
.Timeout
.icp_query_max
;
748 if (*timeout
< Config
.Timeout
.icp_query_min
)
749 *timeout
= Config
.Timeout
.icp_query_min
;
755 /* lookup the digest of a given CachePeer */
757 peerDigestLookup(CachePeer
* p
, PeerSelector
* ps
)
759 #if USE_CACHE_DIGESTS
761 HttpRequest
*request
= ps
->request
;
762 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
765 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
766 /* does the peeer have a valid digest? */
769 debugs(15, 5, "peerDigestLookup: gone!");
771 } else if (!peerHTTPOkay(p
, ps
)) {
772 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
774 } else if (!p
->digest
->flags
.needed
) {
775 debugs(15, 5, "peerDigestLookup: note need");
776 peerDigestNeeded(p
->digest
);
778 } else if (!p
->digest
->flags
.usable
) {
779 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
783 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
784 assert(p
->digest
->cd
);
785 /* does digest predict a hit? */
787 if (!p
->digest
->cd
->contains(key
))
790 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
799 /* select best CachePeer based on cache digests */
801 neighborsDigestSelect(PeerSelector
*ps
)
803 CachePeer
*best_p
= NULL
;
804 #if USE_CACHE_DIGESTS
806 HttpRequest
*request
= ps
->request
;
809 int choice_count
= 0;
810 int ichoice_count
= 0;
815 if (!request
->flags
.hierarchical
)
818 storeKeyPublicByRequest(request
);
820 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
829 lookup
= peerDigestLookup(p
, ps
);
831 if (lookup
== LOOKUP_NONE
)
836 if (lookup
== LOOKUP_MISS
)
839 p_rtt
= netdbHostRtt(p
->host
);
841 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
843 /* is this CachePeer better than others in terms of rtt ? */
844 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
848 if (p_rtt
) /* informative choice (aka educated guess) */
851 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
855 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
856 peerNoteDigestLookup(request
, best_p
,
857 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
858 request
->hier
.n_choices
= choice_count
;
859 request
->hier
.n_ichoices
= ichoice_count
;
866 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
868 #if USE_CACHE_DIGESTS
870 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
872 *request
->hier
.cd_host
= '\0';
874 request
->hier
.cd_lookup
= lookup
;
875 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
880 neighborAlive(CachePeer
* p
, const MemObject
*, const icp_common_t
* header
)
883 ++ p
->stats
.pings_acked
;
885 if ((icp_opcode
) header
->opcode
<= ICP_END
)
886 ++ p
->icp
.counts
[header
->opcode
];
888 p
->icp
.version
= (int) header
->version
;
892 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
894 int rtt
, rtt_av_factor
;
899 if (!mem
->start_ping
.tv_sec
)
902 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
904 if (rtt
< 1 || rtt
> 10000)
907 rtt_av_factor
= RTT_AV_FACTOR
;
909 if (p
->options
.weighted_roundrobin
)
910 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
912 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
917 neighborAliveHtcp(CachePeer
* p
, const MemObject
*, const HtcpReplyData
* htcp
)
920 ++ p
->stats
.pings_acked
;
921 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
922 p
->htcp
.version
= htcp
->version
;
928 neighborCountIgnored(CachePeer
* p
)
933 ++ p
->stats
.ignored_replies
;
938 static CachePeer
*non_peers
= NULL
;
941 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
945 for (np
= non_peers
; np
; np
= np
->next
) {
946 if (np
->in_addr
!= from
)
949 if (np
->in_addr
.port() != from
.port())
958 np
->icp
.port
= from
.port();
959 np
->type
= PEER_NONE
;
960 np
->host
= new char[MAX_IPSTRLEN
];
961 from
.toStr(np
->host
,MAX_IPSTRLEN
);
962 np
->next
= non_peers
;
966 ++ np
->icp
.counts
[opcode
];
968 if (isPowTen(++np
->stats
.ignored_replies
))
969 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
972 /* ignoreMulticastReply
974 * * We want to ignore replies from multicast peers if the
975 * * cache_host_domain rules would normally prevent the CachePeer
979 ignoreMulticastReply(CachePeer
* p
, PeerSelector
* ps
)
984 if (!p
->options
.mcast_responder
)
987 if (peerHTTPOkay(p
, ps
))
994 * I should attach these records to the entry. We take the first
995 * hit we get our wait until everyone misses. The timeout handler
996 * call needs to nip this shopping list or call one of the misses.
998 * If a hit process is already started, then sobeit
1001 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
1003 CachePeer
*p
= NULL
;
1005 MemObject
*mem
= NULL
;
1006 peer_t ntype
= PEER_NONE
;
1007 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1009 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1011 if ((entry
= Store::Root().findCallbackXXX(key
)))
1012 mem
= entry
->mem_obj
;
1014 if ((p
= whichPeer(from
)))
1015 neighborAlive(p
, mem
, header
);
1017 if (opcode
> ICP_END
)
1020 const char *opcode_d
= icp_opcode_str
[opcode
];
1023 neighborUpdateRtt(p
, mem
);
1025 /* Does the entry exist? */
1026 if (NULL
== entry
) {
1027 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1028 neighborCountIgnored(p
);
1032 /* check if someone is already fetching it */
1033 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1034 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1035 neighborCountIgnored(p
);
1040 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1041 neighborCountIgnored(p
);
1045 if (entry
->ping_status
!= PING_WAITING
) {
1046 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1047 neighborCountIgnored(p
);
1051 if (!entry
->locked()) {
1052 // TODO: many entries are unlocked; why is this reported at level 1?
1053 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1054 neighborCountIgnored(p
);
1058 if (!mem
->ircb_data
) {
1059 debugs(12, DBG_IMPORTANT
, "BUG: missing ICP callback data for " << *entry
);
1060 neighborCountIgnored(p
);
1064 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1067 ntype
= neighborType(p
, mem
->request
->url
);
1070 if (ignoreMulticastReply(p
, mem
->ircb_data
)) {
1071 neighborCountIgnored(p
);
1072 } else if (opcode
== ICP_MISS
) {
1074 neighborIgnoreNonPeer(from
, opcode
);
1076 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1078 } else if (opcode
== ICP_HIT
) {
1080 neighborIgnoreNonPeer(from
, opcode
);
1082 header
->opcode
= ICP_HIT
;
1083 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1085 } else if (opcode
== ICP_DECHO
) {
1087 neighborIgnoreNonPeer(from
, opcode
);
1088 } else if (ntype
== PEER_SIBLING
) {
1089 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1090 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1092 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1094 } else if (opcode
== ICP_SECHO
) {
1096 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << p
->host
);
1097 neighborCountIgnored(p
);
1099 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1101 } else if (opcode
== ICP_DENIED
) {
1103 neighborIgnoreNonPeer(from
, opcode
);
1104 } else if (p
->stats
.pings_acked
> 100) {
1105 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1106 debugs(15, DBG_CRITICAL
, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1107 debugs(15, DBG_CRITICAL
, "Disabling '" << p
->host
<< "', please check your configuration.");
1111 neighborCountIgnored(p
);
1114 } else if (opcode
== ICP_MISS_NOFETCH
) {
1115 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1117 debugs(15, DBG_CRITICAL
, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1122 peerFindByName(const char *name
)
1124 CachePeer
*p
= NULL
;
1126 for (p
= Config
.peers
; p
; p
= p
->next
) {
1127 if (!strcasecmp(name
, p
->name
))
1135 peerFindByNameAndPort(const char *name
, unsigned short port
)
1137 CachePeer
*p
= NULL
;
1139 for (p
= Config
.peers
; p
; p
= p
->next
) {
1140 if (strcasecmp(name
, p
->name
))
1143 if (port
!= p
->http_port
)
1153 neighborUp(const CachePeer
* p
)
1156 peerProbeConnect(const_cast<CachePeer
*>(p
));
1161 * The CachePeer can not be UP if we don't have any IP addresses
1164 if (0 == p
->n_addresses
) {
1165 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1169 if (p
->options
.no_query
) {
1170 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1174 if (p
->stats
.probe_start
!= 0 &&
1175 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1176 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1180 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1184 /// \returns the effective connect timeout for this peer
1186 peerConnectTimeout(const CachePeer
*peer
)
1188 return peer
->connect_timeout_raw
> 0 ?
1189 peer
->connect_timeout_raw
: Config
.Timeout
.peer_connect
;
1193 positiveTimeout(const time_t timeout
)
1195 return max(static_cast<time_t>(1), timeout
);
1199 peerDNSConfigure(const ipcache_addrs
*ia
, const Dns::LookupDetails
&, void *data
)
1201 // TODO: connections to no-longer valid IP addresses should be
1202 // closed when we can detect such IP addresses.
1204 CachePeer
*p
= (CachePeer
*)data
;
1206 if (p
->n_addresses
== 0) {
1207 debugs(15, DBG_IMPORTANT
, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1209 if (p
->type
== PEER_MULTICAST
)
1210 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1216 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1221 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << p
->host
<< "'!");
1225 for (const auto &ip
: ia
->goodAndBad()) { // TODO: Consider using just good().
1226 if (p
->n_addresses
< PEER_MAX_ADDRESSES
) {
1227 const auto idx
= p
->n_addresses
++;
1228 p
->addresses
[idx
] = ip
;
1229 debugs(15, 2, "--> IP address #" << idx
<< ": " << p
->addresses
[idx
]);
1231 debugs(15, 3, "ignoring remaining " << (ia
->size() - p
->n_addresses
) << " ips");
1236 p
->in_addr
.setEmpty();
1237 p
->in_addr
= p
->addresses
[0];
1238 p
->in_addr
.port(p
->icp
.port
);
1240 peerProbeConnect(p
, true); // detect any died or revived peers ASAP
1242 if (p
->type
== PEER_MULTICAST
)
1243 peerCountMcastPeersSchedule(p
, 10);
1246 if (p
->type
!= PEER_MULTICAST
&& IamWorkerProcess())
1247 if (!p
->options
.no_netdb_exchange
)
1248 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1251 if (p
->standby
.mgr
.valid())
1252 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "resolved peer");
1256 peerRefreshDNS(void *data
)
1258 CachePeer
*p
= NULL
;
1260 if (eventFind(peerRefreshDNS
, NULL
))
1261 eventDelete(peerRefreshDNS
, NULL
);
1263 if (!data
&& 0 == stat5minClientRequests()) {
1264 /* no recent client traffic, wait a bit */
1265 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1269 for (p
= Config
.peers
; p
; p
= p
->next
)
1270 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1272 /* Reconfigure the peers every hour */
1273 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1277 peerConnectFailedSilent(CachePeer
* p
)
1279 p
->stats
.last_connect_failure
= squid_curtime
;
1282 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1290 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1291 p
->stats
.logged_state
= PEER_DEAD
;
1296 peerConnectFailed(CachePeer
*p
)
1298 debugs(15, DBG_IMPORTANT
, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1299 peerConnectFailedSilent(p
);
1303 peerConnectSucceded(CachePeer
* p
)
1306 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeeded");
1307 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1309 if (!p
->n_addresses
)
1310 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1312 p
->tcp_up
= p
->connect_fail_limit
;
1315 /// whether new TCP probes are currently banned
1317 peerProbeIsBusy(const CachePeer
*p
)
1319 if (p
->testing_now
> 0) {
1320 debugs(15, 8, "yes, probing " << p
);
1323 if (squid_curtime
- p
->stats
.last_connect_probe
== 0) {
1324 debugs(15, 8, "yes, just probed " << p
);
1330 * peerProbeConnect will be called on dead peers by neighborUp
1333 peerProbeConnect(CachePeer
*p
, const bool reprobeIfBusy
)
1335 if (peerProbeIsBusy(p
)) {
1336 p
->reprobe
= reprobeIfBusy
;
1341 const time_t ctimeout
= peerConnectTimeout(p
);
1342 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1343 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1344 Comm::ConnectionPointer conn
= new Comm::Connection
;
1345 conn
->remote
= p
->addresses
[i
];
1346 conn
->remote
.port(p
->http_port
);
1348 getOutgoingAddress(NULL
, conn
);
1352 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1353 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1354 cs
->setHost(p
->host
);
1355 AsyncJob::Start(cs
);
1358 p
->stats
.last_connect_probe
= squid_curtime
;
1362 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, Comm::Flag status
, int, void *data
)
1364 CachePeer
*p
= (CachePeer
*)data
;
1366 if (status
== Comm::OK
) {
1367 peerConnectSucceded(p
);
1369 peerConnectFailedSilent(p
);
1374 // TODO: log this traffic.
1377 peerProbeConnect(p
);
1381 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1383 if (p
->mcast
.flags
.count_event_pending
)
1386 eventAdd("peerCountMcastPeersStart",
1387 peerCountMcastPeersStart
,
1391 p
->mcast
.flags
.count_event_pending
= true;
1395 peerCountMcastPeersStart(void *data
)
1397 // XXX: Do not create lots of complex fake objects (while abusing their
1398 // APIs) to pass around a few basic data points like start_ping and ping!
1399 CachePeer
*p
= (CachePeer
*)data
;
1402 // TODO: use class AnyP::Uri instead of constructing and re-parsing a string
1403 LOCAL_ARRAY(char, url
, MAX_URL
);
1404 assert(p
->type
== PEER_MULTICAST
);
1405 p
->mcast
.flags
.count_event_pending
= false;
1406 snprintf(url
, MAX_URL
, "http://");
1407 p
->in_addr
.toUrl(url
+7, MAX_URL
-8 );
1409 const MasterXaction::Pointer mx
= new MasterXaction(XactionInitiator::initPeerMcast
);
1410 auto *req
= HttpRequest::FromUrlXXX(url
, mx
);
1411 assert(req
!= nullptr);
1412 StoreEntry
*fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1413 const auto psstate
= new PeerSelector(nullptr);
1414 psstate
->request
= req
;
1415 HTTPMSGLOCK(psstate
->request
);
1416 psstate
->entry
= fake
;
1417 psstate
->peerCountMcastPeerXXX
= cbdataReference(p
);
1418 psstate
->ping
.start
= current_time
;
1419 mem
= fake
->mem_obj
;
1420 mem
->request
= psstate
->request
;
1421 mem
->start_ping
= current_time
;
1422 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1423 mem
->ircb_data
= psstate
;
1424 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1425 p
->mcast
.id
= mem
->id
;
1426 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1427 icpCreateAndSend(ICP_QUERY
, 0, url
, reqnum
, 0,
1428 icpOutgoingConn
->fd
, p
->in_addr
, psstate
->al
);
1429 fake
->ping_status
= PING_WAITING
;
1430 eventAdd("peerCountMcastPeersDone",
1431 peerCountMcastPeersDone
,
1433 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1434 p
->mcast
.flags
.counting
= true;
1435 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1439 peerCountMcastPeersDone(void *data
)
1441 const auto psstate
= static_cast<PeerSelector
*>(data
);
1442 StoreEntry
*fake
= psstate
->entry
;
1444 if (cbdataReferenceValid(psstate
->peerCountMcastPeerXXX
)) {
1445 CachePeer
*p
= (CachePeer
*)psstate
->peerCountMcastPeerXXX
;
1446 p
->mcast
.flags
.counting
= false;
1447 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1448 debugs(15, DBG_IMPORTANT
, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1449 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1450 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1451 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1454 cbdataReferenceDone(psstate
->peerCountMcastPeerXXX
);
1456 fake
->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
1457 fake
->mem_obj
->request
= nullptr;
1458 fake
->unlock("peerCountMcastPeersDone");
1463 peerCountHandleIcpReply(CachePeer
* p
, peer_t
, AnyP::ProtocolType proto
, void *, void *data
)
1465 const auto psstate
= static_cast<PeerSelector
*>(data
);
1466 StoreEntry
*fake
= psstate
->entry
;
1468 MemObject
*mem
= fake
->mem_obj
;
1470 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1471 assert(proto
== AnyP::PROTO_ICP
);
1472 ++ psstate
->ping
.n_recv
;
1473 int rtt_av_factor
= RTT_AV_FACTOR
;
1475 if (p
->options
.weighted_roundrobin
)
1476 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1478 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1482 neighborDumpPeers(StoreEntry
* sentry
)
1484 dump_peers(sentry
, Config
.peers
);
1488 neighborDumpNonPeers(StoreEntry
* sentry
)
1490 dump_peers(sentry
, non_peers
);
1494 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1496 if (p
->options
.proxy_only
)
1497 storeAppendPrintf(sentry
, " proxy-only");
1499 if (p
->options
.no_query
)
1500 storeAppendPrintf(sentry
, " no-query");
1502 if (p
->options
.background_ping
)
1503 storeAppendPrintf(sentry
, " background-ping");
1505 if (p
->options
.no_digest
)
1506 storeAppendPrintf(sentry
, " no-digest");
1508 if (p
->options
.default_parent
)
1509 storeAppendPrintf(sentry
, " default");
1511 if (p
->options
.roundrobin
)
1512 storeAppendPrintf(sentry
, " round-robin");
1514 if (p
->options
.carp
)
1515 storeAppendPrintf(sentry
, " carp");
1518 if (p
->options
.userhash
)
1519 storeAppendPrintf(sentry
, " userhash");
1522 if (p
->options
.sourcehash
)
1523 storeAppendPrintf(sentry
, " sourcehash");
1525 if (p
->options
.weighted_roundrobin
)
1526 storeAppendPrintf(sentry
, " weighted-round-robin");
1528 if (p
->options
.mcast_responder
)
1529 storeAppendPrintf(sentry
, " multicast-responder");
1531 #if PEER_MULTICAST_SIBLINGS
1532 if (p
->options
.mcast_siblings
)
1533 storeAppendPrintf(sentry
, " multicast-siblings");
1537 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1539 if (p
->options
.closest_only
)
1540 storeAppendPrintf(sentry
, " closest-only");
1543 if (p
->options
.htcp
) {
1544 storeAppendPrintf(sentry
, " htcp");
1545 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1546 bool doneopts
= false;
1547 if (p
->options
.htcp_oldsquid
) {
1548 storeAppendPrintf(sentry
, "oldsquid");
1551 if (p
->options
.htcp_no_clr
) {
1552 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
?",":"="));
1555 if (p
->options
.htcp_no_purge_clr
) {
1556 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
?",":"="));
1559 if (p
->options
.htcp_only_clr
) {
1560 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
?",":"="));
1561 //doneopts = true; // uncomment if more opts are added
1567 if (p
->options
.no_netdb_exchange
)
1568 storeAppendPrintf(sentry
, " no-netdb-exchange");
1571 if (p
->options
.no_delay
)
1572 storeAppendPrintf(sentry
, " no-delay");
1576 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1578 if (p
->mcast
.ttl
> 0)
1579 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1581 if (p
->connect_timeout_raw
> 0)
1582 storeAppendPrintf(sentry
, " connect-timeout=%d", (int)p
->connect_timeout_raw
);
1584 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1585 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1587 #if USE_CACHE_DIGESTS
1590 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1594 if (p
->options
.allow_miss
)
1595 storeAppendPrintf(sentry
, " allow-miss");
1597 if (p
->options
.no_tproxy
)
1598 storeAppendPrintf(sentry
, " no-tproxy");
1600 if (p
->max_conn
> 0)
1601 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1602 if (p
->standby
.limit
> 0)
1603 storeAppendPrintf(sentry
, " standby=%d", p
->standby
.limit
);
1605 if (p
->options
.originserver
)
1606 storeAppendPrintf(sentry
, " originserver");
1609 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1611 if (p
->connection_auth
== 0)
1612 storeAppendPrintf(sentry
, " connection-auth=off");
1613 else if (p
->connection_auth
== 1)
1614 storeAppendPrintf(sentry
, " connection-auth=on");
1615 else if (p
->connection_auth
== 2)
1616 storeAppendPrintf(sentry
, " connection-auth=auto");
1618 p
->secure
.dumpCfg(sentry
,"tls-");
1619 storeAppendPrintf(sentry
, "\n");
1623 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1625 char ntoabuf
[MAX_IPSTRLEN
];
1629 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1631 for (CachePeer
*e
= peers
; e
; e
= e
->next
) {
1632 assert(e
->host
!= NULL
);
1633 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1636 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1640 storeAppendPrintf(sentry
, "Flags :");
1641 dump_peer_options(sentry
, e
);
1643 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1644 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1645 e
->addresses
[i
].toStr(ntoabuf
,MAX_IPSTRLEN
) );
1648 storeAppendPrintf(sentry
, "Status : %s\n",
1649 neighborUp(e
) ? "Up" : "Down");
1650 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1651 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1652 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1654 if (!e
->options
.no_query
) {
1655 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1656 (int) (squid_curtime
- e
->stats
.last_query
));
1658 if (e
->stats
.last_reply
> 0)
1659 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1660 (int) (squid_curtime
- e
->stats
.last_reply
));
1662 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1664 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1666 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1667 e
->stats
.pings_acked
,
1668 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1671 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1673 if (!e
->options
.no_query
) {
1674 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1677 if (e
->options
.htcp
) {
1678 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1680 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1681 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1683 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1687 for (auto op
: WholeEnum
<icp_opcode
>()) {
1688 if (e
->icp
.counts
[op
] == 0)
1691 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1694 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1705 if (e
->stats
.last_connect_failure
) {
1706 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1707 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1710 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1716 neighborsHtcpReply(const cache_key
* key
, HtcpReplyData
* htcp
, const Ip::Address
&from
)
1718 StoreEntry
*e
= Store::Root().findCallbackXXX(key
);
1719 MemObject
*mem
= NULL
;
1721 peer_t ntype
= PEER_NONE
;
1722 debugs(15, 6, "neighborsHtcpReply: " <<
1723 (htcp
->hit
? "HIT" : "MISS") << " " <<
1724 storeKeyText(key
) );
1729 if ((p
= whichPeer(from
)))
1730 neighborAliveHtcp(p
, mem
, htcp
);
1732 /* Does the entry exist? */
1734 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1735 neighborCountIgnored(p
);
1739 /* check if someone is already fetching it */
1740 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1741 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1742 neighborCountIgnored(p
);
1747 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1748 neighborCountIgnored(p
);
1752 if (e
->ping_status
!= PING_WAITING
) {
1753 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1754 neighborCountIgnored(p
);
1759 // TODO: many entries are unlocked; why is this reported at level 1?
1760 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1761 neighborCountIgnored(p
);
1765 if (!mem
->ircb_data
) {
1766 debugs(12, DBG_IMPORTANT
, "BUG: missing HTCP callback data for " << *e
);
1767 neighborCountIgnored(p
);
1772 ntype
= neighborType(p
, mem
->request
->url
);
1773 neighborUpdateRtt(p
, mem
);
1776 if (ignoreMulticastReply(p
, mem
->ircb_data
)) {
1777 neighborCountIgnored(p
);
1781 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1782 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1786 * Send HTCP CLR messages to all peers configured to receive them.
1789 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1794 for (p
= Config
.peers
; p
; p
= p
->next
) {
1795 if (!p
->options
.htcp
) {
1798 if (p
->options
.htcp_no_clr
) {
1801 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1804 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.toUrl(buf
, 128));
1805 htcpClear(e
, uri
, req
, method
, p
, reason
);