2021-07-16 16:06:59 +08:00
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <arpa/inet.h>
# include <net/if.h>
# include <unistd.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <assert.h>
# include <errno.h>
# include <sys/prctl.h>
# include <poll.h>
2021-08-04 11:14:56 +08:00
# include <sys/types.h>
# include <sys/stat.h>
# include <fcntl.h>
2021-07-16 16:06:59 +08:00
# include "doris_server_main.h"
# include "doris_server_http.h"
2021-07-19 17:21:38 +08:00
extern struct doris_global_info g_doris_server_info ;
2021-07-16 16:06:59 +08:00
2021-08-04 11:14:56 +08:00
struct version_list_node * lookup_vernode_accord_version ( struct version_list_handle * handle , int64_t version )
{
struct version_list_node * vernode ;
map < int64_t , struct version_list_node * > : : iterator iter ;
vernode = TAILQ_FIRST ( & handle - > version_head ) ;
if ( vernode ! = NULL & & version < vernode - > version ) //<2F> <> ǰȫ<C7B0> <C8AB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> С <EFBFBD> İ汾<C4B0> <E6B1BE>
{
version = vernode - > version ;
}
for ( ; version < = handle - > latest_version ; version + + )
{
if ( ( iter = handle - > version2node - > find ( version ) ) ! = handle - > version2node - > end ( ) )
{
vernode = iter - > second ;
return vernode ;
}
}
return NULL ;
}
2021-08-25 18:40:20 +08:00
/*<2A> <> <EFBFBD> <EFBFBD> ֵ:
* 304 - <EFBFBD> ͻ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ѵ ﵽ <EFBFBD> <EFBFBD> <EFBFBD> ° 汾 <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͬ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> consumer <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
* 300 - <EFBFBD> <EFBFBD> δ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ͬ <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Client <EFBFBD> <EFBFBD> <EFBFBD> ð 汾 <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> */
static int32_t check_producer_ready_sync ( struct doris_business * business , struct evhttp_request * req , int64_t cur_version )
{
const char * client_version ;
int64_t clientversion ;
if ( NULL = = ( client_version = evhttp_find_header ( evhttp_request_get_input_headers ( req ) , " X-Doris-Sync-Current-Version " ) ) )
{
return HTTP_NOTMODIFIED ;
}
/*request from sync client, check http posts-on-the-way first*/
if ( business - > posts_on_the_way )
{
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_DEBUG , " HttpProducer, posts-on-the-way: %d, meta response 300 " , business - > posts_on_the_way ) ;
return 300 ;
}
/*Client<6E> 汾<EFBFBD> <E6B1BE> <EFBFBD> <EFBFBD> ? <20> <> <EFBFBD> <EFBFBD> <EFBFBD> ˴ ӻ<CBB4> <D3BB> <EFBFBD> <EFBFBD> ӻ<EFBFBD> <D3BB> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> £<EFBFBD> <C2A3> <EFBFBD> <EFBFBD> <EFBFBD> Client<6E> <74> <EFBFBD> <EFBFBD> ʱ<EFBFBD> <CAB1> <EFBFBD> Ӷ<EFBFBD> <D3B6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ƣ<EFBFBD> <C6A3> ڻ<EFBFBD> <DABB> <EFBFBD> <EFBFBD> <EFBFBD> ȡ*/
/*<2A> <> <EFBFBD> <EFBFBD> ȡʱ<C8A1> <CAB1> <EFBFBD> õ<EFBFBD> 300<30> <30> Ӧ<EFBFBD> <D3A6> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> ȡʱ<C8A1> <CAB1> ֱ<EFBFBD> <D6B1> ͬ<EFBFBD> <CDAC> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> İ汾<C4B0> <E6B1BE> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 汾<EFBFBD> <E6B1BE> <EFBFBD> <EFBFBD> һ <EFBFBD> £<EFBFBD> <C2A3> <EFBFBD> <EFBFBD> <EFBFBD> 304*/
if ( ( clientversion = atol ( client_version ) ) > cur_version )
{
business_set_sync_peer_abnormal ( business ) ;
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_INFO , " HttpProducer, client version(%lu) is newer than server(%lu) " , clientversion , cur_version ) ;
return 300 ;
}
business_resume_sync_peer_normal ( business ) ;
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_FATAL , " HttpProducer, doris client is OK to sync for business: %s " , business - > bizname ) ;
return HTTP_NOTMODIFIED ;
}
2021-07-16 16:06:59 +08:00
void doris_http_server_meta_cb ( struct evhttp_request * req , void * arg )
{
struct evkeyvalq params ;
2021-08-25 18:40:20 +08:00
const char * version ;
2021-07-16 16:06:59 +08:00
int64_t verlong ;
char * endptr = NULL , length [ 64 ] ;
struct version_list_node * vernode ;
struct evbuffer * evbuf ;
2021-07-22 10:25:42 +08:00
struct doris_business * business ;
2021-07-16 16:06:59 +08:00
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_META_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
if ( evhttp_parse_query ( evhttp_request_get_uri ( req ) , & params ) )
{
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_INVALID_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameters invalid " ) ;
return ;
}
if ( NULL = = ( version = evhttp_find_header ( & params , " version " ) ) )
{
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_INVALID_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-19 17:21:38 +08:00
evhttp_clear_headers ( & params ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameters invalid, no version found " ) ;
return ;
}
if ( 0 = = ( verlong = strtol ( version , & endptr , 10 ) ) | | * endptr ! = ' \0 ' )
{
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_INVALID_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-19 17:21:38 +08:00
evhttp_clear_headers ( & params ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameter version invalid " ) ;
return ;
}
2021-08-25 18:40:20 +08:00
if ( NULL = = ( business = lookup_bizstruct_from_name ( & params ) ) )
2021-07-22 10:25:42 +08:00
{
evhttp_clear_headers ( & params ) ;
2021-08-25 18:40:20 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameter business invalid " ) ;
2021-07-22 10:25:42 +08:00
return ;
}
2021-07-19 17:21:38 +08:00
evhttp_clear_headers ( & params ) ;
2021-07-22 10:25:42 +08:00
pthread_rwlock_rdlock ( & business - > rwlock ) ;
2021-08-04 11:14:56 +08:00
if ( NULL = = ( vernode = lookup_vernode_accord_version ( business - > cfgver_head , verlong ) ) )
2021-07-16 16:06:59 +08:00
{
2021-08-25 18:40:20 +08:00
int code = check_producer_ready_sync ( business , req , business - > cfgver_head - > latest_version ) ;
2021-07-22 10:25:42 +08:00
pthread_rwlock_unlock ( & business - > rwlock ) ;
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_SEND_META_NONEW ] , 0 , FS_OP_ADD , 1 ) ;
2021-08-25 18:40:20 +08:00
evhttp_send_error ( req , code , " No new configs found " ) ;
2021-07-16 16:06:59 +08:00
return ;
}
evbuf = evbuffer_new ( ) ;
evbuffer_add ( evbuf , vernode - > metacont , vernode - > metalen ) ;
sprintf ( length , " %u " , vernode - > metalen ) ;
2021-07-22 10:25:42 +08:00
pthread_rwlock_unlock ( & business - > rwlock ) ;
2021-07-16 16:06:59 +08:00
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , business - > fs_lineid , g_doris_server_info . fsstat_column [ DRS_FSCLM_SEND_META_RES ] , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
evhttp_add_header ( evhttp_request_get_output_headers ( req ) , " Content-Type " , " application/json " ) ;
evhttp_add_header ( evhttp_request_get_output_headers ( req ) , " Connection " , " keep-alive " ) ;
evhttp_add_header ( evhttp_request_get_output_headers ( req ) , " Content-Length " , length ) ;
evhttp_send_reply ( req , HTTP_OK , " OK " , evbuf ) ;
evbuffer_free ( evbuf ) ;
}
2021-08-04 11:14:56 +08:00
struct evbuffer * evbuf_content_from_memory ( struct table_list_node * tablenode , size_t start , size_t end , size_t * length )
{
struct evbuffer * evbuf ;
struct cont_frag_node * fragnode ;
size_t copy_len , offset = start , res_length = 0 ;
evbuf = evbuffer_new ( ) ;
for ( fragnode = TAILQ_FIRST ( & tablenode - > frag_head ) ; fragnode ! = NULL & & fragnode - > start < = end ; fragnode = TAILQ_NEXT ( fragnode , frag_node ) )
{
if ( offset > fragnode - > end )
{
continue ;
}
copy_len = ( end > fragnode - > end ) ? ( fragnode - > end - offset + 1 ) : ( end - offset + 1 ) ;
evbuffer_add ( evbuf , fragnode - > content + ( offset - fragnode - > start ) , copy_len ) ;
offset + = copy_len ;
res_length + = copy_len ;
}
* length = res_length ;
return evbuf ;
}
struct evbuffer * evbuf_content_from_disk ( struct table_list_node * tablenode , size_t start , size_t end , size_t * length )
{
struct evbuffer * evbuf ;
int32_t fd ;
if ( ( fd = open ( tablenode - > localpath , O_RDONLY , 0 ) ) < 0 )
{
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_FATAL , " Send response, open %s failed: %s " , strerror ( errno ) ) ;
return NULL ;
}
evbuf = evbuffer_new ( ) ;
if ( evbuffer_add_file ( evbuf , fd , start , end - start + 1 ) )
{
evbuffer_free ( evbuf ) ;
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_FATAL , " Send response, evbuffer_add_file %s failed " ) ;
close ( fd ) ;
return NULL ;
}
* length = evbuffer_get_length ( evbuf ) ;
return evbuf ;
}
2021-08-25 18:40:20 +08:00
void doris_response_file_range ( struct evhttp_request * req , struct doris_business * business ,
const char * tablename , int64_t verlong , size_t start , size_t end , bool range )
2021-07-16 16:06:59 +08:00
{
struct version_list_node * vernode ;
struct table_list_node * tablenode ;
struct evbuffer * evbuf ;
char length [ 128 ] ;
2021-08-04 11:14:56 +08:00
size_t filesize , res_length ;
2021-07-22 10:25:42 +08:00
pthread_rwlock_rdlock ( & business - > rwlock ) ;
2021-08-04 11:14:56 +08:00
if ( NULL = = ( vernode = lookup_vernode_accord_version ( business - > cfgver_head , verlong ) ) )
2021-07-22 10:25:42 +08:00
{
pthread_rwlock_unlock ( & business - > rwlock ) ;
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_SEND_FILE_RES_404 ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_NOTFOUND , " Version too old " ) ;
return ;
}
tablenode = TAILQ_FIRST ( & vernode - > table_head ) ;
while ( tablenode ! = NULL & & strcmp ( tablename , tablenode - > tablename ) )
{
tablenode = TAILQ_NEXT ( tablenode , table_node ) ;
}
if ( tablenode = = NULL | | start > tablenode - > filesize )
{
2021-07-22 10:25:42 +08:00
pthread_rwlock_unlock ( & business - > rwlock ) ;
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_SEND_FILE_RES_404 ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_NOTFOUND , " No valid content found " ) ;
return ;
}
filesize = tablenode - > filesize ;
if ( end = = 0 | | end > = tablenode - > filesize )
{
end = tablenode - > filesize - 1 ;
}
2021-08-04 11:14:56 +08:00
if ( vernode - > cont_in_disk )
2021-07-16 16:06:59 +08:00
{
2021-08-04 11:14:56 +08:00
evbuf = evbuf_content_from_disk ( tablenode , start , end , & res_length ) ;
}
else
{
evbuf = evbuf_content_from_memory ( tablenode , start , end , & res_length ) ;
2021-07-16 16:06:59 +08:00
}
2021-07-22 10:25:42 +08:00
pthread_rwlock_unlock ( & business - > rwlock ) ;
2021-07-16 16:06:59 +08:00
assert ( res_length = = end + 1 - start ) ;
sprintf ( length , " %lu " , res_length ) ;
2021-08-25 18:40:20 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_SEND_FILES ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_SEND_FILE_BYTES ] , 0 , FS_OP_ADD , res_length ) ;
2021-07-16 16:06:59 +08:00
evhttp_add_header ( evhttp_request_get_output_headers ( req ) , " Content-Length " , length ) ;
2021-08-25 18:40:20 +08:00
evhttp_add_header ( evhttp_request_get_output_headers ( req ) , " Content-Type " , " application/stream " ) ;
evhttp_add_header ( evhttp_request_get_output_headers ( req ) , " Connection " , " keep-alive " ) ;
2021-07-16 16:06:59 +08:00
if ( range )
{
sprintf ( length , " bytes %lu-%lu/%lu " , start , end , filesize ) ;
evhttp_add_header ( evhttp_request_get_output_headers ( req ) , " Content-Range " , length ) ;
2021-08-25 18:40:20 +08:00
evhttp_send_reply ( req , 206 , " Partial Content " , evbuf ) ;
}
else
{
evhttp_send_reply ( req , HTTP_OK , " OK " , evbuf ) ;
2021-07-16 16:06:59 +08:00
}
2021-07-19 17:21:38 +08:00
evbuffer_free ( evbuf ) ;
2021-07-16 16:06:59 +08:00
}
void doris_http_server_file_cb ( struct evhttp_request * req , void * arg )
{
struct evkeyvalq params ;
2021-08-25 18:40:20 +08:00
struct doris_business * business ;
const char * version , * tablename , * content_range ;
2021-07-16 16:06:59 +08:00
int64_t verlong ;
char * endptr = NULL ;
size_t req_start = 0 , req_end = 0 ;
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_FILE_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
if ( evhttp_parse_query ( evhttp_request_get_uri ( req ) , & params ) )
{
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_INVALID_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameters invalid " ) ;
return ;
}
if ( NULL = = ( version = evhttp_find_header ( & params , " version " ) ) | | NULL = = ( tablename = evhttp_find_header ( & params , " tablename " ) ) )
{
2021-07-19 17:21:38 +08:00
evhttp_clear_headers ( & params ) ;
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_INVALID_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameters invalid, no version/tablename found " ) ;
return ;
}
if ( 0 = = ( verlong = strtol ( version , & endptr , 10 ) ) | | * endptr ! = ' \0 ' )
{
2021-07-19 17:21:38 +08:00
evhttp_clear_headers ( & params ) ;
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_INVALID_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameter version invalid " ) ;
return ;
}
if ( NULL ! = ( content_range = evhttp_find_header ( evhttp_request_get_input_headers ( req ) , " Range " ) ) & &
sscanf ( content_range , " %*[^0-9]%lu-%lu " , & req_start , & req_end ) < 1 )
{
2021-07-19 17:21:38 +08:00
evhttp_clear_headers ( & params ) ;
2021-07-22 10:25:42 +08:00
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_INVALID_REQ ] , 0 , FS_OP_ADD , 1 ) ;
2021-07-16 16:06:59 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Header Range invalid " ) ;
return ;
2021-08-25 18:40:20 +08:00
}
if ( NULL = = ( business = lookup_bizstruct_from_name ( & params ) ) )
2021-07-22 10:25:42 +08:00
{
evhttp_clear_headers ( & params ) ;
2021-08-25 18:40:20 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameter business invalid " ) ;
2021-07-22 10:25:42 +08:00
return ;
}
2021-07-16 16:06:59 +08:00
2021-08-25 18:40:20 +08:00
doris_response_file_range ( req , business , tablename , verlong , req_start , req_end , ( content_range = = NULL ) ? false : true ) ;
2021-07-19 17:21:38 +08:00
evhttp_clear_headers ( & params ) ;
2021-07-16 16:06:59 +08:00
}
2021-08-10 10:02:22 +08:00
void doris_http_server_version_cb ( struct evhttp_request * req , void * arg )
{
struct evkeyvalq params ;
struct doris_business * business ;
char verbuf [ 32 ] ;
if ( evhttp_parse_query ( evhttp_request_get_uri ( req ) , & params ) )
{
FS_operate ( g_doris_server_info . fsstat_handle , g_doris_server_info . fsstat_field [ DRS_FSSTAT_CLIENT_INVALID_REQ ] , 0 , FS_OP_ADD , 1 ) ;
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameters invalid " ) ;
return ;
}
2021-08-25 18:40:20 +08:00
if ( NULL = = ( business = lookup_bizstruct_from_name ( & params ) ) )
2021-08-10 10:02:22 +08:00
{
evhttp_clear_headers ( & params ) ;
2021-08-25 18:40:20 +08:00
evhttp_send_error ( req , HTTP_BADREQUEST , " Parameter business invalid " ) ;
2021-08-10 10:02:22 +08:00
return ;
}
evhttp_clear_headers ( & params ) ;
pthread_rwlock_rdlock ( & business - > rwlock ) ;
sprintf ( verbuf , " %lu " , business - > cfgver_head - > latest_version ) ;
pthread_rwlock_unlock ( & business - > rwlock ) ;
evhttp_add_header ( evhttp_request_get_output_headers ( req ) , " X-Latest-Version " , verbuf ) ;
evhttp_send_reply ( req , HTTP_OK , " OK " , NULL ) ;
}
2021-07-16 16:06:59 +08:00
void doris_http_server_generic_cb ( struct evhttp_request * req , void * arg )
{
evhttp_send_error ( req , HTTP_BADREQUEST , " Not Supported. " ) ;
}
2021-07-19 17:21:38 +08:00
pthread_t nirvana_pthreads_thread_id ( void )
{
return pthread_self ( ) ;
}
void nirvana_pthreads_locking_callback ( int mode , int type , const char * file , int line )
{
if ( mode & CRYPTO_LOCK )
{
pthread_mutex_lock ( & g_doris_server_info . lock_cs [ type ] ) ;
}
else
{
pthread_mutex_unlock ( & g_doris_server_info . lock_cs [ type ] ) ;
}
}
int server_verify_callback ( int ok , X509_STORE_CTX * ctx )
{
X509 * client_cert ;
char * subject , * issuer ;
client_cert = X509_STORE_CTX_get_current_cert ( ctx ) ;
subject = X509_NAME_oneline ( X509_get_subject_name ( client_cert ) , 0 , 0 ) ;
issuer = X509_NAME_oneline ( X509_get_issuer_name ( client_cert ) , 0 , 0 ) ;
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_DEBUG , " ClientCert suject: %s, issuer: %s, state: %d. " , subject , issuer , ok ) ;
OPENSSL_free ( subject ) ;
OPENSSL_free ( issuer ) ;
return ok ;
}
SSL_CTX * doris_connections_create_ssl_ctx ( void )
{
int crypto_num ;
SSL_CTX * ssl_ctx ;
char session_id_appname [ ] = " DorisServer " ;
SSL_library_init ( ) ;
SSLeay_add_ssl_algorithms ( ) ;
OpenSSL_add_all_algorithms ( ) ;
SSL_load_error_strings ( ) ;
ERR_load_BIO_strings ( ) ;
crypto_num = CRYPTO_num_locks ( ) ;
g_doris_server_info . lock_cs = ( pthread_mutex_t * ) OPENSSL_malloc ( crypto_num * sizeof ( pthread_mutex_t ) ) ;
for ( int i = 0 ; i < crypto_num ; i + + )
{
pthread_mutex_init ( & g_doris_server_info . lock_cs [ i ] , NULL ) ;
}
CRYPTO_set_id_callback ( nirvana_pthreads_thread_id ) ;
CRYPTO_set_locking_callback ( nirvana_pthreads_locking_callback ) ;
ssl_ctx = SSL_CTX_new ( SSLv23_server_method ( ) ) ;
//SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT|SSL_VERIFY_CLIENT_ONCE, server_verify_callback);
//<2F> <> <EFBFBD> <EFBFBD> SESSION Resumption<6F> <6E> ˫<EFBFBD> <CBAB> <EFBFBD> <EFBFBD> <EFBFBD> ã<EFBFBD> <C3A3> <EFBFBD> Ϊ<EFBFBD> <CEAA> ֤<EFBFBD> <D6A4> ˫<EFBFBD> <CBAB> <EFBFBD> ģ<EFBFBD>
SSL_CTX_set_session_cache_mode ( ssl_ctx , SSL_SESS_CACHE_BOTH ) ;
//<2F> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> HoldĬ<64> <C4AC> SSL_SESSION_CACHE_MAX_SIZE_DEFAULT(1024*20)<29> <> SESSION<4F> <4E> 0-<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
SSL_CTX_sess_set_cache_size ( ssl_ctx , SSL_SESSION_CACHE_MAX_SIZE_DEFAULT ) ;
SSL_CTX_set_session_id_context ( ssl_ctx , ( unsigned char * ) session_id_appname , strlen ( session_id_appname ) ) ;
SSL_CTX_set_default_passwd_cb_userdata ( ssl_ctx , g_doris_server_info . ssl_key_passwd ) ;
if ( ! SSL_CTX_load_verify_locations ( ssl_ctx , NULL , g_doris_server_info . ssl_CA_path ) )
{
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_FATAL , " SSL_CTX_load_verify_locations error: %s. " , ERR_reason_error_string ( ERR_get_error ( ) ) ) ;
SSL_CTX_free ( ssl_ctx ) ;
return NULL ;
}
if ( ! SSL_CTX_use_certificate_file ( ssl_ctx , g_doris_server_info . ssl_cert_file , SSL_FILETYPE_PEM ) )
{
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_FATAL , " SSL_CTX_use_certificate_file error: %s. " , ERR_reason_error_string ( ERR_get_error ( ) ) ) ;
SSL_CTX_free ( ssl_ctx ) ;
return NULL ;
}
if ( SSL_CTX_use_PrivateKey_file ( ssl_ctx , g_doris_server_info . ssl_key_file , SSL_FILETYPE_PEM ) < 0 )
{
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_FATAL , " SSL_CTX_use_PrivateKey_file_pass error: %s. " , ERR_reason_error_string ( ERR_get_error ( ) ) ) ;
SSL_CTX_free ( ssl_ctx ) ;
return NULL ;
}
if ( ! SSL_CTX_check_private_key ( ssl_ctx ) )
{
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_FATAL , " SSL_CTX_check_private_key error: %s. " , ERR_reason_error_string ( ERR_get_error ( ) ) ) ;
SSL_CTX_free ( ssl_ctx ) ;
return NULL ;
}
return ssl_ctx ;
}
2021-07-16 16:06:59 +08:00
void * thread_doris_http_server ( void * arg )
{
struct event_base * worker_evbase ;
struct evhttp * worker_http ;
prctl ( PR_SET_NAME , " http_server " ) ;
worker_evbase = event_base_new ( ) ;
worker_http = evhttp_new ( worker_evbase ) ;
2021-07-19 17:21:38 +08:00
if ( g_doris_server_info . ssl_conn_on )
{
evhttp_set_bevcb ( worker_http , doris_https_bufferevent_cb , g_doris_server_info . ssl_instance ) ;
}
2021-07-22 10:25:42 +08:00
evhttp_set_cb ( worker_http , " /configmeta " , doris_http_server_meta_cb , NULL ) ;
evhttp_set_cb ( worker_http , " /configfile " , doris_http_server_file_cb , NULL ) ;
2021-08-10 10:02:22 +08:00
evhttp_set_cb ( worker_http , " /latestversion " , doris_http_server_version_cb , NULL ) ;
2021-07-22 10:25:42 +08:00
evhttp_set_gencb ( worker_http , doris_http_server_generic_cb , NULL ) ;
2021-07-16 16:06:59 +08:00
evhttp_set_allowed_methods ( worker_http , EVHTTP_REQ_GET | EVHTTP_REQ_HEAD ) ;
2021-08-25 18:40:20 +08:00
if ( evhttp_accept_socket ( worker_http , g_doris_server_info . listener_csum ) )
2021-07-16 16:06:59 +08:00
{
2021-08-25 18:40:20 +08:00
printf ( " evhttp_accept_socket %d error! \n " , g_doris_server_info . listener_csum ) ;
2021-07-16 16:06:59 +08:00
assert ( 0 ) ; return NULL ;
}
event_base_dispatch ( worker_evbase ) ;
printf ( " Libevent dispath error, should not run here. \n " ) ;
MESA_RUNTIME_LOGV3 ( g_doris_server_info . log_runtime , RLOG_LV_FATAL , " Libevent dispath error, should not run here. " ) ;
return NULL ;
}