2 * Copyright (C) 1996-2018 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 44 Peer Selection Algorithm */
12 #include "acl/FilledChecklist.h"
13 #include "base/InstanceId.h"
14 #include "CachePeer.h"
16 #include "client_side.h"
17 #include "dns/LookupDetails.h"
18 #include "errorpage.h"
22 #include "hier_code.h"
24 #include "http/Stream.h"
25 #include "HttpRequest.h"
26 #include "icmp/net_db.h"
30 #include "neighbors.h"
31 #include "peer_sourcehash.h"
32 #include "peer_userhash.h"
33 #include "PeerSelectState.h"
34 #include "SquidConfig.h"
35 #include "SquidTime.h"
40 * A CachePeer which has been selected as a possible destination.
41 * Listed as pointers here so as to prevent duplicates being added but will
42 * be converted to a set of IP address path options before handing back out
45 * Certain connection flags and outgoing settings will also be looked up and
46 * set based on the received request and CachePeer settings before handing back.
50 MEMPROXY_CLASS(FwdServer
);
53 FwdServer(CachePeer
*p
, hier_code c
) :
59 CbcPointer
<CachePeer
> _peer
; /* NULL --> origin server */
68 static const char *DirectStr
[] = {
75 /// a helper class to report a selected destination (for debugging)
76 class PeerSelectionDumper
79 PeerSelectionDumper(const PeerSelector
* const aSelector
, const CachePeer
* const aPeer
, const hier_code aCode
):
80 selector(aSelector
), peer(aPeer
), code(aCode
) {}
82 const PeerSelector
* const selector
; ///< selection parameters
83 const CachePeer
* const peer
; ///< successful selection info
84 const hier_code code
; ///< selection algorithm
87 CBDATA_CLASS_INIT(PeerSelector
);
89 /// prints PeerSelectionDumper (for debugging)
91 operator <<(std::ostream
&os
, const PeerSelectionDumper
&fsd
)
93 os
<< hier_code_str
[fsd
.code
];
96 os
<< '/' << fsd
.peer
->host
;
97 else if (fsd
.selector
) // useful for DIRECT and gone PINNED destinations
98 os
<< '#' << fsd
.selector
->request
->url
.host();
103 PeerSelector::~PeerSelector()
106 FwdServer
*next
= servers
->next
;
112 debugs(44, 3, entry
->url());
114 if (entry
->ping_status
== PING_WAITING
)
115 eventDelete(HandlePingTimeout
, this);
117 entry
->ping_status
= PING_DONE
;
121 debugs(44, DBG_IMPORTANT
, "BUG: peer selector gone while waiting for a slow ACL");
122 delete acl_checklist
;
125 HTTPMSGUNLOCK(request
);
128 assert(entry
->ping_status
!= PING_WAITING
);
129 entry
->unlock("peerSelect");
137 peerSelectIcpPing(HttpRequest
* request
, int direct
, StoreEntry
* entry
)
141 assert(entry
->ping_status
== PING_NONE
);
142 assert(direct
!= DIRECT_YES
);
143 debugs(44, 3, entry
->url());
145 if (!request
->flags
.hierarchical
&& direct
!= DIRECT_NO
)
148 if (EBIT_TEST(entry
->flags
, KEY_PRIVATE
) && !neighbors_do_private_keys
)
149 if (direct
!= DIRECT_NO
)
152 n
= neighborsCount(request
);
154 debugs(44, 3, "counted " << n
<< " neighbors");
160 peerSelect(PeerSelectionInitiator
*initiator
,
161 HttpRequest
* request
,
162 AccessLogEntry::Pointer
const &al
,
166 debugs(44, 3, *entry
<< ' ' << entry
->url());
168 debugs(44, 3, request
->method
);
170 const auto selector
= new PeerSelector(initiator
);
172 selector
->request
= request
;
173 HTTPMSGLOCK(selector
->request
);
176 selector
->entry
= entry
;
178 #if USE_CACHE_DIGESTS
180 request
->hier
.peer_select_start
= current_time
;
185 selector
->entry
->lock("peerSelect");
187 selector
->selectMore();
191 PeerSelectionInitiator::startSelectingDestinations(HttpRequest
*request
, const AccessLogEntry::Pointer
&ale
, StoreEntry
*entry
)
194 peerSelect(this, request
, ale
, entry
);
195 // and wait for noteDestination() and/or noteDestinationsEnd() calls
199 PeerSelector::checkNeverDirectDone(const allow_t answer
)
201 acl_checklist
= nullptr;
202 debugs(44, 3, answer
);
203 never_direct
= answer
;
206 /** if never_direct says YES, do that. */
208 debugs(44, 3, "direct = " << DirectStr
[direct
] << " (never_direct allow)");
210 case ACCESS_DENIED
: // not relevant.
211 case ACCESS_DUNNO
: // not relevant.
213 case ACCESS_AUTH_REQUIRED
:
214 debugs(44, DBG_IMPORTANT
, "WARNING: never_direct resulted in " << answer
<< ". Username ACLs are not reliable here.");
221 PeerSelector::CheckNeverDirectDone(allow_t answer
, void *data
)
223 static_cast<PeerSelector
*>(data
)->checkNeverDirectDone(answer
);
227 PeerSelector::checkAlwaysDirectDone(const allow_t answer
)
229 acl_checklist
= nullptr;
230 debugs(44, 3, answer
);
231 always_direct
= answer
;
234 /** if always_direct says YES, do that. */
236 debugs(44, 3, "direct = " << DirectStr
[direct
] << " (always_direct allow)");
238 case ACCESS_DENIED
: // not relevant.
239 case ACCESS_DUNNO
: // not relevant.
241 case ACCESS_AUTH_REQUIRED
:
242 debugs(44, DBG_IMPORTANT
, "WARNING: always_direct resulted in " << answer
<< ". Username ACLs are not reliable here.");
249 PeerSelector::CheckAlwaysDirectDone(allow_t answer
, void *data
)
251 static_cast<PeerSelector
*>(data
)->checkAlwaysDirectDone(answer
);
254 /// \returns true (after destroying "this") if the peer initiator is gone
255 /// \returns false (without side effects) otherwise
257 PeerSelector::selectionAborted()
259 if (interestedInitiator())
262 debugs(44, 3, "Aborting peer selection: Initiator gone or lost interest.");
267 /// A single DNS resolution loop iteration: Converts selected FwdServer to IPs.
269 PeerSelector::resolveSelected()
271 if (selectionAborted())
274 FwdServer
*fs
= servers
;
276 // Bug 3243: CVE 2009-0801
277 // Bypass of browser same-origin access control in intercepted communication
278 // To resolve this we must use only the original client destination when going DIRECT
279 // on intercepted traffic which failed Host verification
280 const HttpRequest
*req
= request
;
281 const bool isIntercepted
= !req
->flags
.redirected
&&
282 (req
->flags
.intercepted
|| req
->flags
.interceptTproxy
);
283 const bool useOriginalDst
= Config
.onoff
.client_dst_passthru
|| !req
->flags
.hostVerified
;
284 const bool choseDirect
= fs
&& fs
->code
== HIER_DIRECT
;
285 if (isIntercepted
&& useOriginalDst
&& choseDirect
) {
286 // check the client is still around before using any of its details
287 if (req
->clientConnectionManager
.valid()) {
288 // construct a "result" adding the ORIGINAL_DST to the set instead of DIRECT
289 Comm::ConnectionPointer p
= new Comm::Connection();
290 p
->remote
= req
->clientConnectionManager
->clientConnection
->local
;
291 fs
->code
= ORIGINAL_DST
; // fs->code is DIRECT. This fixes the display.
295 // clear the used fs and continue
302 // convert the list of FwdServer destinations into destinations IP addresses
303 if (fs
&& wantsMoreDestinations()) {
304 // send the next one off for DNS lookup.
305 const char *host
= fs
->_peer
.valid() ? fs
->_peer
->host
: request
->url
.host();
306 debugs(44, 2, "Find IP destination for: " << url() << "' via " << host
);
307 Dns::nbgethostbyname(host
, this);
311 // Bug 3605: clear any extra listed FwdServer destinations, when the options exceeds max_foward_tries.
312 // due to the allocation method of fs, we must deallocate each manually.
313 // TODO: use a std::list so we can get the size and abort adding whenever the selection loops reach Config.forward_max_tries
315 assert(fs
== servers
);
323 // done with DNS lookups. pass back to caller
325 debugs(44, 2, id
<< " found all " << foundPaths
<< " destinations for " << url());
326 debugs(44, 2, " always_direct = " << always_direct
);
327 debugs(44, 2, " never_direct = " << never_direct
);
328 debugs(44, 2, " timedout = " << ping
.timedout
);
330 ping
.stop
= current_time
;
331 request
->hier
.ping
= ping
; // final result
333 if (lastError
&& foundPaths
) {
334 // nobody cares about errors if we found destinations despite them
335 debugs(44, 3, "forgetting the last error");
340 if (const auto initiator
= interestedInitiator())
341 initiator
->noteDestinationsEnd(lastError
);
342 lastError
= nullptr; // initiator owns the ErrorState object now
347 PeerSelector::noteLookup(const Dns::LookupDetails
&details
)
349 /* ignore lookup delays that occurred after the initiator moved on */
351 if (selectionAborted())
354 if (!wantsMoreDestinations())
357 request
->recordLookup(details
);
361 PeerSelector::noteIp(const Ip::Address
&ip
)
363 if (selectionAborted())
366 if (!wantsMoreDestinations())
369 const auto peer
= servers
->_peer
.valid();
371 // for TPROXY spoofing, we must skip unusable addresses
372 if (request
->flags
.spoofClientIp
&& !(peer
&& peer
->options
.no_tproxy
) ) {
373 if (ip
.isIPv4() != request
->client_addr
.isIPv4())
374 return; // cannot spoof the client address on this link
377 Comm::ConnectionPointer p
= new Comm::Connection();
379 p
->remote
.port(peer
? peer
->http_port
: request
->url
.port());
380 handlePath(p
, *servers
);
384 PeerSelector::noteIps(const Dns::CachedIps
*ia
, const Dns::LookupDetails
&details
)
386 if (selectionAborted())
389 FwdServer
*fs
= servers
;
391 debugs(44, 3, "Unknown host: " << (fs
->_peer
.valid() ? fs
->_peer
->host
: request
->url
.host()));
392 // discard any previous error.
395 if (fs
->code
== HIER_DIRECT
) {
396 lastError
= new ErrorState(ERR_DNS_FAIL
, Http::scServiceUnavailable
, request
);
397 lastError
->dnsError
= details
.error
;
400 // else noteIp() calls have already processed all IPs in *ia
405 // continue resolving selected peers
410 PeerSelector::checkNetdbDirect()
417 if (direct
== DIRECT_NO
)
420 /* base lookup on RTT and Hops if ICMP NetDB is enabled. */
422 myrtt
= netdbHostRtt(request
->url
.host());
423 debugs(44, 3, "MY RTT = " << myrtt
<< " msec");
424 debugs(44, 3, "minimum_direct_rtt = " << Config
.minDirectRtt
<< " msec");
426 if (myrtt
&& myrtt
<= Config
.minDirectRtt
)
429 myhops
= netdbHostHops(request
->url
.host());
431 debugs(44, 3, "MY hops = " << myhops
);
432 debugs(44, 3, "minimum_direct_hops = " << Config
.minDirectHops
);
434 if (myhops
&& myhops
<= Config
.minDirectHops
)
437 p
= whichPeer(closest_parent_miss
);
442 debugs(44, 3, "closest_parent_miss RTT = " << ping
.p_rtt
<< " msec");
444 if (myrtt
&& myrtt
<= ping
.p_rtt
)
447 #endif /* USE_ICMP */
453 PeerSelector::selectMore()
455 if (selectionAborted())
458 debugs(44, 3, request
->method
<< ' ' << request
->url
.host());
460 /** If we don't know whether DIRECT is permitted ... */
461 if (direct
== DIRECT_UNKNOWN
) {
462 if (always_direct
== ACCESS_DUNNO
) {
463 debugs(44, 3, "direct = " << DirectStr
[direct
] << " (always_direct to be checked)");
464 /** check always_direct; */
465 ACLFilledChecklist
*ch
= new ACLFilledChecklist(Config
.accessList
.AlwaysDirect
, request
, NULL
);
468 acl_checklist
->nonBlockingCheck(CheckAlwaysDirectDone
, this);
470 } else if (never_direct
== ACCESS_DUNNO
) {
471 debugs(44, 3, "direct = " << DirectStr
[direct
] << " (never_direct to be checked)");
472 /** check never_direct; */
473 ACLFilledChecklist
*ch
= new ACLFilledChecklist(Config
.accessList
.NeverDirect
, request
, NULL
);
476 acl_checklist
->nonBlockingCheck(CheckNeverDirectDone
, this);
478 } else if (request
->flags
.noDirect
) {
479 /** if we are accelerating, direct is not an option. */
481 debugs(44, 3, "direct = " << DirectStr
[direct
] << " (forced non-direct)");
482 } else if (request
->flags
.loopDetected
) {
483 /** if we are in a forwarding-loop, direct is not an option. */
485 debugs(44, 3, "direct = " << DirectStr
[direct
] << " (forwarding loop detected)");
486 } else if (checkNetdbDirect()) {
488 debugs(44, 3, "direct = " << DirectStr
[direct
] << " (checkNetdbDirect)");
490 direct
= DIRECT_MAYBE
;
491 debugs(44, 3, "direct = " << DirectStr
[direct
] << " (default)");
494 debugs(44, 3, "direct = " << DirectStr
[direct
]);
497 if (!entry
|| entry
->ping_status
== PING_NONE
)
501 } else if (entry
->ping_status
== PING_NONE
) {
502 selectSomeNeighbor();
504 if (entry
->ping_status
== PING_WAITING
)
506 } else if (entry
->ping_status
== PING_WAITING
) {
507 selectSomeNeighborReplies();
508 entry
->ping_status
= PING_DONE
;
524 if (Config
.onoff
.prefer_direct
)
527 if (request
->flags
.hierarchical
|| !Config
.onoff
.nonhierarchical_direct
) {
532 if (!Config
.onoff
.prefer_direct
)
538 // end peer selection; start resolving selected peers
542 bool peerAllowedToUse(const CachePeer
* p
, HttpRequest
* request
);
544 /// Selects a pinned connection if it exists, is valid, and is allowed.
546 PeerSelector::selectPinned()
548 // TODO: Avoid all repeated calls. Relying on PING_DONE is not enough.
549 if (!request
->pinnedConnection())
551 CachePeer
*pear
= request
->pinnedConnection()->pinnedPeer();
552 if (Comm::IsConnOpen(request
->pinnedConnection()->validatePinnedConnection(request
, pear
))) {
553 const bool usePinned
= pear
? peerAllowedToUse(pear
, request
) : (direct
!= DIRECT_NO
);
555 addSelection(pear
, PINNED
);
557 entry
->ping_status
= PING_DONE
; // skip ICP
560 // If the pinned connection is prohibited (for this request) or gone, then
561 // the initiator must decide whether it is OK to open a new one instead.
565 * Selects a neighbor (parent or sibling) based on one of the
569 * ICMP Netdb RTT estimates
573 PeerSelector::selectSomeNeighbor()
576 hier_code code
= HIER_NONE
;
577 assert(entry
->ping_status
== PING_NONE
);
579 if (direct
== DIRECT_YES
) {
580 entry
->ping_status
= PING_DONE
;
584 #if USE_CACHE_DIGESTS
585 if ((p
= neighborsDigestSelect(request
))) {
586 if (neighborType(p
, request
->url
) == PEER_PARENT
)
587 code
= CD_PARENT_HIT
;
589 code
= CD_SIBLING_HIT
;
592 if ((p
= netdbClosestParent(request
))) {
593 code
= CLOSEST_PARENT
;
594 } else if (peerSelectIcpPing(request
, direct
, entry
)) {
595 debugs(44, 3, "Doing ICP pings");
596 ping
.start
= current_time
;
597 ping
.n_sent
= neighborsUdpPing(request
,
601 &ping
.n_replies_expected
,
604 if (ping
.n_sent
== 0)
605 debugs(44, DBG_CRITICAL
, "WARNING: neighborsUdpPing returned 0");
606 debugs(44, 3, ping
.n_replies_expected
<<
607 " ICP replies expected, RTT " << ping
.timeout
<<
610 if (ping
.n_replies_expected
> 0) {
611 entry
->ping_status
= PING_WAITING
;
612 eventAdd("PeerSelector::HandlePingTimeout",
615 0.001 * ping
.timeout
,
621 if (code
!= HIER_NONE
) {
623 addSelection(p
, code
);
626 entry
->ping_status
= PING_DONE
;
629 /// Selects a neighbor (parent or sibling) based on ICP/HTCP replies.
631 PeerSelector::selectSomeNeighborReplies()
634 hier_code code
= HIER_NONE
;
635 assert(entry
->ping_status
== PING_WAITING
);
636 assert(direct
!= DIRECT_YES
);
638 if (checkNetdbDirect()) {
639 code
= CLOSEST_DIRECT
;
640 addSelection(nullptr, code
);
645 code
= hit_type
== PEER_PARENT
? PARENT_HIT
: SIBLING_HIT
;
647 if (!closest_parent_miss
.isAnyAddr()) {
648 p
= whichPeer(closest_parent_miss
);
649 code
= CLOSEST_PARENT_MISS
;
650 } else if (!first_parent_miss
.isAnyAddr()) {
651 p
= whichPeer(first_parent_miss
);
652 code
= FIRST_PARENT_MISS
;
655 if (p
&& code
!= HIER_NONE
) {
656 addSelection(p
, code
);
660 /// Adds a "direct" entry if the request can be forwarded to the origin server.
662 PeerSelector::selectSomeDirect()
664 if (direct
== DIRECT_NO
)
667 /* WAIS is not implemented natively */
668 if (request
->url
.getScheme() == AnyP::PROTO_WAIS
)
671 addSelection(nullptr, HIER_DIRECT
);
675 PeerSelector::selectSomeParent()
678 hier_code code
= HIER_NONE
;
679 debugs(44, 3, request
->method
<< ' ' << request
->url
.host());
681 if (direct
== DIRECT_YES
)
684 if ((p
= peerSourceHashSelectParent(request
))) {
685 code
= SOURCEHASH_PARENT
;
687 } else if ((p
= peerUserHashSelectParent(request
))) {
688 code
= USERHASH_PARENT
;
690 } else if ((p
= carpSelectParent(request
))) {
692 } else if ((p
= getRoundRobinParent(request
))) {
693 code
= ROUNDROBIN_PARENT
;
694 } else if ((p
= getWeightedRoundRobinParent(request
))) {
695 code
= ROUNDROBIN_PARENT
;
696 } else if ((p
= getFirstUpParent(request
))) {
697 code
= FIRSTUP_PARENT
;
698 } else if ((p
= getDefaultParent(request
))) {
699 code
= DEFAULT_PARENT
;
702 if (code
!= HIER_NONE
) {
703 addSelection(p
, code
);
707 /// Adds alive parents. Used as a last resort for never_direct.
709 PeerSelector::selectAllParents()
712 /* Add all alive parents */
714 for (p
= Config
.peers
; p
; p
= p
->next
) {
715 /* XXX: neighbors.c lacks a public interface for enumerating
716 * parents to a request so we have to dig some here..
719 if (neighborType(p
, request
->url
) != PEER_PARENT
)
722 if (!peerHTTPOkay(p
, request
))
725 addSelection(p
, ANY_OLD_PARENT
);
728 /* XXX: should add dead parents here, but it is currently
729 * not possible to find out which parents are dead or which
730 * simply are not configured to handle the request.
732 /* Add default parent as a last resort */
733 if ((p
= getDefaultParent(request
))) {
734 addSelection(p
, DEFAULT_PARENT
);
739 PeerSelector::handlePingTimeout()
741 debugs(44, 3, url());
744 entry
->ping_status
= PING_DONE
;
746 if (selectionAborted())
749 ++PeerStats
.timeouts
;
755 PeerSelector::HandlePingTimeout(void *data
)
757 static_cast<PeerSelector
*>(data
)->handlePingTimeout();
763 memset(&PeerStats
, '\0', sizeof(PeerStats
));
767 PeerSelector::handleIcpParentMiss(CachePeer
*p
, icp_common_t
*header
)
772 if (Config
.onoff
.query_icmp
) {
773 if (header
->flags
& ICP_FLAG_SRC_RTT
) {
774 rtt
= header
->pad
& 0xFFFF;
775 int hops
= (header
->pad
>> 16) & 0xFFFF;
777 if (rtt
> 0 && rtt
< 0xFFFF)
778 netdbUpdatePeer(request
->url
, p
, rtt
, hops
);
780 if (rtt
&& (ping
.p_rtt
== 0 || rtt
< ping
.p_rtt
)) {
781 closest_parent_miss
= p
->in_addr
;
786 #endif /* USE_ICMP */
788 /* if closest-only is set, then don't allow FIRST_PARENT_MISS */
789 if (p
->options
.closest_only
)
792 /* set FIRST_MISS if there is no CLOSEST parent */
793 if (!closest_parent_miss
.isAnyAddr())
796 rtt
= (tvSubMsec(ping
.start
, current_time
) - p
->basetime
) / p
->weight
;
801 if (first_parent_miss
.isAnyAddr() || rtt
< ping
.w_rtt
) {
802 first_parent_miss
= p
->in_addr
;
808 PeerSelector::handleIcpReply(CachePeer
*p
, const peer_t type
, icp_common_t
*header
)
810 icp_opcode op
= header
->getOpCode();
811 debugs(44, 3, icp_opcode_str
[op
] << ' ' << url());
812 #if USE_CACHE_DIGESTS && 0
813 /* do cd lookup to count false misses */
816 peerNoteDigestLookup(request
, p
,
817 peerDigestLookup(p
, request
, entry
));
823 if (op
== ICP_MISS
|| op
== ICP_DECHO
) {
824 if (type
== PEER_PARENT
)
825 handleIcpParentMiss(p
, header
);
826 } else if (op
== ICP_HIT
) {
833 if (ping
.n_recv
< ping
.n_replies_expected
)
841 PeerSelector::handleHtcpReply(CachePeer
*p
, const peer_t type
, HtcpReplyData
*htcp
)
843 debugs(44, 3, (htcp
->hit
? "HIT" : "MISS") << ' ' << url());
853 if (type
== PEER_PARENT
)
854 handleHtcpParentMiss(p
, htcp
);
856 if (ping
.n_recv
< ping
.n_replies_expected
)
863 PeerSelector::handleHtcpParentMiss(CachePeer
*p
, HtcpReplyData
*htcp
)
868 if (Config
.onoff
.query_icmp
) {
869 if (htcp
->cto
.rtt
> 0) {
870 rtt
= (int) htcp
->cto
.rtt
* 1000;
871 int hops
= (int) htcp
->cto
.hops
* 1000;
872 netdbUpdatePeer(request
->url
, p
, rtt
, hops
);
874 if (rtt
&& (ping
.p_rtt
== 0 || rtt
< ping
.p_rtt
)) {
875 closest_parent_miss
= p
->in_addr
;
880 #endif /* USE_ICMP */
882 /* if closest-only is set, then don't allow FIRST_PARENT_MISS */
883 if (p
->options
.closest_only
)
886 /* set FIRST_MISS if there is no CLOSEST parent */
887 if (!closest_parent_miss
.isAnyAddr())
890 rtt
= (tvSubMsec(ping
.start
, current_time
) - p
->basetime
) / p
->weight
;
895 if (first_parent_miss
.isAnyAddr() || rtt
< ping
.w_rtt
) {
896 first_parent_miss
= p
->in_addr
;
904 PeerSelector::HandlePingReply(CachePeer
* p
, peer_t type
, AnyP::ProtocolType proto
, void *pingdata
, void *data
)
906 if (proto
== AnyP::PROTO_ICP
)
907 static_cast<PeerSelector
*>(data
)->handleIcpReply(p
, type
, static_cast<icp_common_t
*>(pingdata
));
911 else if (proto
== AnyP::PROTO_HTCP
)
912 static_cast<PeerSelector
*>(data
)->handleHtcpReply(p
, type
, static_cast<HtcpReplyData
*>(pingdata
));
917 debugs(44, DBG_IMPORTANT
, "ERROR: ignoring an ICP reply with unknown protocol " << proto
);
921 PeerSelector::addSelection(CachePeer
*peer
, const hier_code code
)
923 // Find the end of the servers list. Bail on a duplicate destination.
924 auto **serversTail
= &servers
;
925 while (const auto server
= *serversTail
) {
926 // There can be at most one PINNED destination.
927 // Non-PINNED destinations are uniquely identified by their CachePeer
928 // (even though a DIRECT destination might match a cache_peer address).
929 const bool duplicate
= (server
->code
== PINNED
) ?
930 (code
== PINNED
) : (server
->_peer
== peer
);
932 debugs(44, 3, "skipping " << PeerSelectionDumper(this, peer
, code
) <<
933 "; have " << PeerSelectionDumper(this, server
->_peer
.get(), server
->code
));
936 serversTail
= &server
->next
;
939 debugs(44, 3, "adding " << PeerSelectionDumper(this, peer
, code
));
940 *serversTail
= new FwdServer(peer
, code
);
943 PeerSelector::PeerSelector(PeerSelectionInitiator
*initiator
):
946 always_direct(Config
.accessList
.AlwaysDirect
?ACCESS_DUNNO
:ACCESS_DENIED
),
947 never_direct(Config
.accessList
.NeverDirect
?ACCESS_DUNNO
:ACCESS_DENIED
),
948 direct(DIRECT_UNKNOWN
),
952 closest_parent_miss(),
955 acl_checklist (NULL
),
956 initiator_(initiator
)
958 ; // no local defaults.
962 PeerSelector::url() const
965 return SBuf(entry
->url());
968 return request
->effectiveRequestUri();
970 static const SBuf
noUrl("[no URL]");
974 /// \returns valid/interested peer initiator or nil
975 PeerSelectionInitiator
*
976 PeerSelector::interestedInitiator()
978 const auto initiator
= initiator_
.valid();
981 debugs(44, 3, id
<< " initiator gone");
985 if (!initiator
->subscribed
) {
986 debugs(44, 3, id
<< " initiator lost interest");
995 PeerSelector::wantsMoreDestinations() const {
996 const auto maxCount
= Config
.forward_max_tries
;
997 return maxCount
>= 0 && foundPaths
<
998 static_cast<std::make_unsigned
<decltype(maxCount
)>::type
>(maxCount
);
1002 PeerSelector::handlePath(Comm::ConnectionPointer
&path
, FwdServer
&fs
)
1006 path
->peerType
= fs
.code
;
1007 path
->setPeer(fs
._peer
.get());
1009 // check for a configured outgoing address for this destination...
1010 getOutgoingAddress(request
, path
);
1012 request
->hier
.ping
= ping
; // may be updated later
1014 debugs(44, 2, id
<< " found " << path
<< ", destination #" << foundPaths
<< " for " << url());
1015 debugs(44, 2, " always_direct = " << always_direct
);
1016 debugs(44, 2, " never_direct = " << never_direct
);
1017 debugs(44, 2, " timedout = " << ping
.timedout
);
1019 if (const auto initiator
= interestedInitiator())
1020 initiator
->noteDestination(path
);
1023 InstanceIdDefinitions(PeerSelector
, "PeerSelector");
1025 ping_data::ping_data() :
1028 n_replies_expected(0),