diff --git a/plugin/protocol/http2/include/internal/http2_stream.h b/plugin/protocol/http2/include/internal/http2_stream.h index 6f246dc..e8548b7 100644 --- a/plugin/protocol/http2/include/internal/http2_stream.h +++ b/plugin/protocol/http2/include/internal/http2_stream.h @@ -116,9 +116,9 @@ struct tfe_h2_stream unsigned int thread_id; /** for down stream as server */ - nghttp2_session *as_server; + nghttp2_session *http2_server_handle; /** for up stream as client*/ - nghttp2_session *as_client; + nghttp2_session *http2_client_handle; const struct tfe_stream *tf_stream; }; diff --git a/plugin/protocol/http2/src/http2_stream.cpp b/plugin/protocol/http2/src/http2_stream.cpp index 87da35f..0f296ed 100644 --- a/plugin/protocol/http2/src/http2_stream.cpp +++ b/plugin/protocol/http2/src/http2_stream.cpp @@ -54,7 +54,7 @@ static const struct value_string method_vals[] = typedef enum { NGHTTP2_USER_SEND = 0x0b, NGHTTP2_USER_COLSE = 0x0c, -} nghttp2_frame_user_type; +} http2_frame_user_type; struct user_event_dispatch { @@ -63,9 +63,47 @@ struct user_event_dispatch unsigned int thread_id; }; +static uint32_t hash(int32_t key, uint32_t mod) +{ + uint32_t h = (uint32_t)key; + h ^= (h >> 20) ^ (h >> 12); + h ^= (h >> 7) ^ (h >> 4); + return h & (mod - 1); +} + +nghttp2_map_entry *http2_map_find(nghttp2_map *map, key_type key) +{ + uint32_t h; + nghttp2_map_entry *entry; + + h = hash(key, map->tablelen); + for (entry = map->table[h]; entry; entry = entry->next) + { + if (entry->key == key) + { + return entry; + } + } + + return NULL; +} + +nghttp2_stream *http2_get_stream_by_stream_id(nghttp2_session *session, int32_t stream_id) +{ + nghttp2_stream *stream; + + stream = (nghttp2_stream *)http2_map_find(&session->streams, stream_id); + + if (stream == NULL || (stream->flags & NGHTTP2_STREAM_FLAG_CLOSED) || stream->state == NGHTTP2_STREAM_IDLE) + { + return NULL; + } + + return stream; +} + /*up stream */ -static struct tfe_h2_session * -TAILQ_LIST_FIND(struct tfe_h2_stream *h2_stream_info, int32_t stream_id) +static struct tfe_h2_session *TAILQ_LIST_FIND(struct tfe_h2_stream *h2_stream_info, int32_t stream_id) { struct tfe_h2_session *stream = NULL, *_next_stream = NULL; @@ -78,8 +116,7 @@ TAILQ_LIST_FIND(struct tfe_h2_stream *h2_stream_info, int32_t stream_id) return stream; } -static void -tfe_h2_header_add_field(struct tfe_h2_header *h2_header, const struct http_field_name * field, const char * value, int at_tail) +static void tfe_h2_header_add_field(struct tfe_h2_header *h2_header, const struct http_field_name * field, const char * value, int at_tail) { struct tfe_h2_field *peer_h2_field = ALLOC(struct tfe_h2_field, 1); peer_h2_field->field = http_field_name_duplicate(field); @@ -102,8 +139,7 @@ tfe_h2_header_add_field(struct tfe_h2_header *h2_header, const struct http_field TAILQ_INSERT_HEAD(&h2_header->h2_field_list, peer_h2_field, next); } -static nghttp2_nv* -tfe_h2_header_modify_field(struct tfe_h2_header *header, nghttp2_nv *hdrs, const char *field_name, const char *filed_value) +static nghttp2_nv* tfe_h2_header_modify_field(struct tfe_h2_header *header, nghttp2_nv *hdrs, const char *field_name, const char *filed_value) { int nvlen = 0; struct tfe_h2_field *h2_field = NULL, *peer_h2_field = NULL; @@ -128,8 +164,7 @@ tfe_h2_header_modify_field(struct tfe_h2_header *header, nghttp2_nv *hdrs, const return hdrs; } -static inline void -headers_init(struct tfe_h2_header *header) +static inline void headers_init(struct tfe_h2_header *header) { header->nvlen = 0; header->flag = 0; @@ -150,8 +185,7 @@ const char * method_idx_to_str(int encode) } } -static int -method_to_str_idx(const char * method) +static int method_to_str_idx(const char * method) { if (strcasestr(method, "gzip") != NULL) return HTTP2_CONTENT_ENCODING_GZIP; @@ -173,8 +207,7 @@ method_to_str_idx(const char * method) return HTTP2_CONTENT_ENCODING_NONE; } -static nghttp2_nv* -tfe_h2_header_convert_nv(struct tfe_h2_header *header, nghttp2_nv *hdrs) +static nghttp2_nv* tfe_h2_header_convert_nv(struct tfe_h2_header *header, nghttp2_nv *hdrs) { int nvlen = 0; struct tfe_h2_field *h2_field = NULL, *peer_h2_field = NULL; @@ -190,22 +223,21 @@ tfe_h2_header_convert_nv(struct tfe_h2_header *header, nghttp2_nv *hdrs) return hdrs; } -static enum tfe_http_std_method -nghttp2_get_method(struct tfe_h2_half_private *half_private) +static enum tfe_http_std_method http2_get_method(struct tfe_h2_half_private *half_private) { struct tfe_http_req_spec *req_spec = &(half_private->half_public.req_spec); return req_spec->method; } -static nghttp2_session * tfe_h2_stream_get_nghttp2_session(struct tfe_h2_stream *connection, enum tfe_conn_dir dir) +static nghttp2_session * tfe_h2_stream_get_http2_session(struct tfe_h2_stream *connection, enum tfe_conn_dir dir) { - return (dir==CONN_DIR_UPSTREAM?connection->as_server:connection->as_client); + return (dir==CONN_DIR_UPSTREAM?connection->http2_server_handle:connection->http2_client_handle); } -static nghttp2_session * tfe_h2_stream_get_nghttp2_peer_session(struct tfe_h2_stream *connection, enum tfe_conn_dir dir) +static nghttp2_session * tfe_h2_stream_get_http2_peer_session(struct tfe_h2_stream *connection, enum tfe_conn_dir dir) { - return (dir==CONN_DIR_UPSTREAM?connection->as_client: connection->as_server); + return (dir==CONN_DIR_UPSTREAM?connection->http2_client_handle: connection->http2_server_handle); } static struct tfe_h2_half_private *tfe_h2_stream_get_half(struct tfe_h2_session *h2_session, enum tfe_conn_dir dir) @@ -213,9 +245,7 @@ static struct tfe_h2_half_private *tfe_h2_stream_get_half(struct tfe_h2_session return (dir==CONN_DIR_UPSTREAM?h2_session->resp: h2_session->req); } -static nghttp2_settings_entry* -nghttp2_iv_packet(nghttp2_settings settings, - nghttp2_settings_entry *out_iv) +static nghttp2_settings_entry* http2_iv_packet(nghttp2_settings settings, nghttp2_settings_entry *out_iv) { int i = 0; @@ -228,8 +258,7 @@ nghttp2_iv_packet(nghttp2_settings settings, return out_iv; } -static void -delete_nv_packet_data(struct tfe_h2_header *header) +static void delete_nv_packet_data(struct tfe_h2_header *header) { struct tfe_h2_field *h2_filed=NULL, *peer_h2_filed=NULL; @@ -255,8 +284,7 @@ delete_nv_packet_data(struct tfe_h2_header *header) header->flag = 0; } -static int event_dispatch_cb(struct tfe_h2_half_private * half_private, - enum tfe_http_event ev, const unsigned char * data, size_t len, void * user) +static int event_dispatch_cb(struct tfe_h2_half_private * half_private, enum tfe_http_event ev, const unsigned char * data, size_t len, void * user) { struct user_event_dispatch *event = (struct user_event_dispatch *)user; struct http_frame_session_ctx *frame_ctx = half_private->frame_ctx; @@ -267,8 +295,7 @@ static int event_dispatch_cb(struct tfe_h2_half_private * half_private, return 0; } -void half_set_callback(struct tfe_h2_half_private * half_private, - void * user, void (* user_deleter)(void *)) +void half_set_callback(struct tfe_h2_half_private * half_private, void * user, void (* user_deleter)(void *)) { half_private->event_cb = event_dispatch_cb; half_private->event_cb_user = user; @@ -328,8 +355,7 @@ int h2_half_ops_field_write(struct tfe_http_half * half, const struct http_field return 0; } -static struct tfe_http_half * -h2_half_ops_allow_write(const struct tfe_http_half * half) +static struct tfe_http_half *h2_half_ops_allow_write(const struct tfe_http_half * half) { return (struct tfe_http_half *) half; } @@ -357,8 +383,7 @@ const char * h2_half_ops_field_iterate(const struct tfe_http_half * half, void * return (const char *)(*h2_filed)->nv.value; } -static int -h2_half_ops_append_body(struct tfe_http_half * half, char * buff, size_t size, int flag) +static int h2_half_ops_append_body(struct tfe_http_half * half, char * buff, size_t size, int flag) { int xret = -1; struct tfe_h2_half_private * resp = nghttp2_to_half_private(half); @@ -522,8 +547,7 @@ struct tfe_http_half_ops h2_half_ops = .ops_free = h2_half_ops_free }; -static struct tfe_http_session* -h2_ops_allow_write(const struct tfe_http_session * session) +static struct tfe_http_session* h2_ops_allow_write(const struct tfe_http_session * session) { struct tfe_h2_session *stream_data = nghttp2_to_stream_data((struct tfe_http_session *)session); @@ -584,9 +608,7 @@ void h2_ops_response_set(struct tfe_http_session * session, struct tfe_http_half stream_data->plugin_built_resp = half_user; } -static struct tfe_h2_half_private* -tfe_half_private_init(enum tfe_http_direction direction, int32_t stream_id, - nghttp2_session *session) +static struct tfe_h2_half_private* tfe_half_private_init(enum tfe_http_direction direction, int32_t stream_id, nghttp2_session *session) { struct tfe_h2_half_private *half_private = ALLOC(struct tfe_h2_half_private, 1); assert(half_private); @@ -611,8 +633,7 @@ tfe_half_private_init(enum tfe_http_direction direction, int32_t stream_id, return half_private; } -struct tfe_http_half * h2_ops_request_create(struct tfe_http_session * session, - enum tfe_http_std_method method, const char * uri) +struct tfe_http_half * h2_ops_request_create(struct tfe_http_session * session, enum tfe_http_std_method method, const char * uri) { struct tfe_h2_half_private * req = tfe_half_private_init(TFE_HTTP_REQUEST, 0, NULL); @@ -642,7 +663,7 @@ void h2_ops_kill(struct tfe_http_session * session) h2_stream->kill_signal = 1; } -struct tfe_http_session_ops nghttp2_session_ops = +struct tfe_http_session_ops http2_session_ops = { .ops_allow_write = h2_ops_allow_write, .ops_detach = h2_ops_detach, @@ -656,12 +677,8 @@ struct tfe_http_session_ops nghttp2_session_ops = .ops_response_create = h2_ops_response_create }; -static ssize_t -no_data_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, - uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) +static ssize_t no_data_read_callback(nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, + uint32_t *data_flags, nghttp2_data_source *source, void *user_data) { (void)session; (void)stream_id; @@ -674,12 +691,8 @@ no_data_read_callback(nghttp2_session *session, int32_t stream_id, return 0; } -static ssize_t -upstream_read_callback(nghttp2_session *session, int32_t stream_id, - uint8_t *buf, size_t length, - uint32_t *data_flags, - nghttp2_data_source *source, - void *user_data) +static ssize_t upstream_read_callback(nghttp2_session *session, int32_t stream_id, uint8_t *buf, size_t length, + uint32_t *data_flags, nghttp2_data_source *source,void *user_data) { unsigned char *input = NULL; ssize_t datalen = 0, inputlen=0; @@ -710,9 +723,27 @@ upstream_read_callback(nghttp2_session *session, int32_t stream_id, return datalen; } -static enum tfe_stream_action -nghttp2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session) +static int http_session_update_window_size(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session, int32_t buffer_length) +{ + nghttp2_stream *stream = http2_get_stream_by_stream_id(h2_stream_info->http2_server_handle, h2_session->ngh2_stream_id); + if(stream == NULL) + { + return 0; + } + + if(stream->remote_window_size < buffer_length) + { + stream->remote_window_size += ((buffer_length - stream->remote_window_size) + 9); + } + int32_t remote_window_size = nghttp2_session_get_remote_window_size(h2_stream_info->http2_server_handle); + if(remote_window_size < buffer_length) + { + h2_stream_info->http2_server_handle->remote_window_size += ((buffer_length - remote_window_size) + 9); + } + return 1; +} + +static enum tfe_stream_action http2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session) { int rv = -1; struct tfe_h2_header *h2_header = NULL; @@ -735,23 +766,25 @@ nghttp2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info, snprintf(value, sizeof(value), "%d", pangu_resp->method_or_status); tfe_http_nonstd_field_write(&pangu_resp->half_public, ":status", NULL); tfe_h2_header_add_field(h2_header, &field, (const char *)value, 0); + pangu_resp->message_state = H2_READ_STATE_COMPLETE; struct tfe_h2_payload *body = &pangu_resp->h2_payload; body->flags |= NGHTTP2_FLAG_END_STREAM; char str_sz_evbuf_body[TFE_STRING_MAX]; snprintf(str_sz_evbuf_body, sizeof(str_sz_evbuf_body) - 1, "%lu", evbuffer_get_length(body->evbuf_body)); - const static struct http_field_name cont_field = {TFE_HTTP_CONT_LENGTH, NULL}; + const static struct http_field_name cont_field = {TFE_HTTP_CONT_LENGTH, NULL}; tfe_http_field_write(&pangu_resp->half_public, &cont_field, NULL); tfe_http_field_write(&pangu_resp->half_public, &cont_field, str_sz_evbuf_body); if (body->gzip != HTTP2_CONTENT_ENCODING_NONE) { const static struct http_field_name encoding_field = {TFE_HTTP_CONT_ENCODING, NULL}; - const char *content_encoding = method_idx_to_str(body->gzip); + const char *content_encoding = method_idx_to_str(body->gzip); tfe_http_field_write(&pangu_resp->half_public, &encoding_field, NULL); tfe_http_field_write(&pangu_resp->half_public, &encoding_field, content_encoding); } + http_session_update_window_size(h2_stream_info, h2_session, evbuffer_get_length(body->evbuf_body)); nghttp2_data_provider data_prd; data_prd.source.ptr = (void *)body; @@ -760,7 +793,7 @@ nghttp2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info, nghttp2_nv hdrs[h2_header->nvlen]; /*Adapt Http uri Settings**/ - rv = nghttp2_submit_response(h2_stream_info->as_server, h2_session->ngh2_stream_id, tfe_h2_header_convert_nv(h2_header, hdrs), + rv = nghttp2_submit_response(h2_stream_info->http2_server_handle, h2_session->ngh2_stream_id, tfe_h2_header_convert_nv(h2_header, hdrs), h2_header->nvlen, &data_prd); if (rv != 0){ return ACTION_FORWARD_DATA; @@ -769,9 +802,7 @@ nghttp2_frame_submit_built_resp(struct tfe_h2_stream *h2_stream_info, return ACTION_DROP_DATA; } -static enum tfe_stream_action -nghttp2_frame_submit_built_req(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session) +static enum tfe_stream_action http2_frame_submit_built_req(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session) { int32_t stream_id = -1; struct tfe_h2_header *h2_header = NULL; @@ -799,8 +830,8 @@ nghttp2_frame_submit_built_req(struct tfe_h2_stream *h2_stream_info, nghttp2_nv hdrs[h2_header->nvlen]; /*Adapt Http uri Settings**/ - nghttp2_session_set_next_stream_id(h2_stream_info->as_client, h2_session->ngh2_stream_id); - stream_id = nghttp2_submit_request(h2_stream_info->as_client, NULL, + nghttp2_session_set_next_stream_id(h2_stream_info->http2_client_handle, h2_session->ngh2_stream_id); + stream_id = nghttp2_submit_request(h2_stream_info->http2_client_handle, NULL, tfe_h2_header_modify_field(h2_header, hdrs, ":path", plugin_built_req->url_storage), h2_header->nvlen, &data_prd, h2_session); @@ -813,11 +844,10 @@ nghttp2_frame_submit_built_req(struct tfe_h2_stream *h2_stream_info, return ACTION_DROP_DATA; } -static void -nghttp2_submit_end_data_by_h2_half(struct tfe_h2_stream *h2_stream_info, int32_t stream_id, enum tfe_conn_dir dir) +static void http2_submit_end_data_by_h2_half(struct tfe_h2_stream *h2_stream_info, int32_t stream_id, enum tfe_conn_dir dir) { int xret = -1; - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(h2_stream_info, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(h2_stream_info, dir); nghttp2_data_provider data_provider; data_provider.read_callback = no_data_read_callback; @@ -835,21 +865,20 @@ nghttp2_submit_end_data_by_h2_half(struct tfe_h2_stream *h2_stream_info, int32_t return; } -static enum tfe_stream_action -nghttp2_submit_data_by_h2_half(struct tfe_h2_stream *connection, struct tfe_h2_session *h2_session, enum tfe_conn_dir dir, int compress_result) +static enum tfe_stream_action http2_submit_data_by_h2_half(struct tfe_h2_stream *connection, struct tfe_h2_session *h2_session, enum tfe_conn_dir dir, int compress_result) { enum tfe_stream_action stream_action = ACTION_DROP_DATA; struct tfe_h2_half_private *h2_half = tfe_h2_stream_get_half(h2_session, dir); - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(connection, dir); if (h2_session->plugin_built_resp && compress_result) { - stream_action = nghttp2_frame_submit_built_resp(connection, h2_session); + stream_action = http2_frame_submit_built_resp(connection, h2_session); } else if (h2_session->plugin_built_req && compress_result) { - stream_action = nghttp2_frame_submit_built_req(connection, h2_session); + stream_action = http2_frame_submit_built_req(connection, h2_session); } else { @@ -865,29 +894,24 @@ nghttp2_submit_data_by_h2_half(struct tfe_h2_stream *connection, struct tfe_h2_s if (rv != 0) { stream_action = ACTION_FORWARD_DATA; - //printf("Fatal server submit data error: %s\n", nghttp2_strerror(rv)); } } return stream_action; } -typedef int (*nghttp2_frame_callback) (struct tfe_h2_stream *, const nghttp2_frame *, - enum tfe_conn_dir dir); +typedef int (*http2_frame_callback) (struct tfe_h2_stream *, const nghttp2_frame *, enum tfe_conn_dir dir); -typedef int (*nghttp2_callback) (nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, - size_t namelen, const uint8_t *value, +typedef int (*http2_callback) (nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir); -static int -nghttp2_submit_frame_priority(struct tfe_h2_stream *connection,const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_priority(struct tfe_h2_stream *connection,const nghttp2_frame *frame, enum tfe_conn_dir dir) { int xret = -1; enum tfe_stream_action stream_action = ACTION_DROP_DATA; const nghttp2_priority *priority = &frame->priority; - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(connection, dir); int rv = nghttp2_submit_priority(ngh2_session, priority->hd.flags, priority->hd.stream_id, &(priority->pri_spec)); @@ -908,16 +932,14 @@ nghttp2_submit_frame_priority(struct tfe_h2_stream *connection,const nghttp2_fra return 0; } -static int -nghttp2_submit_frame_rst_stream(struct tfe_h2_stream *connection,const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_rst_stream(struct tfe_h2_stream *connection,const nghttp2_frame *frame, enum tfe_conn_dir dir) { int xret = -1; enum tfe_stream_action stream_action = ACTION_DROP_DATA; const nghttp2_rst_stream *rst_stream = &frame->rst_stream; - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(connection, dir); int rv = nghttp2_submit_rst_stream(ngh2_session, rst_stream->hd.flags, rst_stream->hd.stream_id, rst_stream->error_code); @@ -937,9 +959,7 @@ nghttp2_submit_frame_rst_stream(struct tfe_h2_stream *connection,const nghttp2_f return 0; } -static int -nghttp2_submit_frame_settings(struct tfe_h2_stream *connection,const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_settings(struct tfe_h2_stream *connection,const nghttp2_frame *frame, enum tfe_conn_dir dir) { int xret = -1, rv = -1; nghttp2_settings_entry iv[6] = {0}; @@ -947,21 +967,18 @@ nghttp2_submit_frame_settings(struct tfe_h2_stream *connection,const nghttp2_fra nghttp2_settings settings = frame->settings; - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(connection, dir); - rv = nghttp2_submit_settings(ngh2_session, settings.hd.flags, - nghttp2_iv_packet(settings, iv), settings.niv); + rv = nghttp2_submit_settings(ngh2_session, settings.hd.flags, http2_iv_packet(settings, iv), settings.niv); if (rv != 0) { stream_action = ACTION_FORWARD_DATA; - TFE_LOG_ERROR(logger()->handle, "dir(%d), Submit settings error: %s\n", - dir, nghttp2_strerror(rv)); + TFE_LOG_ERROR(logger()->handle, "dir(%d), Submit settings error: %s\n", dir, nghttp2_strerror(rv)); return 0; } xret = nghttp2_session_send(ngh2_session); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; - TFE_LOG_ERROR(logger()->handle, "dir(%d), Fatal send error: %s\n", - dir, nghttp2_strerror(xret)); + TFE_LOG_ERROR(logger()->handle, "dir(%d), Fatal send error: %s\n", dir, nghttp2_strerror(xret)); } connection->stream_action = stream_action; #ifdef TFE_LOG_HTTP2 @@ -971,16 +988,14 @@ nghttp2_submit_frame_settings(struct tfe_h2_stream *connection,const nghttp2_fra return 0; } -static int -nghttp2_submit_frame_ping(struct tfe_h2_stream *connection,const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_ping(struct tfe_h2_stream *connection,const nghttp2_frame *frame, enum tfe_conn_dir dir) { int xret = -1 ,rv = -1; enum tfe_stream_action stream_action = ACTION_DROP_DATA; const nghttp2_ping *ping = &frame->ping; - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(connection, dir); rv = nghttp2_submit_ping(ngh2_session, ping->hd.flags, ping->opaque_data); if (rv != 0) @@ -998,8 +1013,7 @@ nghttp2_submit_frame_ping(struct tfe_h2_stream *connection,const nghttp2_frame * return 0; } -void -nghttp2_write_access_log(struct tfe_h2_session *h2_session, const char * str_stream_info) +void http2_write_access_log(struct tfe_h2_session *h2_session, const char * str_stream_info) { /* Request */ struct tfe_h2_half_private *req = h2_session->req; @@ -1033,9 +1047,7 @@ nghttp2_write_access_log(struct tfe_h2_session *h2_session, const char * str_str free(access_log); } -void delete_http2_stream_data(struct tfe_h2_session *h2_session, - const struct tfe_stream *tf_stream, - int body_flag) +void delete_http2_stream_data(struct tfe_h2_session *h2_session, const struct tfe_stream *tf_stream, int body_flag) { delete_stream_half_data(&h2_session->req, body_flag, CONN_DIR_DOWNSTREAM); @@ -1046,7 +1058,7 @@ void delete_http2_stream_data(struct tfe_h2_session *h2_session, delete_stream_half_data(&h2_session->plugin_built_resp, body_flag, CONN_DIR_UPSTREAM); } -void nghttp2_disect_goaway(struct tfe_h2_stream *h2_stream_info) +void http2_disect_goaway(struct tfe_h2_stream *h2_stream_info) { unsigned int thread_id = h2_stream_info->thread_id; const struct tfe_stream * stream = h2_stream_info->tf_stream; @@ -1065,26 +1077,24 @@ void nghttp2_disect_goaway(struct tfe_h2_stream *h2_stream_info) free(h2_session); h2_session = NULL; } - if (h2_stream_info->as_client){ - nghttp2_session_del(h2_stream_info->as_client); - h2_stream_info->as_client = NULL; + if (h2_stream_info->http2_client_handle){ + nghttp2_session_del(h2_stream_info->http2_client_handle); + h2_stream_info->http2_client_handle = NULL; } - if (h2_stream_info->as_server){ - nghttp2_session_del(h2_stream_info->as_server); - h2_stream_info->as_server = NULL; + if (h2_stream_info->http2_server_handle){ + nghttp2_session_del(h2_stream_info->http2_server_handle); + h2_stream_info->http2_server_handle = NULL; } } -static int -nghttp2_submit_frame_goaway(struct tfe_h2_stream *connection, const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_goaway(struct tfe_h2_stream *connection, const nghttp2_frame *frame, enum tfe_conn_dir dir) { int xret = -1; enum tfe_stream_action stream_action = ACTION_DROP_DATA; char *error = NULL; size_t eroro_len=0; const nghttp2_goaway *goaway = &frame->goaway; - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(connection, dir); int rv = nghttp2_submit_goaway(ngh2_session, goaway->hd.flags, goaway->last_stream_id, goaway->error_code, goaway->opaque_data, goaway->opaque_data_len); @@ -1112,16 +1122,14 @@ finish: return 0; } -static int -nghttp2_submit_frame_window_update(struct tfe_h2_stream *connection,const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_window_update(struct tfe_h2_stream *connection,const nghttp2_frame *frame, enum tfe_conn_dir dir) { int xret = -1; enum tfe_stream_action stream_action = ACTION_DROP_DATA; const nghttp2_window_update *window_update = &(frame->window_update); - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(connection, dir); int rv = nghttp2_submit_window_update(ngh2_session, window_update->hd.flags,window_update->hd.stream_id, window_update->window_size_increment); @@ -1141,9 +1149,7 @@ nghttp2_submit_frame_window_update(struct tfe_h2_stream *connection,const nghttp return 0; } -static int -nghttp2_submit_header_by_not_modify(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session) +static int http2_submit_header_by_not_modify(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session) { int xret = -1; int32_t stream_id = 0; @@ -1157,7 +1163,7 @@ nghttp2_submit_header_by_not_modify(struct tfe_h2_stream *h2_stream_info, } nghttp2_nv hdrs[headers.nvlen]; - stream_id = nghttp2_submit_headers(h2_stream_info->as_server, headers.flag, + stream_id = nghttp2_submit_headers(h2_stream_info->http2_server_handle, headers.flag, h2_session->ngh2_stream_id, NULL, tfe_h2_header_convert_nv(&headers, hdrs), headers.nvlen, h2_session); if (stream_id < 0){ @@ -1166,7 +1172,7 @@ nghttp2_submit_header_by_not_modify(struct tfe_h2_stream *h2_stream_info, } if (stream_action == ACTION_DROP_DATA){ - xret = nghttp2_session_send(h2_stream_info->as_server); + xret = nghttp2_session_send(h2_stream_info->http2_server_handle); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s, %d\n",nghttp2_strerror(xret), __LINE__); @@ -1176,15 +1182,13 @@ nghttp2_submit_header_by_not_modify(struct tfe_h2_stream *h2_stream_info, return 0; } -static int -nghttp2_submit_complete_data(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session, enum tfe_conn_dir dir) +static int http2_submit_complete_data(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session, enum tfe_conn_dir dir) { int xret = -1; enum tfe_stream_action stream_action = ACTION_DROP_DATA; struct tfe_h2_half_private *h2_half = tfe_h2_stream_get_half(h2_session, dir); - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(h2_stream_info, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(h2_stream_info, dir); enum tfe_http_event http_body_event = (dir==CONN_DIR_UPSTREAM?EV_HTTP_RESP_BODY_END: EV_HTTP_REQ_BODY_END); @@ -1208,7 +1212,7 @@ nghttp2_submit_complete_data(struct tfe_h2_stream *h2_stream_info, h2_half->body_state = H2_READ_STATE_COMPLETE; h2_half->message_state = H2_READ_STATE_COMPLETE; - stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, dir, 1); + stream_action = http2_submit_data_by_h2_half(h2_stream_info, h2_session, dir, 1); if (stream_action == ACTION_DROP_DATA) { xret = nghttp2_session_send(ngh2_session); @@ -1224,17 +1228,15 @@ nghttp2_submit_complete_data(struct tfe_h2_stream *h2_stream_info, return 1; } -static int -nghttp2_submit_frame_data(struct tfe_h2_stream *h2_stream_info,const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_data(struct tfe_h2_stream *h2_stream_info,const nghttp2_frame *frame, enum tfe_conn_dir dir) { struct tfe_h2_session *h2_session = NULL; - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_peer_session(h2_stream_info, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_peer_session(h2_stream_info, dir); h2_session = (struct tfe_h2_session *)nghttp2_session_get_stream_user_data(ngh2_session, frame->hd.stream_id); if (h2_session == NULL) { - nghttp2_submit_end_data_by_h2_half(h2_stream_info, frame->hd.stream_id, dir); + http2_submit_end_data_by_h2_half(h2_stream_info, frame->hd.stream_id, dir); h2_stream_info->stream_action = ACTION_DROP_DATA; return 0; } @@ -1242,7 +1244,7 @@ nghttp2_submit_frame_data(struct tfe_h2_stream *h2_stream_info,const nghttp2_fra /*HEAD STREMA_END + DATA(9)**/ if (h2_half == NULL) { - nghttp2_submit_end_data_by_h2_half(h2_stream_info, frame->hd.stream_id, dir); + http2_submit_end_data_by_h2_half(h2_stream_info, frame->hd.stream_id, dir); h2_stream_info->stream_action = ACTION_DROP_DATA; return 0; } @@ -1252,21 +1254,20 @@ nghttp2_submit_frame_data(struct tfe_h2_stream *h2_stream_info,const nghttp2_fra h2_half->h2_payload.padlen = frame->data.padlen; if (h2_half->body_state != H2_READ_STATE_COMPLETE){ - nghttp2_submit_complete_data(h2_stream_info, h2_session, dir); + http2_submit_complete_data(h2_stream_info, h2_session, dir); } } return 0; } -static int tfe_half_session_init(struct tfe_h2_session *h2_session, int32_t stream_id, - enum tfe_http_direction direction) +static int tfe_half_session_init(struct tfe_h2_session *h2_session, int32_t stream_id, enum tfe_http_direction direction) { struct tfe_http_session *tfe_session = &h2_session->tfe_session; tfe_session->major_version = 2; if (direction == TFE_HTTP_REQUEST){ struct tfe_h2_half_private *req = h2_session->req; - tfe_session->ops = &nghttp2_session_ops; + tfe_session->ops = &http2_session_ops; tfe_session->req = &req->half_public; tfe_session->session_id = stream_id; @@ -1279,9 +1280,7 @@ static int tfe_half_session_init(struct tfe_h2_session *h2_session, int32_t stre return 0; } -static void -upstream_create_req(struct tfe_h2_stream *h2_stream_info, nghttp2_session *as_server, - struct tfe_h2_session *h2_session, int32_t stream_id) +static void upstream_create_req(struct tfe_h2_stream *h2_stream_info, nghttp2_session *as_server, struct tfe_h2_session *h2_session, int32_t stream_id) { struct user_event_dispatch *event = NULL; struct tfe_h2_half_private *half_private = NULL; @@ -1319,9 +1318,7 @@ finish: return; } -static enum tfe_stream_action -nghttp2_server_frame_submit_push_promise(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session) +static enum tfe_stream_action http2_server_frame_submit_push_promise(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session) { int32_t stream_id = -1; struct tfe_h2_header *headers = NULL; @@ -1342,7 +1339,7 @@ nghttp2_server_frame_submit_push_promise(struct tfe_h2_stream *h2_stream_info, assert(peer_h2_stream); nghttp2_nv hdrs[headers->nvlen]; - stream_id = nghttp2_submit_push_promise(h2_stream_info->as_server, headers->flag, + stream_id = nghttp2_submit_push_promise(h2_stream_info->http2_server_handle, headers->flag, h2_session->ngh2_stream_id, tfe_h2_header_convert_nv(headers, hdrs), headers->nvlen, peer_h2_stream); if (stream_id < 0){ @@ -1351,7 +1348,7 @@ nghttp2_server_frame_submit_push_promise(struct tfe_h2_stream *h2_stream_info, TFE_STREAM_LOG_ERROR(h2_session, "Failed to submit push promise: %s", nghttp2_strerror(stream_id)); goto finish; } - upstream_create_req(h2_stream_info, h2_stream_info->as_server, peer_h2_stream, stream_id); + upstream_create_req(h2_stream_info, h2_stream_info->http2_server_handle, peer_h2_stream, stream_id); /*clean header message **/ delete_nv_packet_data(headers); @@ -1360,9 +1357,7 @@ finish: return stream_action; } -static int -nghttp2_submit_frame_push_promise(struct tfe_h2_stream *h2_stream_info,const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_push_promise(struct tfe_h2_stream *h2_stream_info,const nghttp2_frame *frame, enum tfe_conn_dir dir) { int xret = -1; struct tfe_h2_session *h2_session = NULL; @@ -1371,7 +1366,7 @@ nghttp2_submit_frame_push_promise(struct tfe_h2_stream *h2_stream_info,const ngh if (dir == CONN_DIR_DOWNSTREAM) goto finish; - h2_session = (struct tfe_h2_session *)nghttp2_session_get_stream_user_data(h2_stream_info->as_client, + h2_session = (struct tfe_h2_session *)nghttp2_session_get_stream_user_data(h2_stream_info->http2_client_handle, frame->hd.stream_id); if (!h2_session){ TFE_LOG_ERROR(logger()->handle, "Upstream id %d, can't find stream information(addr = %p)", @@ -1379,9 +1374,9 @@ nghttp2_submit_frame_push_promise(struct tfe_h2_stream *h2_stream_info,const ngh goto finish; } - stream_action = nghttp2_server_frame_submit_push_promise(h2_stream_info, h2_session); + stream_action = http2_server_frame_submit_push_promise(h2_stream_info, h2_session); if (stream_action == ACTION_DROP_DATA){ - xret = nghttp2_session_send(h2_stream_info->as_server); + xret = nghttp2_session_send(h2_stream_info->http2_server_handle); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; TFE_LOG_ERROR(logger()->handle, "dir(%d), Fatal send error: %s\n", @@ -1398,9 +1393,7 @@ finish: } #ifdef TFE_CACHE -static int -suspend_start(struct tfe_h2_session *h2_session, - struct tfe_h2_half_private *half, const struct tfe_stream *stream) +static int suspend_start(struct tfe_h2_session *h2_session, struct tfe_h2_half_private *half, const struct tfe_stream *stream) { if (h2_session->cache.spd_valid != 1){ return 0; @@ -1423,8 +1416,7 @@ suspend_start(struct tfe_h2_session *h2_session, } #endif -static void -fill_resp_spec_from_handle(struct tfe_h2_half_private *half_private) +static void fill_resp_spec_from_handle(struct tfe_h2_half_private *half_private) { struct tfe_h2_field *h2_field = NULL, *peer_h2_field = NULL; struct tfe_h2_header *header = &half_private->header; @@ -1451,7 +1443,7 @@ fill_resp_spec_from_handle(struct tfe_h2_half_private *half_private) return; } -int nghttp2_write_log(struct tfe_h2_session *h2_session, const char * str_stream_info, int dir) +int http2_write_log(struct tfe_h2_session *h2_session, const char * str_stream_info, int dir) { /* Request */ struct tfe_h2_half_private *req = h2_session->req; @@ -1491,9 +1483,7 @@ int nghttp2_write_log(struct tfe_h2_session *h2_session, const char * str_stream return 0; } -static enum tfe_stream_action -nghttp2_submit_built_response(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session) +static enum tfe_stream_action http2_submit_built_response(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session) { int xret = -1; char value[128] = {0}; @@ -1506,10 +1496,10 @@ nghttp2_submit_built_response(struct tfe_h2_stream *h2_stream_info, snprintf(value, sizeof(value), "tfe/%s", tfe_version()); tfe_h2_header_add_field(&resp->header, &field, (const char *)value, 0); - stream_action = nghttp2_frame_submit_built_resp(h2_stream_info, h2_session); + stream_action = http2_frame_submit_built_resp(h2_stream_info, h2_session); if (stream_action == ACTION_DROP_DATA) { - xret = nghttp2_session_send(h2_stream_info->as_server); + xret = nghttp2_session_send(h2_stream_info->http2_server_handle); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; TFE_LOG_ERROR(logger()->handle, "Fatal downstream send error: %s\n", @@ -1523,9 +1513,7 @@ nghttp2_submit_built_response(struct tfe_h2_stream *h2_stream_info, return stream_action; } -static enum tfe_stream_action -nghttp2_server_frame_submit_header(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session) +static enum tfe_stream_action http2_server_frame_submit_header(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session) { int32_t xret = 0; struct tfe_h2_header *headers = NULL; @@ -1536,7 +1524,7 @@ nghttp2_server_frame_submit_header(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_payload *h2_payload = &(h2_session->plugin_built_resp->h2_payload); if (h2_payload->evbuf_body != NULL && (evbuffer_get_length(h2_payload->evbuf_body) > 0)) { - stream_action = nghttp2_submit_built_response(h2_stream_info, h2_session); + stream_action = http2_submit_built_response(h2_stream_info, h2_session); } else { @@ -1553,7 +1541,7 @@ nghttp2_server_frame_submit_header(struct tfe_h2_stream *h2_stream_info, return ACTION_FORWARD_DATA; } nghttp2_nv hdrs[headers->nvlen]; - xret = nghttp2_submit_headers(h2_stream_info->as_server, headers->flag, + xret = nghttp2_submit_headers(h2_stream_info->http2_server_handle, headers->flag, h2_session->ngh2_stream_id, NULL, tfe_h2_header_convert_nv(headers, hdrs), headers->nvlen, h2_session); if (xret < 0){ @@ -1563,8 +1551,7 @@ nghttp2_server_frame_submit_header(struct tfe_h2_stream *h2_stream_info, return stream_action; } -static int -nghttp2_server_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t stream_id) +static int http2_server_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t stream_id) { int xret = -1; struct tfe_h2_half_private *resp = NULL; @@ -1572,8 +1559,7 @@ nghttp2_server_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t strea enum tfe_stream_action stream_action = ACTION_DROP_DATA; - h2_session = (struct tfe_h2_session *)nghttp2_session_get_stream_user_data(h2_stream_info->as_client, - stream_id); + h2_session = (struct tfe_h2_session *)nghttp2_session_get_stream_user_data(h2_stream_info->http2_client_handle, stream_id); if (!h2_session) { stream_action = ACTION_FORWARD_DATA; @@ -1601,12 +1587,12 @@ nghttp2_server_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t strea // int googletest, h2_stream_info->tf_stream is NULL if (h2_session && h2_stream_info && h2_stream_info->tf_stream) { - nghttp2_write_log(h2_session, h2_stream_info->tf_stream->str_stream_info, CONN_DIR_UPSTREAM); + http2_write_log(h2_session, h2_stream_info->tf_stream->str_stream_info, CONN_DIR_UPSTREAM); } - stream_action = nghttp2_server_frame_submit_header(h2_stream_info, h2_session); + stream_action = http2_server_frame_submit_header(h2_stream_info, h2_session); if (stream_action == ACTION_DROP_DATA){ - xret = nghttp2_session_send(h2_stream_info->as_server); + xret = nghttp2_session_send(h2_stream_info->http2_server_handle); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s\n", nghttp2_strerror(xret)); @@ -1651,9 +1637,7 @@ static void fill_req_spec_from_handle(struct tfe_h2_half_private *half_private) } #ifdef TFE_CACHE -static int -suspend_stop(struct tfe_h2_session *h2_session, - const struct tfe_stream *tf_stream, enum tfe_conn_dir dir) +static int suspend_stop(struct tfe_h2_session *h2_session, const struct tfe_stream *tf_stream, enum tfe_conn_dir dir) { int xret = -1; @@ -1667,8 +1651,7 @@ suspend_stop(struct tfe_h2_session *h2_session, } #endif -static void -downstream_create_resp(struct tfe_h2_session *h2_session, nghttp2_session *as_client, +static void downstream_create_resp(struct tfe_h2_session *h2_session, nghttp2_session *as_client, nghttp2_session *as_server, const struct tfe_stream *tf_stream, unsigned int thread_id) { struct user_event_dispatch *event = NULL; @@ -1693,9 +1676,7 @@ finish: return; } -static enum tfe_stream_action -nghttp2_client_frame_submit_header(struct tfe_h2_stream *h2_stream_info, - struct tfe_h2_session *h2_session) +static enum tfe_stream_action http2_client_frame_submit_header(struct tfe_h2_stream *h2_stream_info, struct tfe_h2_session *h2_session) { int32_t stream_id = -1; struct tfe_h2_header *headers = NULL; @@ -1708,12 +1689,12 @@ nghttp2_client_frame_submit_header(struct tfe_h2_stream *h2_stream_info, return ACTION_FORWARD_DATA; } /*Create C' half_private_resp**/ - downstream_create_resp(h2_session, h2_stream_info->as_client, h2_stream_info->as_server, + downstream_create_resp(h2_session, h2_stream_info->http2_client_handle, h2_stream_info->http2_server_handle, h2_stream_info->tf_stream, h2_stream_info->thread_id); /*Adapt inconsistent client and server stream ids ***/ if (h2_session->plugin_built_resp) { - stream_action = nghttp2_submit_built_response(h2_stream_info, h2_session); + stream_action = http2_submit_built_response(h2_stream_info, h2_session); return stream_action; } headers = &req->header; @@ -1722,7 +1703,7 @@ nghttp2_client_frame_submit_header(struct tfe_h2_stream *h2_stream_info, return ACTION_FORWARD_DATA; } - method = nghttp2_get_method(h2_session->req); + method = http2_get_method(h2_session->req); if (method == (enum tfe_http_std_method)NGHTTP2_METHOD_POST || method == (enum tfe_http_std_method)NGHTTP2_METHOD_PUT) { if (h2_session->plugin_built_req != NULL) @@ -1733,8 +1714,8 @@ nghttp2_client_frame_submit_header(struct tfe_h2_stream *h2_stream_info, } nghttp2_nv hdrs[headers->nvlen]; /**Register the stream id as -1 and read the next stream id */ - nghttp2_session_set_next_stream_id(h2_stream_info->as_client, h2_session->ngh2_stream_id); - stream_id = nghttp2_submit_headers(h2_stream_info->as_client, headers->flag, + nghttp2_session_set_next_stream_id(h2_stream_info->http2_client_handle, h2_session->ngh2_stream_id); + stream_id = nghttp2_submit_headers(h2_stream_info->http2_client_handle, headers->flag, -1, NULL, tfe_h2_header_modify_field(headers, hdrs, ":path", req->url_storage), headers->nvlen, h2_session); @@ -1749,8 +1730,7 @@ finish: return stream_action; } -static int -nghttp2_client_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t stream_id) +static int http2_client_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t stream_id) { int xret = -1; struct tfe_h2_half_private *req = NULL; @@ -1758,7 +1738,7 @@ nghttp2_client_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t strea enum tfe_stream_action stream_action = ACTION_DROP_DATA; - h2_session = (struct tfe_h2_session *)nghttp2_session_get_stream_user_data(h2_stream_info->as_server, + h2_session = (struct tfe_h2_session *)nghttp2_session_get_stream_user_data(h2_stream_info->http2_server_handle, stream_id); if (!h2_session){ stream_action = ACTION_FORWARD_DATA; @@ -1774,11 +1754,11 @@ nghttp2_client_submit_header(struct tfe_h2_stream *h2_stream_info, int32_t strea // int googletest, h2_stream_info->tf_stream is NULL if (h2_session && h2_stream_info && h2_stream_info->tf_stream) { - nghttp2_write_log(h2_session, h2_stream_info->tf_stream->str_stream_info, CONN_DIR_DOWNSTREAM); + http2_write_log(h2_session, h2_stream_info->tf_stream->str_stream_info, CONN_DIR_DOWNSTREAM); } - stream_action = nghttp2_client_frame_submit_header(h2_stream_info, h2_session); + stream_action = http2_client_frame_submit_header(h2_stream_info, h2_session); if (stream_action == ACTION_DROP_DATA){ - xret = nghttp2_session_send(h2_stream_info->as_client); + xret = nghttp2_session_send(h2_stream_info->http2_client_handle); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; TFE_LOG_ERROR(logger()->handle, "Fatal downstream send error: %s\n", @@ -1793,9 +1773,7 @@ finish: return 0; } -static int -nghttp2_submit_frame_header(struct tfe_h2_stream *h2_stream_info,const nghttp2_frame *frame, - enum tfe_conn_dir dir) +static int http2_submit_frame_header(struct tfe_h2_stream *h2_stream_info,const nghttp2_frame *frame, enum tfe_conn_dir dir) { int xret = 0; @@ -1803,34 +1781,32 @@ nghttp2_submit_frame_header(struct tfe_h2_stream *h2_stream_info,const nghttp2_f { if (dir == CONN_DIR_UPSTREAM) { - xret = nghttp2_server_submit_header(h2_stream_info, frame->hd.stream_id); + xret = http2_server_submit_header(h2_stream_info, frame->hd.stream_id); } if (dir == CONN_DIR_DOWNSTREAM) { - xret = nghttp2_client_submit_header(h2_stream_info, frame->hd.stream_id); + xret = http2_client_submit_header(h2_stream_info, frame->hd.stream_id); } } return xret; } -nghttp2_frame_callback nghttp2_frame_callback_array[] = { - [NGHTTP2_DATA] = nghttp2_submit_frame_data, - [NGHTTP2_HEADERS] = nghttp2_submit_frame_header, - [NGHTTP2_PRIORITY] = nghttp2_submit_frame_priority, - [NGHTTP2_RST_STREAM] = nghttp2_submit_frame_rst_stream, - [NGHTTP2_SETTINGS] = nghttp2_submit_frame_settings, - [NGHTTP2_PUSH_PROMISE] = nghttp2_submit_frame_push_promise, - [NGHTTP2_PING] = nghttp2_submit_frame_ping, - [NGHTTP2_GOAWAY] = nghttp2_submit_frame_goaway, - [NGHTTP2_WINDOW_UPDATE] = nghttp2_submit_frame_window_update, +http2_frame_callback http2_frame_callback_array[] = { + [NGHTTP2_DATA] = http2_submit_frame_data, + [NGHTTP2_HEADERS] = http2_submit_frame_header, + [NGHTTP2_PRIORITY] = http2_submit_frame_priority, + [NGHTTP2_RST_STREAM] = http2_submit_frame_rst_stream, + [NGHTTP2_SETTINGS] = http2_submit_frame_settings, + [NGHTTP2_PUSH_PROMISE] = http2_submit_frame_push_promise, + [NGHTTP2_PING] = http2_submit_frame_ping, + [NGHTTP2_GOAWAY] = http2_submit_frame_goaway, + [NGHTTP2_WINDOW_UPDATE] = http2_submit_frame_window_update, [NGHTTP2_CONTINUATION] = NULL, [NGHTTP2_ALTSVC] = NULL, }; -static int -nghttp2_fill_up_header(nghttp2_session *ngh2_session, const nghttp2_frame *frame, const uint8_t *name, - size_t namelen, const uint8_t *value, size_t valuelen, - uint8_t flags, void *user_data, enum tfe_conn_dir dir) +static int http2_fill_up_header(nghttp2_session *ngh2_session, const nghttp2_frame *frame, const uint8_t *name, + size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir) { struct tfe_h2_header *h2_header = NULL; @@ -1863,10 +1839,8 @@ nghttp2_fill_up_header(nghttp2_session *ngh2_session, const nghttp2_frame *frame return 0; } -static int -nghttp2_fill_up_promise(nghttp2_session *ngh2_session, const nghttp2_frame *frame, const uint8_t *name, - size_t namelen, const uint8_t *value, - size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir) +static int http2_fill_up_promise(nghttp2_session *ngh2_session, const nghttp2_frame *frame, const uint8_t *name, + size_t namelen, const uint8_t *value,size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir) { struct tfe_h2_header *headers = NULL; struct tfe_h2_half_private *resp = NULL; @@ -1898,10 +1872,9 @@ nghttp2_fill_up_promise(nghttp2_session *ngh2_session, const nghttp2_frame *fram return 0; } -static int -nghttp2_data_send(nghttp2_session *ngh2_session, const nghttp2_frame *frame, const uint8_t *data, - size_t length, const uint8_t *value, - size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir) +static int http2_data_send(nghttp2_session *ngh2_session, const nghttp2_frame *frame, const uint8_t *data, size_t length, const uint8_t *value, + size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir) + { int ret = -1; @@ -1914,10 +1887,8 @@ nghttp2_data_send(nghttp2_session *ngh2_session, const nghttp2_frame *frame, con return (ssize_t)length; } -static int -nghttp2_on_stream_close(nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, - size_t namelen, const uint8_t *value, - size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir) +static int http2_on_stream_close(nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, + size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, void *user_data, enum tfe_conn_dir dir) { struct tfe_h2_session *h2_session = NULL; struct tfe_h2_half_private *resp = NULL; @@ -1942,7 +1913,7 @@ nghttp2_on_stream_close(nghttp2_session *session, const nghttp2_frame *frame, co if (error_code == 0 && resp->body_state != H2_READ_STATE_COMPLETE){ if (resp->body_state == H2_READ_STATE_BEGIN && h2_stream_info->stream_action != ACTION_DEFER_DATA) - nghttp2_submit_header_by_not_modify(h2_stream_info, h2_session); + http2_submit_header_by_not_modify(h2_stream_info, h2_session); goto end; } finish: @@ -1958,8 +1929,8 @@ finish: h2_session->frame_ctx = NULL; delete_http2_stream_data(h2_session, h2_stream_info->tf_stream, 1); /*The stream connection is closed, Force clear context**/ - nghttp2_session_set_stream_user_data(h2_stream_info->as_client, stream_id, NULL); - nghttp2_session_set_stream_user_data(h2_stream_info->as_server, stream_id, NULL); + nghttp2_session_set_stream_user_data(h2_stream_info->http2_client_handle, stream_id, NULL); + nghttp2_session_set_stream_user_data(h2_stream_info->http2_server_handle, stream_id, NULL); free(h2_session); h2_session = NULL; } @@ -1967,55 +1938,48 @@ end: return 0; } -nghttp2_callback nghttp2_callback_array[] = { +http2_callback http2_callback_array[] = { [NGHTTP2_DATA] = NULL, - [NGHTTP2_HEADERS] = nghttp2_fill_up_header, + [NGHTTP2_HEADERS] = http2_fill_up_header, [NGHTTP2_PRIORITY] = NULL, [NGHTTP2_RST_STREAM] = NULL, [NGHTTP2_SETTINGS] = NULL, - [NGHTTP2_PUSH_PROMISE] = nghttp2_fill_up_promise, + [NGHTTP2_PUSH_PROMISE] = http2_fill_up_promise, [NGHTTP2_PING] = NULL, [NGHTTP2_GOAWAY] = NULL, [NGHTTP2_WINDOW_UPDATE] = NULL, [NGHTTP2_CONTINUATION] = NULL, [NGHTTP2_ALTSVC] = NULL, - [NGHTTP2_USER_SEND] = nghttp2_data_send, - [NGHTTP2_USER_COLSE] = nghttp2_on_stream_close + [NGHTTP2_USER_SEND] = http2_data_send, + [NGHTTP2_USER_COLSE] = http2_on_stream_close }; -static ssize_t -nghttp2_client_send(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) +static ssize_t http2_client_send(nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data) { - if ( nghttp2_callback_array[NGHTTP2_USER_SEND] != NULL){ - return (ssize_t)nghttp2_callback_array[NGHTTP2_USER_SEND](session, NULL, data, length, + if ( http2_callback_array[NGHTTP2_USER_SEND] != NULL){ + return (ssize_t)http2_callback_array[NGHTTP2_USER_SEND](session, NULL, data, length, NULL, 0, flags, user_data, CONN_DIR_UPSTREAM); } return (ssize_t)length; } -static int -nghttp2_client_on_frame_recv(nghttp2_session *session, - const nghttp2_frame *frame, void *user_data) +static int http2_client_on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame, void *user_data) { struct tfe_h2_stream *h2_stream_info = (struct tfe_h2_stream *)user_data; - if ( nghttp2_frame_callback_array[frame->hd.type] != NULL){ - return nghttp2_frame_callback_array[frame->hd.type](h2_stream_info, frame, CONN_DIR_UPSTREAM); + if ( http2_frame_callback_array[frame->hd.type] != NULL){ + return http2_frame_callback_array[frame->hd.type](h2_stream_info, frame, CONN_DIR_UPSTREAM); } return 0; } -static enum tfe_stream_action -nghttp2_submit_data_by_user(struct tfe_h2_stream *connection, - struct tfe_h2_session *h2_session, - enum tfe_conn_dir dir) -{ +static enum tfe_stream_action http2_submit_data_by_user(struct tfe_h2_stream *connection,struct tfe_h2_session *h2_session, enum tfe_conn_dir dir) +{ int rv = -1; enum tfe_stream_action stream_action = ACTION_DROP_DATA; struct tfe_h2_half_private *h2_half = tfe_h2_stream_get_half(h2_session, dir); - nghttp2_session *ngh2_session = tfe_h2_stream_get_nghttp2_session(connection, dir); + nghttp2_session *ngh2_session = tfe_h2_stream_get_http2_session(connection, dir); struct tfe_h2_payload *body = &h2_half->h2_payload; @@ -2032,10 +1996,8 @@ nghttp2_submit_data_by_user(struct tfe_h2_stream *connection, return stream_action; } -static int -nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, - int32_t stream_id, const uint8_t *input, - size_t input_len, void *user_data) +static int http2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, int32_t stream_id, const uint8_t *input, + size_t input_len, void *user_data) { size_t len; char *uncompr = NULL; @@ -2043,7 +2005,7 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, enum tfe_stream_action stream_action = ACTION_DROP_DATA; int uncompr_len = 0, __attribute__((__unused__))ret = 0; const unsigned char *data; - struct tfe_h2_half_private * resp = NULL; + struct tfe_h2_half_private *resp=NULL, *pangu_resp=NULL; struct tfe_h2_stream *h2_stream_info = (struct tfe_h2_stream *)user_data; @@ -2060,7 +2022,15 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, { h2_stream_info->stream_action = ACTION_DROP_DATA; return 0; - } + } + + pangu_resp = h2_session->plugin_built_resp; + if(pangu_resp != NULL && pangu_resp->message_state == H2_READ_STATE_COMPLETE) + { + h2_stream_info->stream_action = ACTION_DROP_DATA; + return 0; + } + evbuffer_add(resp->h2_payload.evbuf_body, input, input_len); if (resp->h2_payload.gzip != HTTP2_CONTENT_ENCODING_NONE) { @@ -2077,10 +2047,10 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, if (flags != NGHTTP2_FLAG_END_STREAM && h2_session->plugin_built_resp == NULL) { /**Decompression failed, send this data**/ - stream_action = nghttp2_submit_data_by_user(h2_stream_info, h2_session, CONN_DIR_UPSTREAM); + stream_action = http2_submit_data_by_user(h2_stream_info, h2_session, CONN_DIR_UPSTREAM); if (stream_action == ACTION_DROP_DATA) { - xret = nghttp2_session_send(h2_stream_info->as_server); + xret = nghttp2_session_send(h2_stream_info->http2_server_handle); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; @@ -2133,10 +2103,10 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, { FREE(&uncompr); } - stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_UPSTREAM, compress_result); + stream_action = http2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_UPSTREAM, compress_result); if (stream_action == ACTION_DROP_DATA) { - xret = nghttp2_session_send(h2_stream_info->as_server); + xret = nghttp2_session_send(h2_stream_info->http2_server_handle); if (xret != 0) { stream_action = ACTION_FORWARD_DATA; @@ -2149,39 +2119,32 @@ nghttp2_client_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, return 0; } -static int -nghttp2_client_on_stream_close(nghttp2_session *session, int32_t stream_id, - uint32_t error_code, void *user_data) +static int http2_client_on_stream_close(nghttp2_session *session, int32_t stream_id, uint32_t error_code, void *user_data) { nghttp2_frame frame; memset(&frame, 0, sizeof(frame)); frame.hd.stream_id = stream_id; frame.goaway.error_code = error_code; - if ( nghttp2_callback_array[NGHTTP2_USER_COLSE] != NULL){ - return nghttp2_callback_array[NGHTTP2_USER_COLSE](session, &frame, NULL, 0, + if ( http2_callback_array[NGHTTP2_USER_COLSE] != NULL){ + return http2_callback_array[NGHTTP2_USER_COLSE](session, &frame, NULL, 0, NULL, 0, 0, user_data, CONN_DIR_UPSTREAM); } return 0; } -static int -nghttp2_client_on_header(nghttp2_session *session, - const nghttp2_frame *frame, const uint8_t *name, - size_t namelen, const uint8_t *value, - size_t valuelen, uint8_t flags, void *user_data) +static int http2_client_on_header(nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, + size_t namelen, const uint8_t *value,size_t valuelen, uint8_t flags, void *user_data) { - if ( nghttp2_callback_array[frame->hd.type] != NULL){ - return nghttp2_callback_array[frame->hd.type](session, frame, name, namelen, + if ( http2_callback_array[frame->hd.type] != NULL){ + return http2_callback_array[frame->hd.type](session, frame, name, namelen, value, valuelen, flags, user_data, CONN_DIR_UPSTREAM); } return 0; } -static struct tfe_h2_session* -create_upstream_data(nghttp2_session *session, int32_t stream_id, - struct tfe_h2_stream *h2_stream_info) +static struct tfe_h2_session* create_upstream_data(nghttp2_session *session, int32_t stream_id, struct tfe_h2_stream *h2_stream_info) { struct tfe_h2_session *h2_session = NULL; struct user_event_dispatch *event = NULL; @@ -2203,7 +2166,7 @@ resp: h2_session->ngh2_stream_id = stream_id; h2_session->tf_stream = h2_stream_info->tf_stream; - h2_session->resp = tfe_half_private_init(TFE_HTTP_RESPONSE, stream_id, h2_stream_info->as_server); + h2_session->resp = tfe_half_private_init(TFE_HTTP_RESPONSE, stream_id, h2_stream_info->http2_server_handle); tfe_half_session_init(h2_session, stream_id, TFE_HTTP_RESPONSE); event = ALLOC(struct user_event_dispatch, 1); @@ -2233,9 +2196,7 @@ finish: return h2_session; } -static ssize_t nghttp2_client_select_padding_callback(nghttp2_session *session, - const nghttp2_frame *frame, - size_t max_payloadlen, void *user_data) +static ssize_t http2_client_select_padding_callback(nghttp2_session *session,const nghttp2_frame *frame,size_t max_payloadlen, void *user_data) { struct tfe_h2_half_private *resp = NULL; struct tfe_h2_stream *h2_stream_info = (struct tfe_h2_stream *)user_data; @@ -2250,10 +2211,7 @@ static ssize_t nghttp2_client_select_padding_callback(nghttp2_session *session, return (ssize_t)MIN(max_payloadlen, frame->hd.length + (resp->h2_payload.padlen)); } -static int -nghttp2_client_on_begin_headers(nghttp2_session * session, - const nghttp2_frame * frame, - void * user_data) +static int http2_client_on_begin_headers(nghttp2_session * session, const nghttp2_frame * frame, void * user_data) { (void)session; @@ -2268,94 +2226,76 @@ nghttp2_client_on_begin_headers(nghttp2_session * session, return 0; } -static -void client_session_init(struct tfe_h2_stream *h2_stream_info) +static void client_session_init(struct tfe_h2_stream *h2_stream_info) { nghttp2_session_callbacks *callbacks; nghttp2_session_callbacks_new(&callbacks); - nghttp2_session_callbacks_set_send_callback(callbacks, - nghttp2_client_send); + nghttp2_session_callbacks_set_send_callback(callbacks, http2_client_send); - nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, - nghttp2_client_on_frame_recv); + nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, http2_client_on_frame_recv); - nghttp2_session_callbacks_set_on_data_chunk_recv_callback(callbacks, - nghttp2_client_on_data_chunk_recv); + nghttp2_session_callbacks_set_on_data_chunk_recv_callback(callbacks, http2_client_on_data_chunk_recv); - nghttp2_session_callbacks_set_select_padding_callback(callbacks, - nghttp2_client_select_padding_callback); + nghttp2_session_callbacks_set_select_padding_callback(callbacks, http2_client_select_padding_callback); - nghttp2_session_callbacks_set_on_stream_close_callback(callbacks, - nghttp2_client_on_stream_close); + nghttp2_session_callbacks_set_on_stream_close_callback(callbacks, http2_client_on_stream_close); - nghttp2_session_callbacks_set_on_header_callback(callbacks, - nghttp2_client_on_header); + nghttp2_session_callbacks_set_on_header_callback(callbacks, http2_client_on_header); - nghttp2_session_callbacks_set_on_begin_headers_callback(callbacks, - nghttp2_client_on_begin_headers); + nghttp2_session_callbacks_set_on_begin_headers_callback(callbacks, http2_client_on_begin_headers); - nghttp2_session_client_new(&h2_stream_info->as_client, callbacks, h2_stream_info); + nghttp2_session_client_new(&h2_stream_info->http2_client_handle, callbacks, h2_stream_info); nghttp2_session_callbacks_del(callbacks); } -static ssize_t -nghttp2_server_send(nghttp2_session *session, const uint8_t *data, - size_t length, int flags, void *user_data) +static ssize_t http2_server_send(nghttp2_session *session, const uint8_t *data, size_t length, int flags, void *user_data) { - if ( nghttp2_callback_array[NGHTTP2_USER_SEND] != NULL){ - return (ssize_t)nghttp2_callback_array[NGHTTP2_USER_SEND](session, NULL, data, length, + if ( http2_callback_array[NGHTTP2_USER_SEND] != NULL){ + return (ssize_t)http2_callback_array[NGHTTP2_USER_SEND](session, NULL, data, length, NULL, 0, flags, user_data, CONN_DIR_DOWNSTREAM); } return (ssize_t)length; } -static int -nghttp2_server_on_frame_recv(nghttp2_session *session, - const nghttp2_frame *frame, void *user_data) +static int http2_server_on_frame_recv(nghttp2_session *session, const nghttp2_frame *frame, void *user_data) { struct tfe_h2_stream *h2_stream_info = (struct tfe_h2_stream *)user_data; - if ( nghttp2_frame_callback_array[frame->hd.type] != NULL){ - return nghttp2_frame_callback_array[frame->hd.type](h2_stream_info, frame, CONN_DIR_DOWNSTREAM); + if ( http2_frame_callback_array[frame->hd.type] != NULL){ + return http2_frame_callback_array[frame->hd.type](h2_stream_info, frame, CONN_DIR_DOWNSTREAM); } return 0; } -static int -nghttp2_server_on_stream_close(nghttp2_session *session, int32_t stream_id, - uint32_t error_code, void *user_data) +static int http2_server_on_stream_close(nghttp2_session *session, int32_t stream_id, uint32_t error_code, void *user_data) { nghttp2_frame frame; memset(&frame, 0, sizeof(frame)); frame.hd.stream_id = stream_id; frame.goaway.error_code = error_code; - if ( nghttp2_callback_array[NGHTTP2_USER_COLSE] != NULL){ - return nghttp2_callback_array[NGHTTP2_USER_COLSE](session, &frame, NULL, 0, + if ( http2_callback_array[NGHTTP2_USER_COLSE] != NULL){ + return http2_callback_array[NGHTTP2_USER_COLSE](session, &frame, NULL, 0, NULL, 0, 0, user_data, CONN_DIR_DOWNSTREAM); } return 0; } -static int -nghttp2_server_on_header(nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, - size_t namelen, const uint8_t *value, - size_t valuelen, uint8_t flags, void *user_data) +static int http2_server_on_header(nghttp2_session *session, const nghttp2_frame *frame, const uint8_t *name, + size_t namelen, const uint8_t *value,size_t valuelen, uint8_t flags, void *user_data) { - if ( nghttp2_callback_array[frame->hd.type] != NULL){ - return nghttp2_callback_array[frame->hd.type](session, frame, name, namelen, value, + if ( http2_callback_array[frame->hd.type] != NULL){ + return http2_callback_array[frame->hd.type](session, frame, name, namelen, value, valuelen, flags, user_data,CONN_DIR_DOWNSTREAM); } return 0; } -static void -create_serv_stream_data(nghttp2_session *session, int32_t stream_id, - struct tfe_h2_stream *h2_stream_info) +static void create_serv_stream_data(nghttp2_session *session, int32_t stream_id, struct tfe_h2_stream *h2_stream_info) { struct tfe_h2_session *h2_session = NULL; struct user_event_dispatch *event = NULL; @@ -2370,7 +2310,7 @@ create_serv_stream_data(nghttp2_session *session, int32_t stream_id, h2_session = (struct tfe_h2_session *)ALLOC(struct tfe_h2_session, 1); assert(h2_session); h2_session->ngh2_stream_id = stream_id; - h2_session->session = h2_stream_info->as_server; + h2_session->session = h2_stream_info->http2_server_handle; h2_session->tf_stream = h2_stream_info->tf_stream; h2_session->req = tfe_half_private_init(TFE_HTTP_REQUEST, 0, NULL); @@ -2403,10 +2343,8 @@ finish: return; } -static int -nghttp2_server_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, - int32_t stream_id, const uint8_t *input, - size_t input_len, void *user_data) +static int http2_server_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, int32_t stream_id, const uint8_t *input, + size_t input_len, void *user_data) { size_t __attribute__((__unused__))len; char *uncompr = NULL; @@ -2473,10 +2411,10 @@ nghttp2_server_on_data_chunk_recv(nghttp2_session *session, uint8_t flags, } if (uncompr_len) FREE(&uncompr); - stream_action = nghttp2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_DOWNSTREAM, 1); + stream_action = http2_submit_data_by_h2_half(h2_stream_info, h2_session, CONN_DIR_DOWNSTREAM, 1); if (stream_action == ACTION_DROP_DATA){ - xret = nghttp2_session_send(h2_stream_info->as_client); - if (xret != 0) + xret = nghttp2_session_send(h2_stream_info->http2_client_handle); + if (xret != 0) { stream_action = ACTION_FORWARD_DATA; TFE_LOG_ERROR(logger()->handle, "Fatal upstream send error: %s, %d\n",nghttp2_strerror(xret), __LINE__); @@ -2489,10 +2427,7 @@ finish: return 0; } -static int -nghttp2_server_on_begin_headers(nghttp2_session *session, - const nghttp2_frame *frame, - void *user_data) +static int http2_server_on_begin_headers(nghttp2_session *session, const nghttp2_frame *frame,void *user_data) { struct tfe_h2_stream *h2_stream_info = (struct tfe_h2_stream *)user_data; @@ -2505,45 +2440,38 @@ nghttp2_server_on_begin_headers(nghttp2_session *session, return 0; } -static void -server_session_init(struct tfe_h2_stream *h2_stream_info) +static void server_session_init(struct tfe_h2_stream *h2_stream_info) { nghttp2_session_callbacks *callbacks; nghttp2_session_callbacks_new(&callbacks); - nghttp2_session_callbacks_set_send_callback(callbacks, nghttp2_server_send); + nghttp2_session_callbacks_set_send_callback(callbacks, http2_server_send); - nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, - nghttp2_server_on_frame_recv); + nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, http2_server_on_frame_recv); - nghttp2_session_callbacks_set_on_data_chunk_recv_callback(callbacks, - nghttp2_server_on_data_chunk_recv); + nghttp2_session_callbacks_set_on_data_chunk_recv_callback(callbacks, http2_server_on_data_chunk_recv); - nghttp2_session_callbacks_set_on_stream_close_callback( - callbacks, nghttp2_server_on_stream_close); + nghttp2_session_callbacks_set_on_stream_close_callback(callbacks, http2_server_on_stream_close); - nghttp2_session_callbacks_set_on_header_callback(callbacks, - nghttp2_server_on_header); + nghttp2_session_callbacks_set_on_header_callback(callbacks,http2_server_on_header); - nghttp2_session_callbacks_set_on_begin_headers_callback( - callbacks, nghttp2_server_on_begin_headers); + nghttp2_session_callbacks_set_on_begin_headers_callback(callbacks, http2_server_on_begin_headers); - nghttp2_session_server_new(&h2_stream_info->as_server, callbacks, h2_stream_info); - - h2_stream_info->as_server->opt_flags |= NGHTTP2_OPTMASK_NO_CLOSED_STREAMS; + nghttp2_session_server_new(&h2_stream_info->http2_server_handle, callbacks, h2_stream_info); + + h2_stream_info->http2_server_handle->opt_flags |= NGHTTP2_OPTMASK_NO_CLOSED_STREAMS; nghttp2_session_callbacks_del(callbacks); } -static void -delete_server_session_data(struct tfe_h2_stream *h2_stream_info) +static void delete_server_session_data(struct tfe_h2_stream *h2_stream_info) { struct tfe_h2_session *h2_session; struct tfe_h2_session *peer_h2_stream; - nghttp2_session_del(h2_stream_info->as_server); - h2_stream_info->as_server = NULL; + nghttp2_session_del(h2_stream_info->http2_server_handle); + h2_stream_info->http2_server_handle = NULL; TAILQ_FOREACH_SAFE(h2_session, &h2_stream_info->h2_session_list, next, peer_h2_stream) { @@ -2559,14 +2487,13 @@ delete_server_session_data(struct tfe_h2_stream *h2_stream_info) } } -static void -delete_client_session_data(struct tfe_h2_stream *h2_stream_info) +static void delete_client_session_data(struct tfe_h2_stream *h2_stream_info) { struct tfe_h2_session *h2_session = NULL; struct tfe_h2_session *peer_h2_stream; - nghttp2_session_del(h2_stream_info->as_client); - h2_stream_info->as_client = NULL; + nghttp2_session_del(h2_stream_info->http2_client_handle); + h2_stream_info->http2_client_handle = NULL; TAILQ_FOREACH_SAFE(h2_session, &h2_stream_info->h2_session_list, next, peer_h2_stream){ TAILQ_REMOVE(&h2_stream_info->h2_session_list, h2_session, next); @@ -2581,9 +2508,8 @@ delete_client_session_data(struct tfe_h2_stream *h2_stream_info) } } -enum tfe_stream_action -detect_up_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream *tfe_stream, - unsigned int thread_id, const unsigned char *data, size_t len) +enum tfe_stream_action detect_up_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream *tfe_stream, + unsigned int thread_id, const unsigned char *data, size_t len) { int readlen = 0; enum tfe_stream_action stream_action = ACTION_FORWARD_DATA; @@ -2591,9 +2517,9 @@ detect_up_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe h2_stream_info->tf_stream = tfe_stream; h2_stream_info->thread_id = thread_id; - if (!h2_stream_info->as_client) + if (!h2_stream_info->http2_client_handle) goto forward; - readlen = nghttp2_session_mem_recv(h2_stream_info->as_client, data, len); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_client_handle, data, len); if (readlen < 0){ TFE_LOG_ERROR(logger()->handle, "Failed to process server requests. Link message %s", tfe_stream->str_stream_info); @@ -2603,12 +2529,12 @@ detect_up_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe stream_action = h2_stream_info->stream_action; h2_stream_info->stream_action = ACTION_DROP_DATA; if (h2_stream_info->goaway){ - nghttp2_disect_goaway(h2_stream_info); + http2_disect_goaway(h2_stream_info); h2_stream_info->goaway = 0; } if (h2_stream_info->kill_signal) { - nghttp2_disect_goaway(h2_stream_info); + http2_disect_goaway(h2_stream_info); tfe_stream_kill(tfe_stream); } @@ -2625,9 +2551,8 @@ forward: return stream_action; } -enum tfe_stream_action -detect_down_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream *tfe_stream, - unsigned int thread_id, const unsigned char *data, size_t len) +enum tfe_stream_action detect_down_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream *tfe_stream, + unsigned int thread_id, const unsigned char *data, size_t len) { int readlen = 0; enum tfe_stream_action stream_action = ACTION_FORWARD_DATA; @@ -2635,10 +2560,10 @@ detect_down_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct t h2_stream_info->tf_stream = tfe_stream; h2_stream_info->thread_id = thread_id; - if (!h2_stream_info->as_server) + if (!h2_stream_info->http2_server_handle) goto forward; - readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, data, len); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_server_handle, data, len); if (readlen < 0){ TFE_LOG_ERROR(logger()->handle, "Failed to process client requests. Link message %s", tfe_stream->str_stream_info); @@ -2648,7 +2573,7 @@ detect_down_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct t stream_action = h2_stream_info->stream_action; h2_stream_info->stream_action = ACTION_DROP_DATA; if (h2_stream_info->goaway){ - nghttp2_disect_goaway(h2_stream_info); + http2_disect_goaway(h2_stream_info); h2_stream_info->goaway = 0; } if (stream_action == ACTION_DROP_DATA){ @@ -2663,9 +2588,7 @@ forward: return stream_action; } -void -sess_data_ctx_fini(struct tfe_h2_stream *h2_stream_info, - const struct tfe_stream * stream, unsigned int thread_id) +void sess_data_ctx_fini(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream * stream, unsigned int thread_id) { struct tfe_h2_session *h2_session = NULL; struct tfe_h2_session *peer_h2_stream = NULL; @@ -2681,13 +2604,13 @@ sess_data_ctx_fini(struct tfe_h2_stream *h2_stream_info, free(h2_session); h2_session = NULL; } - if (h2_stream_info->as_client){ - nghttp2_session_del(h2_stream_info->as_client); - h2_stream_info->as_client = NULL; + if (h2_stream_info->http2_client_handle){ + nghttp2_session_del(h2_stream_info->http2_client_handle); + h2_stream_info->http2_client_handle = NULL; } - if (h2_stream_info->as_server){ - nghttp2_session_del(h2_stream_info->as_server); - h2_stream_info->as_server = NULL; + if (h2_stream_info->http2_server_handle){ + nghttp2_session_del(h2_stream_info->http2_server_handle); + h2_stream_info->http2_server_handle = NULL; } } diff --git a/plugin/protocol/http2/test/test_http2_stream.cpp b/plugin/protocol/http2/test/test_http2_stream.cpp index 029986d..e1b5160 100644 --- a/plugin/protocol/http2/test/test_http2_stream.cpp +++ b/plugin/protocol/http2/test/test_http2_stream.cpp @@ -196,7 +196,7 @@ TEST(Http2StreamParser, GetFrameWithMagic) EXPECT_EQ(memcmp(magic_headers, kMagicHello, MAGIC_FRAME_LENGTH), 0); /*Recv data magic**/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, magic_headers, sizeof(magic_headers)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_server_handle, magic_headers, sizeof(magic_headers)); EXPECT_GT(readlen, 0); sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0); @@ -216,14 +216,14 @@ TEST(Http2StreamParser, GetFrameWithHeader_01) struct tfe_h2_stream *h2_stream_info = tapinfo->h2_stream_info; /*Recv data magic**/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, magic_headers, sizeof(magic_headers)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_server_handle, magic_headers, sizeof(magic_headers)); EXPECT_GT(readlen, 0); /*Recv request Headers**/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, request_get_headers, sizeof(request_get_headers)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_server_handle, request_get_headers, sizeof(request_get_headers)); EXPECT_GT(readlen, 0); - UT_Parse_ReqHeaders(h2_stream_info->as_server); + UT_Parse_ReqHeaders(h2_stream_info->http2_server_handle); sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0); free(tapinfo->h2_stream_info); @@ -242,11 +242,11 @@ TEST(Http2StreamParser, GetFrameWithHeader_02) struct tfe_h2_stream *h2_stream_info = tapinfo->h2_stream_info; /*Recv data magic**/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, magic_headers, sizeof(magic_headers)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_server_handle, magic_headers, sizeof(magic_headers)); EXPECT_GT(readlen, 0); /*Recv request Headers**/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, request_get_headers, sizeof(request_get_headers)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_server_handle, request_get_headers, sizeof(request_get_headers)); EXPECT_GT(readlen, 0); /*Send data message**/ @@ -271,11 +271,11 @@ TEST(Http2StreamParser, RespFrameWithHead_01) struct tfe_h2_stream *h2_stream_info = tapinfo->h2_stream_info; /*Recv data magic**/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, magic_headers, sizeof(magic_headers)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_server_handle, magic_headers, sizeof(magic_headers)); EXPECT_GT(readlen, 0); /*Recv request Headers**/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_server, request_get_headers, sizeof(request_get_headers)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_server_handle, request_get_headers, sizeof(request_get_headers)); EXPECT_GT(readlen, 0); /*Send data head message**/ @@ -284,13 +284,13 @@ TEST(Http2StreamParser, RespFrameWithHead_01) //EXPECT_EQ(stream_action, ACTION_DROP_DATA); /*Recv response settings*/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_client, response_settings, sizeof(response_settings)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_client_handle, response_settings, sizeof(response_settings)); EXPECT_GT(readlen, 0); /*Recv response Header*/ - readlen = nghttp2_session_mem_recv(h2_stream_info->as_client, response_header2, sizeof(response_header2)); + readlen = nghttp2_session_mem_recv(h2_stream_info->http2_client_handle, response_header2, sizeof(response_header2)); EXPECT_GT(readlen, 0); - UT_Parse_RespHeaders(h2_stream_info->as_client); + UT_Parse_RespHeaders(h2_stream_info->http2_client_handle); sess_data_ctx_fini(tapinfo->h2_stream_info, NULL, 0); free(tapinfo->h2_stream_info);