1 /*
2  * Copyright (C) 1996-2021 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_CACHEPEER_H_
10 #define SQUID_CACHEPEER_H_
11 
12 #include "acl/forward.h"
13 #include "base/CbcPointer.h"
14 #include "enums.h"
15 #include "icp_opcode.h"
16 #include "ip/Address.h"
17 #include "security/PeerOptions.h"
18 
19 //TODO: remove, it is unconditionally defined and always used.
20 #define PEER_MULTICAST_SIBLINGS 1
21 
22 class NeighborTypeDomainList;
23 class PconnPool;
24 class PeerDigest;
25 class PeerPoolMgr;
26 
27 class CachePeer
28 {
29     CBDATA_CLASS(CachePeer);
30 
31 public:
32     CachePeer();
33     ~CachePeer();
34 
35     u_int index;
36     char *name;
37     char *host;
38     peer_t type;
39 
40     Ip::Address in_addr;
41 
42     struct {
43         int pings_sent;
44         int pings_acked;
45         int fetches;
46         int rtt;
47         int ignored_replies;
48         int n_keepalives_sent;
49         int n_keepalives_recv;
50         time_t probe_start;
51         time_t last_query;
52         time_t last_reply;
53         time_t last_connect_failure;
54         time_t last_connect_probe;
55         int logged_state;   /* so we can print dead/revived msgs */
56         int conn_open;      /* current opened connections */
57     } stats;
58 
59     struct {
60         int version;
61         int counts[ICP_END+1];
62         unsigned short port;
63     } icp;
64 
65 #if USE_HTCP
66     struct {
67         double version;
68         int counts[2];
69         unsigned short port;
70     } htcp;
71 #endif
72 
73     unsigned short http_port;
74     NeighborTypeDomainList *typelist;
75     acl_access *access;
76 
77     struct {
78         bool proxy_only;
79         bool no_query;
80         bool background_ping;
81         bool no_digest;
82         bool default_parent;
83         bool roundrobin;
84         bool weighted_roundrobin;
85         bool mcast_responder;
86         bool closest_only;
87 #if USE_HTCP
88         bool htcp;
89         bool htcp_oldsquid;
90         bool htcp_no_clr;
91         bool htcp_no_purge_clr;
92         bool htcp_only_clr;
93         bool htcp_forward_clr;
94 #endif
95         bool no_netdb_exchange;
96 #if USE_DELAY_POOLS
97         bool no_delay;
98 #endif
99         bool allow_miss;
100         bool carp;
101         struct {
102             bool set; //If false, whole url is to be used. Overrides others
103             bool scheme;
104             bool host;
105             bool port;
106             bool path;
107             bool params;
108         } carp_key;
109 #if USE_AUTH
110         bool userhash;
111 #endif
112         bool sourcehash;
113         bool originserver;
114         bool no_tproxy;
115 #if PEER_MULTICAST_SIBLINGS
116         bool mcast_siblings;
117 #endif
118         bool auth_no_keytab;
119     } options;
120 
121     int weight;
122     int basetime;
123 
124     struct {
125         double avg_n_members;
126         int n_times_counted;
127         int n_replies_expected;
128         int ttl;
129         int id;
130 
131         struct {
132             bool count_event_pending;
133             bool counting;
134         } flags;
135     } mcast;
136 #if USE_CACHE_DIGESTS
137 
138     PeerDigest *digest;
139     char *digest_url;
140 #endif
141 
142     int tcp_up;         /* 0 if a connect() fails */
143     /// whether to do another TCP probe after current TCP probes
144     bool reprobe;
145 
146     Ip::Address addresses[10];
147     int n_addresses;
148     int rr_count;
149     CachePeer *next;
150     int testing_now;
151 
152     struct {
153         unsigned int hash;
154         double load_multiplier;
155         double load_factor; /* normalized weight value */
156     } carp;
157 #if USE_AUTH
158     struct {
159         unsigned int hash;
160         double load_multiplier;
161         double load_factor; /* normalized weight value */
162     } userhash;
163 #endif
164     struct {
165         unsigned int hash;
166         double load_multiplier;
167         double load_factor; /* normalized weight value */
168     } sourcehash;
169 
170     char *login;        /* Proxy authorization */
171     time_t connect_timeout_raw; ///< connect_timeout; use peerConnectTimeout() instead!
172     int connect_fail_limit;
173     int max_conn;
174     struct {
175         PconnPool *pool; ///< idle connection pool for this peer
176         CbcPointer<PeerPoolMgr> mgr; ///< pool manager
177         int limit; ///< the limit itself
178         bool waitingForClose; ///< a conn must close before we open a standby conn
179     } standby; ///< optional "cache_peer standby=limit" feature
180     char *domain;       /* Forced domain */
181 
182     /// security settings for peer connection
183     Security::PeerOptions secure;
184     Security::ContextPointer sslContext;
185     Security::SessionStatePointer sslSession;
186 
187     int front_end_https;
188     int connection_auth;
189 };
190 
191 #endif /* SQUID_CACHEPEER_H_ */
192 
193