]> git.seodisparate.com - UDPConnection/commitdiff
Revert all "change heartbeat time" code
authorStephen Seo <seo.disparate@gmail.com>
Thu, 13 Mar 2025 09:52:57 +0000 (18:52 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 13 Mar 2025 09:52:57 +0000 (18:52 +0900)
src/UDPC.h
src/UDPC_Defines.hpp
src/UDPConnection.cpp
src/test/UDPC_NetworkTest.c

index 624c6123c52412505436c838e9e8ad5d66856379..f491e5d368a2c6968851d8cd0d3f1dac9b559a28 100644 (file)
@@ -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
 
index cefaa9e6b8598c9b528e27962d5e025642faed2b..a9cca9787903354c79a03bdb17622031acb990e2 100644 (file)
@@ -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);
index 0b44b2c1097d2c24e4e6fd285fb4c4fe6d516983..ee82bfc00cbf8d2eb0c51cd752c5cd43b22666d2 100644 (file)
@@ -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<std::shared_mutex> lock(heartbeatMutex);
-                    if(sentDT < heartbeatDuration) {
-                        continue;
-                    }
+                if (sentDT < UDPC::HEARTBEAT_PKT_INTERVAL_DT) {
+                    continue;
                 }
-
                 unsigned int sendSize = 0;
                 std::unique_ptr<char[]> 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<std::shared_mutex> 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;
index a6f638440cabe0ac7cc3b6fee157a75194df2f72..14a98d15e868f388a7c186a9906caba6103027ef 100644 (file)
@@ -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 <addr> - listen addr");
     puts("-lp <port> - listen port");
@@ -49,7 +49,6 @@ void usage() {
     puts("-sk <pubkey> <seckey> - start with pub/sec key pair");
     puts("-p <\"fallback\" or \"strict\"> - set auth policy");
     puts("--hostname <hostname> - dont run test, just lookup hostname");
-    puts("--heartbeat <interval> - 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;