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
174 endorsement,
175 max_open_sessions_soft,
176 max_open_sessions_hard,
177 published_address,
178 protocol,
179 app_protocol,
180 http_configuration,
181 accepted_endpoints,
182 forwarding_timeout_ms,
183 redirections);
188 NodeInfoNetwork_v2, node_to_node_interface, rpc_interfaces);
190
192 {
193 NodeInfoNetwork() = default;
196
197 bool operator==(const NodeInfoNetwork& other) const
198 {
201 }
202 };
203
204 inline static std::pair<std::string, std::string> split_net_address(
205 const NodeInfoNetwork::NetAddress& addr)
206 {
207 auto [host, port] = ccf::nonstd::rsplit_1(addr, ":");
208 return std::make_pair(std::string(host), std::string(port));
209 }
210
211 inline static NodeInfoNetwork::NetAddress make_net_address(
212 const std::string& host, const std::string& port)
213 {
214 return fmt::format("{}:{}", host, port);
215 }
216
217 // The JSON representation of a NodeInfoNetwork is the union of a
218 // NodeInfoNetwork_v1 and a NodeInfoNetwork_v2. It contains the fields of
219 // both, so can be read as (or from!) either
220 inline void to_json(nlohmann::json& j, const NodeInfoNetwork& nin)
221 {
222 {
224 std::tie(v1.nodehost, v1.nodeport) =
225 split_net_address(nin.node_to_node_interface.bind_address);
226
227 if (nin.rpc_interfaces.size() > 0)
228 {
229 const auto& primary_interface = nin.rpc_interfaces.begin()->second;
230 std::tie(v1.rpchost, v1.rpcport) =
231 split_net_address(primary_interface.bind_address);
232 std::tie(v1.pubhost, v1.pubport) =
233 split_net_address(primary_interface.published_address);
234 }
235 to_json(j, v1);
236 }
237
238 to_json(j, (const NodeInfoNetwork_v2&)nin);
239 }
240
241 inline void from_json(const nlohmann::json& j, NodeInfoNetwork& nin)
242 {
243 try
244 {
246 from_json(j, v2);
247 nin = NodeInfoNetwork(v2);
248 }
249 catch (const ccf::JsonParseError& jpe)
250 {
252 try
253 {
254 from_json(j, v1);
255 }
256 catch (const ccf::JsonParseError& _)
257 {
258 // If this also fails to parse as a v1, then rethrow the earlier error.
259 // Configs should now be using v2, and this v1 parsing is just a
260 // backwards-compatibility shim, which does not get to return errors.
261 throw jpe;
262 }
263
265 make_net_address(v1.nodehost, v1.nodeport);
266
267 NodeInfoNetwork::NetInterface primary_interface;
268 primary_interface.bind_address = make_net_address(v1.rpchost, v1.rpcport);
269 primary_interface.published_address =
270 make_net_address(v1.pubhost, v1.pubport);
271
272 nin.rpc_interfaces.emplace(
273 PRIMARY_RPC_INTERFACE, std::move(primary_interface));
274 }
275 }
276}
277
278FMT_BEGIN_NAMESPACE template <>
279struct formatter<ccf::Authority>
280{
281 template <typename ParseContext>
282 constexpr auto parse(ParseContext& ctx)
283 {
284 return ctx.begin();
285 }
286
287 template <typename FormatContext>
288 auto format(const ccf::Authority& authority, FormatContext& ctx) const
289 -> decltype(ctx.out())
290 {
291 switch (authority)
292 {
294 {
295 return format_to(ctx.out(), "Node");
296 }
298 {
299 return format_to(ctx.out(), "Service");
300 }
302 {
303 return format_to(ctx.out(), "ACME");
304 }
306 {
307 return format_to(ctx.out(), "Unsecured");
308 }
309 }
310 }
311};
312FMT_END_NAMESPACE
Definition json.h:24
#define DECLARE_JSON_REQUIRED_FIELDS(TYPE,...)
Definition json.h:712
#define DECLARE_JSON_TYPE(TYPE)
Definition json.h:661
#define DECLARE_JSON_TYPE_WITH_OPTIONAL_FIELDS(TYPE)
Definition json.h:688
#define DECLARE_JSON_OPTIONAL_FIELDS(TYPE,...)
Definition json.h:784
#define DECLARE_JSON_ENUM(TYPE,...)
Definition json.h:835
Definition acme_client.h:30
Definition app_interface.h:15
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:13
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
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:192
bool operator==(const NodeInfoNetwork &other) const
Definition node_info_network.h:197
NodeInfoNetwork(const NodeInfoNetwork_v2 &other)
Definition node_info_network.h:194
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:282
auto format(const ccf::Authority &authority, FormatContext &ctx) const -> decltype(ctx.out())
Definition node_info_network.h:288