From 172cd756457617312991c8766ae3dca7d655e065 Mon Sep 17 00:00:00 2001
From: "Constantin P." <papizh.konstantin@demlabs.net>
Date: Mon, 2 Sep 2024 11:18:55 +0000
Subject: [PATCH] Hotfix 12923

---
 dap-sdk                               |  2 +-
 modules/net/dap_chain_net.c           | 35 +++++++++------------------
 modules/net/dap_chain_net_node_list.c |  2 +-
 3 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/dap-sdk b/dap-sdk
index 1587a436ec..c9259b9949 160000
--- a/dap-sdk
+++ b/dap-sdk
@@ -1 +1 @@
-Subproject commit 1587a436ec9231ac3bb485e74cc5ec2a7534efd5
+Subproject commit c9259b9949a44daee571d2fff3bdc329758ba68a
diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c
index aef3be7fac..ebcbcc348a 100644
--- a/modules/net/dap_chain_net.c
+++ b/modules/net/dap_chain_net.c
@@ -2369,32 +2369,21 @@ bool s_net_load(void *a_arg)
         if (l_chain->callback_created)
             l_chain->callback_created(l_chain, l_net->pub.config);
 
-     if ( dap_config_get_item_bool_default(g_config, "server", "enabled", false) ) {
-        char l_host[DAP_HOSTADDR_STRLEN + 1] = { '\0' };
-        uint16_t l_ext_port = 0;
-        const char *l_ext_addr = dap_config_get_item_str_default(g_config, "server", "ext_address", NULL);
-        if (l_ext_addr) {
-            struct sockaddr_storage l_saddr = { };
-            if ( 0 > dap_net_parse_config_address(l_ext_addr, l_host, &l_ext_port, &l_saddr, NULL) )
-                log_it(L_ERROR, "Invalid server address \"%s\", fix config and restart node", l_ext_addr);
+    if ( dap_config_get_item_bool_default(g_config, "server", "enabled", false) ) {
+        char l_local_ip[INET6_ADDRSTRLEN] = { '\0' };
+        uint16_t l_in_port = 0;
+        const char **l_listening = dap_config_get_array_str(g_config, "server", DAP_CFG_PARAM_LISTEN_ADDRS, NULL);
+        if ( l_listening ) {
+            if ( dap_net_parse_config_address(*l_listening, l_local_ip, &l_in_port, NULL, NULL) < 0 )
+                log_it(L_ERROR, "Invalid server IP address, check [server] section in cellframe-node.cfg");
             else {
-                uint8_t l_hostlen = dap_strlen(l_host);
-                l_net_pvt->node_info->ext_port = l_ext_port;
-                l_net_pvt->node_info->ext_host_len = dap_strncpy(l_net_pvt->node_info->ext_host, l_host, l_hostlen) - l_net_pvt->node_info->ext_host;
+                // power of short-circuit
+                if ( l_in_port || ( l_in_port = dap_config_get_item_int16_default(g_config, "server", DAP_CFG_PARAM_LEGACY_PORT, 8079 )))
+                    log_it(L_INFO, "Server is enabled on \"%s : %u\"", l_local_ip, l_in_port);
+                if (( l_net_pvt->node_info->ext_port = dap_config_get_item_uint16(g_config, "server", "ext_port") ))
+                    log_it(L_INFO, "Set external port %u for adding in node list", l_net_pvt->node_info->ext_port);
             }
         }
-#ifdef DAP_TRY_DEFAULT_PORT
-        log_it(L_INFO, "External address is not set, will be detected automatically");
-        if ( !l_net_pvt->node_info->ext_port ) {
-            const char **l_listening = dap_config_get_array_str(g_config, "server", DAP_CFG_PARAM_LISTEN_ADDRS, NULL);
-            l_net_pvt->node_info->ext_port =
-                ( l_listening && dap_net_parse_config_address(*l_listening, NULL, &l_ext_port, NULL, NULL) > 0 && l_ext_port )
-                    ? l_ext_port
-                    : dap_config_get_item_int16_default(g_config, "server", DAP_CFG_PARAM_LEGACY_PORT, 8079);
-        }
-#endif
-        log_it(L_INFO, "Server is configured with external address %s : %u",
-            l_net_pvt->node_info->ext_host_len ? l_net_pvt->node_info->ext_host : "", l_net_pvt->node_info->ext_port);
     }
 
     l_net_pvt->node_info->address.uint64 = g_node_addr.uint64;
diff --git a/modules/net/dap_chain_net_node_list.c b/modules/net/dap_chain_net_node_list.c
index f247519250..52119f83ee 100644
--- a/modules/net/dap_chain_net_node_list.c
+++ b/modules/net/dap_chain_net_node_list.c
@@ -230,7 +230,7 @@ static int dap_chain_net_node_list_wait(struct node_link_request *a_node_list_re
         return a_node_list_request->response;
     }
     struct timespec l_cond_timeout;
-    clock_gettime(CLOCK_MONOTONIC, &l_cond_timeout);
+    clock_gettime(CLOCK_REALTIME, &l_cond_timeout);
     l_cond_timeout.tv_sec += a_timeout_ms/1000;
     while (!a_node_list_request->response) {
         int l_wait = pthread_cond_timedwait(&a_node_list_request->wait_cond, &a_node_list_request->wait_mutex, &l_cond_timeout);
-- 
GitLab