Skip to content

Commit

Permalink
LocalMsg: add relayed address
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidB137 committed Sep 5, 2024
1 parent 11e3c17 commit 1826096
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/kvik/local_msg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace kvik
{
LocalMsgType type = LocalMsgType::NONE; //!< Type of message
LocalAddr addr = {}; //!< Source/destination address
LocalAddr relayedAddr = {}; //!< Relayed address (processed by relay node)
std::string topic = ""; //!< Topic of message
std::string payload = ""; //!< Payload of message
LocalMsgFailReason failReason = LocalMsgFailReason::NONE; //!< Fail reason
Expand Down Expand Up @@ -108,6 +109,7 @@ struct std::hash<kvik::LocalMsg>
{
return std::hash<kvik::LocalMsgType>{}(msg.type) +
std::hash<kvik::LocalAddr>{}(msg.addr) +
std::hash<kvik::LocalAddr>{}(msg.relayedAddr) +
std::hash<std::string>{}(msg.topic) +
std::hash<std::string>{}(msg.payload) +
std::hash<kvik::LocalMsgFailReason>{}(msg.failReason);
Expand Down
2 changes: 2 additions & 0 deletions src/common/local_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace kvik
") ")
: "") +
(!addr.empty() ? addr.toString() : "(no addr)") + " " +
(!relayedAddr.empty() ? relayedAddr.toString() : "(not relayed)") + " " +
(!topic.empty() ? topic : "(no topic)") + " " +
"(" + std::to_string(payload.length()) + " B payload)";
}
Expand All @@ -73,6 +74,7 @@ namespace kvik
{
return type == other.type &&
addr == other.addr &&
relayedAddr == other.relayedAddr &&
topic == other.topic &&
payload == other.payload &&
failReason == other.failReason;
Expand Down
6 changes: 6 additions & 0 deletions test/tests/local_msg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ TEST_CASE("Comparison", "[LocalMsg]")
REQUIRE(msg1 != msg2);
}

SECTION("Different relayed addresses")
{
msg2.relayedAddr.addr.push_back(0x01);
REQUIRE(msg1 != msg2);
}

SECTION("Different topics")
{
msg2.topic = "1";
Expand Down

0 comments on commit 1826096

Please sign in to comment.