SOLA
Loading...
Searching...
No Matches
dsn_handler.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 ALGORITHMS_ESEARCH_DSN_HANDLER_H_
8#define ALGORITHMS_ESEARCH_DSN_HANDLER_H_
9
10#include <memory>
11#include <queue>
12#include <unordered_map>
13#include <vector>
14
15#include "minhton/algorithms/esearch/distributed_data.h"
16#include "minhton/algorithms/esearch/find_query.h"
17#include "minhton/core/routing_information.h"
18
19namespace minhton {
20
22public:
23 DSNHandler(std::shared_ptr<RoutingInformation> routing_info,
24 std::function<void(const NodeInfo &node)> request_attribute_inquiry_callback);
25
35 bool isActive();
36
49 std::vector<std::tuple<NodeInfo, std::vector<NodeData::Key>>> getUndecidedNodesAndMissingKeys(
50 FindQuery &query, bool all_information_present, const uint64_t &timestamp_now);
51
61 std::vector<NodeInfo> getTrueNodes(FindQuery &query, const uint64_t &timestamp_now);
62
72 NeighborRelationship relationship);
73
74 void onNodeInfoChangeNotification(const minhton::NodeInfo &previous_node_info,
75 const minhton::NodeInfo &new_node_info);
76
77 void requestAttributeInformation(LogicalNodeInfo peer, const DistributedData &distr_data);
78
90 const NodeInfo &inquired_or_updated_node,
91 std::unordered_map<NodeData::Key, NodeData::ValueAndType> attribute_values_and_types,
92 uint64_t update_timestamp);
93
94 // TODO unit tests
95 void updateRemovedAttributes(const NodeInfo &inquired_node,
96 std::vector<NodeData::Key> removed_keys);
97
99 std::unordered_map<LogicalNodeInfo, DistributedData, LogicalNodeInfoHasher> getCoverData() const;
100
101 // TODO unit tests
102 void notifyAboutQueryRequest(const FindQuery &query, uint64_t request_timestamp);
103
104 // LATER unit tests
105 std::unordered_map<NodeInfo, std::vector<NodeData::Key>, NodeInfoHasher>
106 getNodesAndKeysToSubscribe(uint64_t const &timestamp_now);
107
108 // LATER unit tests
109 std::unordered_map<NodeInfo, std::vector<NodeData::Key>, NodeInfoHasher>
110 getNodesAndKeysToUnsubscribe(uint64_t const &timestamp_now);
111
112 // TODO unit tests
113 void setPlacedSubscriptionOrders(
114 std::unordered_map<NodeInfo, std::vector<NodeData::Key>, NodeInfoHasher>
115 subscription_orders_map);
116
117 // TODO unit tests
118 void setPlacedUnsubscriptionOrders(
119 std::unordered_map<NodeInfo, std::vector<NodeData::Key>, NodeInfoHasher>
120 unsubscription_orders_map);
121
122 NodeData::Attributes getNodeAttributes(const NodeInfo &node);
123
124private:
127 void checkPosition();
128
131 void buildCoverArea();
132
133 void buildExtendedCoverArea();
134
135 void buildTempCoverArea();
136
138 bool is_active_;
139
140 bool was_previously_active_ = false;
141
143 NodeInfo previous_node_info_;
144
146 std::shared_ptr<RoutingInformation> routing_info_;
147
152 std::unordered_map<LogicalNodeInfo, DistributedData, LogicalNodeInfoHasher> cover_data_;
153
156 std::vector<std::tuple<uint32_t, uint32_t>> cover_area_positions_;
157
158 std::vector<std::tuple<uint32_t, uint32_t>> extended_cover_area_positions_;
159 std::unordered_map<LogicalNodeInfo, DistributedData, LogicalNodeInfoHasher> extended_cover_data_;
160
163 std::unordered_map<NodeData::Key, std::queue<uint64_t>> request_timestamps_;
164
166 uint8_t timestamp_storage_limit_ = 5;
167
168 std::function<void(const NodeInfo &)> request_attribute_inquiry_callback_;
169
177 static double calculateFrequency(std::queue<uint64_t> timestamps, uint64_t const &timestamp_now);
178};
179
180} // namespace minhton
181
182#endif
Definition dsn_handler.h:21
std::unordered_map< LogicalNodeInfo, DistributedData, LogicalNodeInfoHasher > getCoverData() const
Definition dsn_handler.cpp:350
void updateInquiredOrSubscribedAttributeValues(const NodeInfo &inquired_or_updated_node, std::unordered_map< NodeData::Key, NodeData::ValueAndType > attribute_values_and_types, uint64_t update_timestamp)
Definition dsn_handler.cpp:291
bool isActive()
Definition dsn_handler.cpp:39
std::vector< NodeInfo > getTrueNodes(FindQuery &query, const uint64_t &timestamp_now)
Definition dsn_handler.cpp:274
std::vector< std::tuple< NodeInfo, std::vector< NodeData::Key > > > getUndecidedNodesAndMissingKeys(FindQuery &query, bool all_information_present, const uint64_t &timestamp_now)
Definition dsn_handler.cpp:253
void onNeighborChangeNotification(const minhton::NodeInfo &neighbor, NeighborRelationship relationship)
Definition dsn_handler.cpp:192
Definition distributed_data.h:20
Definition find_query.h:21
Definition logical_node_info.h:23
Definition node_info.h:24
Definition minhton_watchdog_ns3.cpp:24
Definition node_info.h:148