2 * DEBUG: section 15 Neighbor Routines
3 * AUTHOR: Harvest Derived
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 #include "acl/FilledChecklist.h"
35 #include "anyp/PortCfg.h"
36 #include "CacheDigest.h"
37 #include "CachePeer.h"
38 #include "CachePeerDomainList.h"
39 #include "comm/Connection.h"
40 #include "comm/ConnOpener.h"
45 #include "HttpRequest.h"
46 #include "icmp/net_db.h"
49 #include "ip/Address.h"
52 #include "MemObject.h"
53 #include "mgr/Registration.h"
54 #include "multicast.h"
55 #include "neighbors.h"
56 #include "NeighborTypeDomainList.h"
58 #include "PeerDigest.h"
59 #include "PeerPoolMgr.h"
60 #include "PeerSelectState.h"
61 #include "RequestFlags.h"
62 #include "SquidConfig.h"
63 #include "SquidMath.h"
64 #include "SquidTime.h"
67 #include "store_key_md5.h"
71 /* count mcast group peers every 15 minutes */
72 #define MCAST_COUNT_RATE 900
74 bool peerAllowedToUse(const CachePeer
*, HttpRequest
*);
75 static int peerWouldBePinged(const CachePeer
*, HttpRequest
*);
76 static void neighborRemove(CachePeer
*);
77 static void neighborAlive(CachePeer
*, const MemObject
*, const icp_common_t
*);
79 static void neighborAliveHtcp(CachePeer
*, const MemObject
*, const HtcpReplyData
*);
81 static void neighborCountIgnored(CachePeer
*);
82 static void peerRefreshDNS(void *);
83 static IPH peerDNSConfigure
;
84 static bool peerProbeConnect(CachePeer
*);
85 static CNCB peerProbeConnectDone
;
86 static void peerCountMcastPeersDone(void *data
);
87 static void peerCountMcastPeersStart(void *data
);
88 static void peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
);
89 static IRCB peerCountHandleIcpReply
;
91 static void neighborIgnoreNonPeer(const Ip::Address
&, icp_opcode
);
92 static OBJH neighborDumpPeers
;
93 static OBJH neighborDumpNonPeers
;
94 static void dump_peers(StoreEntry
* sentry
, CachePeer
* peers
);
96 static unsigned short echo_port
;
98 static int NLateReplies
= 0;
99 static CachePeer
*first_ping
= NULL
;
102 neighborTypeStr(const CachePeer
* p
)
104 if (p
->type
== PEER_NONE
)
107 if (p
->type
== PEER_SIBLING
)
110 if (p
->type
== PEER_MULTICAST
)
111 return "Multicast Group";
117 whichPeer(const Ip::Address
&from
)
122 debugs(15, 3, "whichPeer: from " << from
);
124 for (p
= Config
.peers
; p
; p
= p
->next
) {
125 for (j
= 0; j
< p
->n_addresses
; ++j
) {
126 if (from
== p
->addresses
[j
] && from
.port() == p
->icp
.port
) {
136 neighborType(const CachePeer
* p
, const HttpRequest
* request
)
139 const NeighborTypeDomainList
*d
= NULL
;
141 for (d
= p
->typelist
; d
; d
= d
->next
) {
142 if (0 == matchDomainName(request
->GetHost(), d
->domain
))
143 if (d
->type
!= PEER_NONE
)
146 #if PEER_MULTICAST_SIBLINGS
147 if (p
->type
== PEER_MULTICAST
)
148 if (p
->options
.mcast_siblings
)
156 * \return Whether it is appropriate to fetch REQUEST from PEER.
159 peerAllowedToUse(const CachePeer
* p
, HttpRequest
* request
)
162 const CachePeerDomainList
*d
= NULL
;
163 assert(request
!= NULL
);
165 if (neighborType(p
, request
) == PEER_SIBLING
) {
166 #if PEER_MULTICAST_SIBLINGS
167 if (p
->type
== PEER_MULTICAST
&& p
->options
.mcast_siblings
&&
168 (request
->flags
.noCache
|| request
->flags
.refresh
|| request
->flags
.loopDetected
|| request
->flags
.needValidation
))
169 debugs(15, 2, "peerAllowedToUse(" << p
->name
<< ", " << request
->GetHost() << ") : multicast-siblings optimization match");
171 if (request
->flags
.noCache
)
174 if (request
->flags
.refresh
)
177 if (request
->flags
.loopDetected
)
180 if (request
->flags
.needValidation
)
184 // CONNECT requests are proxy requests. Not to be forwarded to origin servers.
185 // Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
186 if (p
->options
.originserver
&& request
->method
== Http::METHOD_CONNECT
&& request
->port
!= p
->in_addr
.port())
189 if (p
->peer_domain
== NULL
&& p
->access
== NULL
)
192 bool do_ping
= false;
193 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
194 if (0 == matchDomainName(request
->GetHost(), d
->domain
)) {
195 do_ping
= d
->do_ping
;
199 do_ping
= !d
->do_ping
;
202 if (p
->peer_domain
&& !do_ping
)
205 if (p
->access
== NULL
)
208 ACLFilledChecklist
checklist(p
->access
, request
, NULL
);
210 return (checklist
.fastCheck() == ACCESS_ALLOWED
);
213 /* Return TRUE if it is okay to send an ICP request to this CachePeer. */
215 peerWouldBePinged(const CachePeer
* p
, HttpRequest
* request
)
217 if (p
->icp
.port
== 0)
220 if (p
->options
.no_query
)
223 if (p
->options
.mcast_responder
)
226 if (p
->n_addresses
== 0)
229 if (p
->options
.background_ping
&& (squid_curtime
- p
->stats
.last_query
< Config
.backgroundPingRate
))
232 /* the case below seems strange, but can happen if the
233 * URL host is on the other side of a firewall */
234 if (p
->type
== PEER_SIBLING
)
235 if (!request
->flags
.hierarchical
)
238 if (!peerAllowedToUse(p
, request
))
241 /* Ping dead peers every timeout interval */
242 if (squid_curtime
- p
->stats
.last_query
> Config
.Timeout
.deadPeer
)
252 peerCanOpenMore(const CachePeer
*p
)
254 const int effectiveLimit
= p
->max_conn
<= 0 ? Squid_MaxFD
: p
->max_conn
;
255 const int remaining
= effectiveLimit
- p
->stats
.conn_open
;
256 debugs(15, 7, remaining
<< '=' << effectiveLimit
<< '-' << p
->stats
.conn_open
);
257 return remaining
> 0;
261 peerHasConnAvailable(const CachePeer
*p
)
263 // Standby connections can be used without opening new connections.
264 const int standbys
= p
->standby
.pool
? p
->standby
.pool
->count() : 0;
266 // XXX: Some idle pconns can be used without opening new connections.
267 // Complication: Idle pconns cannot be reused for some requests.
268 const int usableIdles
= 0;
270 const int available
= standbys
+ usableIdles
;
271 debugs(15, 7, available
<< '=' << standbys
<< '+' << usableIdles
);
272 return available
> 0;
276 peerConnClosed(CachePeer
*p
)
278 --p
->stats
.conn_open
;
279 if (p
->standby
.waitingForClose
&& peerCanOpenMore(p
)) {
280 p
->standby
.waitingForClose
= false;
281 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "conn closed");
285 /* Return TRUE if it is okay to send an HTTP request to this CachePeer. */
287 peerHTTPOkay(const CachePeer
* p
, HttpRequest
* request
)
289 if (!peerCanOpenMore(p
) && !peerHasConnAvailable(p
))
292 if (!peerAllowedToUse(p
, request
))
302 neighborsCount(HttpRequest
* request
)
307 for (p
= Config
.peers
; p
; p
= p
->next
)
308 if (peerWouldBePinged(p
, request
))
311 debugs(15, 3, "neighborsCount: " << count
);
317 getFirstUpParent(HttpRequest
* request
)
321 for (p
= Config
.peers
; p
; p
= p
->next
) {
325 if (neighborType(p
, request
) != PEER_PARENT
)
328 if (!peerHTTPOkay(p
, request
))
334 debugs(15, 3, "getFirstUpParent: returning " << (p
? p
->host
: "NULL"));
339 getRoundRobinParent(HttpRequest
* request
)
344 for (p
= Config
.peers
; p
; p
= p
->next
) {
345 if (!p
->options
.roundrobin
)
348 if (neighborType(p
, request
) != PEER_PARENT
)
351 if (!peerHTTPOkay(p
, request
))
358 if (p
->weight
== q
->weight
) {
359 if (q
->rr_count
< p
->rr_count
)
361 } else if ( ((double) q
->rr_count
/ q
->weight
) < ((double) p
->rr_count
/ p
->weight
)) {
372 debugs(15, 3, HERE
<< "returning " << (q
? q
->host
: "NULL"));
378 getWeightedRoundRobinParent(HttpRequest
* request
)
384 for (p
= Config
.peers
; p
; p
= p
->next
) {
385 if (!p
->options
.weighted_roundrobin
)
388 if (neighborType(p
, request
) != PEER_PARENT
)
391 if (!peerHTTPOkay(p
, request
))
394 if (q
&& q
->rr_count
< p
->rr_count
)
400 if (q
&& q
->rr_count
> 1000000)
401 for (p
= Config
.peers
; p
; p
= p
->next
) {
402 if (!p
->options
.weighted_roundrobin
)
405 if (neighborType(p
, request
) != PEER_PARENT
)
412 weighted_rtt
= (q
->stats
.rtt
- q
->basetime
) / q
->weight
;
414 if (weighted_rtt
< 1)
417 q
->rr_count
+= weighted_rtt
;
419 debugs(15, 3, "getWeightedRoundRobinParent: weighted_rtt " << weighted_rtt
);
422 debugs(15, 3, "getWeightedRoundRobinParent: returning " << (q
? q
->host
: "NULL"));
427 * This gets called every 5 minutes to clear the round-robin counter.
428 * The exact timing is an arbitrary default, set on estimate timing of a
429 * large number of requests in a high-performance environment during the
430 * period. The larger the number of requests between cycled resets the
431 * more balanced the operations.
434 \todo Make the reset timing a selectable parameter in squid.conf
437 peerClearRRLoop(void *data
)
440 eventAdd("peerClearRR", peerClearRRLoop
, data
, 5 * 60.0, 0);
444 * This gets called on startup and restart to kick off the CachePeer round-robin
445 * maintenance event. It ensures that no matter how many times its called
446 * no more than one event is scheduled.
449 peerClearRRStart(void)
451 static bool event_added
= false;
453 peerClearRRLoop(NULL
);
459 * Called whenever the round-robin counters need to be reset to a sane state.
460 * So far those times are:
461 * - On startup and reconfigure - to set the counters to sane initial settings.
462 * - When a CachePeer has revived from dead, to prevent the revived CachePeer being
463 * flooded with requests which it has 'missed' during the down period.
469 for (p
= Config
.peers
; p
; p
= p
->next
) {
475 * Perform all actions when a CachePeer is detected revived.
478 peerAlive(CachePeer
*p
)
480 if (p
->stats
.logged_state
== PEER_DEAD
&& p
->tcp_up
) {
481 debugs(15, DBG_IMPORTANT
, "Detected REVIVED " << neighborTypeStr(p
) << ": " << p
->name
);
482 p
->stats
.logged_state
= PEER_ALIVE
;
484 if (p
->standby
.mgr
.valid())
485 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "revived peer");
488 p
->stats
.last_reply
= squid_curtime
;
489 p
->stats
.probe_start
= 0;
493 getDefaultParent(HttpRequest
* request
)
497 for (p
= Config
.peers
; p
; p
= p
->next
) {
498 if (neighborType(p
, request
) != PEER_PARENT
)
501 if (!p
->options
.default_parent
)
504 if (!peerHTTPOkay(p
, request
))
507 debugs(15, 3, "getDefaultParent: returning " << p
->host
);
512 debugs(15, 3, "getDefaultParent: returning NULL");
517 getNextPeer(CachePeer
* p
)
529 neighborRemove(CachePeer
* target
)
532 CachePeer
**P
= NULL
;
551 first_ping
= Config
.peers
;
555 neighborsRegisterWithCacheManager()
557 Mgr::RegisterAction("server_list",
558 "Peer Cache Statistics",
559 neighborDumpPeers
, 0, 1);
561 if (Comm::IsConnOpen(icpIncomingConn
)) {
562 Mgr::RegisterAction("non_peers",
563 "List of Unknown sites sending ICP messages",
564 neighborDumpNonPeers
, 0, 1);
571 struct servent
*sep
= NULL
;
572 const char *me
= getMyHostname();
573 CachePeer
*thisPeer
= NULL
;
574 CachePeer
*next
= NULL
;
576 neighborsRegisterWithCacheManager();
578 if (Comm::IsConnOpen(icpIncomingConn
)) {
580 for (thisPeer
= Config
.peers
; thisPeer
; thisPeer
= next
) {
581 next
= thisPeer
->next
;
583 if (0 != strcmp(thisPeer
->host
, me
))
586 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
; s
= s
->next
) {
587 if (thisPeer
->http_port
!= s
->s
.port())
590 debugs(15, DBG_IMPORTANT
, "WARNING: Peer looks like this host");
592 debugs(15, DBG_IMPORTANT
, " Ignoring " <<
593 neighborTypeStr(thisPeer
) << " " << thisPeer
->host
<<
594 "/" << thisPeer
->http_port
<< "/" <<
597 neighborRemove(thisPeer
);
602 peerRefreshDNS((void *) 1);
604 sep
= getservbyname("echo", "udp");
605 echo_port
= sep
? ntohs((unsigned short) sep
->s_port
) : 7;
607 first_ping
= Config
.peers
;
611 neighborsUdpPing(HttpRequest
* request
,
618 const char *url
= entry
->url();
619 MemObject
*mem
= entry
->mem_obj
;
625 int queries_sent
= 0;
626 int peers_pinged
= 0;
627 int parent_timeout
= 0, parent_exprep
= 0;
628 int sibling_timeout
= 0, sibling_exprep
= 0;
629 int mcast_timeout
= 0, mcast_exprep
= 0;
631 if (Config
.peers
== NULL
)
634 assert(entry
->swap_status
== SWAPOUT_NONE
);
636 mem
->start_ping
= current_time
;
638 mem
->ping_reply_callback
= callback
;
640 mem
->ircb_data
= callback_data
;
642 reqnum
= icpSetCacheKey((const cache_key
*)entry
->key
);
644 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
648 debugs(15, 5, "neighborsUdpPing: Peer " << p
->host
);
650 if (!peerWouldBePinged(p
, request
))
651 continue; /* next CachePeer */
655 debugs(15, 4, "neighborsUdpPing: pinging peer " << p
->host
<< " for '" << url
<< "'");
657 debugs(15, 3, "neighborsUdpPing: key = '" << entry
->getMD5Text() << "'");
659 debugs(15, 3, "neighborsUdpPing: reqnum = " << reqnum
);
662 if (p
->options
.htcp
&& !p
->options
.htcp_only_clr
) {
663 if (Config
.Port
.htcp
<= 0) {
664 debugs(15, DBG_CRITICAL
, "HTCP is disabled! Cannot send HTCP request to peer.");
668 debugs(15, 3, "neighborsUdpPing: sending HTCP query");
669 if (htcpQuery(entry
, request
, p
) <= 0)
670 continue; // unable to send.
674 if (Config
.Port
.icp
<= 0 || !Comm::IsConnOpen(icpOutgoingConn
)) {
675 debugs(15, DBG_CRITICAL
, "ICP is disabled! Cannot send ICP request to peer.");
679 if (p
->type
== PEER_MULTICAST
)
680 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
682 if (p
->icp
.port
== echo_port
) {
683 debugs(15, 4, "neighborsUdpPing: Looks like a dumb cache, send DECHO ping");
684 query
= _icp_common_t::createMessage(ICP_DECHO
, 0, url
, reqnum
, 0);
685 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
689 if (Config
.onoff
.query_icmp
)
690 if (p
->icp
.version
== ICP_VERSION_2
)
691 flags
|= ICP_FLAG_SRC_RTT
;
693 query
= _icp_common_t::createMessage(ICP_QUERY
, flags
, url
, reqnum
, 0);
695 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
702 ++ p
->stats
.pings_sent
;
704 if (p
->type
== PEER_MULTICAST
) {
705 mcast_exprep
+= p
->mcast
.n_replies_expected
;
706 mcast_timeout
+= (p
->stats
.rtt
* p
->mcast
.n_replies_expected
);
707 } else if (neighborUp(p
)) {
708 /* its alive, expect a reply from it */
710 if (neighborType(p
, request
) == PEER_PARENT
) {
712 parent_timeout
+= p
->stats
.rtt
;
715 sibling_timeout
+= p
->stats
.rtt
;
718 /* Neighbor is dead; ping it anyway, but don't expect a reply */
719 /* log it once at the threshold */
721 if (p
->stats
.logged_state
== PEER_ALIVE
) {
722 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
723 p
->stats
.logged_state
= PEER_DEAD
;
727 p
->stats
.last_query
= squid_curtime
;
730 * keep probe_start == 0 for a multicast CachePeer,
731 * so neighborUp() never says this CachePeer is dead.
734 if ((p
->type
!= PEER_MULTICAST
) && (p
->stats
.probe_start
== 0))
735 p
->stats
.probe_start
= squid_curtime
;
738 if ((first_ping
= first_ping
->next
) == NULL
)
739 first_ping
= Config
.peers
;
742 * How many replies to expect?
744 *exprep
= parent_exprep
+ sibling_exprep
+ mcast_exprep
;
747 * If there is a configured timeout, use it
749 if (Config
.Timeout
.icp_query
)
750 *timeout
= Config
.Timeout
.icp_query
;
754 *timeout
= 2 * parent_timeout
/ parent_exprep
;
755 else if (mcast_exprep
)
756 *timeout
= 2 * mcast_timeout
/ mcast_exprep
;
758 *timeout
= 2 * sibling_timeout
/ sibling_exprep
;
760 *timeout
= 2000; /* 2 seconds */
762 if (Config
.Timeout
.icp_query_max
)
763 if (*timeout
> Config
.Timeout
.icp_query_max
)
764 *timeout
= Config
.Timeout
.icp_query_max
;
766 if (*timeout
< Config
.Timeout
.icp_query_min
)
767 *timeout
= Config
.Timeout
.icp_query_min
;
773 /* lookup the digest of a given CachePeer */
775 peerDigestLookup(CachePeer
* p
, HttpRequest
* request
)
777 #if USE_CACHE_DIGESTS
778 const cache_key
*key
= request
? storeKeyPublicByRequest(request
) : NULL
;
781 debugs(15, 5, "peerDigestLookup: peer " << p
->host
);
782 /* does the peeer have a valid digest? */
785 debugs(15, 5, "peerDigestLookup: gone!");
787 } else if (!peerHTTPOkay(p
, request
)) {
788 debugs(15, 5, "peerDigestLookup: !peerHTTPOkay");
790 } else if (!p
->digest
->flags
.needed
) {
791 debugs(15, 5, "peerDigestLookup: note need");
792 peerDigestNeeded(p
->digest
);
794 } else if (!p
->digest
->flags
.usable
) {
795 debugs(15, 5, "peerDigestLookup: !ready && " << (p
->digest
->flags
.requested
? "" : "!") << "requested");
799 debugs(15, 5, "peerDigestLookup: OK to lookup peer " << p
->host
);
800 assert(p
->digest
->cd
);
801 /* does digest predict a hit? */
803 if (!cacheDigestTest(p
->digest
->cd
, key
))
806 debugs(15, 5, "peerDigestLookup: peer " << p
->host
<< " says HIT!");
815 /* select best CachePeer based on cache digests */
817 neighborsDigestSelect(HttpRequest
* request
)
819 CachePeer
*best_p
= NULL
;
820 #if USE_CACHE_DIGESTS
823 int choice_count
= 0;
824 int ichoice_count
= 0;
829 if (!request
->flags
.hierarchical
)
832 storeKeyPublicByRequest(request
);
834 for (i
= 0, p
= first_ping
; i
++ < Config
.npeers
; p
= p
->next
) {
843 lookup
= peerDigestLookup(p
, request
);
845 if (lookup
== LOOKUP_NONE
)
850 if (lookup
== LOOKUP_MISS
)
853 p_rtt
= netdbHostRtt(p
->host
);
855 debugs(15, 5, "neighborsDigestSelect: peer " << p
->host
<< " rtt: " << p_rtt
);
857 /* is this CachePeer better than others in terms of rtt ? */
858 if (!best_p
|| (p_rtt
&& p_rtt
< best_rtt
)) {
862 if (p_rtt
) /* informative choice (aka educated guess) */
865 debugs(15, 4, "neighborsDigestSelect: peer " << p
->host
<< " leads with rtt " << best_rtt
);
869 debugs(15, 4, "neighborsDigestSelect: choices: " << choice_count
<< " (" << ichoice_count
<< ")");
870 peerNoteDigestLookup(request
, best_p
,
871 best_p
? LOOKUP_HIT
: (choice_count
? LOOKUP_MISS
: LOOKUP_NONE
));
872 request
->hier
.n_choices
= choice_count
;
873 request
->hier
.n_ichoices
= ichoice_count
;
880 peerNoteDigestLookup(HttpRequest
* request
, CachePeer
* p
, lookup_t lookup
)
882 #if USE_CACHE_DIGESTS
884 strncpy(request
->hier
.cd_host
, p
->host
, sizeof(request
->hier
.cd_host
)-1);
886 *request
->hier
.cd_host
= '\0';
888 request
->hier
.cd_lookup
= lookup
;
889 debugs(15, 4, "peerNoteDigestLookup: peer " << (p
? p
->host
: "<none>") << ", lookup: " << lookup_t_str
[lookup
] );
894 neighborAlive(CachePeer
* p
, const MemObject
* mem
, const icp_common_t
* header
)
897 ++ p
->stats
.pings_acked
;
899 if ((icp_opcode
) header
->opcode
<= ICP_END
)
900 ++ p
->icp
.counts
[header
->opcode
];
902 p
->icp
.version
= (int) header
->version
;
906 neighborUpdateRtt(CachePeer
* p
, MemObject
* mem
)
908 int rtt
, rtt_av_factor
;
913 if (!mem
->start_ping
.tv_sec
)
916 rtt
= tvSubMsec(mem
->start_ping
, current_time
);
918 if (rtt
< 1 || rtt
> 10000)
921 rtt_av_factor
= RTT_AV_FACTOR
;
923 if (p
->options
.weighted_roundrobin
)
924 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
926 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, p
->stats
.pings_acked
, rtt_av_factor
);
931 neighborAliveHtcp(CachePeer
* p
, const MemObject
* mem
, const HtcpReplyData
* htcp
)
934 ++ p
->stats
.pings_acked
;
935 ++ p
->htcp
.counts
[htcp
->hit
? 1 : 0];
936 p
->htcp
.version
= htcp
->version
;
942 neighborCountIgnored(CachePeer
* p
)
947 ++ p
->stats
.ignored_replies
;
952 static CachePeer
*non_peers
= NULL
;
955 neighborIgnoreNonPeer(const Ip::Address
&from
, icp_opcode opcode
)
959 for (np
= non_peers
; np
; np
= np
->next
) {
960 if (np
->in_addr
!= from
)
963 if (np
->in_addr
.port() != from
.port())
970 np
= (CachePeer
*)xcalloc(1, sizeof(CachePeer
));
972 np
->icp
.port
= from
.port();
973 np
->type
= PEER_NONE
;
974 np
->host
= new char[MAX_IPSTRLEN
];
975 from
.toStr(np
->host
,MAX_IPSTRLEN
);
976 np
->next
= non_peers
;
980 ++ np
->icp
.counts
[opcode
];
982 if (isPowTen(++np
->stats
.ignored_replies
))
983 debugs(15, DBG_IMPORTANT
, "WARNING: Ignored " << np
->stats
.ignored_replies
<< " replies from non-peer " << np
->host
);
986 /* ignoreMulticastReply
988 * * We want to ignore replies from multicast peers if the
989 * * cache_host_domain rules would normally prevent the CachePeer
993 ignoreMulticastReply(CachePeer
* p
, MemObject
* mem
)
998 if (!p
->options
.mcast_responder
)
1001 if (peerHTTPOkay(p
, mem
->request
))
1008 * I should attach these records to the entry. We take the first
1009 * hit we get our wait until everyone misses. The timeout handler
1010 * call needs to nip this shopping list or call one of the misses.
1012 * If a hit process is already started, then sobeit
1015 neighborsUdpAck(const cache_key
* key
, icp_common_t
* header
, const Ip::Address
&from
)
1017 CachePeer
*p
= NULL
;
1019 MemObject
*mem
= NULL
;
1020 peer_t ntype
= PEER_NONE
;
1021 icp_opcode opcode
= (icp_opcode
) header
->opcode
;
1023 debugs(15, 6, "neighborsUdpAck: opcode " << opcode
<< " '" << storeKeyText(key
) << "'");
1025 if (NULL
!= (entry
= Store::Root().get(key
)))
1026 mem
= entry
->mem_obj
;
1028 if ((p
= whichPeer(from
)))
1029 neighborAlive(p
, mem
, header
);
1031 if (opcode
> ICP_END
)
1034 const char *opcode_d
= icp_opcode_str
[opcode
];
1037 neighborUpdateRtt(p
, mem
);
1039 /* Does the entry exist? */
1040 if (NULL
== entry
) {
1041 debugs(12, 3, "neighborsUdpAck: Cache key '" << storeKeyText(key
) << "' not found");
1042 neighborCountIgnored(p
);
1046 /* check if someone is already fetching it */
1047 if (EBIT_TEST(entry
->flags
, ENTRY_DISPATCHED
)) {
1048 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1049 neighborCountIgnored(p
);
1054 debugs(15, 2, "Ignoring " << opcode_d
<< " for missing mem_obj: " << storeKeyText(key
));
1055 neighborCountIgnored(p
);
1059 if (entry
->ping_status
!= PING_WAITING
) {
1060 debugs(15, 2, "neighborsUdpAck: Late " << opcode_d
<< " for " << storeKeyText(key
));
1061 neighborCountIgnored(p
);
1065 if (!entry
->locked()) {
1066 // TODO: many entries are unlocked; why is this reported at level 1?
1067 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1068 neighborCountIgnored(p
);
1072 debugs(15, 3, "neighborsUdpAck: " << opcode_d
<< " for '" << storeKeyText(key
) << "' from " << (p
? p
->host
: "source") << " ");
1075 ntype
= neighborType(p
, mem
->request
);
1078 if (ignoreMulticastReply(p
, mem
)) {
1079 neighborCountIgnored(p
);
1080 } else if (opcode
== ICP_MISS
) {
1082 neighborIgnoreNonPeer(from
, opcode
);
1084 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1086 } else if (opcode
== ICP_HIT
) {
1088 neighborIgnoreNonPeer(from
, opcode
);
1090 header
->opcode
= ICP_HIT
;
1091 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1093 } else if (opcode
== ICP_DECHO
) {
1095 neighborIgnoreNonPeer(from
, opcode
);
1096 } else if (ntype
== PEER_SIBLING
) {
1097 debug_trap("neighborsUdpAck: Found non-ICP cache as SIBLING\n");
1098 debug_trap("neighborsUdpAck: non-ICP neighbors must be a PARENT\n");
1100 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1102 } else if (opcode
== ICP_SECHO
) {
1104 debugs(15, DBG_IMPORTANT
, "Ignoring SECHO from neighbor " << p
->host
);
1105 neighborCountIgnored(p
);
1107 debugs(15, DBG_IMPORTANT
, "Unsolicited SECHO from " << from
);
1109 } else if (opcode
== ICP_DENIED
) {
1111 neighborIgnoreNonPeer(from
, opcode
);
1112 } else if (p
->stats
.pings_acked
> 100) {
1113 if (100 * p
->icp
.counts
[ICP_DENIED
] / p
->stats
.pings_acked
> 95) {
1114 debugs(15, DBG_CRITICAL
, "95%% of replies from '" << p
->host
<< "' are UDP_DENIED");
1115 debugs(15, DBG_CRITICAL
, "Disabling '" << p
->host
<< "', please check your configuration.");
1119 neighborCountIgnored(p
);
1122 } else if (opcode
== ICP_MISS_NOFETCH
) {
1123 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_ICP
, header
, mem
->ircb_data
);
1125 debugs(15, DBG_CRITICAL
, "neighborsUdpAck: Unexpected ICP reply: " << opcode_d
);
1130 peerFindByName(const char *name
)
1132 CachePeer
*p
= NULL
;
1134 for (p
= Config
.peers
; p
; p
= p
->next
) {
1135 if (!strcasecmp(name
, p
->name
))
1143 peerFindByNameAndPort(const char *name
, unsigned short port
)
1145 CachePeer
*p
= NULL
;
1147 for (p
= Config
.peers
; p
; p
= p
->next
) {
1148 if (strcasecmp(name
, p
->name
))
1151 if (port
!= p
->http_port
)
1161 neighborUp(const CachePeer
* p
)
1164 if (!peerProbeConnect((CachePeer
*) p
)) {
1165 debugs(15, 8, "neighborUp: DOWN (probed): " << p
->host
<< " (" << p
->in_addr
<< ")");
1171 * The CachePeer can not be UP if we don't have any IP addresses
1174 if (0 == p
->n_addresses
) {
1175 debugs(15, 8, "neighborUp: DOWN (no-ip): " << p
->host
<< " (" << p
->in_addr
<< ")");
1179 if (p
->options
.no_query
) {
1180 debugs(15, 8, "neighborUp: UP (no-query): " << p
->host
<< " (" << p
->in_addr
<< ")");
1184 if (p
->stats
.probe_start
!= 0 &&
1185 squid_curtime
- p
->stats
.probe_start
> Config
.Timeout
.deadPeer
) {
1186 debugs(15, 8, "neighborUp: DOWN (dead): " << p
->host
<< " (" << p
->in_addr
<< ")");
1190 debugs(15, 8, "neighborUp: UP: " << p
->host
<< " (" << p
->in_addr
<< ")");
1195 peerDestroy(void *data
)
1197 CachePeer
*p
= (CachePeer
*)data
;
1202 CachePeerDomainList
*nl
= NULL
;
1204 for (CachePeerDomainList
*l
= p
->peer_domain
; l
; l
= nl
) {
1206 safe_free(l
->domain
);
1212 safe_free(p
->domain
);
1213 #if USE_CACHE_DIGESTS
1215 cbdataReferenceDone(p
->digest
);
1220 peerNoteDigestGone(CachePeer
* p
)
1222 #if USE_CACHE_DIGESTS
1223 cbdataReferenceDone(p
->digest
);
1228 peerDNSConfigure(const ipcache_addrs
*ia
, const DnsLookupDetails
&, void *data
)
1230 // TODO: connections to no-longer valid IP addresses should be
1231 // closed when we can detect such IP addresses.
1233 CachePeer
*p
= (CachePeer
*)data
;
1237 if (p
->n_addresses
== 0) {
1238 debugs(15, DBG_IMPORTANT
, "Configuring " << neighborTypeStr(p
) << " " << p
->host
<< "/" << p
->http_port
<< "/" << p
->icp
.port
);
1240 if (p
->type
== PEER_MULTICAST
)
1241 debugs(15, DBG_IMPORTANT
, " Multicast TTL = " << p
->mcast
.ttl
);
1247 debugs(0, DBG_CRITICAL
, "WARNING: DNS lookup for '" << p
->host
<< "' failed!");
1251 if ((int) ia
->count
< 1) {
1252 debugs(0, DBG_CRITICAL
, "WARNING: No IP address found for '" << p
->host
<< "'!");
1256 p
->tcp_up
= p
->connect_fail_limit
;
1258 for (j
= 0; j
< (int) ia
->count
&& j
< PEER_MAX_ADDRESSES
; ++j
) {
1259 p
->addresses
[j
] = ia
->in_addrs
[j
];
1260 debugs(15, 2, "--> IP address #" << j
<< ": " << p
->addresses
[j
]);
1264 p
->in_addr
.setEmpty();
1265 p
->in_addr
= p
->addresses
[0];
1266 p
->in_addr
.port(p
->icp
.port
);
1268 if (p
->type
== PEER_MULTICAST
)
1269 peerCountMcastPeersSchedule(p
, 10);
1272 if (p
->type
!= PEER_MULTICAST
)
1273 if (!p
->options
.no_netdb_exchange
)
1274 eventAddIsh("netdbExchangeStart", netdbExchangeStart
, p
, 30.0, 1);
1277 if (p
->standby
.mgr
.valid())
1278 PeerPoolMgr::Checkpoint(p
->standby
.mgr
, "resolved peer");
1282 peerRefreshDNS(void *data
)
1284 CachePeer
*p
= NULL
;
1286 if (eventFind(peerRefreshDNS
, NULL
))
1287 eventDelete(peerRefreshDNS
, NULL
);
1289 if (!data
&& 0 == stat5minClientRequests()) {
1290 /* no recent client traffic, wait a bit */
1291 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 180.0, 1);
1295 for (p
= Config
.peers
; p
; p
= p
->next
)
1296 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1298 /* Reconfigure the peers every hour */
1299 eventAddIsh("peerRefreshDNS", peerRefreshDNS
, NULL
, 3600.0, 1);
1303 peerConnectFailedSilent(CachePeer
* p
)
1305 p
->stats
.last_connect_failure
= squid_curtime
;
1308 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<<
1316 debugs(15, DBG_IMPORTANT
, "Detected DEAD " << neighborTypeStr(p
) << ": " << p
->name
);
1317 p
->stats
.logged_state
= PEER_DEAD
;
1322 peerConnectFailed(CachePeer
*p
)
1324 debugs(15, DBG_IMPORTANT
, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " failed");
1325 peerConnectFailedSilent(p
);
1329 peerConnectSucceded(CachePeer
* p
)
1332 debugs(15, 2, "TCP connection to " << p
->host
<< "/" << p
->http_port
<< " succeded");
1333 p
->tcp_up
= p
->connect_fail_limit
; // NP: so peerAlive(p) works properly.
1335 if (!p
->n_addresses
)
1336 ipcache_nbgethostbyname(p
->host
, peerDNSConfigure
, p
);
1338 p
->tcp_up
= p
->connect_fail_limit
;
1342 * peerProbeConnect will be called on dead peers by neighborUp
1345 peerProbeConnect(CachePeer
* p
)
1347 time_t ctimeout
= p
->connect_timeout
> 0 ? p
->connect_timeout
: Config
.Timeout
.peer_connect
;
1348 bool ret
= (squid_curtime
- p
->stats
.last_connect_failure
) > (ctimeout
* 10);
1350 if (p
->testing_now
> 0)
1351 return ret
;/* probe already running */
1353 if (squid_curtime
- p
->stats
.last_connect_probe
== 0)
1354 return ret
;/* don't probe to often */
1356 /* for each IP address of this CachePeer. find one that we can connect to and probe it. */
1357 for (int i
= 0; i
< p
->n_addresses
; ++i
) {
1358 Comm::ConnectionPointer conn
= new Comm::Connection
;
1359 conn
->remote
= p
->addresses
[i
];
1360 conn
->remote
.port(p
->http_port
);
1362 getOutgoingAddress(NULL
, conn
);
1366 AsyncCall::Pointer call
= commCbCall(15,3, "peerProbeConnectDone", CommConnectCbPtrFun(peerProbeConnectDone
, p
));
1367 Comm::ConnOpener
*cs
= new Comm::ConnOpener(conn
, call
, ctimeout
);
1368 cs
->setHost(p
->host
);
1369 AsyncJob::Start(cs
);
1372 p
->stats
.last_connect_probe
= squid_curtime
;
1378 peerProbeConnectDone(const Comm::ConnectionPointer
&conn
, comm_err_t status
, int xerrno
, void *data
)
1380 CachePeer
*p
= (CachePeer
*)data
;
1382 if (status
== COMM_OK
) {
1383 peerConnectSucceded(p
);
1385 peerConnectFailedSilent(p
);
1390 // TODO: log this traffic.
1394 peerCountMcastPeersSchedule(CachePeer
* p
, time_t when
)
1396 if (p
->mcast
.flags
.count_event_pending
)
1399 eventAdd("peerCountMcastPeersStart",
1400 peerCountMcastPeersStart
,
1404 p
->mcast
.flags
.count_event_pending
= true;
1408 peerCountMcastPeersStart(void *data
)
1410 CachePeer
*p
= (CachePeer
*)data
;
1414 icp_common_t
*query
;
1416 LOCAL_ARRAY(char, url
, MAX_URL
);
1417 assert(p
->type
== PEER_MULTICAST
);
1418 p
->mcast
.flags
.count_event_pending
= false;
1419 snprintf(url
, MAX_URL
, "http://");
1420 p
->in_addr
.toUrl(url
+7, MAX_URL
-8 );
1422 fake
= storeCreateEntry(url
, url
, RequestFlags(), Http::METHOD_GET
);
1423 HttpRequest
*req
= HttpRequest::CreateFromUrl(url
);
1424 psstate
= new ps_state
;
1425 psstate
->request
= req
;
1426 HTTPMSGLOCK(psstate
->request
);
1427 psstate
->entry
= fake
;
1428 psstate
->callback
= NULL
;
1429 psstate
->callback_data
= cbdataReference(p
);
1430 psstate
->ping
.start
= current_time
;
1431 mem
= fake
->mem_obj
;
1432 mem
->request
= psstate
->request
;
1433 HTTPMSGLOCK(mem
->request
);
1434 mem
->start_ping
= current_time
;
1435 mem
->ping_reply_callback
= peerCountHandleIcpReply
;
1436 mem
->ircb_data
= psstate
;
1437 mcastSetTtl(icpOutgoingConn
->fd
, p
->mcast
.ttl
);
1438 p
->mcast
.id
= mem
->id
;
1439 reqnum
= icpSetCacheKey((const cache_key
*)fake
->key
);
1440 query
= _icp_common_t::createMessage(ICP_QUERY
, 0, url
, reqnum
, 0);
1441 icpUdpSend(icpOutgoingConn
->fd
, p
->in_addr
, query
, LOG_ICP_QUERY
, 0);
1442 fake
->ping_status
= PING_WAITING
;
1443 eventAdd("peerCountMcastPeersDone",
1444 peerCountMcastPeersDone
,
1446 Config
.Timeout
.mcast_icp_query
/ 1000.0, 1);
1447 p
->mcast
.flags
.counting
= true;
1448 peerCountMcastPeersSchedule(p
, MCAST_COUNT_RATE
);
1452 peerCountMcastPeersDone(void *data
)
1454 ps_state
*psstate
= (ps_state
*)data
;
1455 StoreEntry
*fake
= psstate
->entry
;
1457 if (cbdataReferenceValid(psstate
->callback_data
)) {
1458 CachePeer
*p
= (CachePeer
*)psstate
->callback_data
;
1459 p
->mcast
.flags
.counting
= false;
1460 p
->mcast
.avg_n_members
= Math::doubleAverage(p
->mcast
.avg_n_members
, (double) psstate
->ping
.n_recv
, ++p
->mcast
.n_times_counted
, 10);
1461 debugs(15, DBG_IMPORTANT
, "Group " << p
->host
<< ": " << psstate
->ping
.n_recv
<<
1462 " replies, "<< std::setw(4)<< std::setprecision(2) <<
1463 p
->mcast
.avg_n_members
<<" average, RTT " << p
->stats
.rtt
);
1464 p
->mcast
.n_replies_expected
= (int) p
->mcast
.avg_n_members
;
1467 cbdataReferenceDone(psstate
->callback_data
);
1469 fake
->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
1470 HTTPMSGUNLOCK(fake
->mem_obj
->request
);
1471 fake
->unlock("peerCountMcastPeersDone");
1472 HTTPMSGUNLOCK(psstate
->request
);
1473 cbdataFree(psstate
);
1477 peerCountHandleIcpReply(CachePeer
* p
, peer_t type
, AnyP::ProtocolType proto
, void *hdrnotused
, void *data
)
1481 ps_state
*psstate
= (ps_state
*)data
;
1482 StoreEntry
*fake
= psstate
->entry
;
1483 MemObject
*mem
= fake
->mem_obj
;
1484 int rtt
= tvSubMsec(mem
->start_ping
, current_time
);
1485 assert(proto
== AnyP::PROTO_ICP
);
1488 ++ psstate
->ping
.n_recv
;
1489 rtt_av_factor
= RTT_AV_FACTOR
;
1491 if (p
->options
.weighted_roundrobin
)
1492 rtt_av_factor
= RTT_BACKGROUND_AV_FACTOR
;
1494 p
->stats
.rtt
= Math::intAverage(p
->stats
.rtt
, rtt
, psstate
->ping
.n_recv
, rtt_av_factor
);
1498 neighborDumpPeers(StoreEntry
* sentry
)
1500 dump_peers(sentry
, Config
.peers
);
1504 neighborDumpNonPeers(StoreEntry
* sentry
)
1506 dump_peers(sentry
, non_peers
);
1510 dump_peer_options(StoreEntry
* sentry
, CachePeer
* p
)
1512 if (p
->options
.proxy_only
)
1513 storeAppendPrintf(sentry
, " proxy-only");
1515 if (p
->options
.no_query
)
1516 storeAppendPrintf(sentry
, " no-query");
1518 if (p
->options
.background_ping
)
1519 storeAppendPrintf(sentry
, " background-ping");
1521 if (p
->options
.no_digest
)
1522 storeAppendPrintf(sentry
, " no-digest");
1524 if (p
->options
.default_parent
)
1525 storeAppendPrintf(sentry
, " default");
1527 if (p
->options
.roundrobin
)
1528 storeAppendPrintf(sentry
, " round-robin");
1530 if (p
->options
.carp
)
1531 storeAppendPrintf(sentry
, " carp");
1534 if (p
->options
.userhash
)
1535 storeAppendPrintf(sentry
, " userhash");
1538 if (p
->options
.sourcehash
)
1539 storeAppendPrintf(sentry
, " sourcehash");
1541 if (p
->options
.weighted_roundrobin
)
1542 storeAppendPrintf(sentry
, " weighted-round-robin");
1544 if (p
->options
.mcast_responder
)
1545 storeAppendPrintf(sentry
, " multicast-responder");
1547 #if PEER_MULTICAST_SIBLINGS
1548 if (p
->options
.mcast_siblings
)
1549 storeAppendPrintf(sentry
, " multicast-siblings");
1553 storeAppendPrintf(sentry
, " weight=%d", p
->weight
);
1555 if (p
->options
.closest_only
)
1556 storeAppendPrintf(sentry
, " closest-only");
1559 if (p
->options
.htcp
) {
1560 storeAppendPrintf(sentry
, " htcp");
1561 if (p
->options
.htcp_oldsquid
|| p
->options
.htcp_no_clr
|| p
->options
.htcp_no_purge_clr
|| p
->options
.htcp_only_clr
) {
1563 if (p
->options
.htcp_oldsquid
)
1564 storeAppendPrintf(sentry
, "%soldsquid",(doneopts
++>0?",":"="));
1565 if (p
->options
.htcp_no_clr
)
1566 storeAppendPrintf(sentry
, "%sno-clr",(doneopts
++>0?",":"="));
1567 if (p
->options
.htcp_no_purge_clr
)
1568 storeAppendPrintf(sentry
, "%sno-purge-clr",(doneopts
++>0?",":"="));
1569 if (p
->options
.htcp_only_clr
)
1570 storeAppendPrintf(sentry
, "%sonly-clr",(doneopts
++>0?",":"="));
1575 if (p
->options
.no_netdb_exchange
)
1576 storeAppendPrintf(sentry
, " no-netdb-exchange");
1579 if (p
->options
.no_delay
)
1580 storeAppendPrintf(sentry
, " no-delay");
1584 storeAppendPrintf(sentry
, " login=%s", p
->login
);
1586 if (p
->mcast
.ttl
> 0)
1587 storeAppendPrintf(sentry
, " ttl=%d", p
->mcast
.ttl
);
1589 if (p
->connect_timeout
> 0)
1590 storeAppendPrintf(sentry
, " connect-timeout=%d", (int) p
->connect_timeout
);
1592 if (p
->connect_fail_limit
!= PEER_TCP_MAGIC_COUNT
)
1593 storeAppendPrintf(sentry
, " connect-fail-limit=%d", p
->connect_fail_limit
);
1595 #if USE_CACHE_DIGESTS
1598 storeAppendPrintf(sentry
, " digest-url=%s", p
->digest_url
);
1602 if (p
->options
.allow_miss
)
1603 storeAppendPrintf(sentry
, " allow-miss");
1605 if (p
->options
.no_tproxy
)
1606 storeAppendPrintf(sentry
, " no-tproxy");
1608 if (p
->max_conn
> 0)
1609 storeAppendPrintf(sentry
, " max-conn=%d", p
->max_conn
);
1610 if (p
->standby
.limit
> 0)
1611 storeAppendPrintf(sentry
, " standby=%d", p
->standby
.limit
);
1613 if (p
->options
.originserver
)
1614 storeAppendPrintf(sentry
, " originserver");
1617 storeAppendPrintf(sentry
, " forceddomain=%s", p
->domain
);
1619 if (p
->connection_auth
== 0)
1620 storeAppendPrintf(sentry
, " connection-auth=off");
1621 else if (p
->connection_auth
== 1)
1622 storeAppendPrintf(sentry
, " connection-auth=on");
1623 else if (p
->connection_auth
== 2)
1624 storeAppendPrintf(sentry
, " connection-auth=auto");
1626 storeAppendPrintf(sentry
, "\n");
1630 dump_peers(StoreEntry
* sentry
, CachePeer
* peers
)
1632 CachePeer
*e
= NULL
;
1633 char ntoabuf
[MAX_IPSTRLEN
];
1634 CachePeerDomainList
*d
= NULL
;
1639 storeAppendPrintf(sentry
, "There are no neighbors installed.\n");
1641 for (e
= peers
; e
; e
= e
->next
) {
1642 assert(e
->host
!= NULL
);
1643 storeAppendPrintf(sentry
, "\n%-11.11s: %s\n",
1646 storeAppendPrintf(sentry
, "Host : %s/%d/%d\n",
1650 storeAppendPrintf(sentry
, "Flags :");
1651 dump_peer_options(sentry
, e
);
1653 for (i
= 0; i
< e
->n_addresses
; ++i
) {
1654 storeAppendPrintf(sentry
, "Address[%d] : %s\n", i
,
1655 e
->addresses
[i
].toStr(ntoabuf
,MAX_IPSTRLEN
) );
1658 storeAppendPrintf(sentry
, "Status : %s\n",
1659 neighborUp(e
) ? "Up" : "Down");
1660 storeAppendPrintf(sentry
, "FETCHES : %d\n", e
->stats
.fetches
);
1661 storeAppendPrintf(sentry
, "OPEN CONNS : %d\n", e
->stats
.conn_open
);
1662 storeAppendPrintf(sentry
, "AVG RTT : %d msec\n", e
->stats
.rtt
);
1664 if (!e
->options
.no_query
) {
1665 storeAppendPrintf(sentry
, "LAST QUERY : %8d seconds ago\n",
1666 (int) (squid_curtime
- e
->stats
.last_query
));
1668 if (e
->stats
.last_reply
> 0)
1669 storeAppendPrintf(sentry
, "LAST REPLY : %8d seconds ago\n",
1670 (int) (squid_curtime
- e
->stats
.last_reply
));
1672 storeAppendPrintf(sentry
, "LAST REPLY : none received\n");
1674 storeAppendPrintf(sentry
, "PINGS SENT : %8d\n", e
->stats
.pings_sent
);
1676 storeAppendPrintf(sentry
, "PINGS ACKED: %8d %3d%%\n",
1677 e
->stats
.pings_acked
,
1678 Math::intPercent(e
->stats
.pings_acked
, e
->stats
.pings_sent
));
1681 storeAppendPrintf(sentry
, "IGNORED : %8d %3d%%\n", e
->stats
.ignored_replies
, Math::intPercent(e
->stats
.ignored_replies
, e
->stats
.pings_acked
));
1683 if (!e
->options
.no_query
) {
1684 storeAppendPrintf(sentry
, "Histogram of PINGS ACKED:\n");
1687 if (e
->options
.htcp
) {
1688 storeAppendPrintf(sentry
, "\tMisses\t%8d %3d%%\n",
1690 Math::intPercent(e
->htcp
.counts
[0], e
->stats
.pings_acked
));
1691 storeAppendPrintf(sentry
, "\tHits\t%8d %3d%%\n",
1693 Math::intPercent(e
->htcp
.counts
[1], e
->stats
.pings_acked
));
1697 for (op
= ICP_INVALID
; op
< ICP_END
; ++op
) {
1698 if (e
->icp
.counts
[op
] == 0)
1701 storeAppendPrintf(sentry
, " %12.12s : %8d %3d%%\n",
1704 Math::intPercent(e
->icp
.counts
[op
], e
->stats
.pings_acked
));
1715 if (e
->stats
.last_connect_failure
) {
1716 storeAppendPrintf(sentry
, "Last failed connect() at: %s\n",
1717 Time::FormatHttpd(e
->stats
.last_connect_failure
));
1720 if (e
->peer_domain
!= NULL
) {
1721 storeAppendPrintf(sentry
, "DOMAIN LIST: ");
1723 for (d
= e
->peer_domain
; d
; d
= d
->next
) {
1724 storeAppendPrintf(sentry
, "%s%s ",
1725 d
->do_ping
? null_string
: "!", d
->domain
);
1728 storeAppendPrintf(sentry
, "\n");
1731 storeAppendPrintf(sentry
, "keep-alive ratio: %d%%\n", Math::intPercent(e
->stats
.n_keepalives_recv
, e
->stats
.n_keepalives_sent
));
1737 neighborsHtcpReply(const cache_key
* key
, HtcpReplyData
* htcp
, const Ip::Address
&from
)
1739 StoreEntry
*e
= Store::Root().get(key
);
1740 MemObject
*mem
= NULL
;
1742 peer_t ntype
= PEER_NONE
;
1743 debugs(15, 6, "neighborsHtcpReply: " <<
1744 (htcp
->hit
? "HIT" : "MISS") << " " <<
1745 storeKeyText(key
) );
1750 if ((p
= whichPeer(from
)))
1751 neighborAliveHtcp(p
, mem
, htcp
);
1753 /* Does the entry exist? */
1755 debugs(12, 3, "neighyborsHtcpReply: Cache key '" << storeKeyText(key
) << "' not found");
1756 neighborCountIgnored(p
);
1760 /* check if someone is already fetching it */
1761 if (EBIT_TEST(e
->flags
, ENTRY_DISPATCHED
)) {
1762 debugs(15, 3, "neighborsUdpAck: '" << storeKeyText(key
) << "' already being fetched.");
1763 neighborCountIgnored(p
);
1768 debugs(15, 2, "Ignoring reply for missing mem_obj: " << storeKeyText(key
));
1769 neighborCountIgnored(p
);
1773 if (e
->ping_status
!= PING_WAITING
) {
1774 debugs(15, 2, "neighborsUdpAck: Entry " << storeKeyText(key
) << " is not PING_WAITING");
1775 neighborCountIgnored(p
);
1780 // TODO: many entries are unlocked; why is this reported at level 1?
1781 debugs(12, DBG_IMPORTANT
, "neighborsUdpAck: '" << storeKeyText(key
) << "' has no locks");
1782 neighborCountIgnored(p
);
1787 ntype
= neighborType(p
, mem
->request
);
1788 neighborUpdateRtt(p
, mem
);
1791 if (ignoreMulticastReply(p
, mem
)) {
1792 neighborCountIgnored(p
);
1796 debugs(15, 3, "neighborsHtcpReply: e = " << e
);
1797 mem
->ping_reply_callback(p
, ntype
, AnyP::PROTO_HTCP
, htcp
, mem
->ircb_data
);
1801 * Send HTCP CLR messages to all peers configured to receive them.
1804 neighborsHtcpClear(StoreEntry
* e
, const char *uri
, HttpRequest
* req
, const HttpRequestMethod
&method
, htcp_clr_reason reason
)
1809 for (p
= Config
.peers
; p
; p
= p
->next
) {
1810 if (!p
->options
.htcp
) {
1813 if (p
->options
.htcp_no_clr
) {
1816 if (p
->options
.htcp_no_purge_clr
&& reason
== HTCP_CLR_PURGE
) {
1819 debugs(15, 3, "neighborsHtcpClear: sending CLR to " << p
->in_addr
.toUrl(buf
, 128));
1820 htcpClear(e
, uri
, req
, method
, p
, reason
);