diff --git a/src/network/event.cpp b/src/network/event.cpp index e63216763..adc242262 100644 --- a/src/network/event.cpp +++ b/src/network/event.cpp @@ -41,7 +41,7 @@ constexpr bool isConnectionRequestPacket(unsigned char* data, size_t length) // ============================================================================ Event::Event(ENetEvent* event, std::shared_ptr peer) { - m_arrival_time = (double)StkTime::getTimeSinceEpoch(); + m_arrival_time = StkTime::getMonoTimeMs(); m_pdi = PDI_TIMEOUT; m_peer = peer; diff --git a/src/network/event.hpp b/src/network/event.hpp index 01317569a..7b56d9a94 100644 --- a/src/network/event.hpp +++ b/src/network/event.hpp @@ -84,7 +84,7 @@ private: std::shared_ptr m_peer; /** Arrivial time of the event, for timeouts. */ - double m_arrival_time; + uint64_t m_arrival_time; /** For disconnection event, a bit more info is provided. */ PeerDisconnectInfo m_pdi; @@ -119,7 +119,7 @@ public: m_data->isSynchronous(); } // ------------------------------------------------------------------------ /** Returns the arrival time of this event. */ - double getArrivalTime() const { return m_arrival_time; } + uint64_t getArrivalTime() const { return m_arrival_time; } // ------------------------------------------------------------------------ PeerDisconnectInfo getPeerDisconnectInfo() const { return m_pdi; } // ------------------------------------------------------------------------ diff --git a/src/network/protocol_manager.cpp b/src/network/protocol_manager.cpp index 2418d2cf0..204458f6d 100644 --- a/src/network/protocol_manager.cpp +++ b/src/network/protocol_manager.cpp @@ -449,7 +449,8 @@ bool ProtocolManager::sendEvent(Event* event) can_be_deleted |= m_all_protocols.at(i).notifyEvent(event); } } - return can_be_deleted || StkTime::getTimeSinceEpoch() - event->getArrivalTime() + const uint64_t TIME_TO_KEEP_EVENTS = 1000; + return can_be_deleted || StkTime::getMonoTimeMs() - event->getArrivalTime() >= TIME_TO_KEEP_EVENTS; } // sendEvent diff --git a/src/network/protocol_manager.hpp b/src/network/protocol_manager.hpp index 98c1aa317..72308108d 100644 --- a/src/network/protocol_manager.hpp +++ b/src/network/protocol_manager.hpp @@ -41,8 +41,6 @@ class Event; class STKPeer; -#define TIME_TO_KEEP_EVENTS 1.0 - // ---------------------------------------------------------------------------- /** \enum ProtocolRequestType * \brief Defines actions that can be done about protocols.