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