SOLA
Loading...
Searching...
No Matches
event_dissemination_minhcast.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 SOLA_EVENT_DISSEMINATION_MINHCAST_H_
8#define SOLA_EVENT_DISSEMINATION_MINHCAST_H_
9
10#include "SOLA/logger_interface.h"
11#include "SOLA/message.h"
12#include "event_dissemination/event_dissemination.h"
13#include "minhton/core/minhton.h"
14#include "natter/natter_minhcast.h"
15#include "storage/storage.h"
16
17struct Info {
18 std::string ip;
19 uint16_t port;
20
21 bool operator==(const Info &other) const { return ip == other.ip && port == other.port; }
22 bool operator<(const Info &other) const { return ip < other.ip || port < other.port; }
23};
24
25namespace std {
26template <> struct hash<Info> {
27 size_t operator()(const Info &p) const {
28 return std::hash<std::string>()(p.ip) ^ std::hash<uint16_t>()(p.port);
29 }
30};
31} // namespace std
32
33namespace sola {
34
36 std::vector<natter::logging::LoggerPtr> logger;
37
40 std::function<minhton::Logger::LoggerPtr(std::string)> topic_tree_logger_create_fct;
41};
42
44public:
46 using Logger = natter::logging::LoggerPtr;
47
48 EventDisseminationMinhcast(TopicMessageReceiveFct msgRecvFct, std::shared_ptr<Storage> storage_,
49 const Config &config, LoggerPtr logger);
50 ~EventDisseminationMinhcast() override = default;
51 void publish(const TopicMessage &msg) override;
52 void subscribe(const std::string &topic) override;
53 void unsubscribe(const std::string &topic) override;
54
55 void stop() override;
56 bool canStop() const override;
57
58private:
59 void waitForResults(const std::string &topic);
60 void joinMinhton(minhton::FindResult result, const std::string &topic,
61 const std::vector<minhton::Logger::LoggerPtr> &logger);
62
63 // Implementation in event_dissemination_minhcast_impl.cpp
64 void getResult(const std::string &topic, const std::function<void()> &on_result);
65 void checkTopicJoin(const std::string &topic, bool should_exist);
66
67 const Config config_;
68
69 std::unique_ptr<natter::minhcast::NatterMinhcast> minhcast_;
70
71 using Minhton = std::unique_ptr<minhton::Minhton>;
72 using Topic = std::string;
73 using MinhtonFuture = std::future<minhton::FindResult>;
74
75 std::unordered_map<Topic, MinhtonFuture> result_;
76
77 struct MinhtonTopicLogger {
78 Topic topic;
79 std::vector<minhton::Logger::LoggerPtr> logger;
80 };
81
82 std::vector<MinhtonTopicLogger> minhton_loggers_;
83
84 std::unordered_map<Topic, Minhton> topic_trees_;
85 std::unordered_map<Info, uint32_t> peers_added_natter_;
86 std::shared_ptr<Storage> storage_;
87
88 bool stopping_ = false;
89
90 LoggerPtr logger_; // Logger only for logging msg id mapping. Receive/Send logging
91 // is automatically done within SOLA itself.
92};
93} // namespace sola
94
95#endif
Definition event_dissemination_minhcast.h:43
Definition event_dissemination.h:14
Definition event_dissemination_minhcast.h:17
Definition event_dissemination_minhcast.h:35
std::function< minhton::Logger::LoggerPtr(std::string)> topic_tree_logger_create_fct
Definition event_dissemination_minhcast.h:40
Definition message.h:20