1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
6 #include "include/ceph_features.h"
10 using peer_type_t
= int;
13 * A Policy describes the rules of a Connection. Is there a limit on how
14 * much data this Connection can have locally? When the underlying connection
15 * experiences an error, does the Connection disappear? Can this Messenger
16 * re-establish the underlying connection?
18 template<class ThrottleType
>
20 /// If true, the Connection is tossed out on errors.
22 /// If true, the underlying connection can't be re-established from this end.
24 /// If true, we will standby when idle
26 /// If true, we will try to detect session resets
29 /// Server: register lossy client connections.
30 bool register_lossy_clients
= true;
31 // The net result of this is that a given client can only have one
32 // open connection with the server. If a new connection is made,
33 // the old (registered) one is closed by the messenger during the accept
37 * The throttler is used to limit how much data is held by Messages from
38 * the associated Connection(s). When reading in a new Message, the Messenger
39 * will call throttler->throttle() for the size of the new Message.
41 ThrottleType
* throttler_bytes
;
42 ThrottleType
* throttler_messages
;
44 /// Specify features supported locally by the endpoint.
45 #ifdef MSG_POLICY_UNIT_TESTING
46 uint64_t features_supported
{CEPH_FEATURES_SUPPORTED_DEFAULT
};
48 static constexpr uint64_t features_supported
{CEPH_FEATURES_SUPPORTED_DEFAULT
};
51 /// Specify features any remotes must have to talk to this endpoint.
52 uint64_t features_required
;
55 : lossy(false), server(false), standby(false), resetcheck(true),
56 throttler_bytes(NULL
),
57 throttler_messages(NULL
),
58 features_required(0) {}
60 Policy(bool l
, bool s
, bool st
, bool r
, bool rlc
, uint64_t req
)
61 : lossy(l
), server(s
), standby(st
), resetcheck(r
),
62 register_lossy_clients(rlc
),
63 throttler_bytes(NULL
),
64 throttler_messages(NULL
),
65 features_required(req
) {}
68 static Policy
stateful_server(uint64_t req
) {
69 return Policy(false, true, true, true, true, req
);
71 static Policy
stateless_registered_server(uint64_t req
) {
72 return Policy(true, true, false, false, true, req
);
74 static Policy
stateless_server(uint64_t req
) {
75 return Policy(true, true, false, false, false, req
);
77 static Policy
lossless_peer(uint64_t req
) {
78 return Policy(false, false, true, false, true, req
);
80 static Policy
lossless_peer_reuse(uint64_t req
) {
81 return Policy(false, false, true, true, true, req
);
83 static Policy
lossy_client(uint64_t req
) {
84 return Policy(true, false, false, false, true, req
);
86 static Policy
lossless_client(uint64_t req
) {
87 return Policy(false, false, false, true, true, req
);
91 template<class ThrottleType
>
93 using policy_t
= Policy
<ThrottleType
> ;
94 /// the default Policy we use for Pipes
95 policy_t default_policy
;
96 /// map specifying different Policies for specific peer types
97 std::map
<int, policy_t
> policy_map
; // entity_name_t::type -> Policy
100 const policy_t
& get(peer_type_t peer_type
) const {
101 if (auto found
= policy_map
.find(peer_type
); found
!= policy_map
.end()) {
102 return found
->second
;
104 return default_policy
;
107 policy_t
& get(peer_type_t peer_type
) {
108 if (auto found
= policy_map
.find(peer_type
); found
!= policy_map
.end()) {
109 return found
->second
;
111 return default_policy
;
114 void set(peer_type_t peer_type
, const policy_t
& p
) {
115 policy_map
[peer_type
] = p
;
117 const policy_t
& get_default() const {
118 return default_policy
;
120 void set_default(const policy_t
& p
) {
123 void set_throttlers(peer_type_t peer_type
,
124 ThrottleType
* byte_throttle
,
125 ThrottleType
* msg_throttle
) {
126 auto& policy
= get(peer_type
);
127 policy
.throttler_bytes
= byte_throttle
;
128 policy
.throttler_messages
= msg_throttle
;