From 4f84c8186aa65fdcfd36b46f5809970242d4a937 Mon Sep 17 00:00:00 2001 From: study-faraphel Date: Wed, 6 Nov 2024 15:52:56 +0100 Subject: [PATCH] added timestamp to broadcast search message --- source/main.cpp | 2 -- source/tasks/undefined/UndefinedTask.cpp | 15 +++++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 2d43a70..371aa9f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -5,8 +5,6 @@ int main(int argc, char* argv[]) { - // TODO(Faraphel): move in the Client - // initialize the mpg123 library if (mpg123_init() != MPG123_OK) throw std::runtime_error("Error while initializing mpg123."); diff --git a/source/tasks/undefined/UndefinedTask.cpp b/source/tasks/undefined/UndefinedTask.cpp index 383cae2..d8bbd1d 100644 --- a/source/tasks/undefined/UndefinedTask.cpp +++ b/source/tasks/undefined/UndefinedTask.cpp @@ -10,6 +10,7 @@ #include "../../Context.hpp" #include "../../events/types.hpp" #include "../../packets/base/GenericPacket.hpp" +#include "../../packets/search/SearchPacketData.hpp" namespace drp::task { @@ -61,19 +62,13 @@ void UndefinedTask::handle(Context& context) { packet::GenericPacketContent packetContent {}; packet::SearchPacketData packetData {}; + // broadcast message packet.channel = 0; packet.securityMode = static_cast(packet::SecurityMode::PLAIN); - - packetData.timestamp = std::chrono::high_resolution_clock::now(); + // search message with the time of the message being sent packetContent.eventType = static_cast(event::EventType::SEARCH); - packetContent.data = 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 + packetData.timestamp = std::chrono::high_resolution_clock::now(); + std::memcpy(&packetContent.data, &packetData, sizeof(packetData)); packet.setContent(packetContent); // send the search message