#include "InfoEvent.hpp" #include #include namespace drp::event { void InfoEvent::handle( Context& context, const packet::GenericPacketContent& content, const sockaddr_storage& fromAddress, const socklen_t fromAddressLength ) { // get the peer information Peer peer; std::memcpy(&peer, content.data.data(), sizeof(Peer)); // check if the peer address is already in the map const auto iterator = context.remotePeers.find(peer.id); std::shared_ptr remotePeer; if (iterator == context.remotePeers.end()) { // if not found, create a new peer remotePeer = std::make_shared(); remotePeer->address = fromAddress; remotePeer->addressLength = fromAddressLength; // update the latest discovery time context.latestPeerDiscovery = std::chrono::high_resolution_clock::now(); } else { // get the peer remotePeer = iterator->second; } // TODO(Faraphel): interpret the timestamp and calculate average ping // save it in the peers list remotePeer->information = peer; context.remotePeers[peer.id] = remotePeer; } }