CCF
Loading...
Searching...
No Matches
hooks.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#pragma once
4
10
11namespace ccf
12{
13 struct NodeAddr
14 {
15 std::string hostname;
16 std::string port;
17 };
18
20 {
21 ccf::kv::Version version;
22 std::map<NodeId, std::optional<NodeAddr>> cfg_delta;
23
24 public:
26 version(version_)
27 {
28 for (const auto& [node_id, opt_ni] : w)
29 {
30 if (!opt_ni.has_value())
31 {
32 // Deleted node will have already been retired
33 continue;
34 }
35
36 const auto& ni = opt_ni.value();
37 const auto [host, port] =
38 split_net_address(ni.node_to_node_interface.published_address);
39 switch (ni.status)
40 {
42 {
43 // Pending nodes are not added to consensus until they are
44 // trusted
45 break;
46 }
48 {
49 cfg_delta.try_emplace(node_id, NodeAddr{host, port});
50 break;
51 }
53 {
54 cfg_delta.try_emplace(node_id, std::nullopt);
55 break;
56 }
57 default:
58 {
59 }
60 }
61 }
62 }
63
65 {
66 auto configuration = consensus->get_latest_configuration_unsafe();
67 for (const auto& [node_id, opt_ni] : cfg_delta)
68 {
69 if (opt_ni.has_value())
70 {
71 configuration.try_emplace(node_id, opt_ni->hostname, opt_ni->port);
72 }
73 else
74 {
75 configuration.erase(node_id);
76 }
77 }
78 if (!cfg_delta.empty())
79 {
80 consensus->add_configuration(version, configuration);
81 }
82 }
83 };
84}
Definition hooks.h:20
void call(ccf::kv::ConfigurableConsensus *consensus) override
Definition hooks.h:64
ConfigurationChangeHook(ccf::kv::Version version_, const Nodes::Write &w)
Definition hooks.h:25
Definition kv_types.h:191
Definition hooks.h:15
std::map< K, std::optional< V > > Write
Definition map.h:40
uint64_t Version
Definition version.h:8
Definition app_interface.h:14
Definition consensus_types.h:23
Definition configuration.h:14
Definition hooks.h:14
std::string hostname
Definition hooks.h:15
std::string port
Definition hooks.h:16