Newer
Older
* Dmitriy A. Gearasimov <gerasimov.dmitriy@demlabs.net>
* Alexander Lysikov <alexander.lysikov@demlabs.net>
* Kelvin Project https://github.com/kelvinblockchain
This file is part of DAP (Deus Applications Prototypes) the open source project
DAP (Deus Applicaions Prototypes) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <errno.h>
#include "uthash.h"
#include "utlist.h"
#include "dap_string.h"
#include "dap_chain_common.h"
#include "dap_strfuncs.h"
#include "dap_list.h"
#include "dap_string.h"
#include "dap_chain_node.h"
#include "dap_chain_global_db.h"
#include "dap_chain_node_cli_cmd.h"
#include "dap_chain_datum_tx_items.h"
#include "dap_chain_global_db.h"
#include "dap_chain_global_db_remote.h"
#include "dap_stream_ch_chain_net.h"
#include "dap_stream_ch_chain.h"
#include "dap_stream_ch_chain_pkt.h"
#include "dap_stream_ch_chain_net_pkt.h"
/**
* Find in base addr by alias
*
* return addr, NULL if not found
*/
dap_chain_node_addr_t* dap_chain_node_addr_get_by_alias(const char *a_alias)
dap_chain_node_addr_t *l_addr = NULL;
if(!a_alias)
const char *a_key = a_alias;
l_addr = (dap_chain_node_addr_t*) (void*) dap_chain_global_db_gr_get(a_key, &l_addr_size, GROUP_GLOBAL_ALIAS);
if(l_addr_size != sizeof(dap_chain_node_addr_t)) {
// l_addr = DAP_NEW_Z(dap_chain_node_addr_t);
// if(hex2bin((char*) l_addr, (const unsigned char *) addr_str, sizeof(dap_chain_node_addr_t) * 2) == -1) {
DAP_DELETE(l_addr);
// l_addr = NULL;
// }
// DAP_DELETE(addr_str);
return l_addr;
* return list of addr, NULL if not found
static dap_list_t* get_aliases_by_name(dap_chain_node_addr_t *a_addr)
dap_list_t *list_aliases = NULL;
size_t data_size = 0;
// read all aliases
dap_global_db_obj_t **objs = dap_chain_global_db_gr_load(GROUP_GLOBAL_ALIAS, &data_size);
for(size_t i = 0; i < data_size; i++) {
//dap_chain_node_addr_t addr_i;
dap_global_db_obj_t *obj = objs[i];
dap_chain_node_addr_t *l_addr = (dap_chain_node_addr_t*) (void*) obj->value;
if(l_addr && obj->value_len == sizeof(dap_chain_node_addr_t) && a_addr->uint64 == l_addr->uint64) {
list_aliases = dap_list_prepend(list_aliases, strdup(obj->key));
/* char *addr_str = obj->value;
if(addr_str && strlen(addr_str) == sizeof(dap_chain_node_addr_t) * 2) {
//addr_i = DAP_NEW_Z(dap_chain_node_addr_t);
if(hex2bin((char*) &addr_i, (const unsigned char *) addr_str, sizeof(dap_chain_node_addr_t) * 2) == -1) {
continue;
}
if(a_addr->uint64 == addr_i.uint64) {
list_aliases = dap_list_prepend(list_aliases, strdup(obj->key));
}
}*/
dap_chain_global_db_objs_delete(objs);
return list_aliases;
}
static dap_chain_node_addr_t* com_global_db_get_addr(dap_chain_node_info_t *node_info,
dap_chain_node_addr_t *addr, const char *alias_str)
{
dap_chain_node_addr_t *address = NULL;
address = dap_chain_node_addr_get_by_alias(alias_str);
static dap_chain_node_info_t* dap_chain_node_info_read_and_reply(dap_chain_node_addr_t *address, char **str_reply)
char *l_key = dap_chain_node_addr_to_hash_str(address);
dap_chain_node_cli_set_reply_text(str_reply, "can't calculate hash of addr");
size_t node_info_size = 0;
dap_chain_node_info_t *node_info;
node_info = (dap_chain_node_info_t *) dap_chain_global_db_gr_get(l_key, &node_info_size, GROUP_GLOBAL_ADDRS_LEASED);
dap_chain_node_cli_set_reply_text(str_reply, "node not found in base");
size_t node_info_size_must_be = dap_chain_node_info_get_size(node_info);
if(node_info_size_must_be != node_info_size) {
dap_chain_node_cli_set_reply_text(str_reply, "node has bad size in base=%u (must be %u)", node_info_size,
node_info_size_must_be);
DAP_DELETE(node_info);
DAP_DELETE(l_key);
return NULL;
// dap_chain_node_info_t *node_info = dap_chain_node_info_deserialize(str, (str) ? strlen(str) : 0);
// if(!node_info) {
// set_reply_text(str_reply, "node has invalid format in base");
// }
// DAP_DELETE(str);
DAP_DELETE(l_key);
static bool dap_chain_node_info_save_and_reply(dap_chain_node_info_t *node_info, char **str_reply)
{
if(!node_info || !node_info->hdr.address.uint64) {
dap_chain_node_cli_set_reply_text(str_reply, "node addr not found");
char *a_key = dap_chain_node_addr_to_hash_str(&node_info->hdr.address);
Loading
Loading full blame...