PeerSelectState.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #ifndef SQUID_PEERSELECTSTATE_H
10 #define SQUID_PEERSELECTSTATE_H
11 
12 #include "AccessLogEntry.h"
13 #include "acl/Checklist.h"
14 #include "base/CbcPointer.h"
15 #include "comm/forward.h"
16 #include "hier_code.h"
17 #include "ip/Address.h"
18 #include "ipcache.h"
19 #include "mem/forward.h"
20 #include "PingData.h"
21 #include "typedefs.h" /* for IRCB */
22 
23 class ErrorState;
24 class HtcpReplyData;
25 class HttpRequest;
26 class icp_common_t;
27 class StoreEntry;
28 
29 void peerSelectInit(void);
30 
33 {
34 public:
35  virtual ~PeerSelectionInitiator() = default;
36 
38  virtual void noteDestination(Comm::ConnectionPointer path) = 0;
39 
43  virtual void noteDestinationsEnd(ErrorState *error) = 0;
44 
46  bool subscribed = false;
47 
48  /* protected: */
53 };
54 
55 class FwdServer;
56 
60 {
62 
63 public:
65  virtual ~PeerSelector() override;
66 
67  /* Dns::IpReceiver API */
68  virtual void noteIp(const Ip::Address &ip) override;
69  virtual void noteIps(const Dns::CachedIps *ips, const Dns::LookupDetails &details) override;
70  virtual void noteLookup(const Dns::LookupDetails &details) override;
71 
72  // Produce a URL for display identifying the transaction we are
73  // trying to locate a peer for.
74  const SBuf url() const;
75 
78 
80  bool wantsMoreDestinations() const;
81 
83  void handlePath(const Comm::ConnectionPointer &path, FwdServer &fs);
84 
86  void selectMore();
87 
89  void startPingWaiting();
90 
93 
95  static void HandlePingTimeout(PeerSelector *);
96 
100 
101  void *peerCountMcastPeerXXX = nullptr;
102 
104 
105 protected:
106  bool selectionAborted();
107 
108  void handlePingTimeout();
109  void handleIcpReply(CachePeer*, const peer_t, icp_common_t *header);
111 #if USE_HTCP
114 #endif
115 
116  int checkNetdbDirect();
117  void checkAlwaysDirectDone(const Acl::Answer answer);
118  void checkNeverDirectDone(const Acl::Answer answer);
119 
120  void selectSomeNeighbor();
122  void selectSomeDirect();
123  void selectSomeParent();
124  void selectAllParents();
125  void selectPinned();
126 
127  void addSelection(CachePeer*, const hier_code);
128 
129  void resolveSelected();
130 
134 
135 private:
138  int direct; // TODO: fold always_direct/never_direct/prefer_direct into this now that ACL can do a multi-state result.
139  size_t foundPaths = 0;
141 
143 
144  /*
145  * Why are these Ip::Address instead of CachePeer *? Because a
146  * CachePeer structure can become invalid during the CachePeer selection
147  * phase, specifically after a reconfigure. Thus we need to lookup
148  * the CachePeer * based on the address when we are finally ready to
149  * reference the CachePeer structure.
150  */
151 
153 
155  /*
156  * ->hit can be CachePeer* because it should only be
157  * accessed during the thread when it is set
158  */
162 
165 
167 };
168 
169 #endif /* SQUID_PEERSELECTSTATE_H */
170 
void selectSomeDirect()
Adds a "direct" entry if the request can be forwarded to the origin server.
Definition: peer_select.cc:816
virtual ~PeerSelector() override
Definition: peer_select.cc:230
void resolveSelected()
A single DNS resolution loop iteration: Converts selected FwdServer to IPs.
Definition: peer_select.cc:412
HttpRequest * request
Interface for those who need a list of peers to forward a request to.
virtual ~PeerSelectionInitiator()=default
size_t foundPaths
number of unique destinations identified so far
void handlePath(const Comm::ConnectionPointer &path, FwdServer &fs)
processes a newly discovered/finalized path
virtual void noteLookup(const Dns::LookupDetails &details) override
Definition: peer_select.cc:501
ErrorState * lastError
void handleHtcpParentMiss(CachePeer *, HtcpReplyData *)
virtual void noteIps(const Dns::CachedIps *ips, const Dns::LookupDetails &details) override
Definition: peer_select.cc:538
FwdServer * servers
a linked list of (unresolved) selected peers
void checkAlwaysDirectDone(const Acl::Answer answer)
Definition: peer_select.cc:370
void error(char *format,...)
ping_data ping
void startSelectingDestinations(HttpRequest *request, const AccessLogEntry::Pointer &ale, StoreEntry *entry)
Definition: peer_select.cc:334
Definition: SBuf.h:86
StoreEntry * entry
void handleHtcpReply(CachePeer *, const peer_t, HtcpReplyData *)
Definition: peer_select.cc:998
CBDATA_CHILD(PeerSelector)
const InstanceId< PeerSelector > id
unique identification in worker log
Ip::Address closest_parent_miss
void IRCB(CachePeer *, peer_t, AnyP::ProtocolType, void *, void *data)
Definition: typedefs.h:22
ACLChecklist * acl_checklist
void ACLCB(Acl::Answer, void *)
ACL checklist callback.
Definition: Checklist.h:19
static ACLCB CheckNeverDirectDone
an interface for receiving IP::Addresses from nbgethostbyname()
Definition: ipcache.h:194
peer_t
Definition: enums.h:27
void handleIcpParentMiss(CachePeer *, icp_common_t *)
Definition: peer_select.cc:924
PeerSelectionInitiator * interestedInitiator()
ICP probing of cache_peers during peer selection.
Definition: PingData.h:25
static IRCB HandlePingReply
void checkNeverDirectDone(const Acl::Answer answer)
Definition: peer_select.cc:342
bool subscribed
whether noteDestination() and noteDestinationsEnd() calls are allowed
void addSelection(CachePeer *, const hier_code)
virtual void noteDestinationsEnd(ErrorState *error)=0
bool selectionAborted()
Definition: peer_select.cc:400
AccessLogEntry::Pointer al
info for the future access.log entry
Acl::Answer never_direct
CachePeer * hit
void handlePingTimeout()
Definition: peer_select.cc:893
encapsulates DNS lookup results
Definition: LookupDetails.h:20
void selectSomeParent()
Definition: peer_select.cc:829
void cancelPingTimeoutMonitoring()
terminates ICP ping timeout monitoring
Definition: peer_select.cc:271
static void HandlePingTimeout(PeerSelector *)
called when the given selector should stop expecting ICP ping responses
Definition: peer_select.cc:912
void startPingWaiting()
switches into the PING_WAITING state (and associated timeout monitoring)
Definition: peer_select.cc:262
const SBuf url() const
void selectSomeNeighbor()
Definition: peer_select.cc:729
PeerSelector(PeerSelectionInitiator *)
Acl::Answer always_direct
Initiator initiator_
recipient of the destinations we select; use interestedInitiator() to access
static ACLCB CheckAlwaysDirectDone
virtual void noteIp(const Ip::Address &ip) override
Called when/if nbgethostbyname() discovers a new good IP address.
Definition: peer_select.cc:515
bool wantsMoreDestinations() const
void handleIcpReply(CachePeer *, const peer_t, icp_common_t *header)
Definition: peer_select.cc:965
void selectAllParents()
Adds alive parents. Used as a last resort for never_direct.
Definition: peer_select.cc:863
void selectSomeNeighborReplies()
Selects a neighbor (parent or sibling) based on ICP/HTCP replies.
Definition: peer_select.cc:785
hier_code
Definition: hier_code.h:12
void peerSelectInit(void)
Definition: peer_select.cc:918
virtual void noteDestination(Comm::ConnectionPointer path)=0
called when a new unique destination has been found
void selectPinned()
Selects a pinned connection if it exists, is valid, and is allowed.
Definition: peer_select.cc:703
Ip::Address first_parent_miss
int checkNetdbDirect()
Definition: peer_select.cc:564
void selectMore()
a single selection loop iteration: attempts to add more destinations
Definition: peer_select.cc:607
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
void * peerCountMcastPeerXXX
a hack to help peerCountMcastPeersStart()
CbcPointer< PeerSelectionInitiator > Initiator

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors