SOLA
Loading...
Searching...
No Matches
procedure_info.h
1// Copyright The SOLA Contributors
2//
3// Licensed under the MIT License.
4// For details on the licensing terms, see the LICENSE file.
5// SPDX-License-Identifier: MIT
6
7#ifndef MINHTON_PROCEDURES_INFO_H_
8#define MINHTON_PROCEDURES_INFO_H_
9
10#include <future>
11#include <unordered_map>
12#include <vector>
13
14#include "minhton/algorithms/esearch/find_query.h"
15#include "minhton/core/definitions.h"
16#include "minhton/core/node_info.h"
17#include "minhton/core/physical_node_info.h"
18
19namespace minhton {
20
21enum class ProcedureKey : uint8_t {
22 kBootstrapProcess,
23 kJoinProcedure,
24 kLeaveProcedure,
25 kAcceptChildProcedure,
26 kFindReplacementProcedure,
27 kEntitySearchUndecidedNodeInquiries,
28};
29
39public:
40 ProcedureInfo() = default;
41 ~ProcedureInfo() = default;
42
43 bool hasKey(ProcedureKey key) const;
44
45 void save(ProcedureKey key, const std::vector<minhton::NodeInfo> &value);
46 std::vector<minhton::NodeInfo> load(ProcedureKey key);
47 void update(ProcedureKey key, const std::vector<minhton::NodeInfo> &value);
48 void remove(ProcedureKey key);
49
50 void saveEventId(ProcedureKey key, uint64_t event_id);
51 uint64_t loadEventId(ProcedureKey key);
52 void removeEventId(ProcedureKey key);
53
54 void saveFindQuery(uint64_t ref_event_id, const FindQuery &value);
55 FindQuery loadFindQuery(uint64_t ref_event_id);
56 void updateFindQuery(uint64_t ref_event_id, const FindQuery &value);
57 void removeFindQuery(uint64_t ref_event_id);
58
59 void saveFindQueryUndecidedNodes(uint64_t ref_event_id, const std::vector<NodeInfo> &value);
60 std::vector<NodeInfo> loadFindQueryUndecidedNodes(uint64_t ref_event_id);
61 void updateFindQueryUndecidedNodes(uint64_t ref_event_id, const std::vector<NodeInfo> &value);
62 void removeFindQueryUndecidedNodes(uint64_t ref_event_id);
63
64 void saveFindQueryPreliminaryResults(uint64_t ref_event_id,
65 const NodeData::NodesWithAttributes &value);
66 NodeData::NodesWithAttributes loadFindQueryPreliminaryResults(uint64_t ref_event_id);
67 void addFindQueryPreliminaryResults(uint64_t ref_event_id, const NodeInfo &node,
68 NodeData::Attributes value);
69 void removeFindQueryPreliminaryResults(uint64_t ref_event_id);
70
71 void saveDSNAggregationStartTimestamp(uint64_t ref_event_id, uint64_t value);
72 uint64_t loadDSNAggregationStartTimestamp(uint64_t ref_event_id);
73 void updateDSNAggregationStartTimestamp(uint64_t ref_event_id, uint64_t value);
74 void removeDSNAggregationStartTimestamp(uint64_t ref_event_id);
75 std::unordered_map<uint64_t, uint64_t> getDSNAggregationStartTimestampMap() const;
76
77 void saveInquiryAggregationStartTimestamp(uint64_t ref_event_id, uint64_t value);
78 uint64_t loadInquiryAggregationStartTimestamp(uint64_t ref_event_id);
79 void updateInquiryAggregationStartTimestamp(uint64_t ref_event_id, uint64_t value);
80 void removeInquiryAggregationStartTimestamp(uint64_t ref_event_id);
81 std::unordered_map<uint64_t, uint64_t> getInquiryAggregationStartTimestampMap() const;
82
83 void saveNumberOfAddressedDSNs(uint64_t ref_event_id, uint16_t value);
84 uint16_t loadNumberOfAddressedDSNs(uint64_t ref_event_id);
85 void updateNumberOfAddressedDSNs(uint64_t ref_event_id, uint16_t value);
86 void removeNumberOfAddressedDSNs(uint64_t ref_event_id);
87
88 void saveNumberOfAnsweredDSNs(uint64_t ref_event_id, uint16_t value);
89 uint16_t loadNumberOfAnsweredDSNs(uint64_t ref_event_id);
90 void updateNumberOfAnsweredDSNs(uint64_t ref_event_id, uint16_t value);
91 void removeNumberOfAnsweredDSNs(uint64_t ref_event_id);
92
93 void saveFindResultPromise(uint64_t ref_event_id, std::promise<FindResult> &&promise);
94 std::promise<FindResult> &loadFindResultPromise(uint64_t ref_event_id);
95 void removeFindResultPromise(uint64_t ref_event_id);
96
97 bool hasEvent(ProcedureKey key) const;
98 bool hasNodeInfo(ProcedureKey key) const;
99
100 bool hasFindQueryEvent(uint64_t ref_event_id) const;
101 bool hasFindQueryUndecidedNodes(uint64_t ref_event_id) const;
102 bool hasFindQueryPreliminaryResults(uint64_t ref_event_id) const;
103 bool hasDSNAggregationStartTimestamp(uint64_t ref_event_id) const;
104 bool hasInquiryAggregationStartTimestamp(uint64_t ref_event_id) const;
105 bool hasNumberOfAddressedDSNs(uint64_t ref_event_id) const;
106 bool hasNumberOfAnsweredDSNs(uint64_t ref_event_id) const;
107 bool hasFindResultFuture(uint64_t ref_event_id) const;
108
109private:
110 std::unordered_map<ProcedureKey, std::vector<minhton::NodeInfo>> map_;
111 std::unordered_map<ProcedureKey, uint64_t> event_ids_;
112
113 // RefEventId -> FindQuery
114 std::unordered_map<uint64_t, FindQuery> find_query_requests_;
115
116 // RefEventId -> vector of undecided nodes
117 std::unordered_map<uint64_t, std::vector<NodeInfo>> find_query_undecided_nodes_;
118
119 // RefEventId -> vector answered nodes and preliminary answers
120 std::unordered_map<uint64_t, NodeData::NodesWithAttributes> find_query_preliminary_results_;
121
122 // RefEventId -> Timestamp
123 std::unordered_map<uint64_t, uint64_t> dsn_aggregation_start_timestamp_;
124
125 // RefEventId -> Timestamp
126 std::unordered_map<uint64_t, uint64_t> inquiry_aggregation_start_timestamp_;
127
128 // RefEventId -> Number of addressed DSNs
129 std::unordered_map<uint64_t, uint16_t> number_of_addressed_dsns_;
130
131 // RefEventId -> Number of answered DSNs
132 std::unordered_map<uint64_t, uint16_t> number_of_answered_dsns_;
133
134 std::unordered_map<uint64_t, std::promise<FindResult>> find_result_promises_;
135};
136
137} // namespace minhton
138
139#endif
Definition find_query.h:21
Definition node_info.h:24
Definition procedure_info.h:38
Definition minhton_watchdog_ns3.cpp:24