CCF
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
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
5#include "ccf/ds/logger.h"
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 std::unordered_set<NodeId> learners;
24 std::unordered_set<NodeId> retired_nodes;
25
26 public:
28 version(version_)
29 {
30 for (const auto& [node_id, opt_ni] : w)
31 {
32 if (!opt_ni.has_value())
33 {
34 // Deleted node will have already been retired
35 continue;
36 }
37
38 const auto& ni = opt_ni.value();
39 const auto [host, port] =
40 split_net_address(ni.node_to_node_interface.published_address);
41 switch (ni.status)
42 {
44 {
45 // Pending nodes are not added to consensus until they are
46 // trusted
47 break;
48 }
50 {
51 cfg_delta.try_emplace(node_id, NodeAddr{host, port});
52 break;
53 }
55 {
56 cfg_delta.try_emplace(node_id, std::nullopt);
57 retired_nodes.insert(node_id);
58 break;
59 }
60 default:
61 {
62 }
63 }
64 }
65 }
66
68 {
69 auto configuration = consensus->get_latest_configuration_unsafe();
70 for (const auto& [node_id, opt_ni] : cfg_delta)
71 {
72 if (opt_ni.has_value())
73 {
74 configuration.try_emplace(node_id, opt_ni->hostname, opt_ni->port);
75 }
76 else
77 {
78 configuration.erase(node_id);
79 }
80 }
81 if (!cfg_delta.empty())
82 {
83 consensus->add_configuration(
84 version, configuration, learners, retired_nodes);
85 }
86 }
87 };
88}
Definition hooks.h:20
void call(ccf::kv::ConfigurableConsensus *consensus) override
Definition hooks.h:67
ConfigurationChangeHook(ccf::kv::Version version_, const Nodes::Write &w)
Definition hooks.h:27
Definition kv_types.h:229
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