Skip to content

Commit

Permalink
Node: add buildReportRssiTopic method
Browse files Browse the repository at this point in the history
Common code for all node types, so just implement it in parent class.
  • Loading branch information
DavidB137 committed Sep 24, 2024
1 parent 86dd78c commit c98729c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/kvik/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,12 @@ namespace kvik
bool validateMsgTimestamp(
uint16_t ts,
std::chrono::milliseconds tsDiff = std::chrono::milliseconds(0));

/**
* @brief Builds RSSI report topic
* @param addr Peer address
* @return RSSI report topic
*/
std::string buildReportRssiTopic(const LocalAddr &peer) const;
};
} // namespace kvik
9 changes: 9 additions & 0 deletions src/common/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,13 @@ namespace kvik
return msgTsUnits <= nowUnits &&
msgTsUnits >= nowUnits - maxDriftUnits;
}

std::string INode::buildReportRssiTopic(const LocalAddr &peer) const
{
return m_nodeConf.reporting.baseTopic +
m_nodeConf.topicSep.levelSeparator +
m_nodeConf.reporting.rssiSubtopic +
m_nodeConf.topicSep.levelSeparator +
peer.toString();
}
} // namespace kvik
1 change: 1 addition & 0 deletions test/include/kvik_testing/dummy_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace kvik
using INode::INode;
using INode::validateMsgId;
using INode::validateMsgTimestamp;
using INode::buildReportRssiTopic;

ErrCode pubSubUnsubBulk(const std::vector<PubData> &newPubs,
const std::vector<SubReq> &newSubs,
Expand Down
16 changes: 16 additions & 0 deletions test/tests/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,19 @@ TEST_CASE("Validate message timestamp", "[Node]")
CHECK_FALSE(node.validateMsgTimestamp(msgTsNow - 2, tsDiff));
}
}

TEST_CASE("Build RSSI report topic", "[Node]")
{
auto conf = DEFAULT_CONFIG;
conf.reporting.baseTopic = "REPORT";
conf.reporting.rssiSubtopic = "RSSI";
conf.topicSep.levelSeparator = "..";

LocalAddr peer;
peer.addr = {1, 2, 3};

DummyNode node(conf);

CHECK(node.buildReportRssiTopic(peer) ==
"REPORT..RSSI.." + peer.toString());
}

0 comments on commit c98729c

Please sign in to comment.