#include "InfoEvent.hpp" #include #include namespace drp::event { void InfoEvent::handle( Context& context, const packet::GenericPacketContent& content, sockaddr* fromAddress, const socklen_t fromAddressLength ) { // check if the peer address is already in the map std::shared_ptr remotePeer; auto iterator = context.remotePeers.find(*fromAddress); 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; } // save the remote peer information std::memcpy(&remotePeer->information, &content, sizeof(Peer)); // TODO(Faraphel): interpret the timestamp and calculate average ping // save it in the peers list context.remotePeers[remotePeer->address] = remotePeer; } }