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
16 {
17 NODE,
18 SERVICE,
19 ACME,
21 };
24 {{Authority::NODE, "Node"},
25 {Authority::SERVICE, "Service"},
26 {Authority::ACME, "ACME"},
27 {Authority::UNSECURED, "Unsecured"}});
28
29 using ApplicationProtocol = std::string;
30
32 {
34
35 std::optional<std::string> acme_configuration;
36
37 bool operator==(const Endorsement& other) const
38 {
39 return authority == other.authority &&
41 }
42 };
46
48 {
49 std::string rpchost;
50 std::string pubhost;
51 std::string nodehost;
52 std::string nodeport;
53 std::string rpcport;
54 std::string pubport;
55 };
58 NodeInfoNetwork_v1, rpchost, pubhost, nodehost, nodeport, rpcport, pubport);
59
60 static constexpr auto PRIMARY_RPC_INTERFACE = "primary_rpc_interface";
61
71
82
85 {
86 using NetAddress = std::string;
87 using RpcInterfaceID = std::string;
88 using NetProtocol = std::string;
89
92 {
96 std::optional<ApplicationProtocol> app_protocol = std::nullopt;
97
99 std::optional<size_t> max_open_sessions_soft = std::nullopt;
100
102 std::optional<size_t> max_open_sessions_hard = std::nullopt;
103
105 std::optional<http::ParserConfiguration> http_configuration =
106 std::nullopt;
107
109 std::optional<Endorsement> endorsement = std::nullopt;
110
113 std::optional<std::vector<std::string>> accepted_endpoints = std::nullopt;
114
116 std::optional<size_t> forwarding_timeout_ms = std::nullopt;
117
125
126 std::optional<Redirections> redirections = std::nullopt;
127
141 };
142
144 using RpcInterfaces = std::map<RpcInterfaceID, NetInterface>;
145
148
151
153 struct ACME
154 {
156 std::map<std::string, ccf::ACMEClientConfig> configurations;
157
158 bool operator==(const ACME&) const = default;
159 };
160
162 std::optional<ACME> acme = std::nullopt;
163
164 // Denote whether this node will locally seal the ledger secret
166 };
167
177 endorsement,
178 max_open_sessions_soft,
179 max_open_sessions_hard,
180 published_address,
181 protocol,
182 app_protocol,
183 http_configuration,
184 accepted_endpoints,
185 forwarding_timeout_ms,
186 redirections);
191 NodeInfoNetwork_v2, node_to_node_interface, rpc_interfaces);
193 NodeInfoNetwork_v2, acme, will_locally_seal_ledger_secrets);
194
196 {
197 NodeInfoNetwork() = default;
200
201 bool operator==(const NodeInfoNetwork& other) const
202 {
205 }
206 };
207
208 inline static std::pair<std::string, std::string> split_net_address(
209 const NodeInfoNetwork::NetAddress& addr)
210 {
211 auto [host, port] = ccf::nonstd::rsplit_1(addr, ":");
212 return std::make_pair(std::string(host), std::string(port));
213 }
214
215 inline static NodeInfoNetwork::NetAddress make_net_address(
216 const std::string& host, const std::string& port)
217 {
218 return fmt::format("{}:{}", host, port);
219 }
220
221 // The JSON representation of a NodeInfoNetwork is the union of a
222 // NodeInfoNetwork_v1 and a NodeInfoNetwork_v2. It contains the fields of
223 // both, so can be read as (or from!) either
224 inline void to_json(nlohmann::json& j, const NodeInfoNetwork& nin)
225 {
226 {
228 std::tie(v1.nodehost, v1.nodeport) =
229 split_net_address(nin.node_to_node_interface.bind_address);
230
231 if (nin.rpc_interfaces.size() > 0)
232 {
233 const auto& primary_interface = nin.rpc_interfaces.begin()->second;
234 std::tie(v1.rpchost, v1.rpcport) =
235 split_net_address(primary_interface.bind_address);
236 std::tie(v1.pubhost, v1.pubport) =
237 split_net_address(primary_interface.published_address);
238 }
239 to_json(j, v1);
240 }
241
242 to_json(j, (const NodeInfoNetwork_v2&)nin);
243 }
244
245 inline void from_json(const nlohmann::json& j, NodeInfoNetwork& nin)
246 {
247 try
248 {
250 from_json(j, v2);
251 nin = NodeInfoNetwork(v2);
252 }
253 catch (const ccf::JsonParseError& jpe)
254 {
256 try
257 {
258 from_json(j, v1);
259 }
260 catch (const ccf::JsonParseError& _)
261 {
262 // If this also fails to parse as a v1, then rethrow the earlier error.
263 // Configs should now be using v2, and this v1 parsing is just a
264 // backwards-compatibility shim, which does not get to return errors.
265 throw jpe;
266 }
267
269 make_net_address(v1.nodehost, v1.nodeport);
270
271 NodeInfoNetwork::NetInterface primary_interface;
272 primary_interface.bind_address = make_net_address(v1.rpchost, v1.rpcport);
273 primary_interface.published_address =
274 make_net_address(v1.pubhost, v1.pubport);
275
276 nin.rpc_interfaces.emplace(
277 PRIMARY_RPC_INTERFACE, std::move(primary_interface));
278 }
279 }
280}
281
282FMT_BEGIN_NAMESPACE template <>
283struct formatter<ccf::Authority>
284{
285 template <typename ParseContext>
286 constexpr auto parse(ParseContext& ctx)
287 {
288 return ctx.begin();
289 }
290
291 template <typename FormatContext>
292 auto format(const ccf::Authority& authority, FormatContext& ctx) const
293 -> decltype(ctx.out())
294 {
295 switch (authority)
296 {
298 {
299 return format_to(ctx.out(), "Node");
300 }
302 {
303 return format_to(ctx.out(), "Service");
304 }
306 {
307 return format_to(ctx.out(), "ACME");
308 }
310 {
311 return format_to(ctx.out(), "Unsecured");
312 }
313 }
314 }
315};
316FMT_END_NAMESPACE
Definition json.h:26
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:714
#define DECLARE_JSON_TYPE(TYPE)
Definition json.h:663
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:690
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:786
#define DECLARE_JSON_ENUM(TYPE,...)
Definition json.h:837
Definition acme_client.h:30
Definition app_interface.h:14
RedirectionResolutionKind
Definition node_info_network.h:63
std::string ApplicationProtocol
Definition node_info_network.h:29
void from_json(const nlohmann::json &j, ClaimsDigest &hash)
Definition claims_digest.h:54
Authority
Definition node_info_network.h:16
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
std::optional< std::string > acme_configuration
Definition node_info_network.h:35
bool operator==(const Endorsement &other) const
Definition node_info_network.h:37
Definition node_info_network.h:48
std::string pubport
Definition node_info_network.h:54
std::string nodehost
Definition node_info_network.h:51
std::string rpchost
Definition node_info_network.h:49
std::string rpcport
Definition node_info_network.h:53
std::string nodeport
Definition node_info_network.h:52
std::string pubhost
Definition node_info_network.h:50
ACME configuration description.
Definition node_info_network.h:154
std::map< std::string, ccf::ACMEClientConfig > configurations
Mapping of ACME client configuration names to configurations.
Definition node_info_network.h:156
bool operator==(const ACME &) const =default
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:92
std::optional< size_t > max_open_sessions_hard
Maximum open sessions hard limit.
Definition node_info_network.h:102
std::optional< Redirections > redirections
Definition node_info_network.h:126
NetProtocol protocol
Definition node_info_network.h:95
std::optional< size_t > max_open_sessions_soft
Maximum open sessions soft limit.
Definition node_info_network.h:99
std::optional< size_t > forwarding_timeout_ms
Timeout for forwarded RPC calls (in milliseconds)
Definition node_info_network.h:116
std::optional< ApplicationProtocol > app_protocol
Definition node_info_network.h:96
std::optional< http::ParserConfiguration > http_configuration
HTTP configuration.
Definition node_info_network.h:105
NetAddress bind_address
Definition node_info_network.h:93
std::optional< std::vector< std::string > > accepted_endpoints
Definition node_info_network.h:113
NetAddress published_address
Definition node_info_network.h:94
bool operator==(const NetInterface &other) const
Definition node_info_network.h:128
std::optional< Endorsement > endorsement
Interface endorsement.
Definition node_info_network.h:109
Node network information.
Definition node_info_network.h:85
bool will_locally_seal_ledger_secrets
Definition node_info_network.h:165
NetInterface node_to_node_interface
Node-to-node network interface.
Definition node_info_network.h:147
std::optional< ACME > acme
ACME configuration.
Definition node_info_network.h:162
std::string RpcInterfaceID
Definition node_info_network.h:87
std::string NetProtocol
Definition node_info_network.h:88
std::string NetAddress
Definition node_info_network.h:86
std::map< RpcInterfaceID, NetInterface > RpcInterfaces
RPC interface mapping.
Definition node_info_network.h:144
RpcInterfaces rpc_interfaces
RPC interfaces.
Definition node_info_network.h:150
Definition node_info_network.h:196
bool operator==(const NodeInfoNetwork &other) const
Definition node_info_network.h:201
NodeInfoNetwork(const NodeInfoNetwork_v2 &other)
Definition node_info_network.h:198
NodeInfoNetwork()=default
Definition node_info_network.h:73
bool operator==(const RedirectionResolverConfig &) const =default
RedirectionResolutionKind kind
Definition node_info_network.h:74
nlohmann::json target
Definition node_info_network.h:75
constexpr auto parse(ParseContext &ctx)
Definition node_info_network.h:286
auto format(const ccf::Authority &authority, FormatContext &ctx) const -> decltype(ctx.out())
Definition node_info_network.h:292