diff --git a/cellframe-sdk.pro b/cellframe-sdk.pro index 3df384da834cf270277071332016de2f0ba8d1c0..e553962e9ab90730f0664d36b8f575024c09db5c 100644 --- a/cellframe-sdk.pro +++ b/cellframe-sdk.pro @@ -2,8 +2,8 @@ TEMPLATE = aux linux: !android { - CONFIG(debug, debug | release): sdk_build.commands = $$PWD/../cellframe-sdk/prod_build/build.sh --target linux rwd -DINSTALL_SDK=1 -DCMAKE_INSTALL_PREFIX=/ - CONFIG(release, debug | release): sdk_build.commands = $$PWD/../cellframe-sdk/prod_build/build.sh --target linux release -DINSTALL_SDK=1 -DCMAKE_INSTALL_PREFIX=/ + CONFIG(debug, debug | release): sdk_build.commands = $$PWD/../cellframe-sdk/prod_build/build.sh --target linux rwd -DINSTALL_SDK=1 -DCMAKE_INSTALL_PREFIX=/ -DCELLFRAME_NO_OPTIMIZATION=1 + CONFIG(release, debug | release): sdk_build.commands = $$PWD/../cellframe-sdk/prod_build/build.sh --target linux release -DINSTALL_SDK=1 -DCMAKE_INSTALL_PREFIX=/ -DCELLFRAME_NO_OPTIMIZATION=1 } diff --git a/modules/chain/dap_chain_ch.c b/modules/chain/dap_chain_ch.c index 9af3f8ad1d8a2801ef83dd69c464c34daffa1b0f..661cffe6df1deb570d75247854259a8feb223170 100644 --- a/modules/chain/dap_chain_ch.c +++ b/modules/chain/dap_chain_ch.c @@ -745,7 +745,8 @@ static bool s_stream_ch_packet_in(dap_stream_ch_t* a_ch, void* a_arg) } break; case DAP_CHAIN_CH_PKT_TYPE_CHAIN: { - if (!l_chain_pkt_data_size || l_chain_pkt_data_size > sizeof(dap_chain_ch_pkt_t) + DAP_CHAIN_ATOM_MAX_SIZE) { + if (!l_chain_pkt_data_size || l_chain_pkt_data_size > sizeof(dap_chain_ch_pkt_t) + DAP_CHAIN_ATOM_MAX_SIZE + * 5) { // For legacy block sizes log_it(L_WARNING, "Incorrect data size %zu in packet %s", l_chain_pkt_data_size, dap_chain_ch_pkt_type_to_str(l_ch_pkt->hdr.type)); dap_stream_ch_write_error_unsafe(a_ch, l_chain_pkt->hdr.net_id, diff --git a/modules/net/dap_chain_ledger.c b/modules/net/dap_chain_ledger.c index 827e3cc46527df108467db3d33474b1640e35822..c912bc0e619520854229029b53167af4d146cc4a 100644 --- a/modules/net/dap_chain_ledger.c +++ b/modules/net/dap_chain_ledger.c @@ -5250,11 +5250,6 @@ static dap_ledger_tx_item_t *tx_item_find_by_addr(dap_ledger_t *a_ledger, const // Now work with it dap_chain_datum_tx_t *l_tx = l_iter_current->tx; dap_chain_hash_fast_t *l_tx_hash = &l_iter_current->tx_hash_fast; - // start searching from the next hash after a_tx_first_hash - if (!is_search_started) { - is_search_started = dap_hash_fast_compare(l_tx_hash, a_tx_first_hash); - continue; - } // Get 'out' items from transaction byte_t *it; size_t l_size; TX_ITEM_ITER_TX(it, l_size, l_tx) { diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index aef3be7face0233a03964fdf3348a67c0f12ff54..ebcbcc348ac6d63123fe18faa353dd619caa504f 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 f24751925081e83a881083e5b9decd6e1055ceba..52119f83ee1dcbfbf77d5bbeab3e3543c96f8ac2 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); diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index a65a28b99060eb025468d290b8f4cd27ef985c8b..e8b1aa3c31b465ea5b2720b75d735ca27e84e088 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -975,50 +975,49 @@ int com_node(int a_argc, char ** a_argv, void **a_str_reply) case CMD_ADD: { int l_res = -10; + uint16_t l_port = 0; if (l_addr_str || l_hostname) { if (!dap_chain_net_is_my_node_authorized(l_net)) { dap_cli_server_cmd_set_reply_text(a_str_reply, "You have no access rights"); return l_res; } // We're in authorized list, add directly - uint16_t l_port = 0; struct sockaddr_storage l_verifier = { }; if ( 0 > dap_net_parse_config_address(l_hostname, l_node_info->ext_host, &l_port, &l_verifier, NULL) ) { dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't parse host string %s", l_hostname); return -6; } - if (!l_node_info->ext_port) { - if (l_port) - l_node_info->ext_port = l_port; - else { - dap_cli_server_cmd_set_reply_text(a_str_reply, "Host port is absent"); - return -7; - } - } + if ( !l_node_info->ext_port && !(l_node_info->ext_port = l_port) ) + return dap_cli_server_cmd_set_reply_text(a_str_reply, "Unspecified port"), -7; + l_node_info->ext_host_len = dap_strlen(l_node_info->ext_host); l_res = dap_chain_node_info_save(l_net, l_node_info); - if (l_res) - dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't add node %s, error %d", l_addr_str, l_res); - else - dap_cli_server_cmd_set_reply_text(a_str_reply, "Successfully added node %s", l_addr_str); - return l_res; + return dap_cli_server_cmd_set_reply_text(a_str_reply, l_res ? "Can't add node %s, error %d" : "Successfully added node %s", l_addr_str, l_res), l_res; } // Synchronous request, wait for reply - l_res = dap_chain_net_node_list_request(l_net, - l_port_str ? strtoul(l_port_str, NULL, 10) : dap_chain_net_get_my_node_info(l_net)->ext_port, - true, 'a'); - switch (l_res) + if ( !(l_port = l_node_info->ext_port) + && !(l_port = dap_chain_net_get_my_node_info(l_net)->ext_port) + && !(l_port = dap_config_get_item_int16(g_config, "server", DAP_CFG_PARAM_LEGACY_PORT)) ) { - case 1: dap_cli_server_cmd_set_reply_text(a_str_reply, "Successfully added"); return 0; - case 2: dap_cli_server_cmd_set_reply_text(a_str_reply, "No server"); break; - case 3: dap_cli_server_cmd_set_reply_text(a_str_reply, "Didn't add your address node to node list"); break; - case 4: dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't calculate hash for your addr"); break; - case 5: dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't do handshake for your node"); break; - case 6: dap_cli_server_cmd_set_reply_text(a_str_reply, "The node already exists"); break; - case 7: dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't process node list HTTP request"); break; - default:dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't process request, error %d", l_res); break; + if ( dap_config_get_item_bool_default(g_config, "server", "enabled", false) ) { + const char **l_listening = dap_config_get_array_str(g_config, "server", DAP_CFG_PARAM_LISTEN_ADDRS, NULL); + if ( l_listening && dap_net_parse_config_address(*l_listening, NULL, &l_port, NULL, NULL) < 0 ) + return dap_cli_server_cmd_set_reply_text(a_str_reply, "Invalid server IP address, check [server] section in cellframe-node.cfg"), -8; + } + if (!l_port) + return dap_cli_server_cmd_set_reply_text(a_str_reply, "Unspecified port"), -9; + } + switch ( l_res = dap_chain_net_node_list_request(l_net, l_port, true, 'a') ) + { + case 1: return dap_cli_server_cmd_set_reply_text(a_str_reply, "Successfully added"), 0; + case 2: return dap_cli_server_cmd_set_reply_text(a_str_reply, "No server"), l_res; + case 3: return dap_cli_server_cmd_set_reply_text(a_str_reply, "Didn't add your address node to node list"), l_res; + case 4: return dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't calculate hash for your addr"), l_res; + case 5: return dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't do handshake for your node"), l_res; + case 6: return dap_cli_server_cmd_set_reply_text(a_str_reply, "The node already exists"), l_res; + case 7: return dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't process node list HTTP request"), l_res; + default:return dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't process request, error %d", l_res), l_res; } - return l_res; } case CMD_DEL: {