continued developping the undefined task behavior
This commit is contained in:
parent
93f8701ac5
commit
aa24bb3509
8 changed files with 25 additions and 14 deletions
|
@ -48,6 +48,7 @@ add_executable(M2-PT-DRP
|
|||
source/Context.hpp
|
||||
source/utils/CacheMap.cpp
|
||||
source/utils/CacheMap.hpp
|
||||
source/packets/search/SearchPacketData.hpp
|
||||
)
|
||||
target_include_directories(M2-PT-DRP PRIVATE
|
||||
${MPG123_INCLUDE_DIRS}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "tasks/types.hpp"
|
||||
|
|
|
@ -37,7 +37,7 @@ void AudioEvent::handle(
|
|||
) {
|
||||
// get the audio data in the content
|
||||
packet::AudioPacketData audioData;
|
||||
std::memcpy(&audioData, content.data.data(), content.data.size());
|
||||
std::memcpy(&audioData, content.data.data(), sizeof(packet::AudioPacketData));
|
||||
// save it in the audio queue
|
||||
this->audioQueue.push(audioData);
|
||||
// notify that a new audio chunk is available
|
||||
|
|
|
@ -23,6 +23,8 @@ void InfoEvent::handle(
|
|||
remotePeer->addressLength = fromAddressLength;
|
||||
std::memcpy(&remotePeer->information, &content, sizeof(Peer));
|
||||
|
||||
// TODO(Faraphel): interpret the timestamp and calculate average ping
|
||||
|
||||
// save it in the peers list
|
||||
context.remotePeers.push_back(remotePeer);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,8 @@ void event::SearchEvent::handle(
|
|||
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,
|
||||
|
|
13
source/packets/search/SearchPacketData.hpp
Normal file
13
source/packets/search/SearchPacketData.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
#include <chrono>
|
||||
|
||||
|
||||
namespace drp::packet {
|
||||
|
||||
|
||||
typedef struct {
|
||||
std::chrono::time_point<std::chrono::system_clock> timestamp; /// timestamp when the search request was sent
|
||||
} SearchPacketData;
|
||||
|
||||
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <bits/random.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "../../Context.hpp"
|
||||
|
@ -58,11 +59,15 @@ void UndefinedTask::handle(Context& context) {
|
|||
// prepare a search message
|
||||
packet::GenericPacket packet {};
|
||||
packet::GenericPacketContent packetContent {};
|
||||
packet::SearchPacketData packetData {};
|
||||
|
||||
packet.channel = 0;
|
||||
packet.securityMode = static_cast<std::uint8_t>(packet::SecurityMode::PLAIN);
|
||||
|
||||
packetData.timestamp = std::chrono::high_resolution_clock::now();
|
||||
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
|
||||
|
|
|
@ -10,19 +10,6 @@ namespace drp::task {
|
|||
class UndefinedTask final : public BaseTask {
|
||||
public:
|
||||
void handle(Context& context) override;
|
||||
|
||||
private:
|
||||
std::uniform_int_distribution(
|
||||
std::numeric_limits<std::uint16_t>::min(),
|
||||
std::numeric_limits<std::uint16_t>::max()
|
||||
) broadcastCodeGenerator;
|
||||
|
||||
util::CacheMap<
|
||||
uint32_t,
|
||||
std::chrono::high_resolution_clock::time_point,
|
||||
128
|
||||
> broadcastCode;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue