*/
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
std::mutex setThreadedUpdateMutex;
std::atomic_uint32_t enableDisableFuncRunningCount;
- std::chrono::milliseconds heartbeatDuration;
- std::shared_mutex heartbeatMutex;
-
}; // struct Context
Context *verifyContext(UDPC_HContext ctx);
atostrBufIndexMutex(),
atostrBufIndex(0),
setThreadedUpdateMutex(),
-enableDisableFuncRunningCount(0),
-heartbeatDuration(UDPC::HEARTBEAT_PKT_INTERVAL_DT),
-heartbeatMutex()
+enableDisableFuncRunningCount(0)
{
std::memset(atostrBuf, 0, UDPC_ATOSTR_SIZE);
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)) {
&& "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
}
}
-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;
#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");
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) {
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) {
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();
}
}
- 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;