M2-PT-DRP/source/events/info/InfoEvent.cpp

33 lines
835 B
C++

#include "InfoEvent.hpp"
#include <cstring>
#include <sys/socket.h>
namespace drp::event {
void InfoEvent::handle(
Context& context,
const packet::GenericPacketContent& content,
sockaddr* fromAddress,
const socklen_t fromAddressLength
) {
const auto remotePeer = std::make_shared<RemotePeer>();
// TODO(Faraphel): first check if the peer is already in the list
// do not update the time of the list if yes !
// save the remote peer information
remotePeer->address = *reinterpret_cast<sockaddr*>(&fromAddress);
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);
}
}