Skip to content
Snippets Groups Projects
Commit 07735d51 authored by Roman Khlopkov's avatar Roman Khlopkov 🔜
Browse files

[+] Hostinfo to DNS reply

parent 019b1276
No related branches found
No related tags found
5 merge requests!251Master,!250Master,!162Bugs-4158,!159Bugs-4158,!156bugs-4158
Pipeline #4035 passed with stage
in 19 seconds
...@@ -512,11 +512,13 @@ static int s_net_states_proc(dap_chain_net_t * l_net) ...@@ -512,11 +512,13 @@ static int s_net_states_proc(dap_chain_net_t * l_net)
log_it(L_DEBUG, "%s.state: NET_STATE_LINKS_CONNECTING",l_net->pub.name); log_it(L_DEBUG, "%s.state: NET_STATE_LINKS_CONNECTING",l_net->pub.name);
log_it(L_DEBUG, "Establishing connection with " NODE_ADDR_FP_STR, log_it(L_DEBUG, "Establishing connection with " NODE_ADDR_FP_STR,
NODE_ADDR_FP_ARGS_S( l_pvt_net->links_addrs[l_links_count]) ); NODE_ADDR_FP_ARGS_S( l_pvt_net->links_addrs[l_links_count]) );
dap_chain_node_info_t *l_link_node_info = dap_chain_node_info_read(l_net, &l_pvt_net->links_addrs[l_links_count]); dap_chain_node_info_t l_link_node_info;
if ( l_link_node_info ) { int res = dap_dns_client_get_addr(inet_addr("192.168.10.10"), l_net->pub.name, &l_link_node_info);
dap_chain_node_client_t *l_node_client = dap_chain_node_client_connect(l_link_node_info); // = dap_chain_node_info_read(l_net, &l_pvt_net->links_addrs[l_links_count]);
if (res) {
dap_chain_node_client_t *l_node_client = dap_chain_node_client_connect(&l_link_node_info);
if(!l_node_client) { if(!l_node_client) {
DAP_DELETE(l_link_node_info); //DAP_DELETE(l_link_node_info);
ret = -1; ret = -1;
break; break;
} }
......
...@@ -102,13 +102,16 @@ void dap_dns_buf_put_uint64(dap_dns_buf_t *buf, uint64_t val) { ...@@ -102,13 +102,16 @@ void dap_dns_buf_put_uint64(dap_dns_buf_t *buf, uint64_t val) {
dap_chain_node_info_t *dap_dns_resolve_hostname(char *str) { dap_chain_node_info_t *dap_dns_resolve_hostname(char *str) {
log_it(L_DEBUG, "DNS parser retrieve hostname %s", str); log_it(L_DEBUG, "DNS parser retrieve hostname %s", str);
uint16_t l_nets_count; dap_chain_net_t *l_net = dap_chain_net_by_name(str);
dap_chain_net_t **l_nets = dap_chain_net_list(&l_nets_count); if (l_net == NULL) {
if (!l_nets_count) { uint16_t l_nets_count;
log_it(L_WARNING, "No chain network present"); dap_chain_net_t **l_nets = dap_chain_net_list(&l_nets_count);
return 0; if (!l_nets_count) {
log_it(L_WARNING, "No chain network present");
return 0;
}
l_net = l_nets[rand() % l_nets_count];
} }
dap_chain_net_t *l_net = l_nets[rand() % l_nets_count];
// get nodes list from global_db // get nodes list from global_db
dap_global_db_obj_t *l_objs = NULL; dap_global_db_obj_t *l_objs = NULL;
size_t l_nodes_count = 0; size_t l_nodes_count = 0;
...@@ -368,7 +371,7 @@ void dap_dns_server_stop() { ...@@ -368,7 +371,7 @@ void dap_dns_server_stop() {
DAP_DELETE(s_dns_server); DAP_DELETE(s_dns_server);
} }
int s_dns_get_ip(uint32_t a_addr, char *a_name, uint32_t *a_result) int dap_dns_client_get_addr(uint32_t a_addr, char *a_name, dap_chain_node_info_t *a_result)
{ {
const size_t l_buf_size = 1024; const size_t l_buf_size = 1024;
uint8_t l_buf[l_buf_size]; uint8_t l_buf[l_buf_size];
...@@ -463,17 +466,20 @@ int s_dns_get_ip(uint32_t a_addr, char *a_name, uint32_t *a_result) ...@@ -463,17 +466,20 @@ int s_dns_get_ip(uint32_t a_addr, char *a_name, uint32_t *a_result)
} }
l_cur = l_buf + l_addr_point; l_cur = l_buf + l_addr_point;
if (a_result) { if (a_result) {
*a_result = ntohl(*(uint32_t *)l_cur); a_result->hdr.ext_addr_v4.s_addr = ntohl(*(uint32_t *)l_cur);
}
l_cur = l_buf + 5 * sizeof(uint16_t);
int l_additions_count = ntohs(*(uint16_t *)l_cur);
if (l_additions_count == 1) {
l_cur = l_buf + l_addr_point + DNS_ANSWER_SIZE;
if (a_result) {
a_result->hdr.ext_port = ntohs(*(uint16_t *)l_cur);
}
l_cur += sizeof(uint16_t);
if (a_result) {
a_result->hdr.address.uint64 = be64toh(*(uint64_t *)l_cur);
}
} }
closesocket(l_sock); closesocket(l_sock);
return 0; return 0;
} }
uint32_t dap_dns_client_get_addr(uint32_t a_dns_addr)
{
uint32_t l_res;
if (s_dns_get_ip(a_dns_addr, "kelvin.sync", &l_res)) {
return 0;
}
return l_res;
}
...@@ -124,4 +124,4 @@ void dap_dns_server_start(); ...@@ -124,4 +124,4 @@ void dap_dns_server_start();
void dap_dns_server_stop(); void dap_dns_server_stop();
int dap_dns_zone_register(char *zone, dap_dns_zone_callback_t callback); int dap_dns_zone_register(char *zone, dap_dns_zone_callback_t callback);
int dap_dns_zone_unregister(char *zone); int dap_dns_zone_unregister(char *zone);
uint32_t dap_dns_client_get_addr(uint32_t a_dns_addr); int dap_dns_client_get_addr(uint32_t a_addr, char *a_name, dap_chain_node_info_t *a_result);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment