From dff64e8f10ed6a48b8d8433173063ae89aeb15f3 Mon Sep 17 00:00:00 2001 From: chen-chao666 <1790599142@qq.com> Date: Thu, 20 Mar 2025 19:33:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Revert=20"cm=5Fdestroy=5Fthread=5Fpool=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=89=B9=E9=87=8F=E6=A0=87=E8=AE=B0?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B=E5=85=B3=E9=97=AD=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E9=94=80=E6=AF=81=E7=BA=BF=E7=A8=8B=E6=B1=A0=E7=9A=84=E6=95=88?= =?UTF-8?q?=E7=8E=87"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 44addf6bafc26515e41ca6267c88ae6dbe6c70ea. --- src/cm_concurrency/cm_thread_pool.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/cm_concurrency/cm_thread_pool.c b/src/cm_concurrency/cm_thread_pool.c index 2d5736a..7235671 100644 --- a/src/cm_concurrency/cm_thread_pool.c +++ b/src/cm_concurrency/cm_thread_pool.c @@ -135,7 +135,7 @@ status_t cm_create_thread_pool(cm_thread_pool_t *pool, uint32 thread_stack_size, void cm_destroy_thread_pool(cm_thread_pool_t *pool) { uint32 i; - thread_t *thread = NULL; + pooling_thread_t *obj = NULL; if (pool->starts == 0) { CM_FREE_PROT_PTR(pool->threads); @@ -144,20 +144,8 @@ void cm_destroy_thread_pool(cm_thread_pool_t *pool) cm_thread_lock(&pool->lock); for (i = 0; i < pool->starts; ++i) { - thread = &pool->threads[i].thread; - thread->closed = CM_TRUE; - } - for (i = 0; i < pool->starts; ++i) { - thread = &pool->threads[i].thread; -#ifdef WIN32 - WaitForSingleObject(thread->handle, INFINITE); -#else - void *ret = NULL; - if (thread->id != 0) { - (void)pthread_join(thread->id, &ret); - thread->id = 0; - } -#endif + obj = &pool->threads[i]; + cm_close_thread(&obj->thread); } cm_thread_unlock(&pool->lock); -- Gitee From 3215ac3f112bb74591a3ea865e9c060e3e42351f Mon Sep 17 00:00:00 2001 From: chen-chao666 <1790599142@qq.com> Date: Thu, 20 Mar 2025 19:34:28 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"=E4=BF=AE=E5=A4=8D=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E5=88=9B=E5=BB=BA=E5=A4=B1=E8=B4=A5=E4=BD=86=E6=98=AF?= =?UTF-8?q?thread->id=E4=B8=8D=E4=B8=BA0=EF=BC=8C=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=E7=BA=BF=E7=A8=8B=E9=94=80=E6=AF=81=E8=B0=83=E7=94=A8?= =?UTF-8?q?pthread=5Fjoin=E5=85=A5=E5=8F=82=E4=B8=BA=E6=97=A0=E6=95=88id?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84core=E9=97=AE=E9=A2=98"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 211c438ccd03ee1fb8e4e4bd5d1ca598b97e35b2. --- src/cm_concurrency/cm_thread.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cm_concurrency/cm_thread.c b/src/cm_concurrency/cm_thread.c index 108e105..7bbcf76 100644 --- a/src/cm_concurrency/cm_thread.c +++ b/src/cm_concurrency/cm_thread.c @@ -254,7 +254,6 @@ status_t cm_create_thread(thread_entry_t entry, uint32 stack_size, void *argumen errnum = pthread_create(&thread->id, &attr, cm_thread_run, (void *)thread); if (errnum != 0) { - thread->id = 0; (void)pthread_attr_destroy(&attr); CM_THROW_ERROR_EX(ERR_CREATE_THREAD, "thread create failed, errnum=%d", errnum); return CM_ERROR; -- Gitee From 22be99573af29e44191e4d4d3375d5e3d58bc010 Mon Sep 17 00:00:00 2001 From: chen-chao666 <1790599142@qq.com> Date: Thu, 20 Mar 2025 19:40:12 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Revert=20"=E4=BF=AE=E5=A4=8D=E5=86=85?= =?UTF-8?q?=E5=AD=98=E7=BB=9F=E8=AE=A1=EF=BC=8C=E5=A2=9E=E5=8A=A0crl?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E4=B8=8E=E5=AE=B9=E9=94=99=E5=A4=84=E7=90=86?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c76a3826b2b4d93620ecb8c395fbc0a62142b71c. --- src/cm_mes/mes_func.c | 16 ------ src/cm_mes/mes_interface.h | 7 --- src/cm_mes/mes_mem_stat.c | 44 ++++++-------- src/cm_mes/mes_msg_pool.c | 17 ++---- src/cm_mes/mes_msg_pool.h | 1 - src/cm_mes/mes_queue.c | 6 -- src/cm_protocol/cs_ssl.c | 115 +------------------------------------ src/cm_protocol/cs_ssl.h | 1 - 8 files changed, 27 insertions(+), 180 deletions(-) diff --git a/src/cm_mes/mes_func.c b/src/cm_mes/mes_func.c index 5a2fe9b..ccca15c 100644 --- a/src/cm_mes/mes_func.c +++ b/src/cm_mes/mes_func.c @@ -1246,13 +1246,6 @@ static status_t mes_create_ssl_fd(ssl_config_t *ssl_cfg) return CM_ERROR; } - // check crl expire - if (mes_chk_ssl_crl_expire() != CM_SUCCESS) { - MEMS_RETURN_IFERR(memset_s(plain, sizeof(plain), 0, sizeof(plain))); - LOG_RUN_ERR("[mes] check ssl crl failed"); - return CM_ERROR; - } - // create connector fd MES_GLOBAL_INST_MSG.ssl_connector_fd = cs_ssl_create_connector_fd(ssl_cfg); MEMS_RETURN_IFERR(memset_s(plain, sizeof(plain), 0, sizeof(plain))); @@ -1377,7 +1370,6 @@ static void mes_heartbeat_entry(thread_t *thread) if (periods == SECONDS_PER_DAY && g_ssl_enable) { periods = 0; (void)mes_chk_ssl_cert_expire(); - (void)mes_chk_ssl_crl_expire(); } periods++; @@ -2115,14 +2107,6 @@ int mes_chk_ssl_cert_expire(void) return CM_SUCCESS; } -int mes_chk_ssl_crl_expire(void) -{ - param_value_t crl_notify; - CM_RETURN_IFERR(mes_md_get_param(CBB_PARAM_SSL_CERT_NOTIFY_TIME, &crl_notify)); - (void)ssl_crl_expire(MES_GLOBAL_INST_MSG.ssl_acceptor_fd, (int32)crl_notify.ssl_cert_notify_time); - return CM_SUCCESS; -} - void* mes_get_global_inst(void) { return &g_mes_ptr; diff --git a/src/cm_mes/mes_interface.h b/src/cm_mes/mes_interface.h index 04eaa4a..281712f 100644 --- a/src/cm_mes/mes_interface.h +++ b/src/cm_mes/mes_interface.h @@ -509,13 +509,6 @@ int mes_set_param(const char *param_name, const char *param_value); */ int mes_chk_ssl_cert_expire(void); -/* - * @brief check ssl crl expire - * - * @return 0 - success;otherwise: failed -*/ -int mes_chk_ssl_crl_expire(void); - /* * @brief get global variable address * @return global variable address diff --git a/src/cm_mes/mes_mem_stat.c b/src/cm_mes/mes_mem_stat.c index 70bf185..f6bc068 100644 --- a/src/cm_mes/mes_mem_stat.c +++ b/src/cm_mes/mes_mem_stat.c @@ -35,38 +35,36 @@ mes_mem_info_stat_t g_mes_mem_info_stat[MES_MEM_STAT_ROW_RESULT_COUNT] = { {"mes_receive_msgitem", 0, 0, 0}, }; -uint64 mes_calc_channel_and_pipe_msgbuf(mes_profile_t *profile) +uint64 mes_calc_channels_mem(uint32 channel_cnt) { uint64 total_mem = (uint64)(sizeof(mes_channel_t *) * MES_MAX_INSTANCES + - sizeof(mes_channel_t) * MES_MAX_INSTANCES * profile->channel_cnt); - total_mem += - (MES_MAX_INSTANCES - 1) * profile->channel_cnt * MES_PRIORITY_CEIL * MES_CHANNEL_MAX_SEND_BUFFER_SIZE(profile); - return total_mem; -} - -uint64 mes_calc_msgqueue_and_msgitem(mes_profile_t *profile, bool8 is_send) -{ - if (is_send && !mes_check_need_msg_send_pool(profile)) { - return 0; - } - // msg queue - uint64 total_mem = (uint64)(sizeof(mes_msgqueue_t *) * MES_MAX_INSTANCES + - sizeof(mes_msgqueue_t) * MES_MAX_INSTANCES * profile->channel_cnt); - // msg item + sizeof(mes_channel_t) * MES_MAX_INSTANCES * channel_cnt); + // send queue + total_mem += (uint64)(sizeof(mes_msgqueue_t *) * MES_MAX_INSTANCES + + sizeof(mes_msgqueue_t) * MES_MAX_INSTANCES * channel_cnt); + // receive queue + total_mem += (uint64)(sizeof(mes_msgqueue_t *) * MES_MAX_INSTANCES + + sizeof(mes_msgqueue_t) * MES_MAX_INSTANCES * channel_cnt); + // send msg item + total_mem += INIT_MSGITEM_BUFFER_SIZE * MAX_POOL_BUFFER_COUNT * (uint64)sizeof(mes_msgitem_t); + // receive msg item total_mem += INIT_MSGITEM_BUFFER_SIZE * MAX_POOL_BUFFER_COUNT * (uint64)sizeof(mes_msgitem_t); return total_mem; } uint64 mes_calc_room_pool() { + uint64 total_mem = (uint64)sizeof(mes_waiting_room_pool_t); // broadcast_msg - return (uint64)(sizeof(void *) * CM_MAX_MES_ROOMS * MES_MAX_INSTANCES); - + total_mem += sizeof(void *) * CM_MAX_MES_ROOMS * MES_MAX_INSTANCES; + return total_mem; } uint64 mes_calc_buffer_pool_mem(mes_profile_t *profile, bool8 is_send) { - if (is_send && !mes_check_need_msg_send_pool(profile)) { + if (is_send && profile->send_directly && + (profile->enable_compress_priority == 0 || profile->algorithm == COMPRESS_NONE || + profile->algorithm >= COMPRESS_CEIL)) { return 0; } return profile->msg_pool_attr.total_size; @@ -79,12 +77,8 @@ long long mes_calc_mem_usage(mes_profile_t *profile) total_mem += mes_calc_buffer_pool_mem(profile, CM_TRUE); // mes receive buffer pool total_mem += mes_calc_buffer_pool_mem(profile, CM_FALSE); - // mes channel_t and pipe_msgbuf - total_mem += mes_calc_channel_and_pipe_msgbuf(profile); - // mes send mq msgqueue and msgitem - total_mem += mes_calc_msgqueue_and_msgitem(profile, CM_TRUE); - // mes receive mq msgqueue and msgitem - total_mem += mes_calc_msgqueue_and_msgitem(profile, CM_FALSE); + // mes channels + total_mem += mes_calc_channels_mem(profile->channel_cnt); // mes room pool total_mem += mes_calc_room_pool(); return total_mem; diff --git a/src/cm_mes/mes_msg_pool.c b/src/cm_mes/mes_msg_pool.c index 6da9d8d..2c60adc 100644 --- a/src/cm_mes/mes_msg_pool.c +++ b/src/cm_mes/mes_msg_pool.c @@ -707,15 +707,6 @@ int mes_init_msg_inst_pool_set(bool8 is_send) return ret; } -bool8 mes_check_need_msg_send_pool(mes_profile_t *profile) -{ - if (profile->send_directly && (profile->enable_compress_priority == 0 || profile->algorithm == COMPRESS_NONE || - profile->algorithm >= COMPRESS_CEIL)) { - return CM_FALSE; - } - return CM_TRUE; -} - int mes_init_message_pool(bool8 is_send) { int ret = CM_SUCCESS; @@ -729,7 +720,9 @@ int mes_init_message_pool(bool8 is_send) return CM_SUCCESS; } - if (is_send && !mes_check_need_msg_send_pool(profile)) { + if (is_send && profile->send_directly && + (profile->enable_compress_priority == 0 || profile->algorithm == COMPRESS_NONE || + profile->algorithm >= COMPRESS_CEIL)) { // send_directly and disable compress cm_spin_unlock(&mq_ctx->msg_pool_init_lock); LOG_RUN_INF("[mes][msg pool] no need to init send message pool, cause send directly and compress disable."); @@ -1365,7 +1358,9 @@ int mes_get_message_pool_minimum_info(mes_profile_t *profile, uint8 is_send, static int mes_check_message_pool_size_inner(mes_profile_t *profile, bool8 is_send, uint64 all_metadata_size) { - if (is_send && !mes_check_need_msg_send_pool(profile)) { + if (is_send && profile->send_directly && + (profile->enable_compress_priority == 0 || profile->algorithm == COMPRESS_NONE || + profile->algorithm >= COMPRESS_CEIL)) { // send_directly and disable compress means no need send message pool return CM_SUCCESS; } diff --git a/src/cm_mes/mes_msg_pool.h b/src/cm_mes/mes_msg_pool.h index 2e52bb5..8ce447d 100644 --- a/src/cm_mes/mes_msg_pool.h +++ b/src/cm_mes/mes_msg_pool.h @@ -161,7 +161,6 @@ char *mes_alloc_buf_item_fc(uint32 len, bool32 is_send, uint32 dst_inst, mes_pri void mes_free_buf_item(char *buffer); uint32 mes_get_priority_max_msg_size(mes_priority_t priority); int mes_check_message_pool_size(mes_profile_t *profile); -bool8 mes_check_need_msg_send_pool(mes_profile_t *profile); #ifdef __cplusplus } diff --git a/src/cm_mes/mes_queue.c b/src/cm_mes/mes_queue.c index 0436811..f11aee1 100644 --- a/src/cm_mes/mes_queue.c +++ b/src/cm_mes/mes_queue.c @@ -1051,12 +1051,6 @@ status_t mes_alloc_channel_msg_queue(bool32 is_send) uint32 i, j; mes_profile_t *profile = mq_ctx->profile; - if (is_send && !mes_check_need_msg_send_pool(profile)) { - //send_directly and disable compress - LOG_RUN_INF("[mes][msg queue] no need to init send message queue, cause send directly and compress disable."); - return CM_SUCCESS; - } - // alloc msgqueue alloc_size = (uint32)sizeof(mes_msgqueue_t *) * MES_MAX_INSTANCES + (uint32)sizeof(mes_msgqueue_t) * MES_MAX_INSTANCES * profile->channel_cnt; diff --git a/src/cm_protocol/cs_ssl.c b/src/cm_protocol/cs_ssl.c index 7720b19..69dfef0 100644 --- a/src/cm_protocol/cs_ssl.c +++ b/src/cm_protocol/cs_ssl.c @@ -55,7 +55,6 @@ extern "C" { static spinlock_t g_ssl_init_lock = 0; static volatile bool32 g_ssl_initialized = 0; static spinlock_t g_get_pem_passwd_lock = 0; -static bool8 g_crl_expired = CM_FALSE; const char *g_ssl_default_cipher_list = "ECDHE-ECDSA-AES256-GCM-SHA384:" "ECDHE-ECDSA-AES128-GCM-SHA256:" @@ -862,13 +861,6 @@ static status_t cs_load_crl_file(SSL_CTX *ctx, const char *file) (void)BIO_free(in); return CM_ERROR; } - const ASN1_TIME *next_update = X509_CRL_get0_nextUpdate(crl); - if (X509_cmp_current_time(next_update) <= 0) { - LOG_RUN_WAR("The ssl crl file is expired, jump load crl"); - X509_CRL_free(crl); - (void)BIO_free(in); - return CM_ERROR; - } st = SSL_CTX_get_cert_store(ctx); if (!X509_STORE_add_crl(st, crl)) { @@ -897,8 +889,7 @@ static status_t cs_ssl_set_crl_file(SSL_CTX *ctx, ssl_config_t *config) while (file_name.len > 0) { CM_RETURN_IFERR(cm_text2str(&file_name, filepath, sizeof(filepath))); if (cs_load_crl_file(ctx, filepath) != CM_SUCCESS) { - LOG_RUN_WAR("[MEC]the ssl crl file load failed"); - return CM_SUCCESS; + return CM_ERROR; } cs_ssl_fetch_file_name(&file_list, &file_name); @@ -1244,30 +1235,6 @@ static SSL_CTX *cs_ssl_create_context(ssl_config_t *config, bool32 is_client) return ctx; } -static bool32 cs_is_crl_invalid(int32 errcode) -{ - const int32 err_scenarios[] = { - X509_V_ERR_UNABLE_TO_GET_CRL, - X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE, - X509_V_ERR_CRL_SIGNATURE_FAILURE, - X509_V_ERR_CRL_NOT_YET_VALID, - X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD, - X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD, - X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER, - X509_V_ERR_KEYUSAGE_NO_CRL_SIGN, - X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION, - X509_V_ERR_DIFFERENT_CRL_SCOPE, - X509_V_ERR_CRL_PATH_VALIDATION_ERROR - }; - - for (int32 i = 0; i < sizeof(err_scenarios) / sizeof(err_scenarios[0]); i++) { - if (errcode == err_scenarios[i]) { - return CM_TRUE; - } - } - return CM_FALSE; -} - /* * Certificate verification callback * @@ -1282,32 +1249,6 @@ static bool32 cs_is_crl_invalid(int32 errcode) */ static int32 cs_ssl_verify_cb(int32 ok, X509_STORE_CTX *ctx) { - if (ok) { - return ok; - } - int err_code = X509_STORE_CTX_get_error(ctx); - if (err_code == X509_V_ERR_CRL_HAS_EXPIRED) { - X509_STORE_CTX_set_error(ctx, X509_V_OK); - if (!g_crl_expired) { - LOG_RUN_WAR("the ssl crl file is expired"); - g_crl_expired = CM_TRUE; - } - return 1; - } else if (cs_is_crl_invalid(err_code)) { - X509_STORE_CTX_set_error(ctx, X509_V_OK); - if (!g_crl_expired) { - const char *errmsg = X509_verify_cert_error_string(err_code); - LOG_RUN_WAR("SSL connection warning: the ssl crl file is invalid. " - "{ssl err code: %d, ssl err message: %s}", - err_code, errmsg); - g_crl_expired = CM_TRUE; - } - return 1; - } - if (err_code == X509_V_ERR_CERT_REVOKED && g_crl_expired) { - X509_STORE_CTX_set_error(ctx, X509_V_OK); - return 1; - } return ok; } @@ -1384,58 +1325,6 @@ void ssl_ca_cert_expire(const ssl_ctx_t *ssl_context, int32 alert_day) return; } -static status_t ssl_check_crl_expire(X509_CRL *crl, int32 alert_day) -{ - const ASN1_TIME *next_update_time = NULL; - int32 expire_day; - - if (crl == NULL) { - return CM_SUCCESS; - } - - next_update_time = X509_CRL_get0_nextUpdate(crl); - if (X509_cmp_current_time(next_update_time) <= 0) { - LOG_RUN_WAR("[MEC]The %s is expired","crl"); - return CM_ERROR; - } else { - time_t curr_time = cm_current_time(); - expire_day = ssl_get_expire_day(next_update_time, &curr_time); - if (expire_day >= 0 && alert_day >= expire_day) { - LOG_RUN_WAR("[MEC]The %s will expire in %d days", "crl", expire_day); - return CM_SUCCESS; - } - } - return CM_SUCCESS; -} - -status_t ssl_crl_expire(const ssl_ctx_t *ssl_context, int32 alert_day) -{ - SSL_CTX *ctx = SSL_CTX_PTR(ssl_context); - X509_CRL *crl = NULL; - X509_STORE *crl_store = NULL; - X509_OBJECT *obj = NULL; - - if (ssl_context == NULL) { - return CM_SUCCESS; - } - - crl_store = SSL_CTX_get_cert_store(ctx); - if (crl_store == NULL) { - return CM_SUCCESS; - } - STACK_OF(X509_OBJECT) *objects = X509_STORE_get0_objects(crl_store); - for (int i = 0; i < sk_X509_OBJECT_num(objects); i++) { - obj = sk_X509_OBJECT_value(objects, i); - if (X509_OBJECT_get_type(obj) == X509_LU_CRL) { - crl = X509_OBJECT_get0_X509_CRL(obj); - if (ssl_check_crl_expire(crl, alert_day) == CM_ERROR) { - return CM_ERROR; - } - } - } - - return CM_SUCCESS; -} ssl_ctx_t *cs_ssl_create_acceptor_fd(ssl_config_t *config) { SSL_CTX *ssl_fd = NULL; @@ -1487,7 +1376,7 @@ ssl_ctx_t *cs_ssl_create_connector_fd(ssl_config_t *config) } /* Init the SSL_CTX as a "connector" ie. the client side */ - SSL_CTX_set_verify(ssl_fd, verify, cs_ssl_verify_cb); + SSL_CTX_set_verify(ssl_fd, verify, NULL); SSL_CTX_set_verify_depth(ssl_fd, SSL_VERIFY_DEPTH); return (ssl_ctx_t *)ssl_fd; diff --git a/src/cm_protocol/cs_ssl.h b/src/cm_protocol/cs_ssl.h index 9f56188..7b99722 100644 --- a/src/cm_protocol/cs_ssl.h +++ b/src/cm_protocol/cs_ssl.h @@ -203,7 +203,6 @@ status_t cs_ssl_verify_certificate(ssl_link_t *link, ssl_verify_t vmode, const c status_t cs_ssl_verify_file_stat(const char *file_name); void ssl_ca_cert_expire(const ssl_ctx_t *ssl_context, int32 alert_day); -status_t ssl_crl_expire(const ssl_ctx_t *ssl_context, int32 alert_day); void cs_ssl_throw_error(int32 ssl_err); -- Gitee