added timestamp to broadcast search message
This commit is contained in:
parent
aa24bb3509
commit
4f84c8186a
2 changed files with 5 additions and 12 deletions
|
@ -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.");
|
||||
|
|
|
@ -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<std::uint8_t>(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<std::uint8_t>(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
|
||||
|
|
Loading…
Reference in a new issue