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 
91 
92  void *peerCountMcastPeerXXX = nullptr;
93 
95 
96 protected:
97  bool selectionAborted();
98 
99  void handlePingTimeout();
100  void handleIcpReply(CachePeer*, const peer_t, icp_common_t *header);
102 #if USE_HTCP
105 #endif
106 
107  int checkNetdbDirect();
108  void checkAlwaysDirectDone(const Acl::Answer answer);
109  void checkNeverDirectDone(const Acl::Answer answer);
110 
111  void selectSomeNeighbor();
113  void selectSomeDirect();
114  void selectSomeParent();
115  void selectAllParents();
116  void selectPinned();
117 
118  void addSelection(CachePeer*, const hier_code);
119 
120  void resolveSelected();
121 
126 
127 private:
130  int direct; // TODO: fold always_direct/never_direct/prefer_direct into this now that ACL can do a multi-state result.
131  size_t foundPaths = 0;
133 
135 
136  /*
137  * Why are these Ip::Address instead of CachePeer *? Because a
138  * CachePeer structure can become invalid during the CachePeer selection
139  * phase, specifically after a reconfigure. Thus we need to lookup
140  * the CachePeer * based on the address when we are finally ready to
141  * reference the CachePeer structure.
142  */
143 
145 
147  /*
148  * ->hit can be CachePeer* because it should only be
149  * accessed during the thread when it is set
150  */
154 
157 
159 };
160 
161 #endif /* SQUID_PEERSELECTSTATE_H */
162 
void selectSomeDirect()
Adds a "direct" entry if the request can be forwarded to the origin server.
Definition: peer_select.cc:676
virtual ~PeerSelector() override
Definition: peer_select.cc:102
void resolveSelected()
A single DNS resolution loop iteration: Converts selected FwdServer to IPs.
Definition: peer_select.cc:271
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:360
ErrorState * lastError
void handleHtcpParentMiss(CachePeer *, HtcpReplyData *)
Definition: peer_select.cc:877
virtual void noteIps(const Dns::CachedIps *ips, const Dns::LookupDetails &details) override
Definition: peer_select.cc:397
FwdServer * servers
a linked list of (unresolved) selected peers
void checkAlwaysDirectDone(const Acl::Answer answer)
Definition: peer_select.cc:229
void error(char *format,...)
ping_data ping
void startSelectingDestinations(HttpRequest *request, const AccessLogEntry::Pointer &ale, StoreEntry *entry)
Definition: peer_select.cc:193
Definition: SBuf.h:86
StoreEntry * entry
void handleHtcpReply(CachePeer *, const peer_t, HtcpReplyData *)
Definition: peer_select.cc:855
CBDATA_CHILD(PeerSelector)
static EVH HandlePingTimeout
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:781
PeerSelectionInitiator * interestedInitiator()
Definition: peer_select.cc:990
static IRCB HandlePingReply
void checkNeverDirectDone(const Acl::Answer answer)
Definition: peer_select.cc:201
bool subscribed
whether noteDestination() and noteDestinationsEnd() calls are allowed
void addSelection(CachePeer *, const hier_code)
Definition: peer_select.cc:935
virtual void noteDestinationsEnd(ErrorState *error)=0
bool selectionAborted()
Definition: peer_select.cc:259
AccessLogEntry::Pointer al
info for the future access.log entry
Acl::Answer never_direct
CachePeer * hit
void handlePingTimeout()
Definition: peer_select.cc:753
encapsulates DNS lookup results
Definition: LookupDetails.h:20
void selectSomeParent()
Definition: peer_select.cc:689
const SBuf url() const
Definition: peer_select.cc:976
void selectSomeNeighbor()
Definition: peer_select.cc:587
void EVH(void *)
Definition: event.h:19
PeerSelector(PeerSelectionInitiator *)
Definition: peer_select.cc:957
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:374
bool wantsMoreDestinations() const
void handleIcpReply(CachePeer *, const peer_t, icp_common_t *header)
Definition: peer_select.cc:822
void selectAllParents()
Adds alive parents. Used as a last resort for never_direct.
Definition: peer_select.cc:723
void selectSomeNeighborReplies()
Selects a neighbor (parent or sibling) based on ICP/HTCP replies.
Definition: peer_select.cc:645
hier_code
Definition: hier_code.h:12
void peerSelectInit(void)
Definition: peer_select.cc:775
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:561
Ip::Address first_parent_miss
int checkNetdbDirect()
Definition: peer_select.cc:423
void selectMore()
a single selection loop iteration: attempts to add more destinations
Definition: peer_select.cc:466
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