CCF
Loading...
Searching...
No Matches
node_info_network.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3
4#pragma once
5
6#include "ccf/ds/json.h"
7#include "ccf/ds/nonstd.h"
10
11#include <string>
12
13namespace ccf
14{
15 enum class Authority : uint8_t
16 {
17 NODE,
18 SERVICE,
19 ACME, // DEPRECATED
21 };
24 {{Authority::NODE, "Node"},
25 {Authority::SERVICE, "Service"},
26 {Authority::ACME, "ACME"}, // DEPRECATED
27 {Authority::UNSECURED, "Unsecured"}});
28
29 using ApplicationProtocol = std::string;
30
32 {
34 bool operator==(const Endorsement& other) const
35 {
36 return authority == other.authority;
37 }
38 };
41
43 {
44 std::string rpchost;
45 std::string pubhost;
46 std::string nodehost;
47 std::string nodeport;
48 std::string rpcport;
49 std::string pubport;
50 };
53 NodeInfoNetwork_v1, rpchost, pubhost, nodehost, nodeport, rpcport, pubport);
54
55 static constexpr auto PRIMARY_RPC_INTERFACE = "primary_rpc_interface";
56
57 enum class RedirectionResolutionKind : uint8_t
58 {
61 };
66
77
80 {
81 using NetAddress = std::string;
82 using RpcInterfaceID = std::string;
83 using NetProtocol = std::string;
84
87 {
91 std::optional<ApplicationProtocol> app_protocol = std::nullopt;
92
94 std::optional<size_t> max_open_sessions_soft = std::nullopt;
95
97 std::optional<size_t> max_open_sessions_hard = std::nullopt;
98
100 std::optional<http::ParserConfiguration> http_configuration =
101 std::nullopt;
102
104 std::optional<Endorsement> endorsement = std::nullopt;
105
108 std::optional<std::vector<std::string>> accepted_endpoints = std::nullopt;
109
111 std::optional<size_t> forwarding_timeout_ms = std::nullopt;
112
116 std::set<ccf::endpoints::OperatorFeature> enabled_operator_features;
117
125
126 std::optional<Redirections> redirections = std::nullopt;
127
142 };
143
145 using RpcInterfaces = std::map<RpcInterfaceID, NetInterface>;
146
149
152
153 // Denote whether this node will locally seal the ledger secret
155 };
156
166 endorsement,
167 max_open_sessions_soft,
168 max_open_sessions_hard,
169 published_address,
170 protocol,
171 app_protocol,
172 http_configuration,
173 accepted_endpoints,
174 forwarding_timeout_ms,
175 enabled_operator_features,
176 redirections);
179 NodeInfoNetwork_v2, node_to_node_interface, rpc_interfaces);
181 NodeInfoNetwork_v2, will_locally_seal_ledger_secrets);
182
184 {
185 NodeInfoNetwork() = default;
188
189 bool operator==(const NodeInfoNetwork& other) const
190 {
193 }
194 };
195
196 inline static std::pair<std::string, std::string> split_net_address(
197 const NodeInfoNetwork::NetAddress& addr)
198 {
199 auto [host, port] = ccf::nonstd::rsplit_1(addr, ":");
200 return std::make_pair(std::string(host), std::string(port));
201 }
202
203 inline static NodeInfoNetwork::NetAddress make_net_address(
204 const std::string& host, const std::string& port)
205 {
206 return fmt::format("{}:{}", host, port);
207 }
208
209 // The JSON representation of a NodeInfoNetwork is the union of a
210 // NodeInfoNetwork_v1 and a NodeInfoNetwork_v2. It contains the fields of
211 // both, so can be read as (or from!) either
212 inline void to_json(nlohmann::json& j, const NodeInfoNetwork& nin)
213 {
214 {
216 std::tie(v1.nodehost, v1.nodeport) =
217 split_net_address(nin.node_to_node_interface.bind_address);
218
219 if (!nin.rpc_interfaces.empty())
220 {
221 const auto& primary_interface = nin.rpc_interfaces.begin()->second;
222 std::tie(v1.rpchost, v1.rpcport) =
223 split_net_address(primary_interface.bind_address);
224 std::tie(v1.pubhost, v1.pubport) =
225 split_net_address(primary_interface.published_address);
226 }
227 to_json(j, v1);
228 }
229
230 to_json(j, (const NodeInfoNetwork_v2&)nin);
231 }
232
233 inline void from_json(const nlohmann::json& j, NodeInfoNetwork& nin)
234 {
235 try
236 {
238 from_json(j, v2);
239 nin = NodeInfoNetwork(v2);
240 }
241 catch (const ccf::JsonParseError& jpe)
242 {
244 try
245 {
246 from_json(j, v1);
247 }
248 catch (const ccf::JsonParseError& _)
249 {
250 // If this also fails to parse as a v1, then rethrow the earlier error.
251 // Configs should now be using v2, and this v1 parsing is just a
252 // backwards-compatibility shim, which does not get to return errors.
253 throw jpe;
254 }
255
257 make_net_address(v1.nodehost, v1.nodeport);
258
259 NodeInfoNetwork::NetInterface primary_interface;
260 primary_interface.bind_address = make_net_address(v1.rpchost, v1.rpcport);
261 primary_interface.published_address =
262 make_net_address(v1.pubhost, v1.pubport);
263
264 nin.rpc_interfaces.emplace(
265 PRIMARY_RPC_INTERFACE, std::move(primary_interface));
266 }
267 }
268}
269
270FMT_BEGIN_NAMESPACE template <>
271struct formatter<ccf::Authority>
272{
273 template <typename ParseContext>
274 constexpr auto parse(ParseContext& ctx)
275 {
276 return ctx.begin();
277 }
278
279 template <typename FormatContext>
280 auto format(const ccf::Authority& authority, FormatContext& ctx) const
281 -> decltype(ctx.out())
282 {
283 switch (authority)
284 {
286 {
287 return format_to(ctx.out(), "Node");
288 }
290 {
291 return format_to(ctx.out(), "Service");
292 }
294 {
295 return format_to(ctx.out(), "ACME");
296 }
298 {
299 return format_to(ctx.out(), "Unsecured");
300 }
301 }
302 }
303};
304FMT_END_NAMESPACE
Definition json.h:26
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:718
#define DECLARE_JSON_TYPE(TYPE)
Definition json.h:667
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:694
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:790
#define DECLARE_JSON_ENUM(TYPE,...)
Definition json.h:841
Definition app_interface.h:14
std::string ApplicationProtocol
Definition node_info_network.h:29
Authority
Definition node_info_network.h:16
void from_json(const nlohmann::json &j, ClaimsDigest &hash)
Definition claims_digest.h:54
RedirectionResolutionKind
Definition node_info_network.h:58
void to_json(nlohmann::json &j, const ClaimsDigest &hash)
Definition claims_digest.h:49
Definition configuration.h:14
Definition node_info_network.h:32
Authority authority
Definition node_info_network.h:33
bool operator==(const Endorsement &other) const
Definition node_info_network.h:34
Definition node_info_network.h:43
std::string pubport
Definition node_info_network.h:49
std::string nodehost
Definition node_info_network.h:46
std::string rpchost
Definition node_info_network.h:44
std::string rpcport
Definition node_info_network.h:48
std::string nodeport
Definition node_info_network.h:47
std::string pubhost
Definition node_info_network.h:45
Definition node_info_network.h:119
bool operator==(const Redirections &other) const =default
RedirectionResolverConfig to_primary
Definition node_info_network.h:120
RedirectionResolverConfig to_backup
Definition node_info_network.h:121
Network interface description.
Definition node_info_network.h:87
std::optional< size_t > max_open_sessions_hard
Maximum open sessions hard limit.
Definition node_info_network.h:97
std::optional< Redirections > redirections
Definition node_info_network.h:126
NetProtocol protocol
Definition node_info_network.h:90
std::optional< size_t > max_open_sessions_soft
Maximum open sessions soft limit.
Definition node_info_network.h:94
std::optional< size_t > forwarding_timeout_ms
Timeout for forwarded RPC calls (in milliseconds)
Definition node_info_network.h:111
std::optional< ApplicationProtocol > app_protocol
Definition node_info_network.h:91
std::optional< http::ParserConfiguration > http_configuration
HTTP configuration.
Definition node_info_network.h:100
std::set< ccf::endpoints::OperatorFeature > enabled_operator_features
Definition node_info_network.h:116
NetAddress bind_address
Definition node_info_network.h:88
std::optional< std::vector< std::string > > accepted_endpoints
Definition node_info_network.h:108
NetAddress published_address
Definition node_info_network.h:89
bool operator==(const NetInterface &other) const
Definition node_info_network.h:128
std::optional< Endorsement > endorsement
Interface endorsement.
Definition node_info_network.h:104
Node network information.
Definition node_info_network.h:80
bool will_locally_seal_ledger_secrets
Definition node_info_network.h:154
NetInterface node_to_node_interface
Node-to-node network interface.
Definition node_info_network.h:148
std::string RpcInterfaceID
Definition node_info_network.h:82
std::string NetProtocol
Definition node_info_network.h:83
std::string NetAddress
Definition node_info_network.h:81
std::map< RpcInterfaceID, NetInterface > RpcInterfaces
RPC interface mapping.
Definition node_info_network.h:145
RpcInterfaces rpc_interfaces
RPC interfaces.
Definition node_info_network.h:151
Definition node_info_network.h:184
bool operator==(const NodeInfoNetwork &other) const
Definition node_info_network.h:189
NodeInfoNetwork(const NodeInfoNetwork_v2 &other)
Definition node_info_network.h:186
NodeInfoNetwork()=default
Definition node_info_network.h:68
bool operator==(const RedirectionResolverConfig &) const =default
RedirectionResolutionKind kind
Definition node_info_network.h:69
nlohmann::json target
Definition node_info_network.h:70
constexpr auto parse(ParseContext &ctx)
Definition node_info_network.h:274
auto format(const ccf::Authority &authority, FormatContext &ctx) const -> decltype(ctx.out())
Definition node_info_network.h:280