From 32f742831c1acd3386dd3d0af73985ab2c0914eb Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 13 Mar 2025 18:52:57 +0900 Subject: [PATCH] Revert all "change heartbeat time" code --- src/UDPC.h | 12 ------------ src/UDPC_Defines.hpp | 3 --- src/UDPConnection.cpp | 34 ++++------------------------------ src/test/UDPC_NetworkTest.c | 18 +----------------- 4 files changed, 5 insertions(+), 62 deletions(-) diff --git a/src/UDPC.h b/src/UDPC.h index 624c612..f491e5d 100644 --- a/src/UDPC.h +++ b/src/UDPC.h @@ -925,18 +925,6 @@ UDPC_EXPORT void UDPC_atostr_unsafe_free(const char *addrBuf); */ UDPC_EXPORT void UDPC_atostr_unsafe_free_ptr(const char **addrBuf); -/*! - * \brief REVERTED FUNCTION, SEE DETAILS. - * - * This function and its provided functionality was deemed premature for - * production use. This function will therefore be a no-op until the feature - * is implemented and ready. - * - * \return -1 always, indicating that this function does not yet work as - * intended. - */ -UDPC_EXPORT int UDPC_set_heartbeat_millis(UDPC_HContext ctx, unsigned int millis); - // ============================================================================= // Helpers diff --git a/src/UDPC_Defines.hpp b/src/UDPC_Defines.hpp index cefaa9e..a9cca97 100644 --- a/src/UDPC_Defines.hpp +++ b/src/UDPC_Defines.hpp @@ -279,9 +279,6 @@ public: std::mutex setThreadedUpdateMutex; std::atomic_uint32_t enableDisableFuncRunningCount; - std::chrono::milliseconds heartbeatDuration; - std::shared_mutex heartbeatMutex; - }; // struct Context Context *verifyContext(UDPC_HContext ctx); diff --git a/src/UDPConnection.cpp b/src/UDPConnection.cpp index 0b44b2c..ee82bfc 100644 --- a/src/UDPConnection.cpp +++ b/src/UDPConnection.cpp @@ -257,9 +257,7 @@ keysSet(), atostrBufIndexMutex(), atostrBufIndex(0), setThreadedUpdateMutex(), -enableDisableFuncRunningCount(0), -heartbeatDuration(UDPC::HEARTBEAT_PKT_INTERVAL_DT), -heartbeatMutex() +enableDisableFuncRunningCount(0) { std::memset(atostrBuf, 0, UDPC_ATOSTR_SIZE); @@ -894,13 +892,9 @@ void UDPC::Context::update_impl() { if(iter->second.sendPkts.empty() && iter->second.priorityPkts.empty()) { // nothing in queues, send heartbeat packet auto sentDT = now - iter->second.sent; - { - std::shared_lock lock(heartbeatMutex); - if(sentDT < heartbeatDuration) { - continue; - } + if (sentDT < UDPC::HEARTBEAT_PKT_INTERVAL_DT) { + continue; } - unsigned int sendSize = 0; std::unique_ptr buf; if(flags.test(2) && iter->second.flags.test(6)) { @@ -1690,22 +1684,7 @@ void UDPC::Context::update_impl() { && "Every entry in sentPkts must have a " "corresponding entry in sentInfoMap"); auto duration = now - sentInfoIter->second->sentTime; - std::chrono::milliseconds double_heartbeat_duration; - - // Account for possible heartbeat duration longer than 1 - // second. - { - std::shared_lock lock(heartbeatMutex); - double_heartbeat_duration = heartbeatDuration * 2; - } - - // Pick the longer of PACKET_TIMEOUT_TIME and - // double_heartbeat_duration. Timeout if longer than the - // greater of the two. - if((UDPC::PACKET_TIMEOUT_TIME >= double_heartbeat_duration - && duration > UDPC::PACKET_TIMEOUT_TIME) - || (UDPC::PACKET_TIMEOUT_TIME < double_heartbeat_duration - && duration > double_heartbeat_duration)) { + if(duration > UDPC::PACKET_TIMEOUT_TIME) { bool pktSigned = sentIter->data[UDPC_MIN_HEADER_SIZE] == 1; if((pktSigned @@ -2839,11 +2818,6 @@ void UDPC_atostr_unsafe_free_ptr(const char **addrBuf) { } } -int UDPC_set_heartbeat_millis(UDPC_HContext ctx, unsigned int millis) { - // No-op for now, see docs for details. - return -1; -} - UDPC_IPV6_ADDR_TYPE UDPC_strtoa(const char *addrStr) { UDPC_IPV6_ADDR_TYPE result = in6addr_loopback; std::cmatch matchResults; diff --git a/src/test/UDPC_NetworkTest.c b/src/test/UDPC_NetworkTest.c index a6f6384..14a98d1 100644 --- a/src/test/UDPC_NetworkTest.c +++ b/src/test/UDPC_NetworkTest.c @@ -33,7 +33,7 @@ static void handleSIGINT(int signal) { #define SEND_IDS_SIZE 64 #define WHITELIST_FILES_SIZE 64 -void usage() { +void usage(void) { puts("[-c | -s] - client or server (default server)"); puts("-ll - listen addr"); puts("-lp - listen port"); @@ -49,7 +49,6 @@ void usage() { puts("-sk - start with pub/sec key pair"); puts("-p <\"fallback\" or \"strict\"> - set auth policy"); puts("--hostname - dont run test, just lookup hostname"); - puts("--heartbeat - set heartbeat interval in milliseconds"); } void sleep_seconds(unsigned int seconds) { @@ -108,7 +107,6 @@ int main(int argc, char **argv) { unsigned int whitelist_pk_files_index = 0; unsigned char whitelist_pks[WHITELIST_FILES_SIZE][crypto_sign_PUBLICKEYBYTES]; int authPolicy = UDPC_AUTH_POLICY_FALLBACK; - unsigned long heartbeat_millis = 0; while(argc > 0) { if(strcmp(argv[0], "-c") == 0) { @@ -197,13 +195,6 @@ int main(int argc, char **argv) { UDPC_destroy(ctx); return 0; - } else if (strcmp(argv[0], "--heartbeat") == 0 && argc > 1) { - --argc; ++argv; - heartbeat_millis = strtoul(argv[0], NULL, 10); - if (heartbeat_millis > 0xFFFFFFFF) { - // Clamp to unsigned int maximum value, assuming 4 bytes. - heartbeat_millis = 0xFFFFFFFF; - } } else { printf("ERROR: invalid argument \"%s\"\n", argv[0]); usage(); @@ -328,13 +319,6 @@ int main(int argc, char **argv) { } } - int ret = UDPC_set_heartbeat_millis(context, heartbeat_millis); - if (ret == 1) { - puts("WARNING: Clamped heartbeat interval to minimum 150!"); - } else if (ret == 2) { - puts("WARNING: Clamped heartbeat interval to maxiumum 5000!"); - } - UDPC_enable_threaded_update(context); unsigned int tick = 0; -- 2.49.0