Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/cellframe-sdk
  • MIKA83/cellframe-sdk
2 results
Show changes
Commits on Source (5)
......@@ -229,20 +229,24 @@ bool s_chain_pkt_callback(dap_proc_thread_t *a_thread, void *a_arg)
size_t l_atom_size =0;
if ( l_chain->callback_atom_find_by_hash(l_atom_iter, &l_atom_hash, &l_atom_size) == NULL ) {
dap_chain_atom_verify_res_t l_atom_add_res = l_chain->callback_atom_add(l_chain, l_atom_copy, l_atom_copy_size);
if(l_atom_add_res == ATOM_ACCEPT && dap_chain_has_file_store(l_chain)) {
if ((l_atom_add_res == ATOM_ACCEPT || l_atom_add_res == ATOM_MOVE_TO_THRESHOLD) &&
dap_chain_has_file_store(l_chain)) {
// append to file
dap_chain_cell_t *l_cell = dap_chain_cell_create_fill(l_chain, l_ch_chain->request_cell_id);
if(l_cell){
// add one atom only
int l_res = dap_chain_cell_file_append(l_cell, l_atom_copy, l_atom_copy_size);
// rewrite all file
//l_res = dap_chain_cell_file_update(l_cell);
if(l_res < 0) {
log_it(L_ERROR, "Can't save event 0x%x to the file '%s'", l_atom_hash,
l_cell ? l_cell->file_storage_path : "[null]");
int l_res;
if (l_cell) {
if (l_atom_add_res == ATOM_ACCEPT) {
// add one atom only
l_res = dap_chain_cell_file_append(l_cell, l_atom_copy, l_atom_copy_size);
// rewrite all file
//l_res = dap_chain_cell_file_update(l_cell);
if(l_res < 0) {
log_it(L_ERROR, "Can't save event 0x%x to the file '%s'", l_atom_hash,
l_cell ? l_cell->file_storage_path : "[null]");
}
}
// add all atoms from treshold
if(l_res && l_chain->callback_atom_add_from_treshold){
if (l_chain->callback_atom_add_from_treshold){
dap_chain_atom_ptr_t l_atom_treshold;
do{
size_t l_atom_treshold_size;
......@@ -251,7 +255,7 @@ bool s_chain_pkt_callback(dap_proc_thread_t *a_thread, void *a_arg)
l_atom_treshold = l_chain->callback_atom_add_from_treshold(l_chain, &l_atom_treshold_size);
// add into file
if(l_atom_treshold) {
int l_res = dap_chain_cell_file_append(l_cell, l_atom_treshold, l_atom_treshold_size);
l_res = dap_chain_cell_file_append(l_cell, l_atom_treshold, l_atom_treshold_size);
log_it(L_DEBUG, "Added atom from treshold");
if(l_res < 0) {
log_it(L_ERROR, "Can't save event 0x%x from treshold to the file '%s'",
......
......@@ -418,7 +418,7 @@ static int s_net_states_proc(dap_chain_net_t * l_net)
default: {
// Get DNS request result from root nodes as synchronization links
int l_max_tries = 5;
int l_tries =0;
int l_tries = 0;
while (dap_list_length(l_pvt_net->links_info) < s_max_links_count && l_tries < l_max_tries) {
int i = rand() % l_pvt_net->seed_aliases_count;
dap_chain_node_addr_t *l_remote_addr = dap_chain_node_alias_find(l_net, l_pvt_net->seed_aliases[i]);
......@@ -426,9 +426,9 @@ static int s_net_states_proc(dap_chain_net_t * l_net)
if(l_remote_node_info) {
dap_chain_node_info_t *l_link_node_info = DAP_NEW_Z(dap_chain_node_info_t);
int l_res = dap_dns_client_get_addr(l_remote_node_info->hdr.ext_addr_v4.s_addr, l_net->pub.name, l_link_node_info);
//memcpy(l_link_node_info, l_remote_node_info, sizeof(dap_chain_node_info_t));
if (!l_res && l_link_node_info->hdr.address.uint64 != l_own_addr) {
l_pvt_net->links_info = dap_list_append(l_pvt_net->links_info, l_link_node_info);
l_tries = 0;
}
DAP_DELETE(l_remote_node_info);
}
......@@ -441,8 +441,7 @@ static int s_net_states_proc(dap_chain_net_t * l_net)
}
l_tries++;
}
if (!l_pvt_net->links){
if (dap_list_length(l_pvt_net->links_info) < s_max_links_count) {
for (int i = 0; i < MIN(s_max_links_count, l_pvt_net->seed_aliases_count); i++) {
dap_chain_node_addr_t *l_link_addr = dap_chain_node_alias_find(l_net, l_pvt_net->seed_aliases[i]);
if (l_link_addr->uint64 == l_own_addr) {
......
......@@ -213,6 +213,13 @@ int dap_chain_cs_dag_new(dap_chain_t * a_chain, dap_config_t * a_chain_cfg)
log_it( L_ERROR, "Can't read hash from static_genesis_event \"%s\", ret code %d ", l_static_genesis_event_hash_str, lhr);
}
}
uint16_t l_list_len = 0;
char **l_hard_accept_list = dap_config_get_array_str(a_chain_cfg, "dag", "hard_accept_list", &l_list_len);
for (uint16_t i = 0; i < l_list_len; i++) {
dap_chain_cs_dag_hal_item_t *l_hal_item = DAP_NEW_Z(dap_chain_cs_dag_hal_item_t);
dap_chain_str_to_hash_fast(l_hard_accept_list[i], &l_hal_item->hash);
HASH_ADD(hh, l_dag->hal, hash, sizeof(l_hal_item->hash), l_hal_item);
}
l_dag->is_static_genesis_event = (l_static_genesis_event_hash_str != NULL) && dap_config_get_item_bool_default(a_chain_cfg,"dag","is_static_genesis_event",false);
......@@ -287,26 +294,19 @@ static int s_dap_chain_add_atom_to_ledger(dap_chain_cs_dag_t * a_dag, dap_ledger
return 0;
}
static int s_dap_chain_add_atom_to_events_table(dap_chain_cs_dag_t * a_dag, dap_ledger_t * a_ledger, dap_chain_cs_dag_event_item_t * a_event_item ){
static int s_dap_chain_add_atom_to_events_table(dap_chain_cs_dag_t * a_dag, dap_ledger_t * a_ledger, dap_chain_cs_dag_event_item_t * a_event_item )
{
int res = a_dag->callback_cs_verify(a_dag,a_event_item->event, a_event_item->event_size);
if (res != 0) {
if ( memcmp( &a_event_item->hash, &a_dag->static_genesis_event_hash, sizeof(a_event_item->hash) ) == 0 ){
res = 0;
}
}
if(res == 0){
char l_buf_hash[128];
dap_chain_hash_fast_to_str(&a_event_item->hash,l_buf_hash,sizeof(l_buf_hash)-1);
char l_buf_hash[128];
dap_chain_hash_fast_to_str(&a_event_item->hash,l_buf_hash,sizeof(l_buf_hash)-1);
if (res == 0 || memcmp( &a_event_item->hash, &a_dag->static_genesis_event_hash, sizeof(a_event_item->hash) ) == 0) {
log_it(L_DEBUG,"Dag event %s checked, add it to ledger", l_buf_hash);
s_dap_chain_add_atom_to_ledger(a_dag, a_ledger, a_event_item);
//All correct, no matter for result
HASH_ADD(hh, PVT(a_dag)->events,hash,sizeof (a_event_item->hash), a_event_item);
s_dag_events_lasts_process_new_last_event(a_dag, a_event_item);
} else {
char l_buf_hash[128];
dap_chain_hash_fast_to_str(&a_event_item->hash,l_buf_hash,sizeof(l_buf_hash)-1);
log_it(L_WARNING,"Dag event %s check failed: code %d", l_buf_hash, res );
}
return res;
......@@ -643,9 +643,19 @@ static dap_chain_atom_verify_res_t s_chain_callback_atom_verify(dap_chain_t * a_
dap_chain_atom_verify_res_t res = ATOM_ACCEPT;
if(sizeof (l_event->header) >= a_atom_size){
log_it(L_WARNING,"Size of atom is %zd that is equel or less then header %zd",a_atom_size,sizeof (l_event->header));
log_it(L_WARNING,"Size of atom is %zd that is equal or less then header %zd",a_atom_size,sizeof (l_event->header));
return ATOM_REJECT;
}
// Hard accept list
if (l_dag->hal) {
dap_chain_hash_fast_t l_event_hash;
dap_chain_cs_dag_event_calc_hash(l_event,a_atom_size, &l_event_hash);
dap_chain_cs_dag_hal_item_t *l_hash_found = NULL;
HASH_FIND(hh, l_dag->hal, &l_event_hash, sizeof(l_event_hash), l_hash_found);
if (l_hash_found) {
return ATOM_ACCEPT;
}
}
// genesis or seed mode
if (l_event->header.hash_count == 0){
if(s_seed_mode && !PVT(l_dag)->events){
......
......@@ -22,6 +22,7 @@
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "uthash.h"
#include "dap_chain.h"
#include "dap_chain_cs_dag_event.h"
......@@ -36,6 +37,10 @@ typedef dap_chain_cs_dag_event_t * (*dap_chain_cs_dag_callback_event_create_t)(d
dap_chain_datum_t *,
dap_chain_hash_fast_t *,
size_t, size_t*);
typedef struct dap_chain_cs_dag_hal_item {
dap_chain_hash_fast_t hash;
UT_hash_handle hh;
} dap_chain_cs_dag_hal_item_t;
typedef struct dap_chain_cs_dag
{
......@@ -45,6 +50,7 @@ typedef struct dap_chain_cs_dag
bool is_add_directy;
bool is_static_genesis_event;
dap_chain_hash_fast_t static_genesis_event_hash;
dap_chain_cs_dag_hal_item_t *hal;
uint16_t datum_add_hashes_count;
char * gdb_group_events_round_new;
......