PeerSelectState.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_SRC_PEERSELECTSTATE_H
10 #define SQUID_SRC_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  ~PeerSelectionInitiator() override = 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  ~PeerSelector() override;
66 
67  /* Dns::IpReceiver API */
68  void noteIp(const Ip::Address &ip) override;
69  void noteIps(const Dns::CachedIps *ips, const Dns::LookupDetails &details) override;
70  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  */
161 
164 
166 };
167 
168 #endif /* SQUID_SRC_PEERSELECTSTATE_H */
169 
void selectSomeDirect()
Adds a "direct" entry if the request can be forwarded to the origin server.
Definition: peer_select.cc:811
~PeerSelector() override
Definition: peer_select.cc:231
void resolveSelected()
A single DNS resolution loop iteration: Converts selected FwdServer to IPs.
Definition: peer_select.cc:406
HttpRequest * request
Interface for those who need a list of peers to forward a request to.
size_t foundPaths
number of unique destinations identified so far
void handlePath(const Comm::ConnectionPointer &path, FwdServer &fs)
processes a newly discovered/finalized path
void noteLookup(const Dns::LookupDetails &details) override
Definition: peer_select.cc:495
ErrorState * lastError
void handleHtcpParentMiss(CachePeer *, HtcpReplyData *)
void noteIps(const Dns::CachedIps *ips, const Dns::LookupDetails &details) override
Definition: peer_select.cc:535
FwdServer * servers
a linked list of (unresolved) selected peers
void checkAlwaysDirectDone(const Acl::Answer answer)
Definition: peer_select.cc:365
void error(char *format,...)
ping_data ping
void startSelectingDestinations(HttpRequest *request, const AccessLogEntry::Pointer &ale, StoreEntry *entry)
Definition: peer_select.cc:330
Definition: SBuf.h:93
StoreEntry * entry
void handleHtcpReply(CachePeer *, const peer_t, HtcpReplyData *)
Definition: peer_select.cc:995
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
~PeerSelectionInitiator() override=default
void ACLCB(Acl::Answer, void *)
ACL checklist callback.
Definition: Checklist.h:23
static ACLCB CheckNeverDirectDone
an interface for receiving IP::Addresses from nbgethostbyname()
Definition: ipcache.h:194
peer_t
Definition: enums.h:22
void handleIcpParentMiss(CachePeer *, icp_common_t *)
Definition: peer_select.cc:919
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:338
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:394
AccessLogEntry::Pointer al
info for the future access.log entry
Acl::Answer never_direct
CachePeer * hit
void handlePingTimeout()
Definition: peer_select.cc:888
encapsulates DNS lookup results
Definition: LookupDetails.h:22
void selectSomeParent()
Definition: peer_select.cc:824
void cancelPingTimeoutMonitoring()
terminates ICP ping timeout monitoring
Definition: peer_select.cc:267
static void HandlePingTimeout(PeerSelector *)
called when the given selector should stop expecting ICP ping responses
Definition: peer_select.cc:907
void startPingWaiting()
switches into the PING_WAITING state (and associated timeout monitoring)
Definition: peer_select.cc:258
const SBuf url() const
void selectSomeNeighbor()
Definition: peer_select.cc:724
PeerSelector(PeerSelectionInitiator *)
Acl::Answer always_direct
Initiator initiator_
recipient of the destinations we select; use interestedInitiator() to access
static ACLCB CheckAlwaysDirectDone
void noteIp(const Ip::Address &ip) override
Called when/if nbgethostbyname() discovers a new good IP address.
Definition: peer_select.cc:509
bool wantsMoreDestinations() const
void handleIcpReply(CachePeer *, const peer_t, icp_common_t *header)
Definition: peer_select.cc:962
void selectAllParents()
Adds alive parents. Used as a last resort for never_direct.
Definition: peer_select.cc:858
void selectSomeNeighborReplies()
Selects a neighbor (parent or sibling) based on ICP/HTCP replies.
Definition: peer_select.cc:780
hier_code
Definition: hier_code.h:12
void peerSelectInit(void)
Definition: peer_select.cc:913
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:698
Ip::Address first_parent_miss
int checkNetdbDirect()
Definition: peer_select.cc:561
void selectMore()
a single selection loop iteration: attempts to add more destinations
Definition: peer_select.cc:604
void * peerCountMcastPeerXXX
a hack to help peerCountMcastPeersStart()
CbcPointer< PeerSelectionInitiator > Initiator

 

Introduction

Documentation

Support

Miscellaneous