SOLA
Loading...
Searching...
No Matches
broadcast_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 NATTER_BROADCAST_INFO_H_
8#define NATTER_BROADCAST_INFO_H_
9
10#include <cstdint>
11#include <string>
12
13#include "forwarding_limit.h"
14#include "natter/minhcast_level_number.h"
15#include "solanet/uuid.h"
16#include "utils/tree_helper.h"
17
18namespace natter::minhcast {
20 const std::tuple<solanet::UUID, LevelNumber> own_node;
21 const std::tuple<solanet::UUID, LevelNumber> last_node;
22 const std::tuple<solanet::UUID, LevelNumber> initial_node;
23 const ForwardingLimit forwarding_limit;
24 const std::string topic;
25 const solanet::UUID msg_id;
26 const std::string content;
27 const uint32_t current_round;
28
29 // Own node
30 inline uint32_t ownLevel() const { return std::get<0>(getOwnNodePos()); }
31 inline uint32_t ownNumber() const { return std::get<1>(getOwnNodePos()); }
32 inline uint32_t ownFanout() const { return std::get<2>(getOwnNodePos()); }
33
34 // Last node
35 inline uint32_t lastLevel() const { return std::get<0>(getLastNodePos()); }
36 inline uint32_t lastNumber() const { return std::get<1>(getLastNodePos()); }
37 inline uint32_t lastFanout() const { return std::get<2>(getLastNodePos()); }
38
39 // Initial node
40 inline uint32_t initialLevel() const { return std::get<0>(getInitialNodePos()); }
41 inline uint32_t initialNumber() const { return std::get<1>(getInitialNodePos()); }
42 inline uint32_t initialFanout() const { return std::get<2>(getInitialNodePos()); }
43
44 inline LevelNumber getOwnNodePos() const { return std::get<1>(own_node); }
45 inline LevelNumber getLastNodePos() const { return std::get<1>(last_node); }
46 inline LevelNumber getInitialNodePos() const { return std::get<1>(initial_node); }
47
48 bool isInitialSender() const { return initial_node == own_node; }
49 bool receivedDirectlyFromAbove() const { return lastLevel() + 1 == ownLevel(); }
50 bool receivedFromAbove() const { return lastLevel() < ownLevel(); }
51 bool parentFromInitial() const {
52 return childFromNode(std::get<1>(initial_node), std::get<1>(own_node));
53 }
54 bool allowedDownForward() const { return ownLevel() < forwarding_limit.down(); }
55 bool allowedUpForward() const { return ownLevel() > forwarding_limit.up(); }
56 bool receivedFromLowerAdjacent() const {
57 return lastLevel() > ownLevel() && lastLevel() - 1 > ownLevel();
58 }
59};
60} // namespace natter::minhcast
61
62#endif // DAISI_BROADCAST_INFO_H_
Definition forwarding_limit.h:19
Definition broadcast_info.h:19