]> git.ipfire.org Git - thirdparty/squid.git/blame - src/CachePeer.h
Maintenance: automate header guards 2/3 (#1655)
[thirdparty/squid.git] / src / CachePeer.h
CommitLineData
a011edee 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
a011edee 3 *
bbc27441
AJ
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.
a011edee
FC
7 */
8
ff9d9458
FC
9#ifndef SQUID_SRC_CACHEPEER_H
10#define SQUID_SRC_CACHEPEER_H
bbc27441 11
6f58d7d7 12#include "acl/forward.h"
e8dca475 13#include "base/CbcPointer.h"
a011edee 14#include "enums.h"
022dbabd 15#include "http/StatusCode.h"
a011edee
FC
16#include "icp_opcode.h"
17#include "ip/Address.h"
cdfb670c
AJ
18#include "security/PeerOptions.h"
19
a555a85b
AR
20#include <iosfwd>
21
a7458115
FC
22//TODO: remove, it is unconditionally defined and always used.
23#define PEER_MULTICAST_SIBLINGS 1
24
5844d003 25class NeighborTypeDomainList;
e8dca475 26class PconnPool;
a011edee 27class PeerDigest;
e8dca475 28class PeerPoolMgr;
a011edee 29
1b2f0924
FC
30class CachePeer
31{
719815a0
AJ
32 CBDATA_CLASS(CachePeer);
33
a011edee 34public:
a555a85b 35 explicit CachePeer(const char *hostname);
719815a0
AJ
36 ~CachePeer();
37
022dbabd
EB
38 /// reacts to a successful establishment of a connection to this cache_peer
39 void noteSuccess();
40
41 /// reacts to a failure on a connection to this cache_peer
42 /// \param code a received response status code, if any
43 void noteFailure(Http::StatusCode code);
44
a555a85b
AR
45 /// (re)configure cache_peer name=value
46 void rename(const char *);
47
5f5d319e
FC
48 /// \returns the effective connect timeout for the given peer
49 time_t connectTimeout() const;
50
2e24d0bf 51 /// n-th cache_peer directive, starting with 1
a85952ab 52 u_int index = 0;
a555a85b
AR
53
54 /// cache_peer name (if explicitly configured) or hostname (otherwise).
55 /// Unique across already configured cache_peers in the current configuration.
a555a85b
AR
56 /// The value may change during CachePeer configuration.
57 /// The value affects various peer selection hashes (e.g., carp.hash).
58 /// Preserves configured spelling (i.e. does not lower letters case).
59 /// Never nil.
a85952ab 60 char *name = nullptr;
a555a85b 61
e3732982
EB
62 /// The lowercase version of the configured cache_peer hostname.
63 /// May not be unique among cache_peers.
a555a85b 64 /// Never nil.
a85952ab 65 char *host = nullptr;
a555a85b 66
a85952ab 67 peer_t type = PEER_NONE;
a011edee
FC
68
69 Ip::Address in_addr;
70
71 struct {
a85952ab 72 int pings_sent = 0;
73 int pings_acked = 0;
74 int fetches = 0;
75 int rtt = 0;
76 int ignored_replies = 0;
77 int n_keepalives_sent = 0;
78 int n_keepalives_recv = 0;
79 time_t probe_start = 0;
80 time_t last_query = 0;
81 time_t last_reply = 0;
82 time_t last_connect_failure = 0;
83 time_t last_connect_probe = 0;
84 int logged_state = PEER_ALIVE; ///< so we can print dead/revived msgs
85 int conn_open = 0; ///< current opened connections
a011edee
FC
86 } stats;
87
a85952ab 88 struct icp_ {
89 icp_() { memset(&counts, 0, sizeof(counts)); }
90 int version = ICP_VERSION_CURRENT;
a011edee 91 int counts[ICP_END+1];
a85952ab 92 unsigned short port = CACHE_ICP_PORT;
a011edee
FC
93 } icp;
94
95#if USE_HTCP
96 struct {
a85952ab 97 double version = 0.0;
98 int counts[2] = {0, 0};
99 unsigned short port = 0;
a011edee
FC
100 } htcp;
101#endif
102
a85952ab 103 unsigned short http_port = CACHE_HTTP_PORT;
104 NeighborTypeDomainList *typelist = nullptr;
105 acl_access *access = nullptr;
a011edee
FC
106
107 struct {
a85952ab 108 bool proxy_only = false;
109 bool no_query = false;
110 bool background_ping = false;
111 bool no_digest = false;
112 bool default_parent = false;
113 bool roundrobin = false;
114 bool weighted_roundrobin = false;
115 bool mcast_responder = false;
116 bool closest_only = false;
a011edee 117#if USE_HTCP
a85952ab 118 bool htcp = false;
119 bool htcp_oldsquid = false;
120 bool htcp_no_clr = false;
121 bool htcp_no_purge_clr = false;
122 bool htcp_only_clr = false;
123 bool htcp_forward_clr = false;
a011edee 124#endif
a85952ab 125 bool no_netdb_exchange = false;
a011edee 126#if USE_DELAY_POOLS
a85952ab 127 bool no_delay = false;
a011edee 128#endif
a85952ab 129 bool allow_miss = false;
130 bool carp = false;
a011edee 131 struct {
a85952ab 132 bool set = false; //If false, whole url is to be used. Overrides others
133 bool scheme = false;
134 bool host = false;
135 bool port = false;
136 bool path = false;
137 bool params = false;
a011edee
FC
138 } carp_key;
139#if USE_AUTH
a85952ab 140 bool userhash = false;
a011edee 141#endif
a85952ab 142 bool sourcehash = false;
143 bool originserver = false;
144 bool no_tproxy = false;
a011edee 145#if PEER_MULTICAST_SIBLINGS
a85952ab 146 bool mcast_siblings = false;
a011edee 147#endif
a85952ab 148 bool auth_no_keytab = false;
a011edee
FC
149 } options;
150
a85952ab 151 int weight = 1;
152 int basetime = 0;
a011edee
FC
153
154 struct {
a85952ab 155 double avg_n_members = 0.0;
156 int n_times_counted = 0;
157 int n_replies_expected = 0;
158 int ttl = 0;
159 int id = 0;
a011edee
FC
160
161 struct {
a85952ab 162 bool count_event_pending = false;
163 bool counting = false;
a011edee
FC
164 } flags;
165 } mcast;
a011edee 166
a85952ab 167#if USE_CACHE_DIGESTS
168 PeerDigest *digest = nullptr;
169 char *digest_url = nullptr;
a011edee
FC
170#endif
171
92c4f623
AR
172 /// The number of failures sufficient to stop selecting this cache_peer. All
173 /// cache_peer selection algorithms skip cache_peers with 0 tcp_up values.
174 /// The initial 0 value prevents unprobed cache_peers from being selected.
175 int tcp_up = 0;
176
883b9a4d
AR
177 /// whether to do another TCP probe after current TCP probes
178 bool reprobe = false;
a011edee
FC
179
180 Ip::Address addresses[10];
a85952ab 181 int n_addresses = 0;
182 int rr_count = 0;
a85952ab 183 int testing_now = 0;
a011edee
FC
184
185 struct {
a85952ab 186 unsigned int hash = 0;
187 double load_multiplier = 0.0;
188 double load_factor = 0.0; ///< normalized weight value
a011edee
FC
189 } carp;
190#if USE_AUTH
191 struct {
a85952ab 192 unsigned int hash = 0;
193 double load_multiplier = 0.0;
194 double load_factor = 0.0; ///< normalized weight value
a011edee
FC
195 } userhash;
196#endif
197 struct {
a85952ab 198 unsigned int hash = 0;
199 double load_multiplier = 0.0;
200 double load_factor = 0.0; ///< normalized weight value
a011edee
FC
201 } sourcehash;
202
a85952ab 203 char *login = nullptr; /* Proxy authorization */
5f5d319e 204 time_t connect_timeout_raw = 0; ///< connect_timeout; use connectTimeout() instead!
a85952ab 205 int connect_fail_limit = 0;
206 int max_conn = 0;
207
208 /// optional "cache_peer standby=limit" feature
e8dca475 209 struct {
a85952ab 210 PconnPool *pool = nullptr; ///< idle connection pool for this peer
211 CbcPointer<PeerPoolMgr> mgr; ///< pool manager
212 int limit = 0; ///< the limit itself
213 bool waitingForClose = false; ///< a conn must close before we open a standby conn
214 } standby;
215
216 char *domain = nullptr; ///< Forced domain
a011edee 217
cdfb670c
AJ
218 /// security settings for peer connection
219 Security::PeerOptions secure;
900daee3 220 Security::ContextPointer sslContext;
5d9a65df 221 Security::SessionStatePointer sslSession;
a011edee 222
a85952ab 223 int front_end_https = 0; ///< 0 - off, 1 - on, 2 - auto
224 int connection_auth = 2; ///< 0 - off, 1 - on, 2 - auto
022dbabd
EB
225
226private:
227 void countFailure();
a011edee
FC
228};
229
022dbabd
EB
230/// reacts to a successful establishment of a connection to an origin server or cache_peer
231/// \param peer nil if Squid established a connection to an origin server
232inline void
233NoteOutgoingConnectionSuccess(CachePeer * const peer)
234{
235 if (peer)
236 peer->noteSuccess();
237}
238
239/// reacts to a failure on a connection to an origin server or cache_peer
240/// \param peer nil if the connection is to an origin server
241/// \param code a received response status code, if any
242inline void
243NoteOutgoingConnectionFailure(CachePeer * const peer, const Http::StatusCode code)
244{
245 if (peer)
246 peer->noteFailure(code);
247}
248
a555a85b
AR
249/// identify the given cache peer in cache.log messages and such
250std::ostream &operator <<(std::ostream &, const CachePeer &);
251
ff9d9458 252#endif /* SQUID_SRC_CACHEPEER_H */
70ac5b29 253