#include "SearchEvent.hpp" #include #include #include #include #include #include "../../tasks/types.hpp" #include "../../events/types.hpp" namespace drp { void event::SearchEvent::handle( Context& context, const packet::GenericPacketContent& content, const sockaddr_storage& fromAddress, const socklen_t fromAddressLength ) { packet::GenericPacket packet {}; packet::GenericPacketContent packetContent {}; // create the packet header (available to read for everyone) packet.channel = 0; packet.securityMode = static_cast(packet::SecurityMode::PLAIN); // insert our information into the packet packetContent.eventType = static_cast(EventType::INFO); std::memcpy(&packetContent.data, &context.me, sizeof(context.me)); packet.setContent(packetContent); // TODO(Faraphel): send back the timestamp too // broadcast our information if (sendto( context.socket, &packet, sizeof(packet), 0, reinterpret_cast(&fromAddress), fromAddressLength ) == -1) { std::cerr << "[Receiver] Could not send information: " << strerror(errno) << std::endl; return; } std::cout << "[Receiver] Sent information." << std::endl; } }