From cae0c0913f1183ad88752e797a1fc12fac803429 Mon Sep 17 00:00:00 2001
From: "roman.khlopkov" <roman.khlopkov@demlabs.net>
Date: Mon, 12 Feb 2024 15:19:43 +0300
Subject: [PATCH] [*] Node client states sequence corrected

---
 modules/net/dap_chain_node_client.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/modules/net/dap_chain_node_client.c b/modules/net/dap_chain_node_client.c
index d984143953..d3d5e62f30 100644
--- a/modules/net/dap_chain_node_client.c
+++ b/modules/net/dap_chain_node_client.c
@@ -253,7 +253,15 @@ static void s_stage_connected_callback(dap_client_t *a_client, void *a_arg)
         log_it(L_NOTICE, "Stream connection with node "NODE_ADDR_FP_STR" (%s:%hu) established",
                     NODE_ADDR_FP_ARGS_S(l_node_client->remote_node_addr),
                     l_ip_addr_str, l_node_client->info->hdr.ext_port);
-
+        // set callbacks for C and N channels; for R and S it is not needed
+        if (a_client->active_channels) {
+            size_t l_channels_count = dap_strlen(a_client->active_channels);
+            for(size_t i = 0; i < l_channels_count; i++) {
+                if(s_node_client_set_notify_callbacks(a_client, a_client->active_channels[i]) == -1) {
+                    log_it(L_WARNING, "No ch_chain channel, can't init notify callback for pkt type CH_CHAIN");
+                }
+            }
+        }
         if(l_node_client->callbacks.connected)
             l_node_client->callbacks.connected(l_node_client, l_node_client->callbacks_arg);
         dap_stream_ch_chain_net_pkt_hdr_t l_announce = { .version = DAP_STREAM_CH_CHAIN_NET_PKT_VERSION,
@@ -266,7 +274,6 @@ static void s_stage_connected_callback(dap_client_t *a_client, void *a_arg)
             log_it(L_DEBUG, "Wakeup all who waits");
         dap_cond_signal(l_node_client->wait_cond);
         pthread_mutex_unlock(&l_node_client->wait_mutex);
-
         dap_stream_t * l_stream  = dap_client_get_stream(a_client);
         if (l_stream) {
             l_node_client->esocket_uuid = l_stream->esocket->uuid;
@@ -283,15 +290,6 @@ static void s_stage_connected_callback(dap_client_t *a_client, void *a_arg)
                 }
             }
         }
-        // set callbacks for C and N channels; for R and S it is not needed
-        if (a_client->active_channels) {
-            size_t l_channels_count = dap_strlen(a_client->active_channels);
-            for(size_t i = 0; i < l_channels_count; i++) {
-                if(s_node_client_set_notify_callbacks(a_client, a_client->active_channels[i]) == -1) {
-                    log_it(L_WARNING, "No ch_chain channel, can't init notify callback for pkt type CH_CHAIN");
-                }
-            }
-        }
     }
 }
 
-- 
GitLab