diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8409e5dcbe4792c074fb71d820f8162eed9fe3f3..4a87c39556879cbc2a0ad93dcf5f56c339dbf684 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,68 +16,68 @@ stages: dependencies: [] -linux-amd64-tests: +tests:amd64.gcc: extends: .tests - image: demlabs/amd64/debian-bullseye:linuxbuilder + image: demlabs/debian/amd64:qt5 before_script: /opt/buildtools/prepare_environment.sh amd64-linux script: - mkdir build - cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_CELLFRAME_SDK_TESTS=ON -DOFF_CORE_CELLFRAME_SDK_TESTS_OFF=network-monitor -DOFF_CRYPTO_CELLFRAME_SDK_TESTS_OFF="multisign" && make -j$(nproc) && ctest --verbose -linux-amd64-tests-clang: +tests:amd64.clang: extends: .tests - image: demlabs/amd64/debian-bullseye:linuxbuilder + image: demlabs/debian/amd64:qt5 before_script: /opt/buildtools/prepare_environment.sh amd64-linux script: - mkdir build - cd build && cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Release -DBUILD_CELLFRAME_SDK_TESTS=ON -DOFF_CORE_CELLFRAME_SDK_TESTS_OFF=network-monitor -DOFF_CRYPTO_CELLFRAME_SDK_TESTS_OFF="multisign" && make -j$(nproc) && ctest --verbose -linux-arm32v7-tests: +tests:arm64.gcc: extends: .tests - image: demlabs/arm32v7/debian-bullseye:linuxbuilder - before_script: /opt/buildtools/prepare_environment.sh arm32v7-linux + image: demlabs/debian/arm64:qt5 + before_script: /opt/buildtools/prepare_environment.sh arm64-linux script: - mkdir build - cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_CELLFRAME_SDK_TESTS=ON -DOFF_CORE_CELLFRAME_SDK_TESTS_OFF=network-monitor -DOFF_CRYPTO_CELLFRAME_SDK_TESTS_OFF="multisign" && make -j$(nproc) && ctest --verbose -linux-arm32v7-tests-clang: +tests:arm64.clang: extends: .tests - image: demlabs/arm32v7/debian-bullseye:linuxbuilder - before_script: /opt/buildtools/prepare_environment.sh arm32v7-linux + image: demlabs/debian/arm64:qt5 + before_script: /opt/buildtools/prepare_environment.sh arm64-linux script: - mkdir build - cd build && cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Release -DBUILD_CELLFRAME_SDK_TESTS=ON -DOFF_CORE_CELLFRAME_SDK_TESTS_OFF=network-monitor -DOFF_CRYPTO_CELLFRAME_SDK_TESTS_OFF="multisign" && make -j$(nproc) && ctest --verbose -linux-arm64v8-tests: +tests:arm32.gcc: extends: .tests - image: demlabs/arm64v8/debian-bullseye:linuxbuilder - before_script: /opt/buildtools/prepare_environment.sh arm64-linux + image: demlabs/debian/arm32:qt5 + before_script: /opt/buildtools/prepare_environment.sh arm32v7-linux script: - mkdir build - cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_CELLFRAME_SDK_TESTS=ON -DOFF_CORE_CELLFRAME_SDK_TESTS_OFF=network-monitor -DOFF_CRYPTO_CELLFRAME_SDK_TESTS_OFF="multisign" && make -j$(nproc) && ctest --verbose -linux-arm64v8-tests-clang: +tests:arm32.clang: extends: .tests - image: demlabs/arm64v8/debian-bullseye:linuxbuilder - before_script: /opt/buildtools/prepare_environment.sh arm64-linux + image: demlabs/debian/arm32:qt5 + before_script: /opt/buildtools/prepare_environment.sh arm32v7-linux script: - mkdir build - cd build && cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Release -DBUILD_CELLFRAME_SDK_TESTS=ON -DOFF_CORE_CELLFRAME_SDK_TESTS_OFF=network-monitor -DOFF_CRYPTO_CELLFRAME_SDK_TESTS_OFF="multisign" && make -j$(nproc) && ctest --verbose -windows-tests: +build:windows: extends: .tests - image: demlabs/amd64/debian-bullseye:windowsbuilder + image: demlabs/windows/amd64:qt5 before_script: /opt/buildtools/prepare_environment.sh amd64-windows script: - mkdir build - cd build && export PATH=${MXE_ROOT}/usr/bin:$PATH && x86_64-w64-mingw32.static-cmake .. -DCMAKE_BUILD_TYPE=Release && make -j$(nproc) -macos-tests: +build:macos: extends: .tests - image: demlabs/amd64/debian-bullseye:osxbuilder + image: demlabs/macos/amd64:qt5 before_script: /opt/buildtools/prepare_environment.sh amd64-windows script: - mkdir build diff --git a/modules/chain/dap_chain_cell.c b/modules/chain/dap_chain_cell.c index c1e2456c4a8080866df186a17470ed5c1cecbb73..a38facd229b518af960f9b3103f255eb78f4c893 100644 --- a/modules/chain/dap_chain_cell.c +++ b/modules/chain/dap_chain_cell.c @@ -127,8 +127,11 @@ DAP_STATIC_INLINE int s_cell_map_new_volume(dap_chain_cell_t *a_cell, size_t a_f if ( !a_fpos ) { //if (a_cell->map_range_bounds) // NtClose( (HANDLE)a_cell->map_range_bounds->data ); + off_t l_ssize = !fseeko(a_cell->file_storage, 0, SEEK_END) ? ftello(a_cell->file_storage) : -1; + if (l_ssize < 0) + return log_it(L_ERROR, "Can't get chain size, error %d: \"%s\"", errno, dap_strerror(errno)), -1; LARGE_INTEGER SectionSize = { - .QuadPart = ( fseek(a_cell->file_storage, 0, SEEK_END), ftell(a_cell->file_storage) ) + .QuadPart = l_ssize }; NTSTATUS err = pfnNtCreateSection(&hSection, SECTION_MAP_READ|SECTION_EXTEND_SIZE|SECTION_MAP_WRITE, @@ -237,9 +240,11 @@ dap_chain_cell_t * dap_chain_cell_create_fill(dap_chain_t * a_chain, dap_chain_c .file_storage = l_file, .storage_rwlock = PTHREAD_RWLOCK_INITIALIZER }; - size_t l_size = ( fseek(l_file, 0, SEEK_END), ftell(l_file) ); - if ( l_size < sizeof(dap_chain_cell_file_header_t) ) { - if (l_size) { + off_t l_size = !fseeko(l_file, 0, SEEK_END) ? ftello(l_file) : -1; + if (l_size < 0) + CLEANUP_AND_RET; + else if ( (size_t)l_size < sizeof(dap_chain_cell_file_header_t) ) { + if ( l_size ) { log_it(L_INFO, "Possibly corrupt cell storage 0x%016"DAP_UINT64_FORMAT_X" \"%s\", rewriting it", a_cell_id.uint64, file_storage_path); l_file = freopen(file_storage_path, "w+b", l_file); @@ -401,7 +406,10 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell) { if (!a_cell) return -1; - size_t l_full_size = !fseek(a_cell->file_storage, 0, SEEK_END) ? ftell(a_cell->file_storage) : 0; + off_t l_ssize = !fseeko(a_cell->file_storage, 0, SEEK_END) ? ftello(a_cell->file_storage) : -1; + if (l_ssize < 0) + return log_it(L_ERROR, "Can't get chain size, error %d: \"%s\"", errno, dap_strerror(errno)), -1; + size_t l_full_size = (size_t)l_ssize; if ( l_full_size < sizeof(dap_chain_cell_file_header_t) ) { log_it(L_ERROR, "Chain cell \"%s\" is corrupt, create new file", a_cell->file_storage_path); return -1; @@ -410,7 +418,7 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell) if (a_chain->is_mapped) { l_hdr = (dap_chain_cell_file_header_t*)a_cell->map; } else { - fseek(a_cell->file_storage, 0, SEEK_SET); + fseeko(a_cell->file_storage, 0, SEEK_SET); l_hdr = DAP_NEW(dap_chain_cell_file_header_t); if ( fread(l_hdr, 1, sizeof(*l_hdr), a_cell->file_storage) != sizeof(*l_hdr) ) { log_it(L_ERROR,"Can't read chain header \"%s\"", a_cell->file_storage_path); @@ -435,7 +443,7 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell) if (a_chain->is_mapped) a_cell->map_pos = a_cell->map + l_pos; if (l_full_size == l_pos) { - return fseek(a_cell->file_storage, l_pos, SEEK_SET); + return fseeko(a_cell->file_storage, l_pos, SEEK_SET); } int l_ret = 0; @@ -493,7 +501,7 @@ int dap_chain_cell_load(dap_chain_t *a_chain, dap_chain_cell_t *a_cell) ++q; } } - fseek(a_cell->file_storage, l_pos, SEEK_SET); + fseeko(a_cell->file_storage, l_pos, SEEK_SET); log_it(L_INFO, "Loaded %lu atoms in cell %s", q, a_cell->file_storage_path); return l_ret; } @@ -505,16 +513,18 @@ static int s_cell_file_atom_add(dap_chain_cell_t *a_cell, dap_chain_atom_ptr_t a return -1; } if (a_cell->chain->is_mapped) { - size_t l_pos = ( fseek(a_cell->file_storage, 0, SEEK_END), ftell(a_cell->file_storage) ); - debug_if (s_debug_more, L_DEBUG, "Before filling volume for atom size %lu, stream pos of %s is %lu, map pos is %lu, space left in map %lu", + off_t l_pos = !fseeko(a_cell->file_storage, 0, SEEK_END) ? ftello(a_cell->file_storage) : -1; + if (l_pos < 0) + return log_it(L_ERROR, "Can't get chain size, error %d: \"%s\"", errno, dap_strerror(errno)), -1; + debug_if (s_debug_more, L_DEBUG, "Before filling volume for atom size %ld, stream pos of %s is %lu, map pos is %lu, space left in map %lu", a_atom_size, a_cell->file_storage_path, l_pos, (size_t)(a_cell->map_pos - a_cell->map), (size_t)(a_cell->map_end - a_cell->map_pos)); if ( a_atom_size + sizeof(uint64_t) > (size_t)(a_cell->map_end - a_cell->map_pos) ) - if ( s_cell_map_new_volume(a_cell, l_pos) ) + if ( s_cell_map_new_volume(a_cell, (size_t)l_pos) ) return -2; } - debug_if (s_debug_more && a_cell->chain->is_mapped, L_DEBUG, "Before writing an atom of size %lu, stream pos of %s is %lu and pos is %lu, space left in map %lu", - a_atom_size, a_cell->file_storage_path, ftell(a_cell->file_storage), + debug_if (s_debug_more && a_cell->chain->is_mapped, L_DEBUG, "Before writing an atom of size %lu, stream pos of %s is %ld and pos is %lu, space left in map %lu", + a_atom_size, a_cell->file_storage_path, ftello(a_cell->file_storage), (size_t)(a_cell->map_pos - a_cell->map), (size_t)(a_cell->map_end - a_cell->map_pos)); if (fwrite(&a_atom_size, sizeof(a_atom_size), 1, a_cell->file_storage) != 1) { @@ -529,7 +539,7 @@ static int s_cell_file_atom_add(dap_chain_cell_t *a_cell, dap_chain_atom_ptr_t a return -3; } debug_if (s_debug_more && a_cell->chain->is_mapped, L_DEBUG, "After writing an atom of size %lu, stream pos of %s is %lu and map shift is %lu", - a_atom_size, a_cell->file_storage_path, ftell(a_cell->file_storage), + a_atom_size, a_cell->file_storage_path, ftello(a_cell->file_storage), (size_t)(a_cell->map_pos - a_cell->map)); #ifdef DAP_OS_DARWIN if (a_cell->chain->is_mapped) { @@ -602,11 +612,11 @@ ssize_t dap_chain_cell_file_append(dap_chain_cell_t *a_cell, const void *a_atom, a_cell->chain->is_mapped = was_mapped; a_cell->chain->callback_atom_iter_delete(l_atom_iter); debug_if (s_debug_more && a_cell->chain->is_mapped,L_DEBUG, "After rewriting file %s, stream pos is %lu and map pos is %lu", - a_cell->file_storage_path, ftell(a_cell->file_storage), + a_cell->file_storage_path, ftello(a_cell->file_storage), (size_t)(a_cell->map_pos - a_cell->map)); } else { debug_if (s_debug_more && a_cell->chain->is_mapped,L_DEBUG, "Before appending an atom of size %lu, stream pos of %s is %lu, map pos is %lu", - a_atom_size, a_cell->file_storage_path, ftell(a_cell->file_storage), + a_atom_size, a_cell->file_storage_path, ftello(a_cell->file_storage), (size_t)(a_cell->map_pos - a_cell->map)); if ( s_cell_file_atom_add(a_cell, a_atom, a_atom_size) ) { log_it(L_ERROR, "Chain cell \"%s\" 0x%016"DAP_UINT64_FORMAT_X": can't save atom!", @@ -615,7 +625,7 @@ ssize_t dap_chain_cell_file_append(dap_chain_cell_t *a_cell, const void *a_atom, return -4; } debug_if (s_debug_more && a_cell->chain->is_mapped, L_DEBUG,"After appending an atom of size %lu, stream pos of %s is %lu, map pos is %lu", - a_atom_size, a_cell->file_storage_path, ftell(a_cell->file_storage), + a_atom_size, a_cell->file_storage_path, ftello(a_cell->file_storage), (size_t)(a_cell->map_end - a_cell->map_pos)); ++l_count; l_total_res = a_atom_size + sizeof(uint64_t); @@ -625,12 +635,18 @@ ssize_t dap_chain_cell_file_append(dap_chain_cell_t *a_cell, const void *a_atom, fflush(a_cell->file_storage); #ifdef DAP_OS_WINDOWS if (a_cell->chain->is_mapped) { - LARGE_INTEGER SectionSize = (LARGE_INTEGER) { .QuadPart = ftell(a_cell->file_storage) }; - HANDLE hSection = (HANDLE)a_cell->map_range_bounds->data; - NTSTATUS err = pfnNtExtendSection(hSection, &SectionSize); - if ( !NT_SUCCESS(err) ) { - log_it(L_ERROR, "NtExtendSection() failed, status %lx", err); + off_t l_off = ftello(a_cell->file_storage); + if (l_off < 0) { + log_it(L_ERROR, "Can't get chain size!"); l_err = true; + } else { + LARGE_INTEGER SectionSize = (LARGE_INTEGER) { .QuadPart = l_off }; + HANDLE hSection = (HANDLE)a_cell->map_range_bounds->data; + NTSTATUS err = pfnNtExtendSection(hSection, &SectionSize); + if ( !NT_SUCCESS(err) ) { + log_it(L_ERROR, "NtExtendSection() failed, status %lx", err); + l_err = true; + } } } #endif diff --git a/modules/common/dap_chain_datum.c b/modules/common/dap_chain_datum.c index dc14ef6c110868477f3698ea8f89ab26865be81e..8394a83ea5872759fe1a25480b7602c486bfc783 100644 --- a/modules/common/dap_chain_datum.c +++ b/modules/common/dap_chain_datum.c @@ -775,8 +775,8 @@ bool dap_chain_datum_dump_tx_json(dap_chain_datum_tx_t *a_datum, json_object_object_add(json_obj_item,"Changing vote is", l_voting_params->vote_changing_allowed ? json_object_new_string("available") : json_object_new_string("not available")); l_voting_params->delegate_key_required ? - json_object_object_add(json_obj_item,"Votes max count", json_object_new_string("A delegated key is required to participate in voting.")): - json_object_object_add(json_obj_item,"Votes max count", json_object_new_string("A delegated key is not required to participate in voting.")); + json_object_object_add(json_obj_item,"Delegated key for participating in voting", json_object_new_string("required")): + json_object_object_add(json_obj_item,"Delegated key for participating in voting", json_object_new_string("not required")); dap_list_free_full(l_voting_params->answers_list, NULL); DAP_DELETE(l_voting_params->voting_question); diff --git a/modules/consensus/esbocs/dap_chain_cs_esbocs.c b/modules/consensus/esbocs/dap_chain_cs_esbocs.c index 57f643aa4f203f000bb24b2f702a1b804a1fab33..2a38ee0ae83bad2d9ddcaef624dd2966641ac832 100644 --- a/modules/consensus/esbocs/dap_chain_cs_esbocs.c +++ b/modules/consensus/esbocs/dap_chain_cs_esbocs.c @@ -177,13 +177,13 @@ DAP_STATIC_INLINE uint16_t s_get_round_skip_timeout(dap_chain_esbocs_session_t * int dap_chain_cs_esbocs_init() { - dap_chain_cs_add("esbocs", s_callback_new); + dap_chain_cs_add(DAP_CHAIN_ESBOCS_CS_TYPE_STR, s_callback_new); dap_stream_ch_proc_add(DAP_STREAM_CH_ESBOCS_ID, NULL, NULL, s_stream_ch_packet_in, NULL); - dap_cli_server_cmd_add ("esbocs", s_cli_esbocs, "ESBOCS commands", + dap_cli_server_cmd_add (DAP_CHAIN_ESBOCS_CS_TYPE_STR, s_cli_esbocs, "ESBOCS commands", "esbocs min_validators_count set -net <net_name> [-chain <chain_name>] -cert <poa_cert_name> -val_count <value>\n" "\tSets minimum validators count for ESBOCS consensus\n" "esbocs min_validators_count show -net <net_name> [-chain <chain_name>]\n" @@ -226,29 +226,29 @@ static int s_callback_new(dap_chain_t *a_chain, dap_config_t *a_chain_cfg) l_ret = - 5; goto lb_err; } - l_esbocs_pvt->debug = dap_config_get_item_bool_default(a_chain_cfg, "esbocs", "consensus_debug", false); - l_esbocs_pvt->poa_mode = dap_config_get_item_bool_default(a_chain_cfg, "esbocs", "poa_mode", false); - l_esbocs_pvt->round_start_sync_timeout = dap_config_get_item_uint16_default(a_chain_cfg, "esbocs", "round_start_sync_timeout", 15); - l_esbocs_pvt->new_round_delay = dap_config_get_item_uint16_default(a_chain_cfg, "esbocs", "new_round_delay", 10); - l_esbocs_pvt->round_attempts_max = dap_config_get_item_uint16_default(a_chain_cfg, "esbocs", "round_attempts_max", 4); - l_esbocs_pvt->round_attempt_timeout = dap_config_get_item_uint16_default(a_chain_cfg, "esbocs", "round_attempt_timeout", 10); + l_esbocs_pvt->debug = dap_config_get_item_bool_default(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "consensus_debug", false); + l_esbocs_pvt->poa_mode = dap_config_get_item_bool_default(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "poa_mode", false); + l_esbocs_pvt->round_start_sync_timeout = dap_config_get_item_uint16_default(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "round_start_sync_timeout", 15); + l_esbocs_pvt->new_round_delay = dap_config_get_item_uint16_default(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "new_round_delay", 10); + l_esbocs_pvt->round_attempts_max = dap_config_get_item_uint16_default(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "round_attempts_max", 4); + l_esbocs_pvt->round_attempt_timeout = dap_config_get_item_uint16_default(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "round_attempt_timeout", 10); l_esbocs_pvt->start_validators_min = l_esbocs_pvt->min_validators_count = - dap_config_get_item_uint16(a_chain_cfg, "esbocs", "min_validators_count"); + dap_config_get_item_uint16(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "min_validators_count"); if (!l_esbocs_pvt->min_validators_count) { l_ret = -1; goto lb_err; } - const char *l_auth_certs_prefix = dap_config_get_item_str(a_chain_cfg, "esbocs", "auth_certs_prefix"); + const char *l_auth_certs_prefix = dap_config_get_item_str(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "auth_certs_prefix"); uint16_t l_node_addrs_count; - const char **l_addrs = dap_config_get_array_str(a_chain_cfg, "esbocs", "validators_addrs", &l_node_addrs_count); + const char **l_addrs = dap_config_get_array_str(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "validators_addrs", &l_node_addrs_count); if (l_node_addrs_count < l_esbocs_pvt->min_validators_count) { l_ret = -2; goto lb_err; } dap_chain_net_srv_stake_net_add(a_chain->net_id); - uint16_t l_auth_certs_count = dap_config_get_item_uint16_default(a_chain_cfg, "esbocs", "auth_certs_count", l_node_addrs_count); + uint16_t l_auth_certs_count = dap_config_get_item_uint16_default(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "auth_certs_count", l_node_addrs_count); dap_chain_net_t *l_net = dap_chain_net_by_id(a_chain->net_id); for (size_t i = 0; i < l_auth_certs_count; i++) { char l_cert_name[512]; @@ -289,8 +289,7 @@ static int s_callback_new(dap_chain_t *a_chain, dap_config_t *a_chain_cfg) l_validator->node_addr = l_signer_node_addr; l_validator->weight = uint256_1; l_esbocs_pvt->poa_validators = dap_list_append(l_esbocs_pvt->poa_validators, l_validator); - const char *l_signer_addr = dap_chain_hash_fast_to_str_static(&l_signing_addr.data.hash_fast); - log_it(L_MSG, "add validator addr "NODE_ADDR_FP_STR", signing addr %s", NODE_ADDR_FP_ARGS_S(l_signer_node_addr), l_signer_addr); + log_it(L_MSG, "add validator addr "NODE_ADDR_FP_STR", signing addr %s", NODE_ADDR_FP_ARGS_S(l_signer_node_addr), dap_chain_addr_to_str_static(&l_signing_addr)); if (!l_esbocs_pvt->poa_mode) { // auth certs in PoA mode will be first PoS validators keys dap_hash_fast_t l_stake_tx_hash = {}; @@ -300,7 +299,7 @@ static int s_callback_new(dap_chain_t *a_chain, dap_config_t *a_chain_cfg) } } // Preset reward for block signs, before first reward decree - const char *l_preset_reward_str = dap_config_get_item_str(a_chain_cfg, "esbocs", "preset_reward"); + const char *l_preset_reward_str = dap_config_get_item_str(a_chain_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "preset_reward"); if (l_preset_reward_str) { uint256_t l_preset_reward = dap_chain_balance_scan(l_preset_reward_str); if (!IS_ZERO_256(l_preset_reward)) @@ -470,9 +469,9 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf dap_chain_esbocs_t *l_esbocs = DAP_CHAIN_ESBOCS(l_blocks); dap_chain_esbocs_pvt_t *l_esbocs_pvt = PVT(l_esbocs); - l_esbocs_pvt->collecting_addr = dap_chain_addr_from_str(dap_config_get_item_str(a_chain_net_cfg, "esbocs", "fee_addr")); - l_esbocs_pvt->collecting_level = dap_chain_coins_to_balance(dap_config_get_item_str_default(a_chain_net_cfg, "esbocs", "collecting_level", - dap_config_get_item_str_default(a_chain_net_cfg, "esbocs", "set_collect_fee", "10.0"))); + l_esbocs_pvt->collecting_addr = dap_chain_addr_from_str(dap_config_get_item_str(a_chain_net_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "fee_addr")); + l_esbocs_pvt->collecting_level = dap_chain_coins_to_balance(dap_config_get_item_str_default(a_chain_net_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "collecting_level", + dap_config_get_item_str_default(a_chain_net_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "set_collect_fee", "10.0"))); dap_list_t *l_validators = dap_chain_net_srv_stake_get_validators(a_chain->net_id, false, NULL); for (dap_list_t *it = l_validators; it; it = it->next) { dap_stream_node_addr_t *l_addr = &((dap_chain_net_srv_stake_item_t *)it->data)->node_addr; @@ -487,7 +486,7 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf log_it(L_INFO, "Init ESBOCS session for net:%s, chain:%s", a_chain->net_name, a_chain->name); const char *l_sign_cert_str = NULL; - if( (l_sign_cert_str = dap_config_get_item_str(a_chain_net_cfg, "esbocs", "blocks-sign-cert")) ) { + if( (l_sign_cert_str = dap_config_get_item_str(a_chain_net_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "blocks-sign-cert")) ) { dap_cert_t *l_sign_cert = dap_cert_find_by_name(l_sign_cert_str); if (l_sign_cert == NULL) { log_it(L_ERROR, "Can't load sign certificate, name \"%s\" is wrong", l_sign_cert_str); @@ -537,9 +536,10 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf dap_guuid_compose(l_net->pub.id.uint64, DAP_CHAIN_CLUSTER_ID_ESBOCS), l_sync_group, 72 * 3600, true, DAP_GDB_MEMBER_ROLE_NOBODY, DAP_CLUSTER_TYPE_AUTONOMIC); - DAP_DELETE(l_sync_group); dap_global_db_cluster_add_notify_callback(l_session->db_cluster, s_db_change_notifier, l_session); dap_link_manager_add_net_associate(l_net->pub.id.uint64, l_session->db_cluster->links_cluster); + dap_global_db_del_sync(l_sync_group, NULL); // Drop table on stratup + DAP_DELETE(l_sync_group); #ifdef DAP_CHAIN_CS_ESBOCS_DIRECTIVE_SUPPORT dap_global_db_role_t l_directives_cluster_role_default = DAP_GDB_MEMBER_ROLE_ROOT; @@ -583,7 +583,7 @@ static int s_callback_created(dap_chain_t *a_chain, dap_config_t *a_chain_net_cf log_it(L_ERROR, "No valid order found was signed by this validator delegated key. Switch off validator mode."); return -4; } - l_esbocs_pvt->emergency_mode = dap_config_get_item_bool_default(a_chain_net_cfg, "esbocs", "emergency_mode", false); + l_esbocs_pvt->emergency_mode = dap_config_get_item_bool_default(a_chain_net_cfg, DAP_CHAIN_ESBOCS_CS_TYPE_STR, "emergency_mode", false); if (l_esbocs_pvt->emergency_mode && !s_check_emergency_rights(l_esbocs, &l_my_signing_addr)) { log_it(L_ERROR, "This validator is not allowed to work in emergency mode. Use special decree to supply it"); return -5; @@ -685,7 +685,7 @@ bool dap_chain_esbocs_remove_validator_from_clusters(dap_chain_net_id_t a_net_id uint256_t dap_chain_esbocs_get_collecting_level(dap_chain_t *a_chain) { - dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), "esbocs"), uint256_0); + dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), DAP_CHAIN_ESBOCS_CS_TYPE_STR), uint256_0); dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain); dap_chain_esbocs_t *l_esbocs = DAP_CHAIN_ESBOCS(l_blocks); dap_chain_esbocs_pvt_t *l_esbocs_pvt = PVT(l_esbocs); @@ -695,7 +695,7 @@ uint256_t dap_chain_esbocs_get_collecting_level(dap_chain_t *a_chain) dap_enc_key_t *dap_chain_esbocs_get_sign_key(dap_chain_t *a_chain) { - dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), "esbocs"), NULL); + dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), DAP_CHAIN_ESBOCS_CS_TYPE_STR), NULL); dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain); dap_chain_esbocs_t *l_esbocs = DAP_CHAIN_ESBOCS(l_blocks); dap_chain_esbocs_pvt_t *l_esbocs_pvt = PVT(l_esbocs); @@ -705,7 +705,7 @@ dap_enc_key_t *dap_chain_esbocs_get_sign_key(dap_chain_t *a_chain) int dap_chain_esbocs_set_min_validators_count(dap_chain_t *a_chain, uint16_t a_new_value) { - dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), "esbocs"), -1); + dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), DAP_CHAIN_ESBOCS_CS_TYPE_STR), -1); dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain); dap_chain_esbocs_t *l_esbocs = DAP_CHAIN_ESBOCS(l_blocks); dap_chain_esbocs_pvt_t *l_esbocs_pvt = PVT(l_esbocs); @@ -727,7 +727,7 @@ int dap_chain_esbocs_set_min_validators_count(dap_chain_t *a_chain, uint16_t a_n int dap_chain_esbocs_set_signs_struct_check(dap_chain_t *a_chain, bool a_enable) { - dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), "esbocs"), -1); + dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), DAP_CHAIN_ESBOCS_CS_TYPE_STR), -1); dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain); dap_chain_esbocs_t *l_esbocs = DAP_CHAIN_ESBOCS(l_blocks); dap_chain_esbocs_pvt_t *l_esbocs_pvt = PVT(l_esbocs); @@ -737,7 +737,7 @@ int dap_chain_esbocs_set_signs_struct_check(dap_chain_t *a_chain, bool a_enable) int dap_chain_esbocs_set_emergency_validator(dap_chain_t *a_chain, bool a_add, uint32_t a_sign_type, dap_hash_fast_t *a_validator_hash) { - dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), "esbocs"), -1); + dap_return_val_if_fail(a_chain && !strcmp(dap_chain_get_cs_type(a_chain), DAP_CHAIN_ESBOCS_CS_TYPE_STR), -1); dap_chain_cs_blocks_t *l_blocks = DAP_CHAIN_CS_BLOCKS(a_chain); dap_chain_esbocs_t *l_esbocs = DAP_CHAIN_ESBOCS(l_blocks); dap_chain_esbocs_pvt_t *l_esbocs_pvt = PVT(l_esbocs); @@ -1969,7 +1969,24 @@ static void s_db_change_notifier(dap_store_obj_t *a_obj, void *a_arg) return; } log_it(L_DEBUG, "Got new penalty item for group %s with key %s", a_obj->group, a_obj->key); - l_session->db_hash = dap_global_db_driver_hash_get(a_obj); + if (dap_store_obj_get_type(a_obj) == DAP_GLOBAL_DB_OPTYPE_ADD) + l_session->db_hash = dap_global_db_driver_hash_get(a_obj); + else { + char *l_last_key = NULL; + byte_t *l_value = dap_global_db_get_last_sync(a_obj->group, &l_last_key, NULL, NULL, NULL); + if (l_last_key) { + dap_store_obj_t *l_last_raw = dap_global_db_get_raw_sync(a_obj->group, l_last_key); + assert(l_last_raw); + if (l_last_raw) { + l_session->db_hash = dap_global_db_driver_hash_get(l_last_raw); + dap_store_obj_free_one(l_last_raw); + } else + log_it(L_ERROR, "Last key in %s is %s, but no raw object with this key", a_obj->group, l_last_key); + DAP_DELETE(l_last_key); + } else + l_session->db_hash = c_dap_global_db_driver_hash_blank; + DAP_DEL_Z(l_value); + } } static int s_session_directive_apply(dap_chain_esbocs_directive_t *a_directive, dap_hash_fast_t *a_directive_hash) @@ -2993,7 +3010,7 @@ static int s_cli_esbocs(int a_argc, char **a_argv, void **a_str_reply) CHAIN_TYPE_ANCHOR)) return -3; const char *l_chain_type = dap_chain_get_cs_type(l_chain); - if (strcmp(l_chain_type, "esbocs")) { + if (strcmp(l_chain_type, DAP_CHAIN_ESBOCS_CS_TYPE_STR)) { dap_json_rpc_error_add(DAP_CHAIN_NODE_CLI_COM_ESBOCS_CHAIN_TYPE_ERR,"Type of chain \"%s\" is not block. Chain with current consensus \"%s\" is not supported by this command", l_chain->name, l_chain_type); return -DAP_CHAIN_NODE_CLI_COM_ESBOCS_CHAIN_TYPE_ERR; diff --git a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h index 5462d842fa66893095e97f6482b384720445016b..93c9109637c97c8c791862de9b5662dc08ad94c0 100644 --- a/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h +++ b/modules/consensus/esbocs/include/dap_chain_cs_esbocs.h @@ -32,7 +32,8 @@ along with any CellFrame SDK based project. If not, see <http://www.gnu.org/lic #define DAP_STREAM_CH_ESBOCS_ID 'E' #define DAP_CHAIN_ESBOCS_PROTOCOL_VERSION 8 -#define DAP_CHAIN_ESBOCS_GDB_GROUPS_PREFIX "esbocs" +#define DAP_CHAIN_ESBOCS_CS_TYPE_STR "esbocs" +#define DAP_CHAIN_ESBOCS_GDB_GROUPS_PREFIX DAP_CHAIN_ESBOCS_CS_TYPE_STR #define DAP_CHAIN_CLUSTER_ID_ESBOCS 0x8000 #define DAP_CHAIN_ESBOCS_MSG_TYPE_SUBMIT 0x04 diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index 268a2b416f11c384db288b896998c1adc21aa6d6..909692910a3e6492361c5a6db9db0c8d1d197723 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -2465,6 +2465,8 @@ static void s_ch_in_pkt_callback(dap_stream_ch_t *a_ch, uint8_t a_type, const vo return; case DAP_CHAIN_CH_PKT_TYPE_CHAIN_MISS: { + if (!l_net_pvt->sync_context.cur_chain) + return; dap_chain_ch_miss_info_t *l_miss_info = (dap_chain_ch_miss_info_t *)(((dap_chain_ch_pkt_t *)(a_data))->data); if (!dap_hash_fast_compare(&l_miss_info->missed_hash, &l_net_pvt->sync_context.requested_atom_hash)) { char l_missed_hash_str[DAP_HASH_FAST_STR_SIZE]; @@ -2480,10 +2482,6 @@ static void s_ch_in_pkt_callback(dap_stream_ch_t *a_ch, uint8_t a_type, const vo DAP_CHAIN_CH_ERROR_INCORRECT_SYNC_SEQUENCE); return; } - if (!l_net_pvt->sync_context.cur_chain) { - assert(false); // Strange bug here, stop and investigate it - return; - } dap_chain_atom_iter_t *l_iter = l_net_pvt->sync_context.cur_chain->callback_atom_iter_create( l_net_pvt->sync_context.cur_chain, l_net_pvt->sync_context.cur_cell diff --git a/modules/net/dap_chain_net_balancer.c b/modules/net/dap_chain_net_balancer.c index b54ea0926662a703ff9e1f8a7115ba2f26e2bbee..464500889601e4e72ad3a26fd17ce17efa164b25 100644 --- a/modules/net/dap_chain_net_balancer.c +++ b/modules/net/dap_chain_net_balancer.c @@ -75,10 +75,9 @@ struct json_object *s_balancer_states_json_collect(dap_chain_net_t *a_net, const } /** - * @brief callback to success balancer request - * @param a_net - responce net - * @param a_link_full_node_list - getted node list - * @param a_host_info - host info + * @brief get ignored node addr + * @param a_net - net + * @param a_size - out ingored node count */ static dap_chain_net_links_t *s_get_ignored_node_addrs(dap_chain_net_t *a_net, size_t *a_size) { diff --git a/modules/net/dap_chain_node.c b/modules/net/dap_chain_node.c index eebf0a96a1ea50552eca418759964b4bb59a530e..11cf64eb6bcf0f08c7dc32ce0435b22e34e7bdae 100644 --- a/modules/net/dap_chain_node.c +++ b/modules/net/dap_chain_node.c @@ -50,6 +50,7 @@ typedef struct dap_chain_node_net_states_info { dap_chain_node_addr_t address; + uint64_t events_count; uint64_t atoms_count; uint32_t uplinks_count; uint32_t downlinks_count; @@ -57,8 +58,10 @@ typedef struct dap_chain_node_net_states_info { } DAP_ALIGN_PACKED dap_chain_node_net_states_info_t; static const uint64_t s_cmp_delta_timestamp = (uint64_t)1000 /*sec*/ * (uint64_t)1000000000; -static const uint64_t s_cmp_delta_atom = 50; +static const uint64_t s_cmp_delta_event = 0; +static const uint64_t s_cmp_delta_atom = 10; static const uint64_t s_timer_update_states_info = 10 /*sec*/ * 1000; +static const char *s_states_group = ".nodes.states"; /** * @brief get states info about current @@ -67,8 +70,7 @@ static const uint64_t s_timer_update_states_info = 10 /*sec*/ * 1000; static void s_update_node_states_info(UNUSED_ARG void *a_arg) { for (dap_chain_net_t *l_net = dap_chain_net_iter_start(); l_net; l_net = dap_chain_net_iter_next(l_net)) { - dap_chain_t *l_chain = NULL; - if(dap_chain_net_get_state(l_net) != NET_STATE_OFFLINE && (l_chain = dap_chain_find_by_id(l_net->pub.id, (dap_chain_id_t){ .uint64 = 1 })) ) { + if(dap_chain_net_get_state(l_net) != NET_STATE_OFFLINE) { size_t l_uplinks_count = 0, l_downlinks_count = 0, @@ -83,10 +85,15 @@ static void s_update_node_states_info(UNUSED_ARG void *a_arg) l_info->address.uint64 = g_node_addr.uint64; l_info->uplinks_count = l_uplinks_count; l_info->downlinks_count = l_downlinks_count; - l_info->atoms_count = l_chain->callback_count_atom ? l_chain->callback_count_atom(l_chain) : 0; + + dap_chain_t *l_chain = dap_chain_find_by_id(l_net->pub.id, (dap_chain_id_t){ .uint64 = 0 }); // zerochain + l_info->events_count = (l_chain && l_chain->callback_count_atom) ? l_chain->callback_count_atom(l_chain) : 0; + l_chain =dap_chain_find_by_id(l_net->pub.id, (dap_chain_id_t){ .uint64 = 1 }); // mainchain + l_info->atoms_count = (l_chain && l_chain->callback_count_atom) ? l_chain->callback_count_atom(l_chain) : 0; + memcpy(l_info->links_addrs, l_linked_node_addrs, (l_info->uplinks_count + l_info->downlinks_count) * sizeof(dap_chain_node_addr_t)); // DB write - char *l_gdb_group = dap_strdup_printf("%s.nodes.states", l_net->pub.gdb_groups_prefix); + char *l_gdb_group = dap_strdup_printf("%s%s", l_net->pub.gdb_groups_prefix, s_states_group); const char *l_node_addr_str = dap_stream_node_addr_to_str_static(l_info->address); dap_global_db_set_sync(l_gdb_group, l_node_addr_str, l_info, l_info_size, false); DAP_DEL_MULTY(l_linked_node_addrs, l_info, l_gdb_group); @@ -100,17 +107,19 @@ static void s_states_info_to_str(dap_chain_net_t *a_net, const char *a_node_addr dap_return_if_pass(!a_net || !a_node_addr_str || !l_info_str); // func work dap_nanotime_t l_timestamp = 0; - char *l_gdb_group = dap_strdup_printf("%s.nodes.states", a_net->pub.gdb_groups_prefix); - dap_chain_node_net_states_info_t *l_store_obj = (dap_chain_node_net_states_info_t *)dap_global_db_get_sync(l_gdb_group, a_node_addr_str, NULL, NULL, &l_timestamp); - if (!l_store_obj) { + size_t l_data_size = 0; + char *l_gdb_group = dap_strdup_printf("%s%s", a_net->pub.gdb_groups_prefix, s_states_group); + dap_chain_node_net_states_info_t *l_store_obj = (dap_chain_node_net_states_info_t *)dap_global_db_get_sync(l_gdb_group, a_node_addr_str, &l_data_size, NULL, &l_timestamp); + if (!l_store_obj || l_data_size != sizeof(dap_chain_node_net_states_info_t) + (l_store_obj->uplinks_count + l_store_obj->downlinks_count) * sizeof(dap_chain_node_addr_t)) { log_it(L_ERROR, "Can't find state about %s node", a_node_addr_str); + DAP_DELETE(l_gdb_group); return; } char l_ts[80] = { '\0' }; dap_nanotime_to_str_rfc822(l_ts, sizeof(l_ts), l_timestamp); dap_string_append_printf(l_info_str, - "Record timestamp: %s\nNode addr: %s\nNet: %s\nAtoms count: %"DAP_UINT64_FORMAT_U"\nUplinks count: %u\nDownlinks count: %u\n", - l_ts, a_node_addr_str, a_net->pub.name, l_store_obj->atoms_count, l_store_obj->uplinks_count, l_store_obj->downlinks_count); + "Record timestamp: %s\nNode addr: %s\nNet: %s\nEvents count: %"DAP_UINT64_FORMAT_U"\nAtoms count: %"DAP_UINT64_FORMAT_U"\nUplinks count: %u\nDownlinks count: %u\n", + l_ts, a_node_addr_str, a_net->pub.name, l_store_obj->events_count, l_store_obj->atoms_count, l_store_obj->uplinks_count, l_store_obj->downlinks_count); size_t l_max_links = dap_max(l_store_obj->uplinks_count, l_store_obj->downlinks_count); if(l_max_links) { dap_string_append_printf(l_info_str, @@ -119,10 +128,10 @@ static void s_states_info_to_str(dap_chain_net_t *a_net, const char *a_node_addr "-----------------------------------------------------------------\n"); } for (size_t i = 0; i < l_max_links; ++i) { - char *l_upnlinks = i < l_store_obj->uplinks_count ? dap_stream_node_addr_to_str(l_store_obj->links_addrs[i], false) : dap_strdup("\t\t"); - char *l_downlinks = i < l_store_obj->downlinks_count ? dap_stream_node_addr_to_str(l_store_obj->links_addrs[i + l_store_obj->uplinks_count], false) : dap_strdup("\t\t"); - dap_string_append_printf(l_info_str, "|\t%s\t|\t%s\t|\n", l_upnlinks, l_downlinks); - DAP_DEL_MULTY(l_upnlinks, l_downlinks); + char *l_upnlink_str = i < l_store_obj->uplinks_count ? dap_stream_node_addr_to_str(l_store_obj->links_addrs[i], false) : dap_strdup("\t\t"); + char *l_downlink_str = i < l_store_obj->downlinks_count ? dap_stream_node_addr_to_str(l_store_obj->links_addrs[i + l_store_obj->uplinks_count], false) : dap_strdup("\t\t"); + dap_string_append_printf(l_info_str, "|\t%s\t|\t%s\t|\n", l_upnlink_str, l_downlink_str); + DAP_DEL_MULTY(l_upnlink_str, l_downlink_str); } dap_string_append_printf(l_info_str, "-----------------------------------------------------------------\n"); DAP_DEL_MULTY(l_store_obj, l_gdb_group); @@ -409,6 +418,8 @@ static int s_node_states_info_cmp(dap_list_t *a_first, dap_list_t *a_second) if(a->timestamp > b->timestamp && a->timestamp - b->timestamp > s_cmp_delta_timestamp) return -1; if(b->timestamp > a->timestamp && b->timestamp - a->timestamp > s_cmp_delta_timestamp) return 1; + if(a->events_count > b->events_count && a->events_count - b->events_count > s_cmp_delta_event) return -1; + if(b->events_count > a->events_count && b->events_count - a->events_count > s_cmp_delta_event) return 1; if(a->atoms_count > b->atoms_count && a->atoms_count - b->atoms_count > s_cmp_delta_atom) return -1; if(b->atoms_count > a->atoms_count && b->atoms_count - a->atoms_count > s_cmp_delta_atom) return 1; if(a->downlinks_count < b->downlinks_count) return -1; @@ -432,7 +443,7 @@ dap_list_t *dap_chain_node_get_states_list_sort(dap_chain_net_t *a_net, dap_chai log_it(L_ERROR, "Node list in net %s is empty", a_net->pub.name); return NULL; } - char *l_gdb_group = dap_strdup_printf("%s.nodes.states", a_net->pub.gdb_groups_prefix); + char *l_gdb_group = dap_strdup_printf("%s%s", a_net->pub.gdb_groups_prefix, s_states_group); dap_list_t *l_ret = NULL; for (size_t i = 0; i < l_node_count; ++i) { if (!l_objs[i].value) { @@ -452,17 +463,25 @@ dap_list_t *dap_chain_node_get_states_list_sort(dap_chain_net_t *a_net, dap_chai log_it(L_ERROR, "%s", c_error_memory_alloc); break; } - dap_nanotime_t l_state_timestamp = 0; - dap_chain_node_net_states_info_t *l_state_store_obj = (dap_chain_node_net_states_info_t *)dap_global_db_get_sync(l_gdb_group, l_objs[i].key, NULL, NULL, &l_state_timestamp); - if (!l_state_store_obj) { - log_it(L_WARNING, "Can't find state about %s node, apply low priority", l_objs[i].key); - } l_item->link_info.node_addr.uint64 = ((dap_chain_node_info_t*)(l_objs + i)->value)->address.uint64; l_item->link_info.uplink_port = ((dap_chain_node_info_t*)(l_objs + i)->value)->ext_port; dap_strncpy(l_item->link_info.uplink_addr, ((dap_chain_node_info_t*)(l_objs + i)->value)->ext_host, sizeof(l_item->link_info.uplink_addr) - 1); - l_item->atoms_count = l_state_store_obj ? l_state_store_obj->atoms_count : 0; - l_item->downlinks_count = l_state_store_obj ? l_state_store_obj->downlinks_count : (uint32_t)(-1); - l_item->timestamp = l_state_timestamp; + + dap_nanotime_t l_state_timestamp = 0; + size_t l_data_size = 0; + dap_chain_node_net_states_info_t *l_state_store_obj = (dap_chain_node_net_states_info_t *)dap_global_db_get_sync(l_gdb_group, l_objs[i].key, &l_data_size, NULL, &l_state_timestamp); + if (!l_state_store_obj) { + log_it(L_DEBUG, "Can't find state about %s node, apply low priority", l_objs[i].key); + l_item->downlinks_count = (uint32_t)(-1); + } else if (l_data_size != sizeof(dap_chain_node_net_states_info_t) + (l_state_store_obj->uplinks_count + l_state_store_obj->downlinks_count) * sizeof(dap_chain_node_addr_t)) { + log_it(L_DEBUG, "Wrong %s node record size, expected %zu, get %zu", l_objs[i].key, sizeof(dap_chain_node_net_states_info_t) + (l_state_store_obj->uplinks_count + l_state_store_obj->downlinks_count) * sizeof(dap_chain_node_addr_t), l_data_size); + l_item->downlinks_count = (uint32_t)(-1); + } else { + l_item->atoms_count = l_state_store_obj->atoms_count; + l_item->events_count = l_state_store_obj->events_count; + l_item->downlinks_count = l_state_store_obj->downlinks_count; + l_item->timestamp = l_state_timestamp; + } l_ret = dap_list_insert_sorted(l_ret, (void *)l_item, s_node_states_info_cmp); DAP_DELETE(l_state_store_obj); } diff --git a/modules/net/dap_chain_node_cli_cmd.c b/modules/net/dap_chain_node_cli_cmd.c index 84d8ebe6ceb0b44e20161f269806110fcd2dd689..6e6a98adf95551c9a2f37f48c108a83442fe466c 100644 --- a/modules/net/dap_chain_node_cli_cmd.c +++ b/modules/net/dap_chain_node_cli_cmd.c @@ -807,9 +807,9 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) } size_t l_objs_count = 0; - dap_global_db_obj_t* l_obj = dap_global_db_get_all_sync(l_group_str, &l_objs_count); + dap_store_obj_t *l_objs = dap_global_db_get_all_raw_sync(l_group_str, &l_objs_count); - if (!l_obj || !l_objs_count) + if (!l_objs || !l_objs_count) { dap_json_rpc_error_add(DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_NO_DATA_IN_GROUP,"No data in group %s.", l_group_str); return -DAP_CHAIN_NODE_CLI_COM_GLOBAL_DB_NO_DATA_IN_GROUP; @@ -819,13 +819,15 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) json_object* json_obj_keys = NULL; for(size_t i = 0; i < l_objs_count; i++) { char l_ts[64] = { '\0' }; - dap_nanotime_to_str_rfc822(l_ts, sizeof(l_ts), l_obj[i].timestamp); + dap_nanotime_to_str_rfc822(l_ts, sizeof(l_ts), l_objs[i].timestamp); json_obj_keys = json_object_new_object(); - json_object_object_add(json_obj_keys, "key", json_object_new_string(l_obj[i].key)); + json_object_object_add(json_obj_keys, "key", json_object_new_string(l_objs[i].key)); json_object_object_add(json_obj_keys, "time", json_object_new_string(l_ts)); + json_object_object_add(json_obj_keys, "type", json_object_new_string( + dap_store_obj_get_type(l_objs + i) == DAP_GLOBAL_DB_OPTYPE_ADD ? "record" : "hole")); json_object_array_add(json_arr_keys, json_obj_keys); } - dap_global_db_objs_delete(l_obj, l_objs_count); + dap_store_obj_free(l_objs, l_objs_count); json_object* json_keys_list = json_object_new_object(); json_object_object_add(json_keys_list, "group name", json_object_new_string(l_group_str)); diff --git a/modules/net/dap_chain_node_client.c b/modules/net/dap_chain_node_client.c index 548e6fd9850255fdcb6f6c598460c28089d84788..e08164a47dc01ee669a7bec7dc74788c25339631 100644 --- a/modules/net/dap_chain_node_client.c +++ b/modules/net/dap_chain_node_client.c @@ -395,28 +395,28 @@ int dap_chain_node_client_wait(dap_chain_node_client_t *a_client, int a_waited_s return -2; } - // prepare for signal waiting - struct timespec l_cond_timeout; - clock_gettime(CLOCK_REALTIME, &l_cond_timeout); - l_cond_timeout.tv_sec += a_timeout_ms;//1000; // signal waiting - dap_chain_node_client_state_t l_clinet_state = a_client->state; - while (a_client->state == l_clinet_state) { + while (a_client->state != a_waited_state) { + // prepare for signal waiting + struct timespec l_cond_timeout; + clock_gettime(CLOCK_REALTIME, &l_cond_timeout); + l_cond_timeout.tv_sec += a_timeout_ms; int l_ret_wait = pthread_cond_timedwait(&a_client->wait_cond, &a_client->wait_mutex, &l_cond_timeout); - if(l_ret_wait == 0 && ( - a_client->state == a_waited_state || - (a_client->state == NODE_CLIENT_STATE_ERROR || a_client->state == NODE_CLIENT_STATE_DISCONNECTED)) - ) { + if (l_ret_wait == 0) { + if (a_client->state != a_waited_state) { + if (a_client->state == NODE_CLIENT_STATE_CONNECTING) + continue; // Spurious wakeup? + assert(a_client->state == NODE_CLIENT_STATE_DISCONNECTED || a_client->state == NODE_CLIENT_STATE_ERROR); + } ret = a_client->state == a_waited_state ? 0 : -2; - break; - } - else if(l_ret_wait == ETIMEDOUT) { // 110 260 + } else if (l_ret_wait == ETIMEDOUT) { // 110 260 log_it(L_NOTICE, "Wait for status is stopped by timeout"); ret = -1; - break; - }else if (l_ret_wait != 0 ){ + } else if (l_ret_wait != 0) { log_it(L_CRITICAL, "pthread_cond_timedwait() error %d:\"%s\"", l_ret_wait, dap_strerror(l_ret_wait)); + ret = -4; } + break; } pthread_mutex_unlock(&a_client->wait_mutex); return ret; diff --git a/modules/net/include/dap_chain_node.h b/modules/net/include/dap_chain_node.h index 61d7ab14815b8d9d053fd91e30246bf47a5ed355..6aa06cce6f52db16434e987487561e8153b4837a 100644 --- a/modules/net/include/dap_chain_node.h +++ b/modules/net/include/dap_chain_node.h @@ -56,6 +56,7 @@ typedef struct dap_chain_node_info { // using to easy sorting and formin in balancer typedef struct dap_chain_node_states_info { dap_link_info_t link_info; + uint64_t events_count; uint64_t atoms_count; uint32_t downlinks_count; dap_nanotime_t timestamp; diff --git a/modules/service/voting/dap_chain_net_srv_voting.c b/modules/service/voting/dap_chain_net_srv_voting.c index 06c9e5a0bce82c7394be0f16af2ff8862596296d..263aaeb15cf22184f73c8d8bb8a847b996a5db13 100644 --- a/modules/service/voting/dap_chain_net_srv_voting.c +++ b/modules/service/voting/dap_chain_net_srv_voting.c @@ -681,6 +681,10 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) dap_time_t l_time_expire = 0; if (l_voting_expire_str) l_time_expire = dap_time_from_str_rfc822(l_voting_expire_str); + if(!l_time_expire){ + dap_cli_server_cmd_set_reply_text(a_str_reply, "Wrong time format. -expire parameter must be in format \"Day Month Year HH:MM:SS Timezone\" e.g. \"19 August 2024 22:00:00 +00\""); + return -104; + } uint64_t l_max_count = 0; if (l_max_votes_count_str) l_max_count = strtoul(l_max_votes_count_str, NULL, 10); @@ -855,6 +859,9 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) case DAP_CHAIN_NET_VOTE_VOTING_NO_KEY_FOUND_IN_CERT: { dap_cli_server_cmd_set_reply_text(a_str_reply, "No key found in \"%s\" certificate", l_cert_name); } break; + case DAP_CHAIN_NET_VOTE_VOTING_CERT_REQUIRED: { + dap_cli_server_cmd_set_reply_text(a_str_reply, "This voting required a delegated key. Parameter -cert must contain a valid certificate name"); + } break; case DAP_CHAIN_NET_VOTE_VOTING_NO_PUBLIC_KEY_IN_CERT: { dap_cli_server_cmd_set_reply_text(a_str_reply, "Can't serialize public key of certificate \"%s\"", l_cert_name); @@ -984,7 +991,7 @@ static int s_cli_voting(int a_argc, char **a_argv, void **a_str_reply) if (l_voting->voting_params.voting_expire) { char l_tmp_buf[DAP_TIME_STR_SIZE]; dap_time_to_str_rfc822(l_tmp_buf, DAP_TIME_STR_SIZE, l_voting->voting_params.voting_expire); - dap_string_append_printf(l_str_out, "\t Voting expire: %s", l_tmp_buf); + dap_string_append_printf(l_str_out, "\t Voting expire: %s\n", l_tmp_buf); dap_string_truncate(l_str_out, l_str_out->len - 1); dap_string_append_printf(l_str_out, " (%s)\n", l_voting->voting_params.voting_expire > dap_time_now() ? "active" : "expired"); } @@ -1402,7 +1409,9 @@ int dap_chain_net_vote_voting(dap_cert_t *a_cert, uint256_t a_fee, dap_chain_wal return DAP_CHAIN_NET_VOTE_VOTING_ALREADY_EXPIRED; if (l_voting->voting_params.delegate_key_required) { - if (!a_cert || !a_cert->enc_key) + if (!a_cert) + return DAP_CHAIN_NET_VOTE_VOTING_CERT_REQUIRED; + if (!a_cert->enc_key) return DAP_CHAIN_NET_VOTE_VOTING_NO_KEY_FOUND_IN_CERT; // Get publivc key hash size_t l_pub_key_size = 0; diff --git a/modules/service/voting/include/dap_chain_net_srv_voting.h b/modules/service/voting/include/dap_chain_net_srv_voting.h index 28bfe4f23468f1f201078993344f48535ff052bb..f21c10d291c7ade08ae4ec1ddb21592fec321955 100644 --- a/modules/service/voting/include/dap_chain_net_srv_voting.h +++ b/modules/service/voting/include/dap_chain_net_srv_voting.h @@ -98,6 +98,7 @@ enum DAP_CHAIN_NET_VOTE_VOTING_ERROR{ DAP_CHAIN_NET_VOTE_VOTING_ALREADY_EXPIRED, DAP_CHAIN_NET_VOTE_VOTING_NO_KEY_FOUND_IN_CERT, DAP_CHAIN_NET_VOTE_VOTING_NO_PUBLIC_KEY_IN_CERT, + DAP_CHAIN_NET_VOTE_VOTING_CERT_REQUIRED, DAP_CHAIN_NET_VOTE_VOTING_KEY_IS_NOT_DELEGATED, DAP_CHAIN_NET_VOTE_VOTING_DOES_NOT_ALLOW_CHANGE_YOUR_VOTE, DAP_CHAIN_NET_VOTE_VOTING_SOURCE_ADDRESS_INVALID, diff --git a/modules/service/vpn/dap_chain_net_srv_vpn.c b/modules/service/vpn/dap_chain_net_srv_vpn.c index b4f4f2984cd2e27bfebeb804791c036740d8999c..e64992b108c503592d5911a7a484f9c75e80f383 100644 --- a/modules/service/vpn/dap_chain_net_srv_vpn.c +++ b/modules/service/vpn/dap_chain_net_srv_vpn.c @@ -123,7 +123,7 @@ typedef struct vpn_local_network { #endif bool auto_cpu_reassignment; - ch_vpn_pkt_t * pkt_out[400]; + dap_stream_ch_vpn_pkt_t * pkt_out[400]; size_t pkt_out_size; size_t pkt_out_rindex; size_t pkt_out_windex; @@ -159,7 +159,7 @@ typedef struct tun_socket_msg{ struct in_addr addr; } ip_unassigment; struct{ // CH VPN send operation - ch_vpn_pkt_t * pkt; + dap_stream_ch_vpn_pkt_t * pkt; } ch_vpn_send; }; } tun_socket_msg_t; @@ -241,10 +241,10 @@ static int s_tun_attach_queue(int fd); #endif static bool s_tun_client_send_data(dap_chain_net_srv_ch_vpn_info_t * a_ch_vpn_info, const void * a_data, size_t a_data_size); -static bool s_tun_client_send_data_unsafe(dap_chain_net_srv_ch_vpn_t * l_ch_vpn, ch_vpn_pkt_t * l_pkt_out); +static bool s_tun_client_send_data_unsafe(dap_chain_net_srv_ch_vpn_t * l_ch_vpn, dap_stream_ch_vpn_pkt_t * l_pkt_out); -static bool s_tun_client_send_data_unsafe(dap_chain_net_srv_ch_vpn_t * l_ch_vpn, ch_vpn_pkt_t * l_pkt_out) +static bool s_tun_client_send_data_unsafe(dap_chain_net_srv_ch_vpn_t * l_ch_vpn, dap_stream_ch_vpn_pkt_t * l_pkt_out) { dap_chain_net_srv_stream_session_t *l_srv_session = DAP_CHAIN_NET_SRV_STREAM_SESSION(l_ch_vpn->ch->stream->session); dap_chain_net_srv_usage_t *l_usage = l_srv_session->usage_active;// dap_chain_net_srv_usage_find_unsafe(l_srv_session, l_ch_vpn->usage_id); @@ -272,7 +272,7 @@ static bool s_tun_client_send_data_unsafe(dap_chain_net_srv_ch_vpn_t * l_ch_vpn, * @param a_pkt_out * @return */ -static bool s_tun_client_send_data_inter(dap_events_socket_t * a_es_input, dap_chain_net_srv_ch_vpn_t * a_ch_vpn, ch_vpn_pkt_t * a_pkt_out) +static bool s_tun_client_send_data_inter(dap_events_socket_t * a_es_input, dap_chain_net_srv_ch_vpn_t * a_ch_vpn, dap_stream_ch_vpn_pkt_t * a_pkt_out) { dap_chain_net_srv_stream_session_t * l_srv_session = DAP_CHAIN_NET_SRV_STREAM_SESSION (a_ch_vpn->ch->stream->session ); dap_chain_net_srv_usage_t * l_usage = l_srv_session->usage_active;// dap_chain_net_srv_usage_find_unsafe(l_srv_session, a_ch_vpn->usage_id); @@ -297,7 +297,7 @@ static bool s_tun_client_send_data_inter(dap_events_socket_t * a_es_input, dap_c static bool s_tun_client_send_data(dap_chain_net_srv_ch_vpn_info_t * l_ch_vpn_info, const void * a_data, size_t a_data_size) { assert(a_data_size > sizeof (dap_os_iphdr_t)); - ch_vpn_pkt_t *l_pkt_out = DAP_NEW_Z_SIZE(ch_vpn_pkt_t, sizeof(l_pkt_out->header) + a_data_size); + dap_stream_ch_vpn_pkt_t *l_pkt_out = DAP_NEW_Z_SIZE(dap_stream_ch_vpn_pkt_t, sizeof(l_pkt_out->header) + a_data_size); if (!l_pkt_out) { log_it(L_CRITICAL, "%s", c_error_memory_alloc); return false; @@ -1019,7 +1019,7 @@ static int s_callback_response_success(dap_chain_net_srv_t * a_srv, uint32_t a_u l_srv_session->last_update_ts = time(NULL); if (!l_usage_active->is_grace && l_srv_session->limits_ts <= 0){ char *l_user_key = dap_chain_hash_fast_to_str_new(&l_usage_active->client_pkey_hash); - log_it(L_INFO,"%"DAP_UINT64_FORMAT_U" seconds more for VPN usage for user %s", l_srv_session->limits_ts < 0 ? l_usage_active->receipt->receipt_info.units + l_srv_session->limits_ts : + log_it(L_INFO,"%ld seconds more for VPN usage for user %s", l_srv_session->limits_ts < 0 ? l_usage_active->receipt->receipt_info.units + l_srv_session->limits_ts : l_usage_active->receipt->receipt_info.units, l_user_key); DAP_DELETE(l_user_key); l_srv_session->limits_ts += (time_t)l_usage_active->receipt->receipt_info.units; @@ -1386,7 +1386,7 @@ static void s_update_limits(dap_stream_ch_t * a_ch , a_usage->is_limits_changed = true; if(a_srv_session->limits_ts && a_srv_session->limits_ts < l_current_limit_ts/2 && - !a_usage->receipt_next && !a_usage->is_waiting_first_receipt_sign){ + !a_usage->receipt_next && !a_usage->is_waiting_first_receipt_sign && !a_usage->is_grace){ l_issue_new_receipt = true; } a_srv_session->last_update_ts = time(NULL); @@ -1521,7 +1521,7 @@ static void s_update_limits(dap_stream_ch_t * a_ch , static void send_pong_pkt(dap_stream_ch_t* a_ch) { // log_it(L_DEBUG,"---------------------------------- PONG!"); - ch_vpn_pkt_t *pkt_out = (ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header)); + dap_stream_ch_vpn_pkt_t *pkt_out = (dap_stream_ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header)); if (!pkt_out) { log_it(L_CRITICAL, "%s", c_error_memory_alloc); return; @@ -1550,7 +1550,7 @@ static void s_ch_packet_in_vpn_address_request(dap_stream_ch_t *a_ch, dap_chain_ if ( l_ch_vpn->addr_ipv4.s_addr ) { log_it(L_WARNING, "IP address is already leased"); - ch_vpn_pkt_t* pkt_out = DAP_NEW_STACK_SIZE(ch_vpn_pkt_t, sizeof(pkt_out->header)); + dap_stream_ch_vpn_pkt_t* pkt_out = DAP_NEW_STACK_SIZE(dap_stream_ch_vpn_pkt_t, sizeof(pkt_out->header)); if (!pkt_out) { log_it(L_CRITICAL, "%s", c_error_memory_alloc); return; @@ -1582,7 +1582,7 @@ static void s_ch_packet_in_vpn_address_request(dap_stream_ch_t *a_ch, dap_chain_ HASH_ADD(hh, s_ch_vpn_addrs, addr_ipv4, sizeof (l_ch_vpn->addr_ipv4), l_ch_vpn); pthread_rwlock_unlock( &s_clients_rwlock ); - ch_vpn_pkt_t *l_pkt_out = DAP_NEW_STACK_SIZE(ch_vpn_pkt_t, + dap_stream_ch_vpn_pkt_t *l_pkt_out = DAP_NEW_STACK_SIZE(dap_stream_ch_vpn_pkt_t, sizeof(l_pkt_out->header) + sizeof(l_ch_vpn->addr_ipv4) + sizeof(s_raw_server->ipv4_network_addr)); l_pkt_out->header.sock_id = s_raw_server->tun_fd; l_pkt_out->header.op_code = VPN_PACKET_OP_CODE_VPN_ADDR_REPLY; @@ -1685,7 +1685,7 @@ static void s_ch_packet_in_vpn_address_request(dap_stream_ch_t *a_ch, dap_chain_ HASH_ADD(hh, s_ch_vpn_addrs, addr_ipv4, sizeof (l_ch_vpn->addr_ipv4), l_ch_vpn); pthread_rwlock_unlock( &s_clients_rwlock ); - ch_vpn_pkt_t *pkt_out = DAP_NEW_STACK_SIZE(ch_vpn_pkt_t, + dap_stream_ch_vpn_pkt_t *pkt_out = DAP_NEW_STACK_SIZE(dap_stream_ch_vpn_pkt_t, sizeof(pkt_out->header) + sizeof(l_ch_vpn->addr_ipv4) + sizeof(s_raw_server->ipv4_gw)); pkt_out->header.sock_id = s_raw_server->tun_fd; pkt_out->header.op_code = VPN_PACKET_OP_CODE_VPN_ADDR_REPLY; @@ -1711,7 +1711,7 @@ static void s_ch_packet_in_vpn_address_request(dap_stream_ch_t *a_ch, dap_chain_ } } else { // All the network is filled with clients, can't lease a new address log_it(L_ERROR, "No free IP address left, can't lease one..."); - ch_vpn_pkt_t* pkt_out = DAP_NEW_STACK_SIZE(ch_vpn_pkt_t, sizeof(pkt_out->header)); + dap_stream_ch_vpn_pkt_t* pkt_out = DAP_NEW_STACK_SIZE(dap_stream_ch_vpn_pkt_t, sizeof(pkt_out->header)); pkt_out->header.sock_id = s_raw_server->tun_fd; pkt_out->header.op_code = VPN_PACKET_OP_CODE_PROBLEM; pkt_out->header.usage_id = a_usage->id; @@ -1739,7 +1739,7 @@ static void s_ch_packet_in_vpn_address_request(dap_stream_ch_t *a_ch, dap_chain_ static bool s_ch_packet_in(dap_stream_ch_t* a_ch, void* a_arg) { dap_stream_ch_pkt_t * l_pkt = (dap_stream_ch_pkt_t *) a_arg; - ch_vpn_pkt_t *l_vpn_pkt = (ch_vpn_pkt_t*)l_pkt->data; + dap_stream_ch_vpn_pkt_t *l_vpn_pkt = (dap_stream_ch_vpn_pkt_t*)l_pkt->data; if (l_pkt->hdr.data_size < sizeof(l_vpn_pkt->header)) { log_it(L_WARNING, "Data size of stream channel packet %u is lesser than size of VPN packet header %zu", l_pkt->hdr.data_size, sizeof(l_vpn_pkt->header)); @@ -1940,7 +1940,7 @@ static bool s_es_tun_write(dap_events_socket_t *a_es, void *arg) size_t l_shift = 0; debug_if(s_debug_more, L_DEBUG, "Write %lu bytes to tun", l_tun->es->buf_out_size); for (ssize_t l_pkt_size = 0, l_bytes_written = 0; l_tun->es->buf_out_size; ) { - ch_vpn_pkt_t *l_vpn_pkt = (ch_vpn_pkt_t *)(l_tun->es->buf_out + l_shift); + dap_stream_ch_vpn_pkt_t *l_vpn_pkt = (dap_stream_ch_vpn_pkt_t *)(l_tun->es->buf_out + l_shift); l_pkt_size = l_vpn_pkt->header.op_data.data_size; debug_if(s_debug_more, L_DEBUG, "Packet: op_code 0x%02x, data size %ld", l_vpn_pkt->header.op_code, l_pkt_size); diff --git a/modules/service/vpn/dap_chain_net_vpn_client.c b/modules/service/vpn/dap_chain_net_vpn_client.c index 03ea305bfad2f114c215134cbacebf109461d008..753da5a7267b94b1d8d934331f99ecc7d2089149 100644 --- a/modules/service/vpn/dap_chain_net_vpn_client.c +++ b/modules/service/vpn/dap_chain_net_vpn_client.c @@ -181,7 +181,7 @@ static int s_callback_client_success(dap_chain_net_srv_t * a_srv, uint32_t a_usa if(l_ch) { // Is present in hash table such destination address size_t l_ipv4_str_len = 0; //dap_strlen(a_ipv4_str); - ch_vpn_pkt_t *pkt_out = (ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header) + l_ipv4_str_len); + dap_stream_ch_vpn_pkt_t *pkt_out = (dap_stream_ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header) + l_ipv4_str_len); if (!pkt_out) { log_it(L_CRITICAL, "%s", c_error_memory_alloc); dap_stream_session_unlock(); @@ -682,7 +682,7 @@ dap_chain_net_vpn_client_status_t dap_chain_net_vpn_client_status(void) */ void dap_chain_net_vpn_client_pkt_in(dap_stream_ch_t* a_ch, dap_stream_ch_pkt_t* a_pkt) { - ch_vpn_pkt_t * l_sf_pkt = (ch_vpn_pkt_t *) a_pkt->data; + dap_stream_ch_vpn_pkt_t * l_sf_pkt = (dap_stream_ch_vpn_pkt_t *) a_pkt->data; size_t l_sf_pkt_data_size = a_pkt->hdr.data_size - sizeof(l_sf_pkt->header); if(!a_pkt->hdr.data_size) { diff --git a/modules/service/vpn/dap_chain_net_vpn_client_tun.c b/modules/service/vpn/dap_chain_net_vpn_client_tun.c index f5de32b36fd1feed2f823239d4ade8858b8b51a0..0b3da1c064f4688115525480dd1b3e70632f648d 100644 --- a/modules/service/vpn/dap_chain_net_vpn_client_tun.c +++ b/modules/service/vpn/dap_chain_net_vpn_client_tun.c @@ -384,7 +384,7 @@ static void m_client_tun_read(dap_events_socket_t * a_es, void * arg) log_it(L_ERROR, "No remote client for incoming ip packet %s -> %s", l_str_saddr, l_str_daddr); break; } - ch_vpn_pkt_t* pkt_out = DAP_NEW_STACK_SIZE(ch_vpn_pkt_t, sizeof(pkt_out->header) + l_read_bytes); + dap_stream_ch_vpn_pkt_t* pkt_out = DAP_NEW_STACK_SIZE(dap_stream_ch_vpn_pkt_t, sizeof(pkt_out->header) + l_read_bytes); pkt_out->header.op_code = VPN_PACKET_OP_CODE_VPN_SEND; pkt_out->header.sock_id = s_fd_tun; pkt_out->header.op_data.data_size = l_read_bytes; @@ -617,7 +617,7 @@ int dap_chain_net_vpn_client_tun_status(void) static void ch_sf_pkt_send(dap_stream_ch_t * a_ch, void * a_data, size_t a_data_size) { - ch_vpn_pkt_t *l_pkt_out; + dap_stream_ch_vpn_pkt_t *l_pkt_out; size_t l_pkt_out_size = sizeof(l_pkt_out->header) + a_data_size; //log_it(L_DEBUG,"Peer for addr %s found (pkt_size %d)" // ,inet_ntoa(in_daddr), read_ret); @@ -625,7 +625,7 @@ static void ch_sf_pkt_send(dap_stream_ch_t * a_ch, void * a_data, size_t a_data_ log_it(L_ERROR, "Try to send to NULL channel"); return; } - l_pkt_out = DAP_NEW_SIZE(ch_vpn_pkt_t, l_pkt_out_size); + l_pkt_out = DAP_NEW_SIZE(dap_stream_ch_vpn_pkt_t, l_pkt_out_size); memset(&l_pkt_out->header,0,sizeof(l_pkt_out->header)); l_pkt_out->header.op_code = VPN_PACKET_OP_CODE_VPN_RECV; l_pkt_out->header.sock_id = a_ch->stream->esocket->socket; @@ -669,7 +669,7 @@ void ch_sf_tun_client_send(dap_chain_net_srv_ch_vpn_t * ch_sf, void * pkt_data, // if((ret = write(raw_server->tun_fd, sf_pkt->data, sf_pkt->header.op_data.data_size))<0){ log_it(L_ERROR, "write() error %d : \"%s\"", errno, dap_strerror(errno)); //log_it(ERROR,"raw socket ring buffer overflowed"); - ch_vpn_pkt_t *pkt_out = (ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header)); + dap_stream_ch_vpn_pkt_t *pkt_out = (dap_stream_ch_vpn_pkt_t*) calloc(1, sizeof(pkt_out->header)); if (!pkt_out) { log_it(L_CRITICAL, "%s", c_error_memory_alloc); if(in_daddr_str) @@ -702,7 +702,7 @@ void ch_sf_tun_client_send(dap_chain_net_srv_ch_vpn_t * ch_sf, void * pkt_data, * @param a_pkt * @param a_pkt_data_size */ -int ch_sf_tun_addr_leased(dap_chain_net_srv_ch_vpn_t * a_sf, ch_vpn_pkt_t * a_pkt, size_t a_pkt_data_size) +int ch_sf_tun_addr_leased(dap_chain_net_srv_ch_vpn_t * a_sf, dap_stream_ch_vpn_pkt_t * a_pkt, size_t a_pkt_data_size) { if(a_pkt_data_size < (2 * sizeof(struct in_addr))) { log_it(L_ERROR, "Too small ADDR_REPLY packet (%zu bytes, need at least %zu", a_pkt_data_size, 2 * sizeof(struct in_addr)); diff --git a/modules/service/vpn/include/dap_chain_net_srv_vpn.h b/modules/service/vpn/include/dap_chain_net_srv_vpn.h index dbcbaa095b276cb86c6a9f8b7384bf6d7aa5e00c..fdbae700319d5b7b22979baff69fba823579cb92 100644 --- a/modules/service/vpn/include/dap_chain_net_srv_vpn.h +++ b/modules/service/vpn/include/dap_chain_net_srv_vpn.h @@ -62,7 +62,7 @@ #define TUN_MTU 0xFFFF -typedef struct ch_vpn_pkt { +typedef struct dap_stream_ch_vpn_pkt { struct { int sock_id; // Client's socket id uint32_t op_code; // Operation code @@ -70,25 +70,21 @@ typedef struct ch_vpn_pkt { union { struct { // L4 connect operation uint32_t addr_size; - uint16_t port; - uint16_t padding; - } op_connect; + uint16_t port DAP_ALIGNED(4); + } DAP_PACKED op_connect; struct { // For data transmission, usualy for I/O functions - uint32_t data_size; - uint32_t padding; - } op_data; + uint32_t data_size DAP_ALIGNED(8); + } DAP_PACKED op_data; struct { // We have a problem and we know that! - uint32_t code; // I hope we'll have no more than 4B+ problems, not I?? - uint32_t padding_padding_padding_damned_padding_nobody_nowhere_uses_this_fild_but_if_wil_change_me_pls_with_an_auto_rename; - } op_problem; + uint32_t code DAP_ALIGNED(8); // I hope we'll have no more than 4B+ problems, not I?? + } DAP_PACKED op_problem; struct { - uint32_t padding1; - uint32_t padding2; - } raw; // Raw access to OP bytes + uint64_t op_data_raw DAP_ALIGNED(8); + } DAP_PACKED raw; // Raw access to OP bytes }; } DAP_ALIGN_PACKED header; byte_t data[]; // Binary data nested by packet -}DAP_ALIGN_PACKED ch_vpn_pkt_t; +}DAP_ALIGN_PACKED dap_stream_ch_vpn_pkt_t; typedef struct dap_chain_net_srv_vpn_tun_socket dap_chain_net_srv_vpn_tun_socket_t; typedef struct dap_chain_net_srv_ch_vpn dap_chain_net_srv_ch_vpn_t; diff --git a/modules/service/vpn/include/dap_chain_net_vpn_client_tun.h b/modules/service/vpn/include/dap_chain_net_vpn_client_tun.h index e1c84a307e83c564355b567bc12877682e91f545..1d5022b564311abb91de0b7cbb8584a28d6c9707 100644 --- a/modules/service/vpn/include/dap_chain_net_vpn_client_tun.h +++ b/modules/service/vpn/include/dap_chain_net_vpn_client_tun.h @@ -31,5 +31,5 @@ int dap_chain_net_vpn_client_tun_create(const char *a_ipv4_addr_str, const char int dap_chain_net_vpn_client_tun_delete(void); int dap_chain_net_vpn_client_tun_status(void); -int ch_sf_tun_addr_leased(dap_chain_net_srv_ch_vpn_t * a_sf, ch_vpn_pkt_t * a_pkt, size_t a_pkt_data_size); +int ch_sf_tun_addr_leased(dap_chain_net_srv_ch_vpn_t * a_sf, dap_stream_ch_vpn_pkt_t * a_pkt, size_t a_pkt_data_size); void ch_sf_tun_client_send(dap_chain_net_srv_ch_vpn_t * ch_sf, void * pkt_data, size_t pkt_data_size); diff --git a/modules/service/xchange/dap_chain_net_srv_xchange.c b/modules/service/xchange/dap_chain_net_srv_xchange.c index 399f8172bcb5a488e95bea94500e39b133d18d6f..42cea326359093a8f25eeb79c879444c329ebb39 100644 --- a/modules/service/xchange/dap_chain_net_srv_xchange.c +++ b/modules/service/xchange/dap_chain_net_srv_xchange.c @@ -163,7 +163,7 @@ int dap_chain_net_srv_xchange_init() "srv_xchange tx_list -net <net_name> [-time_from <From_time>] [-time_to <To_time>]" "[[-addr <wallet_addr> [-status {inactive|active|all}] ]\n" /* @RRL: #6294 */ "\tList of exchange transactions\n" - "\tAll times are in RFC822. For example: \"Thu, 7 Dec 2023 21:18:04\"\n" + "\tAll times are in RFC822. For example: \"7 Dec 2023 21:18:04\"\n" "srv_xchange token_pair -net <net_name> list all [-limit <limit>] [-offset <offset>]\n" "\tList of all token pairs\n" @@ -171,7 +171,7 @@ int dap_chain_net_srv_xchange_init() "\tGet average rate for token pair <token from>:<token to> from <From time> to <To time> \n" "srv_xchange token_pair -net <net_name> rate history -token_from <token_ticker> -token_to <token_ticker> [-time_from <From_time>] [-time_to <To_time>] [-limit <limit>] [-offset <offset>]\n" "\tPrint rate history for token pair <token from>:<token to> from <From time> to <To time>\n" - "\tAll times are in RFC822. For example: \"Thu, 7 Dec 2023 21:18:04\"\n" + "\tAll times are in RFC822. For example: \"T7 Dec 2023 21:18:04\"\n" "srv_xchange enable\n" "\tEnable eXchange service\n" diff --git a/prod_build/targets/osx.sh b/prod_build/targets/osx.sh index 67f76e6a7956c63a6f9c3f2b3c58b11bf87807b7..93e9728c88e276a9589cc01fd04d00467189ab06 100644 --- a/prod_build/targets/osx.sh +++ b/prod_build/targets/osx.sh @@ -35,26 +35,18 @@ esac if [ "$MACHINE" != "Mac" ] then echo "Host is $MACHINE, use osx-cross build target" - if [ -z "$OSXCROSS_QT_ROOT" ] + if [ -z "$OSXCROSS_ROOT" ] then - echo "Please, export OSXCROSS_QT_ROOT variable, pointing to Qt-builds locations for osxcross environment" + echo "Please, export OSXCROSS_ROOT variable, pointing to OSXCROSS locations" exit 255 fi - if [ -z "$OSXCROSS_QT_VERSION" ] - then - echo "Please, export OSXCROSS_QT_VERSION variable, scpecifying Qt-version in OSXCROSS_QT_ROOT directory." - exit 255 - fi - echo "Using QT ${OSXCROSS_QT_VERSION} from ${OSXCROSS_QT_ROOT}/${OSXCROSS_QT_VERSION}" - - [ ! -d ${OSXCROSS_QT_ROOT}/${OSXCROSS_QT_VERSION} ] && { echo "No QT ${OSXCROSS_QT_VERSION} found in ${OSXCROSS_QT_ROOT}" && exit 255; } + [ ! -d ${OSXCROSS_ROOT}/ ] && { echo "No OSXCROSS found in ${OSXCROSS_ROOT}" && exit 255; } $(${OSXCROSS_ROOT}/bin/osxcross-conf) - export OSXCROSS_HOST=x86_64-apple-darwin20.4 CMAKE=(cmake -DCMAKE_TOOLCHAIN_FILE=${OSXCROSS_ROOT}/toolchain.cmake)