From 5b39e856970ae4301584490c1e9beabbb450b2e3 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Fri, 22 Dec 2023 15:01:57 +0100 Subject: [PATCH] discard syncs into the future --- solanaceae/zox/ngc_hs.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/solanaceae/zox/ngc_hs.cpp b/solanaceae/zox/ngc_hs.cpp index 9b01f98..a4ee1a0 100644 --- a/solanaceae/zox/ngc_hs.cpp +++ b/solanaceae/zox/ngc_hs.cpp @@ -255,7 +255,7 @@ bool ZoxNGCHistorySync::onEvent(const Events::ZoxNGC_ngch_request& e) { // convert sync delta to ms const int64_t sync_delta_offset_ms = int64_t(e.sync_delta) * 1000 * 60; - const uint64_t ts_start = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() - sync_delta_offset_ms; + const uint64_t ts_start = Message::getTimeMS() - sync_delta_offset_ms; auto view = reg.view(); view.use(); @@ -337,7 +337,14 @@ bool ZoxNGCHistorySync::onEvent(const Events::ZoxNGC_ngch_syncmsg& e) { // convert to ms uint64_t sync_ts = std::chrono::milliseconds(std::chrono::seconds{e.timestamp}).count(); // o.o - uint64_t now_ts = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + uint64_t now_ts = Message::getTimeMS(); + + const uint64_t max_future_ms = 1u*60u*1000u; // accept up to 1 minute into the future + if (sync_ts - max_future_ms > now_ts) { + // message is too far into the future + std::cerr << "ZNGCHS error: message ts was too far into the future\n"; + return true; // false? keep handled? + } // find matches Message3 matching_e = entt::null;