Skip to content
Snippets Groups Projects
Commit c503e42a authored by Dmitriy A. Gerasimov's avatar Dmitriy A. Gerasimov
Browse files

[*] Some renames, as usual

[+] Node ctl object
parent d7315186
No related branches found
No related tags found
1 merge request!24Support 3689
...@@ -3,12 +3,14 @@ project (dap_chain_net) ...@@ -3,12 +3,14 @@ project (dap_chain_net)
set(DAP_CHAIN_NET_SRCS set(DAP_CHAIN_NET_SRCS
dap_chain_net.c dap_chain_net.c
dap_chain_net_node.c dap_chain_node.c
dap_chain_node_ctl.c
) )
set(DAP_CHAIN_NET_HEADERS set(DAP_CHAIN_NET_HEADERS
dap_chain_net.h dap_chain_net.h
dap_chain_net_node.h dap_chain_node.h
dap_chain_node_ctl.h
) )
add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_NET_SRCS} ${DAP_CHAIN_NET_HEADERS}) add_library(${PROJECT_NAME} STATIC ${DAP_CHAIN_NET_SRCS} ${DAP_CHAIN_NET_HEADERS})
......
...@@ -22,17 +22,160 @@ ...@@ -22,17 +22,160 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stddef.h>
#include <string.h>
#include <pthread.h>
#include "dap_common.h" #include "dap_common.h"
#include "dap_config.h"
#include "dap_chain_net.h" #include "dap_chain_net.h"
#include "dap_chain_node_ctl.h"
#include "dap_module.h"
#define LOG_TAG "chain_net" #define LOG_TAG "chain_net"
/**
* @struct dap_chain_net_pvt
* @details Private part of chain_net dap object
*/
typedef struct dap_chain_net_pvt{
pthread_t proc_tid;
pthread_cond_t proc_cond;
dap_chain_node_role_t node_role;
dap_chain_node_ctl_t * node;
} dap_chain_net_pvt_t;
#define PVT(a) ( (dap_chain_net_pvt_t *) a->pvt )
#define PVT_S(a) ( (dap_chain_net_pvt_t *) a.pvt )
size_t s_net_configs_count = 0;
/**
* @brief s_net_proc_thread
* @details Brings up and check the Dap Chain Network
* @param a_cfg Network1 configuration
* @return
*/
static void * s_net_proc_thread ( void * a_net)
{
dap_chain_net_t * l_net = (dap_chain_net_t *) a_net;
return NULL;
}
/**
* @brief net_proc_start
* @param a_cfg
*/
static void s_net_proc_start( dap_chain_net_t * a_net )
{
if ( pthread_create(& PVT(a_net)->proc_tid ,NULL, s_net_proc_thread, a_net) == 0 ){
log_it (L_NOTICE,"Network processing thread started");
dap_chain_node_role_t l_role;
switch (l_role.enums = PVT (a_net)->node_role.enums){
case ROOT:
log_it(L_DEBUG , "Root node functions initialized");
case ROOT_DELEGATE:
log_it(L_DEBUG , "Root delegate node functions initialized");
case ARCHIVE:
log_it(L_DEBUG , "Archive node functions initialized");
case SHARD_DELEGATE:
if ( l_role.enums != ARCHIVE ){
log_it(L_DEBUG , "Shard delegate node functions initialized");
}
case MASTER:
log_it(L_DEBUG , "Master node functions initialized");
case FULL:
log_it(L_DEBUG , "Full node functions initialized");
case LIGHT:
log_it(L_DEBUG , "Light node functions initialized");
default:
log_it(L_NOTICE, "Node role initialized");
}
}
}
/**
* @brief s_net_proc_kill
* @param a_net
*/
static void s_net_proc_kill( dap_chain_net_t * a_net )
{
if ( PVT(a_net)->proc_tid ) {
pthread_cond_signal(& PVT(a_net)->proc_cond);
log_it(L_NOTICE,"Sent KILL signal to the net process thread %d, waiting for shutdown...",PVT(a_net)->proc_tid);
pthread_join( PVT(a_net)->proc_tid , NULL);
log_it(L_NOTICE,"Net process thread %d shutted down",PVT(a_net)->proc_tid);
PVT(a_net)->proc_tid = 0;
}
}
/**
* @brief dap_chain_net_new
* @param a_id
* @param a_name
* @param a_node_role
* @return
*/
dap_chain_net_t * dap_chain_net_new(const char * a_id, const char * a_name , const char * a_node_role)
{
dap_chain_net_t * ret = DAP_NEW_Z_SIZE (dap_chain_net_t, sizeof (ret->pub)+ sizeof (dap_chain_net_pvt_t) );
ret->pub.name = strdup( a_name );
if ( sscanf(a_id,"0x%llu", &ret->pub.id.uint64 ) == 1 ){
if (strcmp (a_node_role, "root")==0){
PVT(ret)->node_role.enums = ROOT;
log_it (L_NOTICE, "Node role \"root\" selected");
}
PVT(ret)->node = dap_chain_node_ctl_new();
} else {
log_it (L_ERROR, "Wrong id format (\"%s\"). Must be like \"0x0123456789ABCDE\"" , a_id );
}
}
/**
* @brief dap_chain_net_delete
* @param a_net
*/
void dap_chain_net_delete( dap_chain_net_t * a_net )
{
DAP_DELETE( PVT(a_net)->node);
DAP_DELETE( PVT(a_net) );
}
/**
* @brief dap_chain_net_init
* @return
*/
int dap_chain_net_init() int dap_chain_net_init()
{ {
return 0; static dap_config_t *l_cfg=NULL;
if((l_cfg = dap_config_open( "network/default" ) ) == NULL) {
log_it(L_ERROR,"Can't open default network config");
return -1;
}else{
dap_chain_net_t * l_net = dap_chain_net_new(
dap_config_get_item_str(l_cfg , "general" , "id" ),
dap_config_get_item_str(l_cfg , "general" , "name" ),
dap_config_get_item_str(l_cfg , "general" , "node-role" )
);
switch ( PVT( l_net )->node_role.enums ) {
case ROOT:
case ROOT_DELEGATE:
case SHARD_DELEGATE:
// dap_chain_net_ca_load ( dap_config_get_item_str (""));
default:
log_it(L_DEBUG,"Net config loaded");
}
s_net_proc_start(l_net);
log_it(L_NOTICE, "Сhain network initialized");
return 0;
}
} }
void dap_chain_net_deinit() void dap_chain_net_deinit()
{ {
} }
...@@ -22,5 +22,24 @@ ...@@ -22,5 +22,24 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma once #pragma once
#include <stdint.h>
#include "dap_chain_common.h"
#include <sys/socket.h>
#include <netinet/in.h>
typedef struct dap_chain_net{
struct {
dap_chain_net_id_t id;
char * name;
} pub;
uint8_t pvt[];
} dap_chain_net_t;
int dap_chain_net_init(); int dap_chain_net_init();
void dap_chain_net_deinit(); void dap_chain_net_deinit();
dap_chain_net_t * dap_chain_net_new (const char * a_id, const char * a_name, const char* a_node_role );
void dap_chain_net_delete( dap_chain_net_t * a_net);
...@@ -19,5 +19,11 @@ ...@@ -19,5 +19,11 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>. along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "dap_chain_net_node.h" #include <sys/socket.h>
#include <netinet/in.h>
#include "dap_chain_net.h"
#include "dap_chain_node.h"
#define LOG_TAG "chain_node"
/*
* Authors:
* Dmitriy A. Gearasimov <naeper@demlabs.net>
* DeM Labs Inc. https://demlabs.net
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/>.
*/
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "dap_common.h"
#include "dap_chain_common.h"
/**
* @struct Node address
*
*/
typedef union dap_chain_node_addr{
uint64_t uint64;
uint8_t raw[sizeof(uint64_t)]; // Access to selected octects
} dap_chain_node_addr_t;
/**
* Node Declaration request
*
*/
#define DAP_CHAIN_NODE_DECL_REQ_INFO_SIZE 32
typedef struct dap_chain_node_delc_req{
dap_chain_node_addr_t node_address;
uint64_t create_ts;
union{
uint8_t raw[DAP_CHAIN_NODE_DECL_REQ_INFO_SIZE];
char str[DAP_CHAIN_NODE_DECL_REQ_INFO_SIZE];
} info;
} DAP_ALIGN_PACKED dap_chain_decl_req_t;
/**
* @struct dap_chain_node decl
* @details New node declaration
*
*/
#define DAP_CHAIN_NODE_DECL_ACCEPT_INFO_SIZE 32
typedef struct dap_chain_node_decl{
dap_chain_decl_req_t request;
uint64_t accept_ts;
struct in_addr accept_addr_v4;
struct in6_addr accept_addr_v6;
union{
uint8_t raw[DAP_CHAIN_NODE_DECL_ACCEPT_INFO_SIZE];
char str[DAP_CHAIN_NODE_DECL_ACCEPT_INFO_SIZE];
} accept_info;
} DAP_ALIGN_PACKED dap_chain_node_decl_t;
typedef struct dap_chain_node_info
{
struct {
dap_chain_node_addr_t address;
dap_chain_shard_id_t shard_id;
uint32_t uplinks_number;
struct in_addr ext_addr_v4;
struct in6_addr ext_addr_v6;
} DAP_ALIGN_PACKED hdr;
dap_chain_addr_t uplinks[];
} DAP_ALIGN_PACKED dap_chain_node_info_t;
typedef struct dap_chain_node_publ{
dap_chain_hash_fast_t decl_hash;
dap_chain_node_info_t node_info;
} DAP_ALIGN_PACKED dap_chain_node_publ_t;
/*
* Authors:
* Dmitriy A. Gearasimov <naeper@demlabs.net>
* DeM Labs Inc. https://demlabs.net
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/socket.h>
#include <netinet/in.h>
#include "dap_config.h"
#include "dap_chain_net.h"
#include "dap_chain_node_ctl.h"
#define LOG_TAG "chain_node_ctl"
typedef struct dap_chain_node_ctl_pvt{
uint_fast64_t padding;
} dap_chain_node_ctl_pvt_t;
#define PVT(a) ( (dap_chain_node_ctl_pvt_t *) (a)->pvt )
#define PVT_S(a) ( (dap_chain_node_ctl_pvt_t *) (a).pvt )
/**
* @brief dap_chain_node_new
* @return
*/
dap_chain_node_ctl_t * dap_chain_node_ctl_new()
{
dap_chain_node_ctl_t * ret = DAP_NEW_Z_SIZE(dap_chain_node_ctl_t, sizeof(ret->pub) + sizeof(dap_chain_node_ctl_pvt_t) );
return ret;
}
/**
* @brief dap_chain_node_delete
* @param a_node
*/
void dap_chain_node_ctl_delete(dap_chain_node_ctl_t * a_node)
{
DAP_DELETE(a_node);
}
/**
* @brief dap_chain_node_ctl_open
* @param a_name
* @return
*/
dap_chain_node_ctl_t * dap_chain_node_ctl_open( const char * a_name )
{
dap_chain_node_ctl_t * l_node = NULL;
const char c_node_folder[]="node";
size_t buf_size = 2+sizeof(a_name)+sizeof(c_node_folder);
char *buf= DAP_NEW_SIZE(char, buf_size);
snprintf(buf,buf_size,"%s/%s",c_node_folder,a_name);
dap_config_t * l_node_cfg = dap_config_open(buf);
if ( l_node_cfg ){
//dap_config_get_item_str_default()
} else {
log_it(L_ERROR,"Can't open node \"%s\". Check the configuration files path.",a_name);
}
DAP_DELETE(buf);
return l_node;
}
...@@ -23,21 +23,23 @@ ...@@ -23,21 +23,23 @@
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <sys/socket.h>
#include <netinet/in.h> #include "dap_chain_common.h"
#include "dap_chain_node.h"
typedef union dap_chain_node_addr{
uint64_t addr_raw;
uint8_t addr_oct[sizeof(uint64_t)]; // Access to selected octects typedef struct dap_chain_node_ctl{
} dap_chain_node_addr_t; struct {
dap_chain_node_addr_t addr;
typedef struct dap_chain_node{ struct in_addr *ipv4_addrs;
dap_chain_node_addr_t addr; size_t ipv4_addrs_size;
dap_chain_node_addr_t *uplinks; struct in6_addr *ipv6_addrs;
dap_chain_node_addr_t *downlinks; size_t ipv6_addrs_size;
} pub;
struct in_addr *ipv4_addrs; uint8_t pvt[];
size_t ipv4_addrs_size; } dap_chain_node_ctl_t;
struct in6_addr *ipv6_addrs;
size_t ipv6_addrs_size; dap_chain_node_ctl_t * dap_chain_node_ctl_new();
} dap_chain_net_node_t; dap_chain_node_ctl_t * dap_chain_node_ctl_open( const char * a_name );
void dap_chain_node_ctl_delete(dap_chain_node_ctl_t * a_node);
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