]> git.ipfire.org Git - thirdparty/squid.git/blame - src/CachePeer.h
Bug 5428: Warn if pkg-config is not found (#1902)
[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
5844d003 22class NeighborTypeDomainList;
e8dca475 23class PconnPool;
a011edee 24class PeerDigest;
e8dca475 25class PeerPoolMgr;
a011edee 26
1b2f0924
FC
27class CachePeer
28{
719815a0
AJ
29 CBDATA_CLASS(CachePeer);
30
a011edee 31public:
a555a85b 32 explicit CachePeer(const char *hostname);
719815a0
AJ
33 ~CachePeer();
34
022dbabd
EB
35 /// reacts to a successful establishment of a connection to this cache_peer
36 void noteSuccess();
37
2e7dea3c
AR
38 /// reacts to a failed attempt to establish a connection to this cache_peer
39 void noteFailure();
022dbabd 40
a555a85b
AR
41 /// (re)configure cache_peer name=value
42 void rename(const char *);
43
5f5d319e
FC
44 /// \returns the effective connect timeout for the given peer
45 time_t connectTimeout() const;
46
908634e8
AR
47 /// TLS settings for communicating with this TLS cache_peer (if encryption
48 /// is required; see secure.encryptTransport) or nil (otherwise)
49 Security::FuturePeerContext *securityContext();
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;
a85952ab 145 bool mcast_siblings = false;
a85952ab 146 bool auth_no_keytab = false;
a011edee
FC
147 } options;
148
a85952ab 149 int weight = 1;
150 int basetime = 0;
a011edee
FC
151
152 struct {
a85952ab 153 double avg_n_members = 0.0;
154 int n_times_counted = 0;
155 int n_replies_expected = 0;
156 int ttl = 0;
157 int id = 0;
a011edee
FC
158
159 struct {
a85952ab 160 bool count_event_pending = false;
161 bool counting = false;
a011edee
FC
162 } flags;
163 } mcast;
a011edee 164
a85952ab 165#if USE_CACHE_DIGESTS
166 PeerDigest *digest = nullptr;
167 char *digest_url = nullptr;
a011edee
FC
168#endif
169
92c4f623
AR
170 /// The number of failures sufficient to stop selecting this cache_peer. All
171 /// cache_peer selection algorithms skip cache_peers with 0 tcp_up values.
172 /// The initial 0 value prevents unprobed cache_peers from being selected.
173 int tcp_up = 0;
174
883b9a4d
AR
175 /// whether to do another TCP probe after current TCP probes
176 bool reprobe = false;
a011edee
FC
177
178 Ip::Address addresses[10];
a85952ab 179 int n_addresses = 0;
180 int rr_count = 0;
a85952ab 181 int testing_now = 0;
a011edee
FC
182
183 struct {
a85952ab 184 unsigned int hash = 0;
185 double load_multiplier = 0.0;
186 double load_factor = 0.0; ///< normalized weight value
a011edee
FC
187 } carp;
188#if USE_AUTH
189 struct {
a85952ab 190 unsigned int hash = 0;
191 double load_multiplier = 0.0;
192 double load_factor = 0.0; ///< normalized weight value
a011edee
FC
193 } userhash;
194#endif
195 struct {
a85952ab 196 unsigned int hash = 0;
197 double load_multiplier = 0.0;
198 double load_factor = 0.0; ///< normalized weight value
a011edee
FC
199 } sourcehash;
200
a85952ab 201 char *login = nullptr; /* Proxy authorization */
5f5d319e 202 time_t connect_timeout_raw = 0; ///< connect_timeout; use connectTimeout() instead!
a85952ab 203 int connect_fail_limit = 0;
204 int max_conn = 0;
205
206 /// optional "cache_peer standby=limit" feature
e8dca475 207 struct {
a85952ab 208 PconnPool *pool = nullptr; ///< idle connection pool for this peer
209 CbcPointer<PeerPoolMgr> mgr; ///< pool manager
210 int limit = 0; ///< the limit itself
211 bool waitingForClose = false; ///< a conn must close before we open a standby conn
212 } standby;
213
214 char *domain = nullptr; ///< Forced domain
a011edee 215
908634e8 216 // TODO: Remove secure and sslContext when FuturePeerContext below becomes PeerContext
cdfb670c
AJ
217 /// security settings for peer connection
218 Security::PeerOptions secure;
900daee3 219 Security::ContextPointer sslContext;
908634e8
AR
220 Security::FuturePeerContext tlsContext;
221
5d9a65df 222 Security::SessionStatePointer sslSession;
a011edee 223
a85952ab 224 int front_end_https = 0; ///< 0 - off, 1 - on, 2 - auto
225 int connection_auth = 2; ///< 0 - off, 1 - on, 2 - auto
022dbabd
EB
226
227private:
228 void countFailure();
a011edee
FC
229};
230
022dbabd
EB
231/// reacts to a successful establishment of a connection to an origin server or cache_peer
232/// \param peer nil if Squid established a connection to an origin server
233inline void
234NoteOutgoingConnectionSuccess(CachePeer * const peer)
235{
236 if (peer)
237 peer->noteSuccess();
238}
239
2e7dea3c 240/// reacts to a failed attempt to establish a connection to an origin server or cache_peer
022dbabd 241/// \param peer nil if the connection is to an origin server
022dbabd 242inline void
2e7dea3c 243NoteOutgoingConnectionFailure(CachePeer * const peer)
022dbabd
EB
244{
245 if (peer)
2e7dea3c 246 peer->noteFailure();
022dbabd
EB
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