2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_CACHEPEER_H_
10 #define SQUID_CACHEPEER_H_
12 #include "acl/forward.h"
13 #include "base/CbcPointer.h"
15 #include "http/StatusCode.h"
16 #include "icp_opcode.h"
17 #include "ip/Address.h"
18 #include "security/PeerOptions.h"
22 //TODO: remove, it is unconditionally defined and always used.
23 #define PEER_MULTICAST_SIBLINGS 1
25 class NeighborTypeDomainList
;
32 CBDATA_CLASS(CachePeer
);
35 explicit CachePeer(const char *hostname
);
38 /// reacts to a successful establishment of a connection to this cache_peer
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
);
45 /// (re)configure cache_peer name=value
46 void rename(const char *);
48 /// \returns the effective connect timeout for the given peer
49 time_t connectTimeout() const;
53 /// cache_peer name (if explicitly configured) or hostname (otherwise).
54 /// Unique across already configured cache_peers in the current configuration.
55 /// Not necessarily unique across discovered non-peers (see mgr:non_peers).
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).
62 /// The lowercase version of the configured cache_peer hostname or
63 /// the IP address of a non-peer (see mgr:non_peers).
64 /// May not be unique among cache_peers and non-peers.
68 peer_t type
= PEER_NONE
;
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
90 icp_() { memset(&counts
, 0, sizeof(counts
)); }
91 int version
= ICP_VERSION_CURRENT
;
92 int counts
[ICP_END
+1];
93 unsigned short port
= CACHE_ICP_PORT
;
99 int counts
[2] = {0, 0};
100 unsigned short port
= 0;
104 unsigned short http_port
= CACHE_HTTP_PORT
;
105 NeighborTypeDomainList
*typelist
= nullptr;
106 acl_access
*access
= nullptr;
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;
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;
126 bool no_netdb_exchange
= false;
128 bool no_delay
= false;
130 bool allow_miss
= false;
133 bool set
= false; //If false, whole url is to be used. Overrides others
141 bool userhash
= false;
143 bool sourcehash
= false;
144 bool originserver
= false;
145 bool no_tproxy
= false;
146 #if PEER_MULTICAST_SIBLINGS
147 bool mcast_siblings
= false;
149 bool auth_no_keytab
= false;
156 double avg_n_members
= 0.0;
157 int n_times_counted
= 0;
158 int n_replies_expected
= 0;
163 bool count_event_pending
= false;
164 bool counting
= false;
168 #if USE_CACHE_DIGESTS
169 PeerDigest
*digest
= nullptr;
170 char *digest_url
= nullptr;
173 /// The number of failures sufficient to stop selecting this cache_peer. All
174 /// cache_peer selection algorithms skip cache_peers with 0 tcp_up values.
175 /// The initial 0 value prevents unprobed cache_peers from being selected.
178 /// whether to do another TCP probe after current TCP probes
179 bool reprobe
= false;
181 Ip::Address addresses
[10];
184 CachePeer
*next
= nullptr;
188 unsigned int hash
= 0;
189 double load_multiplier
= 0.0;
190 double load_factor
= 0.0; ///< normalized weight value
194 unsigned int hash
= 0;
195 double load_multiplier
= 0.0;
196 double load_factor
= 0.0; ///< normalized weight value
200 unsigned int hash
= 0;
201 double load_multiplier
= 0.0;
202 double load_factor
= 0.0; ///< normalized weight value
205 char *login
= nullptr; /* Proxy authorization */
206 time_t connect_timeout_raw
= 0; ///< connect_timeout; use connectTimeout() instead!
207 int connect_fail_limit
= 0;
210 /// optional "cache_peer standby=limit" feature
212 PconnPool
*pool
= nullptr; ///< idle connection pool for this peer
213 CbcPointer
<PeerPoolMgr
> mgr
; ///< pool manager
214 int limit
= 0; ///< the limit itself
215 bool waitingForClose
= false; ///< a conn must close before we open a standby conn
218 char *domain
= nullptr; ///< Forced domain
220 /// security settings for peer connection
221 Security::PeerOptions secure
;
222 Security::ContextPointer sslContext
;
223 Security::SessionStatePointer sslSession
;
225 int front_end_https
= 0; ///< 0 - off, 1 - on, 2 - auto
226 int connection_auth
= 2; ///< 0 - off, 1 - on, 2 - auto
232 /// reacts to a successful establishment of a connection to an origin server or cache_peer
233 /// \param peer nil if Squid established a connection to an origin server
235 NoteOutgoingConnectionSuccess(CachePeer
* const peer
)
241 /// reacts to a failure on a connection to an origin server or cache_peer
242 /// \param peer nil if the connection is to an origin server
243 /// \param code a received response status code, if any
245 NoteOutgoingConnectionFailure(CachePeer
* const peer
, const Http::StatusCode code
)
248 peer
->noteFailure(code
);
251 /// identify the given cache peer in cache.log messages and such
252 std::ostream
&operator <<(std::ostream
&, const CachePeer
&);
254 #endif /* SQUID_CACHEPEER_H_ */