SOLA
Loading...
Searching...
No Matches
node_data.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_ESEARCH_NODE_DATA_H_
8#define MINHTON_ESEARCH_NODE_DATA_H_
9
10#include <string>
11#include <unordered_map>
12#include <variant>
13#include <vector>
14
15#include "minhton/core/node_info.h"
16#include "solanet/serializer/serialize.h"
17
18namespace minhton {
19
20class NodeData {
21public:
22 enum ValueType : uint8_t {
23 kValueDynamic = 0,
24 kValueStatic = 1,
25 };
26
27 using Key = std::string;
28 using Value = std::variant<int, float, bool, std::string>;
29 using ValueAndTimestamp = std::tuple<Value, uint64_t>;
30 using ValueTimestampAndType = std::tuple<Value, uint64_t, ValueType>;
31 using ValueAndType = std::tuple<Value, ValueType>;
32
33 using Attributes = std::vector<std::tuple<NodeData::Key, NodeData::Value>>;
34 using NodesWithAttributes = std::unordered_map<NodeInfo, Attributes, NodeInfoHasher>;
35
36 using AttributesAndTypes =
37 std::vector<std::tuple<NodeData::Key, NodeData::Value, NodeData::ValueType>>;
38 using NodesWithAttributesAndTypes =
39 std::unordered_map<NodeInfo, AttributesAndTypes, NodeInfoHasher>;
40
41 NodeData();
42
43 virtual bool insert(Key key, ValueTimestampAndType value_timestamp_and_type);
44 virtual bool update(Key key, ValueTimestampAndType value_timestamp_and_type);
45 virtual void remove(Key key);
46
47 bool hasKey(const Key &key);
48 Value getValue(Key key);
49 ValueAndTimestamp getValueAndTimestamp(Key key);
50 ValueTimestampAndType getValueTimestampAndType(Key key);
51
52 std::unordered_map<Key, ValueTimestampAndType> getData() const;
53
54 virtual bool isValueUpToDate(const NodeData::Key &key, uint64_t validity_threshold_timestamp);
55
56 virtual bool isLocal() const = 0;
57
58 std::vector<Key> getAllCurrentKeys();
59
60 SERIALIZE(data_);
61
62private:
63 std::unordered_map<Key, ValueTimestampAndType> data_;
64};
65
66} // namespace minhton
67
68#endif
Definition node_data.h:20
Definition minhton_watchdog_ns3.cpp:24