代码重构

This commit is contained in:
liuxueli
2020-05-29 15:10:01 +08:00
parent f77fd01b24
commit 0b50dd7bc2
9 changed files with 831 additions and 975 deletions

View File

@@ -12,7 +12,7 @@
#include <MESA/MESA_handle_logger.h>
#include <MESA/MESA_prof_load.h>
struct quic_param_t g_quic_param;
struct _quic_param_t g_quic_param;
const char *g_quic_proto_conffile="./conf/quic/main.conf";
const char *g_quic_regionname_conffile="./conf/quic/quic.conf";
@@ -39,47 +39,19 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
const char QUIC_VERSION_20200522=0;
int quic_init_stream(void **pme, int thread_seq)
{
struct quic_stream *a_quic_stream=(struct quic_stream *)*pme;
struct _quic_context *_context=(struct _quic_context *)*pme;
a_quic_stream=(struct quic_stream *)dictator_malloc(thread_seq, sizeof(struct quic_stream));
memset(a_quic_stream,0,sizeof(struct quic_stream));
_context=(struct _quic_context *)dictator_malloc(thread_seq, sizeof(struct _quic_context));
memset(_context, 0, sizeof(struct _quic_context));
a_quic_stream->output_region_flag = g_quic_param.quic_interested_region_flag;
a_quic_stream->output_region_mask = QUIC_INTEREST_KEY_MASK;
a_quic_stream->is_quic_stream = QUIC_FALSE;
a_quic_stream->version_cfm = QUIC_FALSE;
a_quic_stream->version = 0;
a_quic_stream->link_state = QUIC_FALSE;
a_quic_stream->fin_flag = QUIC_FALSE;
a_quic_stream->business = (struct quic_business_info *)dictator_malloc(thread_seq,sizeof(struct quic_business_info));
a_quic_stream->business->param = NULL;
a_quic_stream->business->return_value = PROT_STATE_GIVEME;
*pme = (void*)a_quic_stream;
*pme=(void*)_context;
return 0;
}
void quic_release_clientHello(int thread_seq, struct quic_client_hello* st_client_hello)
{
if(st_client_hello!=NULL)
{
if(st_client_hello->ext_tags!=NULL)
{
quic_release_exts(thread_seq, st_client_hello->ext_tags, st_client_hello->ext_tag_num);
dictator_free(thread_seq, st_client_hello->ext_tags);
st_client_hello->ext_tags = NULL;
}
}
return;
}
void quic_release_exts(int thread_seq, quic_tlv_t** ext_tags, UINT16 ext_tag_num)
void quic_release_exts(int thread_seq, quic_tlv_t *ext_tags, int ext_tag_num)
{
int i=0;
@@ -87,62 +59,48 @@ void quic_release_exts(int thread_seq, quic_tlv_t** ext_tags, UINT16 ext_tag_num
{
for(i=0; i<ext_tag_num; i++)
{
if(ext_tags[i] != NULL)
if(ext_tags[i].value!=NULL)
{
if(ext_tags[i]->ptr_value != NULL)
{
dictator_free(thread_seq, ext_tags[i]->ptr_value);
ext_tags[i]->ptr_value = NULL;
}
dictator_free(thread_seq, ext_tags[i]);
ext_tags[i] = NULL;
dictator_free(thread_seq, ext_tags[i].value);
ext_tags[i].value=NULL;
}
}
dictator_free(thread_seq, ext_tags);
ext_tags=NULL;
}
}
void quic_release_stream(struct streaminfo *a_tcp, void** pme, int thread_seq)
{
struct quic_stream *a_quic_stream = (struct quic_stream *)*pme;
if(NULL!=a_quic_stream)
{
a_quic_stream->fin_flag = QUIC_TRUE;
struct _quic_context *_context = (struct _quic_context *)*pme;
if(NULL!=_context)
{
if(_context->quic_info.client_hello!=NULL)
{
quic_release_exts(thread_seq, _context->quic_info.client_hello->ext_tags, _context->quic_info.client_hello->ext_tag_num);
dictator_free(thread_seq, _context->quic_info.client_hello);
_context->quic_info.client_hello=NULL;
}
if(NULL!=a_quic_stream->business)
if(_context->quic_info.server_hello!=NULL)
{
if(a_quic_stream->business->param!=NULL)
{
dictator_free(thread_seq,a_quic_stream->business->param);
a_quic_stream->business->param = NULL;
}
dictator_free(thread_seq,a_quic_stream->business);
a_quic_stream->business = NULL;
quic_release_exts(thread_seq, _context->quic_info.server_hello->ext_tags, _context->quic_info.server_hello->ext_tag_num);
dictator_free(thread_seq, _context->quic_info.server_hello);
_context->quic_info.server_hello=NULL;
}
if(NULL!=a_quic_stream->cert_chain.ptr_value)
if(_context->quic_info.rej!=NULL)
{
dictator_free(thread_seq,a_quic_stream->cert_chain.ptr_value);
a_quic_stream->cert_chain.ptr_value = NULL;
quic_release_exts(thread_seq, _context->quic_info.rej->ext_tags, _context->quic_info.rej->ext_tag_num);
dictator_free(thread_seq, _context->quic_info.rej);
_context->quic_info.rej=NULL;
}
if(NULL!=a_quic_stream->common_cert.ptr_value)
{
dictator_free(thread_seq,a_quic_stream->common_cert.ptr_value);
a_quic_stream->common_cert.ptr_value = NULL;
}
if(NULL!=a_quic_stream->cached_cert.ptr_value)
{
dictator_free(thread_seq,a_quic_stream->cached_cert.ptr_value);
a_quic_stream->cached_cert.ptr_value = NULL;
}
quic_release_exts(thread_seq, a_quic_stream->st_client_hello.ext_tags, a_quic_stream->st_client_hello.ext_tag_num);
quic_release_exts(thread_seq, a_quic_stream->st_server_hello.ext_tags, a_quic_stream->st_server_hello.ext_tag_num);
dictator_free(thread_seq,a_quic_stream);
a_quic_stream = NULL;
dictator_free(thread_seq, _context);
_context=NULL;
*pme=NULL;
}
return;
@@ -157,7 +115,7 @@ extern "C" int QUIC_INIT(void)
int region_id=0;
char region_name[REGION_NAME_LEN]={0};
memset(&g_quic_param,0,sizeof(struct quic_param_t));
memset(&g_quic_param,0,sizeof(struct _quic_param_t));
MESA_load_profile_int_def(g_quic_proto_conffile, "QUIC", "LOG_LEVEL", &level, RLOG_LV_FATAL);
MESA_load_profile_string_def(g_quic_proto_conffile, "QUIC", "LOG_PATH", log_path, sizeof(log_path), "./log/quic/quic");
@@ -278,8 +236,8 @@ extern "C" long long QUIC_FLAG_CHANGE(char* flag_str)
extern "C" char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq, void *a_packet)
{
uint8_t return_val=0;
struct quic_stream *a_quic_stream=(struct quic_stream *)*pme;
int ret=0;
struct _quic_context *_context=(struct _quic_context *)*pme;
if(g_quic_param.quic_interested_region_flag<QUIC_KEY)
{
@@ -296,28 +254,27 @@ extern "C" char QUIC_ENTRY(struct streaminfo *pstream, void**pme, int thread_seq
if(*pme==NULL)
{
quic_init_stream(pme, thread_seq);
a_quic_stream=(struct quic_stream *)*pme;
_context=(struct _quic_context *)*pme;
}
switch(pstream->opstate)
{
case OP_STATE_PENDING:
case OP_STATE_DATA:
return_val=gquic_process(pstream, a_quic_stream, thread_seq, a_packet);
ret=quic_process(pstream, _context, thread_seq, a_packet);
break;
case OP_STATE_CLOSE:
a_quic_stream->fin_flag=QUIC_TRUE;
return_val=gquic_process(pstream, a_quic_stream, thread_seq, a_packet);
ret=quic_process(pstream, _context, thread_seq, a_packet);
break;
default:
break;
}
if(return_val==QUIC_RETURN_DROPME || pstream->opstate==OP_STATE_CLOSE)
if(ret&APP_STATE_DROPME|| pstream->opstate==OP_STATE_CLOSE)
{
quic_release_stream(pstream, pme, thread_seq);
*pme=NULL;
return APP_STATE_DROPME;
return ret;
}
return APP_STATE_GIVEME;