diff --git a/dap-sdk b/dap-sdk index 692e4c19f0ee4cd63770ddd42109ab0a4c51c890..fa5f9b3c5699bb40499b59c3f38819567e0e9fbd 160000 --- a/dap-sdk +++ b/dap-sdk @@ -1 +1 @@ -Subproject commit 692e4c19f0ee4cd63770ddd42109ab0a4c51c890 +Subproject commit fa5f9b3c5699bb40499b59c3f38819567e0e9fbd diff --git a/modules/net-srv/dap_chain_net_srv_order.c b/modules/net-srv/dap_chain_net_srv_order.c index 36e491650c327646b0344e12683053aeecd80f89..4767c733553ba3b2a8a8e2764b8a2ca8dd0a8489 100644 --- a/modules/net-srv/dap_chain_net_srv_order.c +++ b/modules/net-srv/dap_chain_net_srv_order.c @@ -71,6 +71,7 @@ struct dap_order_notify { */ int dap_chain_net_srv_order_init() { + dap_chain_srv_order_pin_init(); return 0; } @@ -82,6 +83,36 @@ void dap_chain_net_srv_order_deinit() } +int dap_chain_srv_order_pin_init() { + dap_list_t *l_group_list = dap_global_db_driver_get_groups_by_mask("*.service.orders"); + for (dap_list_t *l_list = l_group_list; l_list; l_list = dap_list_next(l_list)) { + size_t l_ret_count; + dap_store_obj_t * l_ret = dap_global_db_get_all_raw_sync((char*)l_list->data, &l_ret_count); + if (!l_ret) { + dap_store_obj_free(l_ret, l_ret_count); + return -2; + } + dap_cert_t *l_cert = dap_cert_find_by_name("node-addr"); + if (!l_cert) + return -1; + dap_stream_node_addr_t l_addr = dap_stream_node_addr_from_cert(l_cert); + const char * l_node_addr_str = dap_stream_node_addr_to_str_static(l_addr); + for(size_t i = 0; i < l_ret_count; i++) { + const dap_chain_net_srv_order_t *l_order = dap_chain_net_srv_order_check(l_ret[i].key, l_ret[i].value, l_ret[i].value_len); + if (!l_order) + continue; + const char * l_addr_str = dap_stream_node_addr_to_str_static(l_order->node_addr); + if (!dap_strcmp(l_node_addr_str, l_addr_str)) { + dap_global_db_pin_sync(l_ret[i].group, l_ret[i].key); + log_it(L_DEBUG, "Pin *.service.orders obj %s group, %s key", l_ret[i].group, l_ret[i].key); + } + } + // DAP_DELETE(l_order); order delete in dap_store_obj_free + dap_store_obj_free(l_ret, l_ret_count); + } + return 0; +} + uint64_t dap_chain_net_srv_order_get_size(const dap_chain_net_srv_order_t *a_order) { if (!a_order || a_order->version != ORDER_CURRENT_VERSION) diff --git a/modules/net-srv/include/dap_chain_net_srv_order.h b/modules/net-srv/include/dap_chain_net_srv_order.h index de6eae09178df9ad59a35b63a1468ebd88460956..5c5995896853c7131ce4c2ae33ff7c62c503fe69 100644 --- a/modules/net-srv/include/dap_chain_net_srv_order.h +++ b/modules/net-srv/include/dap_chain_net_srv_order.h @@ -51,6 +51,7 @@ typedef struct dap_chain_net_srv_order { // Init/deinit should be call only if private int dap_chain_net_srv_order_init(); void dap_chain_net_srv_order_deinit(void); +int dap_chain_srv_order_pin_init(); uint64_t dap_chain_net_srv_order_get_size(const dap_chain_net_srv_order_t *a_order); const dap_chain_net_srv_order_t *dap_chain_net_srv_order_check(const char *a_order_hash_str, const byte_t *a_order, size_t a_order_size); diff --git a/modules/net/dap_chain_net.c b/modules/net/dap_chain_net.c index f20f69afa42d49d0e1f0383e8d62f61ae5d8bc9d..ec841d15a7970b1d0db8b98b75450163fd564ff5 100644 --- a/modules/net/dap_chain_net.c +++ b/modules/net/dap_chain_net.c @@ -2173,7 +2173,7 @@ static void *s_net_load(void *a_arg) snprintf(l_net->pub.gdb_nodes, sizeof(l_net->pub.gdb_nodes), "%s.%s", l_net->pub.gdb_groups_prefix, s_gdb_nodes_postfix); l_net_pvt->nodes_cluster = dap_global_db_cluster_add(dap_global_db_instance_get_default(), l_net->pub.name, dap_guuid_compose(l_net->pub.id.uint64, 0), - l_net->pub.gdb_nodes, 0, true, + l_net->pub.gdb_nodes, 7200, true, DAP_GDB_MEMBER_ROLE_GUEST, DAP_CLUSTER_TYPE_EMBEDDED); if (!l_net_pvt->nodes_cluster) { diff --git a/modules/net/dap_chain_node.c b/modules/net/dap_chain_node.c index a52e02f7bdb915b447d78fad27f6cc84d4af7f3c..b240cf8e940daac71e616fe7e9aa65bef46ee953 100644 --- a/modules/net/dap_chain_node.c +++ b/modules/net/dap_chain_node.c @@ -43,9 +43,11 @@ #include "dap_chain_net.h" #include "dap_global_db.h" #include "dap_chain_node.h" +#include "dap_chain_node_client.h" #include "dap_chain_cs_esbocs.h" #include "dap_chain_ledger.h" #include "dap_cli_server.h" +#include "dap_chain_net_balancer.h" #define LOG_TAG "dap_chain_node" #define DAP_CHAIN_NODE_NET_STATES_INFO_CURRENT_VERSION 2 @@ -200,6 +202,57 @@ dap_string_t *dap_chain_node_states_info_read(dap_chain_net_t *a_net, dap_stream return l_ret; } +void dap_chain_node_list_cluster_del_callback(dap_store_obj_t *a_obj, void *a_arg) { + UNUSED(a_arg); + dap_return_if_fail(a_obj); + log_it(L_DEBUG, "Start check node list %s group %s key", a_obj->group, a_obj->key); + + if (a_obj->value_len == 0) { + dap_global_db_del_sync(a_obj->group, a_obj->key); + log_it(L_DEBUG, "Can't find value in %s group %s key delete from node list", a_obj->group, a_obj->key); + return; + } + dap_chain_node_info_t *l_node_info = (dap_chain_node_info_t*)a_obj->value; + dap_return_if_fail(l_node_info); + char ** l_group_strings = dap_strsplit(a_obj->group, ".", 3); + dap_chain_net_t *l_net = dap_chain_net_by_name(l_group_strings[0]); + if (dap_strcmp("nodes", l_group_strings[1]) || dap_strcmp("list", l_group_strings[2])) { + log_it(L_ERROR, "Try to delete from nodelist by the %s group %s key", a_obj->group, a_obj->key); + dap_strfreev(l_group_strings); + return; + } + int l_ret = -1; + for (size_t i = 0; i < 3 || l_ret == 0; i++) { + dap_chain_node_client_t *l_client = dap_chain_node_client_connect_default_channels(l_net, l_node_info); + if (l_client) + l_ret = dap_chain_node_client_wait(l_client, NODE_CLIENT_STATE_ESTABLISHED, 30000); + dap_chain_node_client_close_unsafe(l_client); + if (!l_ret) + break; + } + if (l_ret == 0) { + a_obj->timestamp = dap_time_now(); + dap_global_db_driver_apply(a_obj, 1); + } else { + dap_global_db_driver_delete(a_obj, 1); + log_it(L_DEBUG, "Can't do handshake with %s [ %s : %u ] delete from node list", a_obj->key, l_node_info->ext_host, l_node_info->ext_port); + } + dap_strfreev(l_group_strings); +} + +int dap_chain_node_list_clean_init() { + 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_node_role_t l_role = dap_chain_net_get_role(l_net); + if (l_role.enums == NODE_ROLE_ROOT) { + char * l_group_name = dap_strdup_printf("%s.nodes.list", l_net->pub.name); + dap_global_db_cluster_t *l_cluster = dap_global_db_cluster_by_group(dap_global_db_instance_get_default(), l_group_name); + l_cluster->del_callback = dap_chain_node_list_cluster_del_callback; + log_it(L_DEBUG, "Node list clean inited for net %s", l_net->pub.name); + } + } + return 0; +} + int dap_chain_node_init() { if (dap_proc_thread_timer_add(NULL, s_update_node_states_info, NULL, s_timer_update_states_info)) { diff --git a/modules/net/include/dap_chain_node.h b/modules/net/include/dap_chain_node.h index 203ed53078ca454cc0ee5ffa5a38f3d56618f8ab..28c72a6d4190d5f66c360f9ffd9d48aa1d4538ee 100644 --- a/modules/net/include/dap_chain_node.h +++ b/modules/net/include/dap_chain_node.h @@ -96,6 +96,7 @@ int dap_chain_node_info_del(dap_chain_net_t * l_net,dap_chain_node_info_t *node_ dap_chain_node_info_t* dap_chain_node_info_read(dap_chain_net_t *l_net, dap_chain_node_addr_t *address); int dap_chain_node_init(); +int dap_chain_node_list_clean_init(); bool dap_chain_node_mempool_need_process(dap_chain_t *a_chain, dap_chain_datum_t *a_datum); bool dap_chain_node_mempool_process(dap_chain_t *a_chain, dap_chain_datum_t *a_datum, const char *a_datum_hash_str); void dap_chain_node_mempool_process_all(dap_chain_t *a_chain, bool a_force); diff --git a/modules/node-cli/dap_chain_node_cli_cmd.c b/modules/node-cli/dap_chain_node_cli_cmd.c index 67e2e9b3590e05f251c2fa7a429f323e96988d85..1df9b70867ff8f27638bdc9e1518889017e4795d 100644 --- a/modules/node-cli/dap_chain_node_cli_cmd.c +++ b/modules/node-cli/dap_chain_node_cli_cmd.c @@ -528,7 +528,7 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) json_object_object_add(json_obj_rec, "pinned status", json_object_new_string("record already pinned")); break; } - if(dap_global_db_set_sync( l_group, l_key, l_value, l_value_len, true) ==0 ){ + if(dap_global_db_pin_sync( l_group, l_key) ==0 ){ json_object_object_add(json_obj_rec, "pinned status", json_object_new_string("record successfully pinned")); } else{ @@ -544,7 +544,7 @@ int com_global_db(int a_argc, char ** a_argv, void **a_str_reply) json_object_object_add(json_obj_rec, "unpinned status", json_object_new_string("record already unpinned")); break; } - if(dap_global_db_set_sync(l_group,l_key, l_value, l_value_len, false) == 0 ) { + if(dap_global_db_unpin_sync(l_group,l_key) == 0 ) { json_object_object_add(json_obj_rec, "unpinned status", json_object_new_string("record successfully unpinned")); } else {