added timestamp to broadcast search message

This commit is contained in:
study-faraphel 2024-11-06 15:52:56 +01:00
parent aa24bb3509
commit 4f84c8186a
2 changed files with 5 additions and 12 deletions

View file

@ -5,8 +5,6 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
// TODO(Faraphel): move in the Client
// initialize the mpg123 library // initialize the mpg123 library
if (mpg123_init() != MPG123_OK) if (mpg123_init() != MPG123_OK)
throw std::runtime_error("Error while initializing mpg123."); throw std::runtime_error("Error while initializing mpg123.");

View file

@ -10,6 +10,7 @@
#include "../../Context.hpp" #include "../../Context.hpp"
#include "../../events/types.hpp" #include "../../events/types.hpp"
#include "../../packets/base/GenericPacket.hpp" #include "../../packets/base/GenericPacket.hpp"
#include "../../packets/search/SearchPacketData.hpp"
namespace drp::task { namespace drp::task {
@ -61,19 +62,13 @@ void UndefinedTask::handle(Context& context) {
packet::GenericPacketContent packetContent {}; packet::GenericPacketContent packetContent {};
packet::SearchPacketData packetData {}; packet::SearchPacketData packetData {};
// broadcast message
packet.channel = 0; packet.channel = 0;
packet.securityMode = static_cast<std::uint8_t>(packet::SecurityMode::PLAIN); packet.securityMode = static_cast<std::uint8_t>(packet::SecurityMode::PLAIN);
// search message with the time of the message being sent
packetData.timestamp = std::chrono::high_resolution_clock::now();
packetContent.eventType = static_cast<std::uint8_t>(event::EventType::SEARCH); packetContent.eventType = static_cast<std::uint8_t>(event::EventType::SEARCH);
packetContent.data = packetData; packetData.timestamp = std::chrono::high_resolution_clock::now();
std::memcpy(&packetContent.data, &packetData, sizeof(packetData));
// TODO(Faraphel): generate a random broadcast code and put it in the packet.
// when sending the response to this message, include this broadcast code.
// it will allow us to determinate an estimation of the ping of the machine
// will help when electing a server.
// Bonus: when electing a server, define a random value in the constructor to send
// to every election, allowing for distinction of machines
packet.setContent(packetContent); packet.setContent(packetContent);
// send the search message // send the search message