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