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 (26)
Showing
with 128 additions and 85 deletions
......@@ -136,9 +136,9 @@ WEPOLL_EXPORT int epoll_wait(HANDLE ephnd,
#pragma warning(push, 1)
#endif
#include <WS2tcpip.h>
#include <WinSock2.h>
#include <Windows.h>
#include <ws2tcpip.h>
#include <winsock2.h>
#include <windows.h>
#ifndef __GNUC__
#pragma warning(pop)
......
......@@ -30,7 +30,7 @@
#ifdef _WIN32
#include <Windows.h>
#include <windows.h>
/* On Win32, the canonical directory separator is the backslash, and
* the search path separator is the semicolon. Note that also the
......
......@@ -332,16 +332,21 @@ void _log_it(const char *a_log_tag, enum dap_log_level a_ll, const char *a_fmt,
if ( a_ll < s_dap_log_level || a_ll >= 16 || !a_log_tag )
return;
log_str_t *l_log_string = DAP_NEW_Z(log_str_t);
strncpy(l_log_string->str, s_ansi_seq_color[a_ll],sizeof (l_log_string->str)-1);
size_t offset2 = sizeof(l_log_string->str) - 2;
strncpy(l_log_string->str, s_ansi_seq_color[a_ll], offset2);
l_log_string->offset = s_ansi_seq_color_len[a_ll];
s_update_log_time(l_log_string->str + l_log_string->offset);
size_t offset = strlen(l_log_string->str);
offset += dap_snprintf(l_log_string->str + offset, sizeof (l_log_string->str) -offset, "%s[%s%s", s_log_level_tag[a_ll], a_log_tag, "] ");
offset += dap_snprintf(l_log_string->str + offset, offset2, "%s[%s%s", s_log_level_tag[a_ll], a_log_tag, "] ");
offset2 -= offset;
va_list va;
va_start( va, a_fmt );
offset += dap_vsnprintf(l_log_string->str + offset,sizeof (l_log_string->str) -offset, a_fmt, va);
size_t l_offset = dap_vsnprintf(l_log_string->str + offset, offset2, a_fmt, va);
offset = (l_offset < offset2) ? offset + l_offset : offset;
offset2 = (l_offset < offset2) ? offset2 - offset : 0;
va_end( va );
memcpy(&l_log_string->str[offset], "\n", 1);
char *dummy = (offset2 == 0) ? memcpy(&l_log_string->str[sizeof(l_log_string->str) - 6], "...\n\0", 5)
: memcpy(&l_log_string->str[offset], "\n", 1);
pthread_mutex_lock(&s_log_mutex);
DL_APPEND(s_log_buffer, l_log_string);
++s_log_count;
......
......@@ -805,7 +805,7 @@ main(int argc, char** argv) {
#endif
#ifdef _WIN32
#include <Windows.h>
#include <windows.h>
static void
test_initialize(void) {
......
......@@ -13,7 +13,7 @@
#endif
#ifdef _WIN32
# include <Windows.h>
# include <windows.h>
# include <process.h>
static unsigned __stdcall
......
......@@ -2,7 +2,7 @@
#include <timer.h>
#if defined(_WIN32)
# include <Windows.h>
# include <windows.h>
#elif defined(__APPLE__)
# include <mach/mach_time.h>
static mach_timebase_info_data_t _time_info;
......
......@@ -305,7 +305,7 @@ dap_list_t *dap_cert_get_all_mem()
dap_list_t *l_ret = NULL;
dap_cert_item_t *l_cert_item = NULL, *l_cert_tmp;
HASH_ITER(hh, s_certs, l_cert_item, l_cert_tmp) {
l_ret = dap_list_append(l_ret, l_cert_item);
l_ret = dap_list_append(l_ret, l_cert_item->cert);
}
return l_ret;
}
......
......@@ -18,7 +18,7 @@
#include <string.h>
#include <assert.h>
#if defined (__WIN32)
#include <Windows.h>
#include <windows.h>
#include <bcrypt.h>
#elif defined (__APPLE__)
#include "macos_specific_endian.h"
......
......@@ -324,7 +324,7 @@ void dap_events_socket_delete( dap_events_socket_t *a_es, bool preserve_inherito
#endif
}
pthread_mutex_destroy(&a_es->write_hold);
free( a_es );
DAP_DELETE( a_es );
}
/**
......
......@@ -412,10 +412,17 @@ static void s_headers_read( dap_http_client_t *a_http_client, void *a_arg )
DAP_HTTP_SIMPLE(a_http_client)->reply_byte = DAP_NEW_Z_SIZE(uint8_t, DAP_HTTP_SIMPLE(a_http_client)->reply_size_max );
if( a_http_client->in_content_length ) {
if( a_http_client->in_content_length < DAP_HTTP_SIMPLE_REQUEST_MAX )
DAP_HTTP_SIMPLE(a_http_client)->request = calloc( 1, a_http_client->in_content_length + 1 );
// dbg if( a_http_client->in_content_length < 3){
if( a_http_client->in_content_length > 0){
DAP_HTTP_SIMPLE(a_http_client)->request_size_max = a_http_client->in_content_length + 1;
DAP_HTTP_SIMPLE(a_http_client)->request = DAP_NEW_Z_SIZE(void, DAP_HTTP_SIMPLE(a_http_client)->request_size_max);
if(!DAP_HTTP_SIMPLE(a_http_client)->request){
DAP_HTTP_SIMPLE(a_http_client)->request_size_max = 0;
log_it(L_ERROR, "Too big content-length %u in request", a_http_client->in_content_length);
}
}
else
log_it( L_ERROR, "Too big content-length %u in request", a_http_client->in_content_length );
log_it(L_ERROR, "Not defined content-length %u in request", a_http_client->in_content_length);
} else {
log_it( L_DEBUG, "No data section, execution proc callback" );
queue_http_request_put( DAP_HTTP_SIMPLE(a_http_client) );
......@@ -435,8 +442,17 @@ void s_data_read( dap_http_client_t *a_http_client, void * a_arg )
a_http_client->client->buf_in_size : ( a_http_client->in_content_length - l_http_simple->request_size );
if( bytes_to_read ) {
memcpy( l_http_simple->request_byte + l_http_simple->request_size, a_http_client->client->buf_in, bytes_to_read );
l_http_simple->request_size += bytes_to_read;
// Oops! The client sent more data than write in the CONTENT_LENGTH header
if(l_http_simple->request_size + bytes_to_read > l_http_simple->request_size_max){
log_it(L_WARNING, "Oops! Client sent more data length=%u than in content-length=%u in request", l_http_simple->request_size + bytes_to_read, a_http_client->in_content_length);
l_http_simple->request_size_max = l_http_simple->request_size + bytes_to_read + 1;
// increase input buffer
l_http_simple->request = DAP_REALLOC(l_http_simple->request, l_http_simple->request_size_max);
}
if(l_http_simple->request){// request_byte=request
memcpy( l_http_simple->request_byte + l_http_simple->request_size, a_http_client->client->buf_in, bytes_to_read );
l_http_simple->request_size += bytes_to_read;
}
}
if( l_http_simple->request_size >= a_http_client->in_content_length ) {
......
......@@ -28,7 +28,7 @@ See more details here <http://www.gnu.org/licenses/>.
#include "dap_http.h"
//#define DAP_HTTP_SIMPLE_REQUEST_MAX 100000
// number of simultaneous http requests
#define DAP_HTTP_SIMPLE_REQUEST_MAX 65536
struct dap_http_simple;
......@@ -51,6 +51,7 @@ typedef struct dap_http_simple {
};
size_t request_size;
size_t request_size_max;
size_t reply_size;
size_t reply_size_max;
size_t reply_sent;
......
......@@ -117,6 +117,8 @@ dap_stream_ch_t* dap_stream_ch_new(dap_stream_t* a_stream, uint8_t id)
bool dap_stream_ch_valid(dap_stream_ch_t *a_ch)
{
struct dap_stream_ch_table_t *l_ret;
if(!a_ch)
return false;
pthread_mutex_lock(&s_ch_table_lock);
HASH_FIND_PTR(s_ch_table, a_ch, l_ret);
pthread_mutex_unlock(&s_ch_table_lock);
......
......@@ -201,7 +201,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch, void* a_arg)
strcpy(l_err_str, "ERROR_NET_INVALID_ID");
l_error = true;
}
if (!l_error && !a_ch->stream->session->acl[l_acl_idx]) { // Access denied
if (!l_error && a_ch->stream->session->acl && !a_ch->stream->session->acl[l_acl_idx]) {
log_it(L_WARNING, "Unauthorized request attempt to network %s",
dap_chain_net_by_id(l_ch_chain_net_pkt->hdr.net_id)->pub.name);
strcpy(l_err_str, "ERROR_NET_NOT_AUTHORIZED");
......
......@@ -138,7 +138,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch, void* a_arg)
strcpy(l_err_str, "ERROR_NET_INVALID_ID");
l_error = true;
}
if (!l_error && !a_ch->stream->session->acl[l_acl_idx]) { // Access denied
if (!l_error && a_ch->stream->session->acl && !a_ch->stream->session->acl[l_acl_idx]) {
log_it(L_WARNING, "Unauthorized request attempt to network %s",
dap_chain_net_by_id(l_chain_pkt->hdr.net_id)->pub.name);
strcpy(l_err_str, "ERROR_NET_NOT_AUTHORIZED");
......@@ -357,6 +357,7 @@ void s_stream_ch_packet_in(dap_stream_ch_t* a_ch, void* a_arg)
memcpy(l_atom_copy, l_chain_pkt->data, l_chain_pkt_data_size);
if(l_chain->callback_atom_add(l_chain, l_atom_copy) == 0 &&
dap_chain_has_file_store(l_chain)) {
/* TODO: if atom was ignored (i.e. it's bad or already exists) memory is leaked */
// append to file
dap_chain_cell_id_t l_cell_id;
l_cell_id.uint64 = l_chain_pkt->hdr.cell_id.uint64;
......
......@@ -1255,7 +1255,7 @@ static void *s_list_thread_proc(void *arg)
while(l_dap_db_log_list->group_cur < l_dap_db_log_list->group_number) {
l_dap_db_log_list->group_cur++;
// check for empty group
if(l_dap_db_log_list->group_number_items[l_dap_db_log_list->group_cur] < 1) {
if( !(l_dap_db_log_list->group_number) || (l_dap_db_log_list->group_number_items[l_dap_db_log_list->group_cur] < 1)) {
continue;
}
break;
......
......@@ -557,7 +557,7 @@ dap_chain_hash_fast_t* dap_chain_proc_tx_create_cond(dap_chain_net_t * a_net,
if(a_net->pub.default_chain)
l_chain = a_net->pub.default_chain;
else
dap_chain_net_get_chain_by_chain_type(a_net, CHAIN_TYPE_TX);
l_chain = dap_chain_net_get_chain_by_chain_type(a_net, CHAIN_TYPE_TX);
if(!l_chain)
return NULL;
......
......@@ -1096,6 +1096,35 @@ void dap_chain_net_load_all()
DAP_DELETE (l_net_dir_str);
}
void s_set_reply_text_node_status(char **a_str_reply, dap_chain_net_t * a_net){
const char* l_node_address_text_block = NULL;
dap_chain_node_addr_t l_cur_node_addr = { 0 };
l_cur_node_addr.uint64 = dap_chain_net_get_cur_addr(a_net) ? dap_chain_net_get_cur_addr(a_net)->uint64 : dap_db_get_cur_node_addr(a_net->pub.name);
if(!l_cur_node_addr.uint64)
l_node_address_text_block = dap_strdup_printf(", cur node address not defined");
else
l_node_address_text_block = dap_strdup_printf(", cur node address " NODE_ADDR_FP_STR,NODE_ADDR_FP_ARGS_S(l_cur_node_addr));
const char* l_sync_current_link_text_block = NULL;
if(PVT(a_net)->state == NET_STATE_LINKS_PREPARE ||
PVT(a_net)->state == NET_STATE_LINKS_CONNECTING ||
PVT(a_net)->state == NET_STATE_SYNC_GDB ||
PVT(a_net)->state == NET_STATE_SYNC_CHAINS)
l_sync_current_link_text_block = dap_strdup_printf(", processing link %u from %u",
PVT(a_net)->links_count, PVT(a_net)->links_addrs_count);
dap_chain_node_cli_set_reply_text(a_str_reply,
"Network \"%s\" has state %s (target state %s)%s%s",
a_net->pub.name, c_net_states[PVT(a_net)->state],
c_net_states[PVT(a_net)->state_target],
(l_sync_current_link_text_block)? l_sync_current_link_text_block: "",
l_node_address_text_block
);
DAP_DELETE(l_sync_current_link_text_block);
DAP_DELETE(l_node_address_text_block);
}
/**
* @brief s_cli_net
* @param argc
......@@ -1237,26 +1266,7 @@ static int s_cli_net( int argc, char **argv, void *arg_func, char **a_str_reply)
} else if ( l_get_str){
if ( strcmp(l_get_str,"status") == 0 ) {
// get current node address
dap_chain_node_addr_t l_cur_node_addr = { 0 };
l_cur_node_addr.uint64 = dap_chain_net_get_cur_addr(l_net) ? dap_chain_net_get_cur_addr(l_net)->uint64 : dap_db_get_cur_node_addr(l_net->pub.name);
if(!l_cur_node_addr.uint64) {
dap_chain_node_cli_set_reply_text(a_str_reply,
"Network \"%s\" has state %s (target state %s), active links %u from %u, cur node address not defined",
l_net->pub.name, c_net_states[PVT(l_net)->state],
c_net_states[PVT(l_net)->state_target], PVT(l_net)->links_count,
PVT(l_net)->links_addrs_count
);
}
else {
dap_chain_node_cli_set_reply_text(a_str_reply,
"Network \"%s\" has state %s (target state %s), active links %u from %u, cur node address " NODE_ADDR_FP_STR,
l_net->pub.name, c_net_states[PVT(l_net)->state],
c_net_states[PVT(l_net)->state_target], PVT(l_net)->links_count,
PVT(l_net)->links_addrs_count,
NODE_ADDR_FP_ARGS_S(l_cur_node_addr)
);
}
s_set_reply_text_node_status(a_str_reply, l_net);
ret = 0;
}
} else if ( l_links_str ){
......@@ -2542,7 +2552,7 @@ static bool s_net_check_acl(dap_chain_net_t *a_net, dap_chain_hash_fast_t *a_pke
dap_config_t *l_cfg = dap_config_open(l_cfg_path);
const char *l_auth_type = dap_config_get_item_str(l_cfg, "auth", "type");
bool l_authorized = true;
if (!strcmp(l_auth_type, "ca")) {
if (l_auth_type && !strcmp(l_auth_type, "ca")) {
if (dap_hash_fast_is_blank(a_pkey_hash)) {
return false;
}
......@@ -2572,7 +2582,7 @@ static bool s_net_check_acl(dap_chain_net_t *a_net, dap_chain_hash_fast_t *a_pke
}
if (!l_authorized) {
const char *l_acl_chains = dap_config_get_item_str(l_cfg, "auth", "acl_accept_ca_chains");
if (!strcmp(l_acl_chains, "all")) {
if (l_acl_chains && !strcmp(l_acl_chains, "all")) {
dap_list_t *l_certs = dap_cert_get_all_mem();
for (dap_list_t *l_tmp = l_certs; l_tmp; l_tmp = dap_list_next(l_tmp)) {
dap_cert_t *l_cert = (dap_cert_t *)l_tmp->data;
......
......@@ -55,10 +55,14 @@ static int64_t bugreport_write_to_file(byte_t *a_request_byte, size_t a_request_
const time_t l_timer = time(NULL);
struct tm l_tm;
localtime_r(&l_timer, &l_tm);
// create unique number for bugreport
randombytes(&l_report_number, sizeof(int64_t));
if(l_report_number<0)
if(l_report_number < 0)
l_report_number = -l_report_number;
// create unique number for bugreport
//l_report_number 5 characters long
l_report_number %= 100000ll;
/*
// l_report_number 20 characters long
l_report_number -= l_report_number%1000000000000ll;
l_report_number+=(int64_t)(l_tm.tm_year - 100)*10000000000;
l_report_number+=(int64_t)(l_tm.tm_mon)*100000000;
......@@ -66,7 +70,8 @@ static int64_t bugreport_write_to_file(byte_t *a_request_byte, size_t a_request_
l_report_number+=(int64_t)(l_tm.tm_hour)*10000;
l_report_number+=(int64_t)(l_tm.tm_min)*100;
l_report_number+=(int64_t)(l_tm.tm_sec);
char *l_filename_str = dap_strdup_printf("%s/%02d-%02d-%02d_%02d:%02d:%02d_%08lld.brt", l_dir_str,
*/
char *l_filename_str = dap_strdup_printf("%s/%02d-%02d-%02d_%02d:%02d:%02d_%05lld.brt", l_dir_str,
l_tm.tm_year - 100, l_tm.tm_mon, l_tm.tm_mday,
l_tm.tm_hour, l_tm.tm_min, l_tm.tm_sec,
l_report_number);
......@@ -112,7 +117,10 @@ static void bugreport_http_proc(struct dap_http_simple *a_http_simple, void * a_
int64_t l_bugreport_number = bugreport_write_to_file(a_http_simple->request_byte, a_http_simple->request_size);
if(l_bugreport_number >= 0) {
a_http_simple->reply = dap_strdup_printf("Bug Report #%020lld saved successfully)", l_bugreport_number);
//l_report_number 5 characters long
a_http_simple->reply = dap_strdup_printf("Bug Report #%05lld saved successfully)", l_bugreport_number);
//l_report_number 20 characters long
//a_http_simple->reply = dap_strdup_printf("Bug Report #%020lld saved successfully)", l_bugreport_number);
}
else {
a_http_simple->reply = dap_strdup_printf("Bug Report not saved( code=%lld", l_bugreport_number);
......
......@@ -1968,6 +1968,35 @@ int com_token_decl_sign(int argc, char ** argv, void *arg_func, char ** a_str_re
}
}
void s_com_mempool_list_print_for_chain(const dap_chain_net_t * a_net, const dap_chain_t * a_chain, dap_string_t * a_str_tmp){
char * l_gdb_group_mempool = dap_chain_net_get_gdb_group_mempool(a_chain);
if(!l_gdb_group_mempool){
dap_string_append_printf(a_str_tmp, "%s.%s: chain not found\n", a_net->pub.name, a_chain->name);
}else{
size_t l_objs_size = 0;
dap_global_db_obj_t * l_objs = dap_chain_global_db_gr_load(l_gdb_group_mempool, &l_objs_size);
if(l_objs_size > 0)
dap_string_append_printf(a_str_tmp, "%s.%s: Found %u records :\n", a_net->pub.name, a_chain->name,
l_objs_size);
else
dap_string_append_printf(a_str_tmp, "%s.%s: Not found records\n", a_net->pub.name, a_chain->name);
for(size_t i = 0; i < l_objs_size; i++) {
dap_chain_datum_t * l_datum = (dap_chain_datum_t*) l_objs[i].value;
char buf[50];
time_t l_ts_create = (time_t) l_datum->header.ts_create;
dap_string_append_printf(a_str_tmp, "%s: type_id=%s data_size=%u ts_create=%s", // \n included in timestamp
l_objs[i].key, c_datum_type_str[l_datum->header.type_id],
l_datum->header.data_size, ctime_r(&l_ts_create, buf));
dap_chain_net_dump_datum(a_str_tmp, l_datum);
}
dap_chain_global_db_objs_delete(l_objs, l_objs_size);
}
DAP_DELETE(l_gdb_group_mempool);
}
/**
* @brief com_token_decl_list
* @param argc
......@@ -1993,43 +2022,14 @@ int com_mempool_list(int argc, char ** argv, void *arg_func, char ** a_str_reply
}
if(l_net) {
char * l_gdb_group_mempool = NULL, *l_gdb_group_mempool_tmp;
if(l_chain) {
l_gdb_group_mempool = dap_chain_net_get_gdb_group_mempool(l_chain);
l_gdb_group_mempool_tmp = l_gdb_group_mempool;
}
dap_string_t * l_str_tmp = dap_string_new(NULL);
DL_FOREACH(l_net->pub.chains, l_chain) {
if(!l_gdb_group_mempool) {
l_gdb_group_mempool_tmp = dap_chain_net_get_gdb_group_mempool(l_chain);
}
size_t l_objs_size = 0;
dap_global_db_obj_t * l_objs = dap_chain_global_db_gr_load(l_gdb_group_mempool_tmp, &l_objs_size);
if(l_objs_size > 0)
dap_string_append_printf(l_str_tmp, "%s.%s: Found %u records :\n", l_net->pub.name, l_chain->name,
l_objs_size);
else
dap_string_append_printf(l_str_tmp, "%s.%s: Not found records\n", l_net->pub.name, l_chain->name);
for(size_t i = 0; i < l_objs_size; i++) {
dap_chain_datum_t * l_datum = (dap_chain_datum_t*) l_objs[i].value;
char buf[50];
time_t l_ts_create = (time_t) l_datum->header.ts_create;
dap_string_append_printf(l_str_tmp, "%s: type_id=%s data_size=%u ts_create=%s", // \n included in timestamp
l_objs[i].key, c_datum_type_str[l_datum->header.type_id],
l_datum->header.data_size, ctime_r(&l_ts_create, buf));
if(l_chain)
s_com_mempool_list_print_for_chain(l_net, l_chain, l_str_tmp);
else
DL_FOREACH(l_net->pub.chains, l_chain)
s_com_mempool_list_print_for_chain(l_net, l_chain, l_str_tmp);
dap_chain_net_dump_datum(l_str_tmp, l_datum);
}
// Clean up
dap_chain_global_db_objs_delete(l_objs, l_objs_size);
if (l_gdb_group_mempool_tmp)
DAP_DELETE(l_gdb_group_mempool_tmp);
// only one time if group defined
if(l_gdb_group_mempool) {
break;
}
}
dap_chain_node_cli_set_reply_text(a_str_reply, l_str_tmp->str);
dap_string_free(l_str_tmp, false);
......
......@@ -477,7 +477,7 @@ dap_chain_node_client_t* dap_chain_client_connect(dap_chain_node_info_t *a_node_
l_node_client->remote_node_addr.uint64 = a_node_info->hdr.address.uint64;
dap_client_set_active_channels(l_node_client->client, a_active_channels);
// dap_client_set_auth_cert(l_node_client->client, dap_cert_find_by_name("auth")); // TODO provide the certificate choice
//dap_client_set_auth_cert(l_node_client->client, dap_cert_find_by_name("auth")); // TODO provide the certificate choice
int hostlen = 128;
char host[hostlen];
......