diff --git a/CMakeLists.txt b/CMakeLists.txt index da1232731cc5f4a5f0099e55dcc2ab8ccf33f1a0..8226ff439a5ae1b6431d162d157de6ffdd48b955 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ project(cellframe-sdk C) cmake_minimum_required(VERSION 2.8) set(CMAKE_C_STANDARD 11) -set(CELLFRAME_SDK_NATIVE_VERSION "2.8-8") +set(CELLFRAME_SDK_NATIVE_VERSION "2.8-9") add_definitions ("-DCELLFRAME_SDK_VERSION=\"${CELLFRAME_SDK_NATIVE_VERSION}\"") set(DAPSDK_MODULES "") diff --git a/dap-sdk/crypto/src/dap_enc_dilithium.c b/dap-sdk/crypto/src/dap_enc_dilithium.c index c548ae2364a9989d21dde74105d19c4f89969909..dc19676a6f02b475f5448038ed7e5ec98db15e8d 100755 --- a/dap-sdk/crypto/src/dap_enc_dilithium.c +++ b/dap-sdk/crypto/src/dap_enc_dilithium.c @@ -195,15 +195,16 @@ dilithium_signature_t* dap_enc_dilithium_read_signature(uint8_t *a_buf, size_t a l_shift_mem + l_sign->sig_len ); return NULL; } - l_shift_mem+= l_sign->sig_len; l_sign->sig_data = DAP_NEW_SIZE(unsigned char, l_sign->sig_len); - if (!l_sign->sig_data) + if (!l_sign->sig_data){ log_it(L_ERROR,"::read_signature() Can't allocate sig_data %"DAP_UINT64_FORMAT_u" size", l_sign->sig_len); - - memcpy(l_sign->sig_data, a_buf + l_shift_mem, l_sign->sig_len); - l_shift_mem += l_sign->sig_len; - return l_sign; + DAP_DELETE(l_sign); + return NULL; + }else{ + memcpy(l_sign->sig_data, a_buf + l_shift_mem, l_sign->sig_len); + return l_sign; + } } /** @@ -243,13 +244,12 @@ dilithium_signature_t* dap_enc_dilithium_read_signature_old(uint8_t *a_buf, size return NULL; } - l_shift_mem += sizeof(unsigned long long); l_sign->sig_data = DAP_NEW_SIZE(unsigned char, l_sign->sig_len); if (!l_sign->sig_data) log_it(L_ERROR,"::read_signature_old() Can't allocate sig_data %"DAP_UINT64_FORMAT_u" size", l_sign->sig_len); memcpy(l_sign->sig_data, a_buf + l_shift_mem, l_sign->sig_len); - l_shift_mem += l_sign->sig_len; + return l_sign; } @@ -296,7 +296,6 @@ dilithium_signature_t* dap_enc_dilithium_read_signature_old2(uint8_t *a_buf, siz if (!l_sign->sig_data) log_it(L_ERROR,"::read_signature_old() Can't allocate sig_data %"DAP_UINT64_FORMAT_u" size", l_sign->sig_len); memcpy(l_sign->sig_data, a_buf + l_shift_mem, l_sign->sig_len); - l_shift_mem += l_sign->sig_len; return l_sign; } diff --git a/dap-sdk/net/client/dap_client_http.c b/dap-sdk/net/client/dap_client_http.c index 1b800771f7836e267ce910c5ca739b8e1f60b9c3..b989d58697cc1d1b2161fb5df54466995412568c 100644 --- a/dap-sdk/net/client/dap_client_http.c +++ b/dap-sdk/net/client/dap_client_http.c @@ -126,22 +126,27 @@ static bool s_timer_timeout_check(void * a_arg) if(dap_events_socket_check_unsafe(l_worker, l_es) ){ if (!dap_uint128_check_equal(l_es->uuid,l_es_handler->uuid)){ - // Timer esocket wrong argument, ignore this timeout... + log_it(L_DEBUG,"Timer esocket wrong argument, ignore this timeout..."); DAP_DEL_Z(l_es_handler) return false; } - dap_client_http_pvt_t * l_http_pvt = PVT(l_es); - log_it(L_WARNING,"Connection timeout for request http://%s:%u/%s, possible network problems or host is down", - l_http_pvt->uplink_addr, l_http_pvt->uplink_port, l_http_pvt->path); - if(l_http_pvt->error_callback) { - l_http_pvt->error_callback(ETIMEDOUT, l_http_pvt->obj); - l_http_pvt->were_callbacks_called = true; - } - l_http_pvt->is_closed_by_timeout = true; - log_it(L_INFO, "Close %s sock %u type %d by timeout", - l_es->remote_addr_str ? l_es->remote_addr_str : "", l_es->socket, l_es->type); - dap_events_socket_remove_and_delete_unsafe(l_es, true); - } + if (l_es->flags & DAP_SOCK_CONNECTING ){ + dap_client_http_pvt_t * l_http_pvt = PVT(l_es); + log_it(L_WARNING,"Connecting timeout for request http://%s:%u/%s, possible network problems or host is down", + l_http_pvt->uplink_addr, l_http_pvt->uplink_port, l_http_pvt->path); + if(l_http_pvt->error_callback) { + l_http_pvt->error_callback(ETIMEDOUT, l_http_pvt->obj); + l_http_pvt->were_callbacks_called = true; + } + l_http_pvt->is_closed_by_timeout = true; + log_it(L_INFO, "Close %s sock %u type %d by timeout", + l_es->remote_addr_str ? l_es->remote_addr_str : "", l_es->socket, l_es->type); + dap_events_socket_remove_and_delete_unsafe(l_es, true); + }else + log_it(L_DEBUG,"Socket %d is connected, close check timer", l_es->socket); + }else + log_it(L_DEBUG,"Esocket %p is finished, close check timer", l_es); + DAP_DEL_Z(l_es_handler) return false; } diff --git a/dap-sdk/net/client/dap_client_pvt.c b/dap-sdk/net/client/dap_client_pvt.c index 32a98e2596e34b9bdfee5fc7a8f3bf0a874222bb..321a191079cc7d84123bdadc38d7a905f14ba899 100644 --- a/dap-sdk/net/client/dap_client_pvt.c +++ b/dap-sdk/net/client/dap_client_pvt.c @@ -185,6 +185,46 @@ static void s_stream_connected(dap_client_pvt_t * a_client_pvt) s_stage_status_after(a_client_pvt); } +static bool s_timer_timeout_check(void * a_arg) +{ + dap_events_socket_handler_t *l_es_handler = (dap_events_socket_handler_t*) a_arg; + assert(l_es_handler); + dap_events_socket_t * l_es = l_es_handler->esocket; + assert(l_es); + dap_events_t * l_events = dap_events_get_default(); + assert(l_events); + + dap_worker_t * l_worker =(dap_worker_t*) pthread_getspecific(l_events->pth_key_worker); // We're in own esocket context + assert(l_worker); + + if(dap_events_socket_check_unsafe(l_worker, l_es) ){ + if (!dap_uint128_check_equal(l_es->uuid,l_es_handler->uuid)){ + log_it(L_DEBUG,"Timer esocket wrong argument, ignore this timeout..."); + DAP_DEL_Z(l_es_handler) + return false; + } + if (l_es->flags & DAP_SOCK_CONNECTING ){ + dap_client_pvt_t * l_client_pvt =(dap_client_pvt_t *) l_es->_inheritor;//(l_client) ? DAP_CLIENT_PVT(l_client) : NULL; + + log_it(L_WARNING,"Connecting timeout for stream uplink request http://%s:%u/, possible network problems or host is down", + l_client_pvt->uplink_addr, l_client_pvt->uplink_port); + l_client_pvt->is_closed_by_timeout = true; + if(l_es->callbacks.error_callback) { + l_es->callbacks.error_callback(l_es,ETIMEDOUT); + } + log_it(L_INFO, "Close %s sock %u type %d by timeout", + l_es->remote_addr_str ? l_es->remote_addr_str : "", l_es->socket, l_es->type); + dap_events_socket_remove_and_delete_unsafe(l_es, true); + }else + log_it(L_DEBUG,"Socket %d is connected, close check timer", l_es->socket); + }else + log_it(L_DEBUG,"Esocket %p is finished, close check timer", l_es); + + DAP_DEL_Z(l_es_handler) + return false; +} + + /** * @brief s_client_internal_stage_status_proc * @param a_client @@ -412,6 +452,10 @@ static bool s_stage_status_after(dap_client_pvt_t * a_client_pvt) log_it(L_INFO,"Connecting stream to remote %s:%u",a_client_pvt->uplink_addr, a_client_pvt->uplink_port); // add to dap_worker dap_worker_add_events_socket( a_client_pvt->stream_es, l_worker); + dap_events_socket_handler_t * l_stream_es_handler = DAP_NEW_Z(dap_events_socket_handler_t); + l_stream_es_handler->esocket = a_client_pvt->stream_es; + l_stream_es_handler->uuid = a_client_pvt->stream_es->uuid; + dap_timerfd_start_on_worker(a_client_pvt->worker, 10000, s_timer_timeout_check,l_stream_es_handler); } } } diff --git a/dap-sdk/net/client/include/dap_client_pvt.h b/dap-sdk/net/client/include/dap_client_pvt.h index e4e390e4b27b9125d089068ed6e3a543c5ad86c2..cb58fa43c4591d1acc08760763b2a8876945627e 100644 --- a/dap-sdk/net/client/include/dap_client_pvt.h +++ b/dap-sdk/net/client/include/dap_client_pvt.h @@ -88,6 +88,7 @@ typedef struct dap_client_internal bool is_encrypted; bool is_encrypted_headers; bool is_close_session;// the last request in session, in the header will be added "SessionCloseAfterRequest: true" + bool is_closed_by_timeout; dap_client_callback_data_size_t request_response_callback; dap_client_callback_int_t request_error_callback;