diff options
author | Craig Tiller <ctiller@google.com> | 2015-09-22 10:42:19 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-09-22 10:42:19 -0700 |
commit | 45724b35e411fef7c5da66a74c78428c11d56843 (patch) | |
tree | 9264034aca675c89444e02f72ef58e67d7043604 /src/core/transport/chttp2 | |
parent | 298751c1195523ef6228595043b583c3a6270e08 (diff) |
indent pass to get logical source lines on one physical line
Diffstat (limited to 'src/core/transport/chttp2')
40 files changed, 4179 insertions, 3848 deletions
diff --git a/src/core/transport/chttp2/alpn.c b/src/core/transport/chttp2/alpn.c index 69da4e6718..f008615c9a 100644 --- a/src/core/transport/chttp2/alpn.c +++ b/src/core/transport/chttp2/alpn.c @@ -36,21 +36,29 @@ #include <grpc/support/useful.h> /* in order of preference */ -static const char *const supported_versions[] = {"h2"}; +static const char *const supported_versions[] = { "h2" }; -int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size) { +int +grpc_chttp2_is_alpn_version_supported (const char *version, size_t size) +{ size_t i; - for (i = 0; i < GPR_ARRAY_SIZE(supported_versions); i++) { - if (!strncmp(version, supported_versions[i], size)) return 1; - } + for (i = 0; i < GPR_ARRAY_SIZE (supported_versions); i++) + { + if (!strncmp (version, supported_versions[i], size)) + return 1; + } return 0; } -size_t grpc_chttp2_num_alpn_versions(void) { - return GPR_ARRAY_SIZE(supported_versions); +size_t +grpc_chttp2_num_alpn_versions (void) +{ + return GPR_ARRAY_SIZE (supported_versions); } -const char *grpc_chttp2_get_alpn_version_index(size_t i) { - GPR_ASSERT(i < GPR_ARRAY_SIZE(supported_versions)); +const char * +grpc_chttp2_get_alpn_version_index (size_t i) +{ + GPR_ASSERT (i < GPR_ARRAY_SIZE (supported_versions)); return supported_versions[i]; } diff --git a/src/core/transport/chttp2/alpn.h b/src/core/transport/chttp2/alpn.h index f38b4c3167..b45081eccf 100644 --- a/src/core/transport/chttp2/alpn.h +++ b/src/core/transport/chttp2/alpn.h @@ -37,13 +37,13 @@ #include <string.h> /* Retuns 1 if the version is supported, 0 otherwise. */ -int grpc_chttp2_is_alpn_version_supported(const char *version, size_t size); +int grpc_chttp2_is_alpn_version_supported (const char *version, size_t size); /* Returns the number of protocol versions to advertise */ -size_t grpc_chttp2_num_alpn_versions(void); +size_t grpc_chttp2_num_alpn_versions (void); /* Returns the protocol version at index i (0 <= i < * grpc_chttp2_num_alpn_versions()) */ -const char *grpc_chttp2_get_alpn_version_index(size_t i); +const char *grpc_chttp2_get_alpn_version_index (size_t i); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_ALPN_H */ diff --git a/src/core/transport/chttp2/bin_encoder.c b/src/core/transport/chttp2/bin_encoder.c index e21d800083..929f65ad66 100644 --- a/src/core/transport/chttp2/bin_encoder.c +++ b/src/core/transport/chttp2/bin_encoder.c @@ -38,51 +38,56 @@ #include "src/core/transport/chttp2/huffsyms.h" #include <grpc/support/log.h> -static const char alphabet[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -typedef struct { +typedef struct +{ gpr_uint16 bits; gpr_uint8 length; } b64_huff_sym; static const b64_huff_sym huff_alphabet[64] = { - {0x21, 6}, {0x5d, 7}, {0x5e, 7}, {0x5f, 7}, {0x60, 7}, {0x61, 7}, - {0x62, 7}, {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7}, {0x67, 7}, - {0x68, 7}, {0x69, 7}, {0x6a, 7}, {0x6b, 7}, {0x6c, 7}, {0x6d, 7}, - {0x6e, 7}, {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7}, {0xfc, 8}, - {0x73, 7}, {0xfd, 8}, {0x3, 5}, {0x23, 6}, {0x4, 5}, {0x24, 6}, - {0x5, 5}, {0x25, 6}, {0x26, 6}, {0x27, 6}, {0x6, 5}, {0x74, 7}, - {0x75, 7}, {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5}, {0x2b, 6}, - {0x76, 7}, {0x2c, 6}, {0x8, 5}, {0x9, 5}, {0x2d, 6}, {0x77, 7}, - {0x78, 7}, {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x0, 5}, {0x1, 5}, - {0x2, 5}, {0x19, 6}, {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6}, - {0x1e, 6}, {0x1f, 6}, {0x7fb, 11}, {0x18, 6}}; - -static const gpr_uint8 tail_xtra[3] = {0, 2, 3}; - -gpr_slice grpc_chttp2_base64_encode(gpr_slice input) { - size_t input_length = GPR_SLICE_LENGTH(input); + {0x21, 6}, {0x5d, 7}, {0x5e, 7}, {0x5f, 7}, {0x60, 7}, {0x61, 7}, + {0x62, 7}, {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7}, {0x67, 7}, + {0x68, 7}, {0x69, 7}, {0x6a, 7}, {0x6b, 7}, {0x6c, 7}, {0x6d, 7}, + {0x6e, 7}, {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7}, {0xfc, 8}, + {0x73, 7}, {0xfd, 8}, {0x3, 5}, {0x23, 6}, {0x4, 5}, {0x24, 6}, + {0x5, 5}, {0x25, 6}, {0x26, 6}, {0x27, 6}, {0x6, 5}, {0x74, 7}, + {0x75, 7}, {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5}, {0x2b, 6}, + {0x76, 7}, {0x2c, 6}, {0x8, 5}, {0x9, 5}, {0x2d, 6}, {0x77, 7}, + {0x78, 7}, {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x0, 5}, {0x1, 5}, + {0x2, 5}, {0x19, 6}, {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6}, + {0x1e, 6}, {0x1f, 6}, {0x7fb, 11}, {0x18, 6} +}; + +static const gpr_uint8 tail_xtra[3] = { 0, 2, 3 }; + +gpr_slice +grpc_chttp2_base64_encode (gpr_slice input) +{ + size_t input_length = GPR_SLICE_LENGTH (input); size_t input_triplets = input_length / 3; size_t tail_case = input_length % 3; size_t output_length = input_triplets * 4 + tail_xtra[tail_case]; - gpr_slice output = gpr_slice_malloc(output_length); - gpr_uint8 *in = GPR_SLICE_START_PTR(input); - char *out = (char *)GPR_SLICE_START_PTR(output); + gpr_slice output = gpr_slice_malloc (output_length); + gpr_uint8 *in = GPR_SLICE_START_PTR (input); + char *out = (char *) GPR_SLICE_START_PTR (output); size_t i; /* encode full triplets */ - for (i = 0; i < input_triplets; i++) { - out[0] = alphabet[in[0] >> 2]; - out[1] = alphabet[((in[0] & 0x3) << 4) | (in[1] >> 4)]; - out[2] = alphabet[((in[1] & 0xf) << 2) | (in[2] >> 6)]; - out[3] = alphabet[in[2] & 0x3f]; - out += 4; - in += 3; - } + for (i = 0; i < input_triplets; i++) + { + out[0] = alphabet[in[0] >> 2]; + out[1] = alphabet[((in[0] & 0x3) << 4) | (in[1] >> 4)]; + out[2] = alphabet[((in[1] & 0xf) << 2) | (in[2] >> 6)]; + out[3] = alphabet[in[2] & 0x3f]; + out += 4; + in += 3; + } /* encode the remaining bytes */ - switch (tail_case) { + switch (tail_case) + { case 0: break; case 1: @@ -98,14 +103,16 @@ gpr_slice grpc_chttp2_base64_encode(gpr_slice input) { out += 3; in += 2; break; - } + } - GPR_ASSERT(out == (char *)GPR_SLICE_END_PTR(output)); - GPR_ASSERT(in == GPR_SLICE_END_PTR(input)); + GPR_ASSERT (out == (char *) GPR_SLICE_END_PTR (output)); + GPR_ASSERT (in == GPR_SLICE_END_PTR (input)); return output; } -gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) { +gpr_slice +grpc_chttp2_huffman_compress (gpr_slice input) +{ size_t nbits; gpr_uint8 *in; gpr_uint8 *out; @@ -114,73 +121,85 @@ gpr_slice grpc_chttp2_huffman_compress(gpr_slice input) { gpr_uint32 temp_length = 0; nbits = 0; - for (in = GPR_SLICE_START_PTR(input); in != GPR_SLICE_END_PTR(input); ++in) { - nbits += grpc_chttp2_huffsyms[*in].length; - } - - output = gpr_slice_malloc(nbits / 8 + (nbits % 8 != 0)); - out = GPR_SLICE_START_PTR(output); - for (in = GPR_SLICE_START_PTR(input); in != GPR_SLICE_END_PTR(input); ++in) { - int sym = *in; - temp <<= grpc_chttp2_huffsyms[sym].length; - temp |= grpc_chttp2_huffsyms[sym].bits; - temp_length += grpc_chttp2_huffsyms[sym].length; - - while (temp_length > 8) { - temp_length -= 8; - *out++ = (gpr_uint8)(temp >> temp_length); + for (in = GPR_SLICE_START_PTR (input); in != GPR_SLICE_END_PTR (input); ++in) + { + nbits += grpc_chttp2_huffsyms[*in].length; } - } - if (temp_length) { - *out++ = (gpr_uint8)(temp << (8u - temp_length)) | - (gpr_uint8)(0xffu >> temp_length); - } + output = gpr_slice_malloc (nbits / 8 + (nbits % 8 != 0)); + out = GPR_SLICE_START_PTR (output); + for (in = GPR_SLICE_START_PTR (input); in != GPR_SLICE_END_PTR (input); ++in) + { + int sym = *in; + temp <<= grpc_chttp2_huffsyms[sym].length; + temp |= grpc_chttp2_huffsyms[sym].bits; + temp_length += grpc_chttp2_huffsyms[sym].length; + + while (temp_length > 8) + { + temp_length -= 8; + *out++ = (gpr_uint8) (temp >> temp_length); + } + } - GPR_ASSERT(out == GPR_SLICE_END_PTR(output)); + if (temp_length) + { + *out++ = (gpr_uint8) (temp << (8u - temp_length)) | (gpr_uint8) (0xffu >> temp_length); + } + + GPR_ASSERT (out == GPR_SLICE_END_PTR (output)); return output; } -typedef struct { +typedef struct +{ gpr_uint32 temp; gpr_uint32 temp_length; gpr_uint8 *out; } huff_out; -static void enc_flush_some(huff_out *out) { - while (out->temp_length > 8) { - out->temp_length -= 8; - *out->out++ = (gpr_uint8)(out->temp >> out->temp_length); - } +static void +enc_flush_some (huff_out * out) +{ + while (out->temp_length > 8) + { + out->temp_length -= 8; + *out->out++ = (gpr_uint8) (out->temp >> out->temp_length); + } } -static void enc_add2(huff_out *out, gpr_uint8 a, gpr_uint8 b) { +static void +enc_add2 (huff_out * out, gpr_uint8 a, gpr_uint8 b) +{ b64_huff_sym sa = huff_alphabet[a]; b64_huff_sym sb = huff_alphabet[b]; - out->temp = (out->temp << (sa.length + sb.length)) | - ((gpr_uint32)sa.bits << sb.length) | sb.bits; - out->temp_length += (gpr_uint32)sa.length + (gpr_uint32)sb.length; - enc_flush_some(out); + out->temp = (out->temp << (sa.length + sb.length)) | ((gpr_uint32) sa.bits << sb.length) | sb.bits; + out->temp_length += (gpr_uint32) sa.length + (gpr_uint32) sb.length; + enc_flush_some (out); } -static void enc_add1(huff_out *out, gpr_uint8 a) { +static void +enc_add1 (huff_out * out, gpr_uint8 a) +{ b64_huff_sym sa = huff_alphabet[a]; out->temp = (out->temp << sa.length) | sa.bits; out->temp_length += sa.length; - enc_flush_some(out); + enc_flush_some (out); } -gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) { - size_t input_length = GPR_SLICE_LENGTH(input); +gpr_slice +grpc_chttp2_base64_encode_and_huffman_compress (gpr_slice input) +{ + size_t input_length = GPR_SLICE_LENGTH (input); size_t input_triplets = input_length / 3; size_t tail_case = input_length % 3; size_t output_syms = input_triplets * 4 + tail_xtra[tail_case]; size_t max_output_bits = 11 * output_syms; size_t max_output_length = max_output_bits / 8 + (max_output_bits % 8 != 0); - gpr_slice output = gpr_slice_malloc(max_output_length); - gpr_uint8 *in = GPR_SLICE_START_PTR(input); - gpr_uint8 *start_out = GPR_SLICE_START_PTR(output); + gpr_slice output = gpr_slice_malloc (max_output_length); + gpr_uint8 *in = GPR_SLICE_START_PTR (input); + gpr_uint8 *start_out = GPR_SLICE_START_PTR (output); huff_out out; size_t i; @@ -189,42 +208,45 @@ gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input) { out.out = start_out; /* encode full triplets */ - for (i = 0; i < input_triplets; i++) { - enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4) | (in[1] >> 4)); - enc_add2(&out, (gpr_uint8)((in[1] & 0xf) << 2) | (in[2] >> 6), - (gpr_uint8)(in[2] & 0x3f)); - in += 3; - } + for (i = 0; i < input_triplets; i++) + { + enc_add2 (&out, in[0] >> 2, (gpr_uint8) ((in[0] & 0x3) << 4) | (in[1] >> 4)); + enc_add2 (&out, (gpr_uint8) ((in[1] & 0xf) << 2) | (in[2] >> 6), (gpr_uint8) (in[2] & 0x3f)); + in += 3; + } /* encode the remaining bytes */ - switch (tail_case) { + switch (tail_case) + { case 0: break; case 1: - enc_add2(&out, in[0] >> 2, (gpr_uint8)((in[0] & 0x3) << 4)); + enc_add2 (&out, in[0] >> 2, (gpr_uint8) ((in[0] & 0x3) << 4)); in += 1; break; case 2: - enc_add2(&out, in[0] >> 2, - (gpr_uint8)((in[0] & 0x3) << 4) | (gpr_uint8)(in[1] >> 4)); - enc_add1(&out, (gpr_uint8)((in[1] & 0xf) << 2)); + enc_add2 (&out, in[0] >> 2, (gpr_uint8) ((in[0] & 0x3) << 4) | (gpr_uint8) (in[1] >> 4)); + enc_add1 (&out, (gpr_uint8) ((in[1] & 0xf) << 2)); in += 2; break; - } + } - if (out.temp_length) { - *out.out++ = (gpr_uint8)(out.temp << (8u - out.temp_length)) | - (gpr_uint8)(0xffu >> out.temp_length); - } + if (out.temp_length) + { + *out.out++ = (gpr_uint8) (out.temp << (8u - out.temp_length)) | (gpr_uint8) (0xffu >> out.temp_length); + } - GPR_ASSERT(out.out <= GPR_SLICE_END_PTR(output)); - GPR_SLICE_SET_LENGTH(output, out.out - start_out); + GPR_ASSERT (out.out <= GPR_SLICE_END_PTR (output)); + GPR_SLICE_SET_LENGTH (output, out.out - start_out); - GPR_ASSERT(in == GPR_SLICE_END_PTR(input)); + GPR_ASSERT (in == GPR_SLICE_END_PTR (input)); return output; } -int grpc_is_binary_header(const char *key, size_t length) { - if (length < 5) return 0; - return 0 == memcmp(key + length - 4, "-bin", 4); +int +grpc_is_binary_header (const char *key, size_t length) +{ + if (length < 5) + return 0; + return 0 == memcmp (key + length - 4, "-bin", 4); } diff --git a/src/core/transport/chttp2/bin_encoder.h b/src/core/transport/chttp2/bin_encoder.h index d3e5a855dd..6e57615f7f 100644 --- a/src/core/transport/chttp2/bin_encoder.h +++ b/src/core/transport/chttp2/bin_encoder.h @@ -38,19 +38,19 @@ /* base64 encode a slice. Returns a new slice, does not take ownership of the input */ -gpr_slice grpc_chttp2_base64_encode(gpr_slice input); +gpr_slice grpc_chttp2_base64_encode (gpr_slice input); /* Compress a slice with the static huffman encoder detailed in the hpack standard. Returns a new slice, does not take ownership of the input */ -gpr_slice grpc_chttp2_huffman_compress(gpr_slice input); +gpr_slice grpc_chttp2_huffman_compress (gpr_slice input); /* equivalent to: gpr_slice x = grpc_chttp2_base64_encode(input); gpr_slice y = grpc_chttp2_huffman_compress(x); gpr_slice_unref(x); return y; */ -gpr_slice grpc_chttp2_base64_encode_and_huffman_compress(gpr_slice input); +gpr_slice grpc_chttp2_base64_encode_and_huffman_compress (gpr_slice input); -int grpc_is_binary_header(const char *key, size_t length); +int grpc_is_binary_header (const char *key, size_t length); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_BIN_ENCODER_H */ diff --git a/src/core/transport/chttp2/frame.h b/src/core/transport/chttp2/frame.h index 879ee036fa..84aa154967 100644 --- a/src/core/transport/chttp2/frame.h +++ b/src/core/transport/chttp2/frame.h @@ -39,7 +39,8 @@ /* Common definitions for frame handling in the chttp2 transport */ -typedef enum { +typedef enum +{ GRPC_CHTTP2_PARSE_OK, GRPC_CHTTP2_STREAM_ERROR, GRPC_CHTTP2_CONNECTION_ERROR diff --git a/src/core/transport/chttp2/frame_data.c b/src/core/transport/chttp2/frame_data.c index a58189a136..461a1e26f8 100644 --- a/src/core/transport/chttp2/frame_data.c +++ b/src/core/transport/chttp2/frame_data.c @@ -42,133 +42,146 @@ #include <grpc/support/useful.h> #include "src/core/transport/transport.h" -grpc_chttp2_parse_error grpc_chttp2_data_parser_init( - grpc_chttp2_data_parser *parser) { +grpc_chttp2_parse_error +grpc_chttp2_data_parser_init (grpc_chttp2_data_parser * parser) +{ parser->state = GRPC_CHTTP2_DATA_FH_0; - grpc_sopb_init(&parser->incoming_sopb); + grpc_sopb_init (&parser->incoming_sopb); return GRPC_CHTTP2_PARSE_OK; } -void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser *parser) { - grpc_sopb_destroy(&parser->incoming_sopb); +void +grpc_chttp2_data_parser_destroy (grpc_chttp2_data_parser * parser) +{ + grpc_sopb_destroy (&parser->incoming_sopb); } -grpc_chttp2_parse_error grpc_chttp2_data_parser_begin_frame( - grpc_chttp2_data_parser *parser, gpr_uint8 flags) { - if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM) { - gpr_log(GPR_ERROR, "unsupported data flags: 0x%02x", flags); - return GRPC_CHTTP2_STREAM_ERROR; - } +grpc_chttp2_parse_error +grpc_chttp2_data_parser_begin_frame (grpc_chttp2_data_parser * parser, gpr_uint8 flags) +{ + if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM) + { + gpr_log (GPR_ERROR, "unsupported data flags: 0x%02x", flags); + return GRPC_CHTTP2_STREAM_ERROR; + } - if (flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM) { - parser->is_last_frame = 1; - } else { - parser->is_last_frame = 0; - } + if (flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM) + { + parser->is_last_frame = 1; + } + else + { + parser->is_last_frame = 0; + } return GRPC_CHTTP2_PARSE_OK; } -grpc_chttp2_parse_error grpc_chttp2_data_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { - gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice); - gpr_uint8 *const end = GPR_SLICE_END_PTR(slice); +grpc_chttp2_parse_error +grpc_chttp2_data_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ + gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice); + gpr_uint8 *const end = GPR_SLICE_END_PTR (slice); gpr_uint8 *cur = beg; grpc_chttp2_data_parser *p = parser; gpr_uint32 message_flags = 0; - if (is_last && p->is_last_frame) { - stream_parsing->received_close = 1; - } + if (is_last && p->is_last_frame) + { + stream_parsing->received_close = 1; + } - if (cur == end) { - return GRPC_CHTTP2_PARSE_OK; - } + if (cur == end) + { + return GRPC_CHTTP2_PARSE_OK; + } - switch (p->state) { - fh_0: + switch (p->state) + { + fh_0: case GRPC_CHTTP2_DATA_FH_0: p->frame_type = *cur; - switch (p->frame_type) { - case 0: - p->is_frame_compressed = 0; /* GPR_FALSE */ - break; - case 1: - p->is_frame_compressed = 1; /* GPR_TRUE */ - break; - default: - gpr_log(GPR_ERROR, "Bad GRPC frame type 0x%02x", p->frame_type); - return GRPC_CHTTP2_STREAM_ERROR; - } - if (++cur == end) { - p->state = GRPC_CHTTP2_DATA_FH_1; - return GRPC_CHTTP2_PARSE_OK; - } - /* fallthrough */ + switch (p->frame_type) + { + case 0: + p->is_frame_compressed = 0; /* GPR_FALSE */ + break; + case 1: + p->is_frame_compressed = 1; /* GPR_TRUE */ + break; + default: + gpr_log (GPR_ERROR, "Bad GRPC frame type 0x%02x", p->frame_type); + return GRPC_CHTTP2_STREAM_ERROR; + } + if (++cur == end) + { + p->state = GRPC_CHTTP2_DATA_FH_1; + return GRPC_CHTTP2_PARSE_OK; + } + /* fallthrough */ case GRPC_CHTTP2_DATA_FH_1: - p->frame_size = ((gpr_uint32)*cur) << 24; - if (++cur == end) { - p->state = GRPC_CHTTP2_DATA_FH_2; - return GRPC_CHTTP2_PARSE_OK; - } - /* fallthrough */ + p->frame_size = ((gpr_uint32) * cur) << 24; + if (++cur == end) + { + p->state = GRPC_CHTTP2_DATA_FH_2; + return GRPC_CHTTP2_PARSE_OK; + } + /* fallthrough */ case GRPC_CHTTP2_DATA_FH_2: - p->frame_size |= ((gpr_uint32)*cur) << 16; - if (++cur == end) { - p->state = GRPC_CHTTP2_DATA_FH_3; - return GRPC_CHTTP2_PARSE_OK; - } - /* fallthrough */ + p->frame_size |= ((gpr_uint32) * cur) << 16; + if (++cur == end) + { + p->state = GRPC_CHTTP2_DATA_FH_3; + return GRPC_CHTTP2_PARSE_OK; + } + /* fallthrough */ case GRPC_CHTTP2_DATA_FH_3: - p->frame_size |= ((gpr_uint32)*cur) << 8; - if (++cur == end) { - p->state = GRPC_CHTTP2_DATA_FH_4; - return GRPC_CHTTP2_PARSE_OK; - } - /* fallthrough */ + p->frame_size |= ((gpr_uint32) * cur) << 8; + if (++cur == end) + { + p->state = GRPC_CHTTP2_DATA_FH_4; + return GRPC_CHTTP2_PARSE_OK; + } + /* fallthrough */ case GRPC_CHTTP2_DATA_FH_4: - p->frame_size |= ((gpr_uint32)*cur); + p->frame_size |= ((gpr_uint32) * cur); p->state = GRPC_CHTTP2_DATA_FRAME; ++cur; - if (p->is_frame_compressed) { - message_flags |= GRPC_WRITE_INTERNAL_COMPRESS; - } - grpc_sopb_add_begin_message(&p->incoming_sopb, p->frame_size, - message_flags); - /* fallthrough */ + if (p->is_frame_compressed) + { + message_flags |= GRPC_WRITE_INTERNAL_COMPRESS; + } + grpc_sopb_add_begin_message (&p->incoming_sopb, p->frame_size, message_flags); + /* fallthrough */ case GRPC_CHTTP2_DATA_FRAME: - if (cur == end) { - grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, - stream_parsing); - return GRPC_CHTTP2_PARSE_OK; - } - grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, - stream_parsing); - if ((gpr_uint32)(end - cur) == p->frame_size) { - grpc_sopb_add_slice( - &p->incoming_sopb, - gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); - p->state = GRPC_CHTTP2_DATA_FH_0; - return GRPC_CHTTP2_PARSE_OK; - } else if ((gpr_uint32)(end - cur) > p->frame_size) { - grpc_sopb_add_slice(&p->incoming_sopb, - gpr_slice_sub(slice, (size_t)(cur - beg), - (size_t)(cur + p->frame_size - beg))); - cur += p->frame_size; - goto fh_0; /* loop */ - } else { - grpc_sopb_add_slice( - &p->incoming_sopb, - gpr_slice_sub(slice, (size_t)(cur - beg), (size_t)(end - beg))); - GPR_ASSERT(end - cur <= p->frame_size); - p->frame_size -= (gpr_uint32)(end - cur); - return GRPC_CHTTP2_PARSE_OK; - } - } + if (cur == end) + { + grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing); + return GRPC_CHTTP2_PARSE_OK; + } + grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing); + if ((gpr_uint32) (end - cur) == p->frame_size) + { + grpc_sopb_add_slice (&p->incoming_sopb, gpr_slice_sub (slice, (size_t) (cur - beg), (size_t) (end - beg))); + p->state = GRPC_CHTTP2_DATA_FH_0; + return GRPC_CHTTP2_PARSE_OK; + } + else if ((gpr_uint32) (end - cur) > p->frame_size) + { + grpc_sopb_add_slice (&p->incoming_sopb, gpr_slice_sub (slice, (size_t) (cur - beg), (size_t) (cur + p->frame_size - beg))); + cur += p->frame_size; + goto fh_0; /* loop */ + } + else + { + grpc_sopb_add_slice (&p->incoming_sopb, gpr_slice_sub (slice, (size_t) (cur - beg), (size_t) (end - beg))); + GPR_ASSERT (end - cur <= p->frame_size); + p->frame_size -= (gpr_uint32) (end - cur); + return GRPC_CHTTP2_PARSE_OK; + } + } - gpr_log(GPR_ERROR, "should never reach here"); - abort(); + gpr_log (GPR_ERROR, "should never reach here"); + abort (); return GRPC_CHTTP2_CONNECTION_ERROR; } diff --git a/src/core/transport/chttp2/frame_data.h b/src/core/transport/chttp2/frame_data.h index ccd56a132c..6284433b19 100644 --- a/src/core/transport/chttp2/frame_data.h +++ b/src/core/transport/chttp2/frame_data.h @@ -42,7 +42,8 @@ #include "src/core/transport/stream_op.h" #include "src/core/transport/chttp2/frame.h" -typedef enum { +typedef enum +{ GRPC_CHTTP2_DATA_FH_0, GRPC_CHTTP2_DATA_FH_1, GRPC_CHTTP2_DATA_FH_2, @@ -51,7 +52,8 @@ typedef enum { GRPC_CHTTP2_DATA_FRAME } grpc_chttp2_stream_state; -typedef struct { +typedef struct +{ grpc_chttp2_stream_state state; gpr_uint8 is_last_frame; gpr_uint8 frame_type; @@ -62,23 +64,18 @@ typedef struct { } grpc_chttp2_data_parser; /* initialize per-stream state for data frame parsing */ -grpc_chttp2_parse_error grpc_chttp2_data_parser_init( - grpc_chttp2_data_parser *parser); +grpc_chttp2_parse_error grpc_chttp2_data_parser_init (grpc_chttp2_data_parser * parser); -void grpc_chttp2_data_parser_destroy(grpc_chttp2_data_parser *parser); +void grpc_chttp2_data_parser_destroy (grpc_chttp2_data_parser * parser); /* start processing a new data frame */ -grpc_chttp2_parse_error grpc_chttp2_data_parser_begin_frame( - grpc_chttp2_data_parser *parser, gpr_uint8 flags); +grpc_chttp2_parse_error grpc_chttp2_data_parser_begin_frame (grpc_chttp2_data_parser * parser, gpr_uint8 flags); /* handle a slice of a data frame - is_last indicates the last slice of a frame */ -grpc_chttp2_parse_error grpc_chttp2_data_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list); +grpc_chttp2_parse_error grpc_chttp2_data_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); /* create a slice with an empty data frame and is_last set */ -gpr_slice grpc_chttp2_data_frame_create_empty_close(gpr_uint32 id); +gpr_slice grpc_chttp2_data_frame_create_empty_close (gpr_uint32 id); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_DATA_H */ diff --git a/src/core/transport/chttp2/frame_goaway.c b/src/core/transport/chttp2/frame_goaway.c index d338b56611..f990e86465 100644 --- a/src/core/transport/chttp2/frame_goaway.c +++ b/src/core/transport/chttp2/frame_goaway.c @@ -39,137 +39,151 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser *p) { +void +grpc_chttp2_goaway_parser_init (grpc_chttp2_goaway_parser * p) +{ p->debug_data = NULL; } -void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser *p) { - gpr_free(p->debug_data); +void +grpc_chttp2_goaway_parser_destroy (grpc_chttp2_goaway_parser * p) +{ + gpr_free (p->debug_data); } -grpc_chttp2_parse_error grpc_chttp2_goaway_parser_begin_frame( - grpc_chttp2_goaway_parser *p, gpr_uint32 length, gpr_uint8 flags) { - if (length < 8) { - gpr_log(GPR_ERROR, "goaway frame too short (%d bytes)", length); - return GRPC_CHTTP2_CONNECTION_ERROR; - } +grpc_chttp2_parse_error +grpc_chttp2_goaway_parser_begin_frame (grpc_chttp2_goaway_parser * p, gpr_uint32 length, gpr_uint8 flags) +{ + if (length < 8) + { + gpr_log (GPR_ERROR, "goaway frame too short (%d bytes)", length); + return GRPC_CHTTP2_CONNECTION_ERROR; + } - gpr_free(p->debug_data); + gpr_free (p->debug_data); p->debug_length = length - 8; - p->debug_data = gpr_malloc(p->debug_length); + p->debug_data = gpr_malloc (p->debug_length); p->debug_pos = 0; p->state = GRPC_CHTTP2_GOAWAY_LSI0; return GRPC_CHTTP2_PARSE_OK; } -grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { - gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice); - gpr_uint8 *const end = GPR_SLICE_END_PTR(slice); +grpc_chttp2_parse_error +grpc_chttp2_goaway_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ + gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice); + gpr_uint8 *const end = GPR_SLICE_END_PTR (slice); gpr_uint8 *cur = beg; grpc_chttp2_goaway_parser *p = parser; - switch (p->state) { + switch (p->state) + { case GRPC_CHTTP2_GOAWAY_LSI0: - if (cur == end) { - p->state = GRPC_CHTTP2_GOAWAY_LSI0; - return GRPC_CHTTP2_PARSE_OK; - } - p->last_stream_id = ((gpr_uint32)*cur) << 24; + if (cur == end) + { + p->state = GRPC_CHTTP2_GOAWAY_LSI0; + return GRPC_CHTTP2_PARSE_OK; + } + p->last_stream_id = ((gpr_uint32) * cur) << 24; ++cur; - /* fallthrough */ + /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI1: - if (cur == end) { - p->state = GRPC_CHTTP2_GOAWAY_LSI1; - return GRPC_CHTTP2_PARSE_OK; - } - p->last_stream_id |= ((gpr_uint32)*cur) << 16; + if (cur == end) + { + p->state = GRPC_CHTTP2_GOAWAY_LSI1; + return GRPC_CHTTP2_PARSE_OK; + } + p->last_stream_id |= ((gpr_uint32) * cur) << 16; ++cur; - /* fallthrough */ + /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI2: - if (cur == end) { - p->state = GRPC_CHTTP2_GOAWAY_LSI2; - return GRPC_CHTTP2_PARSE_OK; - } - p->last_stream_id |= ((gpr_uint32)*cur) << 8; + if (cur == end) + { + p->state = GRPC_CHTTP2_GOAWAY_LSI2; + return GRPC_CHTTP2_PARSE_OK; + } + p->last_stream_id |= ((gpr_uint32) * cur) << 8; ++cur; - /* fallthrough */ + /* fallthrough */ case GRPC_CHTTP2_GOAWAY_LSI3: - if (cur == end) { - p->state = GRPC_CHTTP2_GOAWAY_LSI3; - return GRPC_CHTTP2_PARSE_OK; - } - p->last_stream_id |= ((gpr_uint32)*cur); + if (cur == end) + { + p->state = GRPC_CHTTP2_GOAWAY_LSI3; + return GRPC_CHTTP2_PARSE_OK; + } + p->last_stream_id |= ((gpr_uint32) * cur); ++cur; - /* fallthrough */ + /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR0: - if (cur == end) { - p->state = GRPC_CHTTP2_GOAWAY_ERR0; - return GRPC_CHTTP2_PARSE_OK; - } - p->error_code = ((gpr_uint32)*cur) << 24; + if (cur == end) + { + p->state = GRPC_CHTTP2_GOAWAY_ERR0; + return GRPC_CHTTP2_PARSE_OK; + } + p->error_code = ((gpr_uint32) * cur) << 24; ++cur; - /* fallthrough */ + /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR1: - if (cur == end) { - p->state = GRPC_CHTTP2_GOAWAY_ERR1; - return GRPC_CHTTP2_PARSE_OK; - } - p->error_code |= ((gpr_uint32)*cur) << 16; + if (cur == end) + { + p->state = GRPC_CHTTP2_GOAWAY_ERR1; + return GRPC_CHTTP2_PARSE_OK; + } + p->error_code |= ((gpr_uint32) * cur) << 16; ++cur; - /* fallthrough */ + /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR2: - if (cur == end) { - p->state = GRPC_CHTTP2_GOAWAY_ERR2; - return GRPC_CHTTP2_PARSE_OK; - } - p->error_code |= ((gpr_uint32)*cur) << 8; + if (cur == end) + { + p->state = GRPC_CHTTP2_GOAWAY_ERR2; + return GRPC_CHTTP2_PARSE_OK; + } + p->error_code |= ((gpr_uint32) * cur) << 8; ++cur; - /* fallthrough */ + /* fallthrough */ case GRPC_CHTTP2_GOAWAY_ERR3: - if (cur == end) { - p->state = GRPC_CHTTP2_GOAWAY_ERR3; - return GRPC_CHTTP2_PARSE_OK; - } - p->error_code |= ((gpr_uint32)*cur); + if (cur == end) + { + p->state = GRPC_CHTTP2_GOAWAY_ERR3; + return GRPC_CHTTP2_PARSE_OK; + } + p->error_code |= ((gpr_uint32) * cur); ++cur; - /* fallthrough */ + /* fallthrough */ case GRPC_CHTTP2_GOAWAY_DEBUG: - memcpy(p->debug_data + p->debug_pos, cur, (size_t)(end - cur)); - GPR_ASSERT(end - cur < GPR_UINT32_MAX - p->debug_pos); - p->debug_pos += (gpr_uint32)(end - cur); + memcpy (p->debug_data + p->debug_pos, cur, (size_t) (end - cur)); + GPR_ASSERT (end - cur < GPR_UINT32_MAX - p->debug_pos); + p->debug_pos += (gpr_uint32) (end - cur); p->state = GRPC_CHTTP2_GOAWAY_DEBUG; - if (is_last) { - transport_parsing->goaway_received = 1; - transport_parsing->goaway_last_stream_index = p->last_stream_id; - gpr_slice_unref(transport_parsing->goaway_text); - transport_parsing->goaway_error = (grpc_status_code)p->error_code; - transport_parsing->goaway_text = - gpr_slice_new(p->debug_data, p->debug_length, gpr_free); - p->debug_data = NULL; - } + if (is_last) + { + transport_parsing->goaway_received = 1; + transport_parsing->goaway_last_stream_index = p->last_stream_id; + gpr_slice_unref (transport_parsing->goaway_text); + transport_parsing->goaway_error = (grpc_status_code) p->error_code; + transport_parsing->goaway_text = gpr_slice_new (p->debug_data, p->debug_length, gpr_free); + p->debug_data = NULL; + } return GRPC_CHTTP2_PARSE_OK; - } - gpr_log(GPR_ERROR, "Should never end up here"); - abort(); + } + gpr_log (GPR_ERROR, "Should never end up here"); + abort (); return GRPC_CHTTP2_CONNECTION_ERROR; } -void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, - gpr_slice debug_data, - gpr_slice_buffer *slice_buffer) { - gpr_slice header = gpr_slice_malloc(9 + 4 + 4); - gpr_uint8 *p = GPR_SLICE_START_PTR(header); +void +grpc_chttp2_goaway_append (gpr_uint32 last_stream_id, gpr_uint32 error_code, gpr_slice debug_data, gpr_slice_buffer * slice_buffer) +{ + gpr_slice header = gpr_slice_malloc (9 + 4 + 4); + gpr_uint8 *p = GPR_SLICE_START_PTR (header); gpr_uint32 frame_length; - GPR_ASSERT(GPR_SLICE_LENGTH(debug_data) < GPR_UINT32_MAX - 4 - 4); - frame_length = 4 + 4 + (gpr_uint32)GPR_SLICE_LENGTH(debug_data); + GPR_ASSERT (GPR_SLICE_LENGTH (debug_data) < GPR_UINT32_MAX - 4 - 4); + frame_length = 4 + 4 + (gpr_uint32) GPR_SLICE_LENGTH (debug_data); /* frame header: length */ - *p++ = (gpr_uint8)(frame_length >> 16); - *p++ = (gpr_uint8)(frame_length >> 8); - *p++ = (gpr_uint8)(frame_length); + *p++ = (gpr_uint8) (frame_length >> 16); + *p++ = (gpr_uint8) (frame_length >> 8); + *p++ = (gpr_uint8) (frame_length); /* frame header: type */ *p++ = GRPC_CHTTP2_FRAME_GOAWAY; /* frame header: flags */ @@ -180,16 +194,16 @@ void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, *p++ = 0; *p++ = 0; /* payload: last stream id */ - *p++ = (gpr_uint8)(last_stream_id >> 24); - *p++ = (gpr_uint8)(last_stream_id >> 16); - *p++ = (gpr_uint8)(last_stream_id >> 8); - *p++ = (gpr_uint8)(last_stream_id); + *p++ = (gpr_uint8) (last_stream_id >> 24); + *p++ = (gpr_uint8) (last_stream_id >> 16); + *p++ = (gpr_uint8) (last_stream_id >> 8); + *p++ = (gpr_uint8) (last_stream_id); /* payload: error code */ - *p++ = (gpr_uint8)(error_code >> 24); - *p++ = (gpr_uint8)(error_code >> 16); - *p++ = (gpr_uint8)(error_code >> 8); - *p++ = (gpr_uint8)(error_code); - GPR_ASSERT(p == GPR_SLICE_END_PTR(header)); - gpr_slice_buffer_add(slice_buffer, header); - gpr_slice_buffer_add(slice_buffer, debug_data); + *p++ = (gpr_uint8) (error_code >> 24); + *p++ = (gpr_uint8) (error_code >> 16); + *p++ = (gpr_uint8) (error_code >> 8); + *p++ = (gpr_uint8) (error_code); + GPR_ASSERT (p == GPR_SLICE_END_PTR (header)); + gpr_slice_buffer_add (slice_buffer, header); + gpr_slice_buffer_add (slice_buffer, debug_data); } diff --git a/src/core/transport/chttp2/frame_goaway.h b/src/core/transport/chttp2/frame_goaway.h index e45d55418c..7cacec5f94 100644 --- a/src/core/transport/chttp2/frame_goaway.h +++ b/src/core/transport/chttp2/frame_goaway.h @@ -40,7 +40,8 @@ #include <grpc/support/slice.h> #include <grpc/support/slice_buffer.h> -typedef enum { +typedef enum +{ GRPC_CHTTP2_GOAWAY_LSI0, GRPC_CHTTP2_GOAWAY_LSI1, GRPC_CHTTP2_GOAWAY_LSI2, @@ -52,7 +53,8 @@ typedef enum { GRPC_CHTTP2_GOAWAY_DEBUG } grpc_chttp2_goaway_parse_state; -typedef struct { +typedef struct +{ grpc_chttp2_goaway_parse_state state; gpr_uint32 last_stream_id; gpr_uint32 error_code; @@ -61,17 +63,11 @@ typedef struct { gpr_uint32 debug_pos; } grpc_chttp2_goaway_parser; -void grpc_chttp2_goaway_parser_init(grpc_chttp2_goaway_parser *p); -void grpc_chttp2_goaway_parser_destroy(grpc_chttp2_goaway_parser *p); -grpc_chttp2_parse_error grpc_chttp2_goaway_parser_begin_frame( - grpc_chttp2_goaway_parser *parser, gpr_uint32 length, gpr_uint8 flags); -grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list); +void grpc_chttp2_goaway_parser_init (grpc_chttp2_goaway_parser * p); +void grpc_chttp2_goaway_parser_destroy (grpc_chttp2_goaway_parser * p); +grpc_chttp2_parse_error grpc_chttp2_goaway_parser_begin_frame (grpc_chttp2_goaway_parser * parser, gpr_uint32 length, gpr_uint8 flags); +grpc_chttp2_parse_error grpc_chttp2_goaway_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); -void grpc_chttp2_goaway_append(gpr_uint32 last_stream_id, gpr_uint32 error_code, - gpr_slice debug_data, - gpr_slice_buffer *slice_buffer); +void grpc_chttp2_goaway_append (gpr_uint32 last_stream_id, gpr_uint32 error_code, gpr_slice debug_data, gpr_slice_buffer * slice_buffer); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_GOAWAY_H */ diff --git a/src/core/transport/chttp2/frame_ping.c b/src/core/transport/chttp2/frame_ping.c index d4bf43eb37..6cd1fae1a6 100644 --- a/src/core/transport/chttp2/frame_ping.c +++ b/src/core/transport/chttp2/frame_ping.c @@ -39,9 +39,11 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -gpr_slice grpc_chttp2_ping_create(gpr_uint8 ack, gpr_uint8 *opaque_8bytes) { - gpr_slice slice = gpr_slice_malloc(9 + 8); - gpr_uint8 *p = GPR_SLICE_START_PTR(slice); +gpr_slice +grpc_chttp2_ping_create (gpr_uint8 ack, gpr_uint8 * opaque_8bytes) +{ + gpr_slice slice = gpr_slice_malloc (9 + 8); + gpr_uint8 *p = GPR_SLICE_START_PTR (slice); *p++ = 0; *p++ = 0; @@ -52,55 +54,61 @@ gpr_slice grpc_chttp2_ping_create(gpr_uint8 ack, gpr_uint8 *opaque_8bytes) { *p++ = 0; *p++ = 0; *p++ = 0; - memcpy(p, opaque_8bytes, 8); + memcpy (p, opaque_8bytes, 8); return slice; } -grpc_chttp2_parse_error grpc_chttp2_ping_parser_begin_frame( - grpc_chttp2_ping_parser *parser, gpr_uint32 length, gpr_uint8 flags) { - if (flags & 0xfe || length != 8) { - gpr_log(GPR_ERROR, "invalid ping: length=%d, flags=%02x", length, flags); - return GRPC_CHTTP2_CONNECTION_ERROR; - } +grpc_chttp2_parse_error +grpc_chttp2_ping_parser_begin_frame (grpc_chttp2_ping_parser * parser, gpr_uint32 length, gpr_uint8 flags) +{ + if (flags & 0xfe || length != 8) + { + gpr_log (GPR_ERROR, "invalid ping: length=%d, flags=%02x", length, flags); + return GRPC_CHTTP2_CONNECTION_ERROR; + } parser->byte = 0; parser->is_ack = flags; return GRPC_CHTTP2_PARSE_OK; } -grpc_chttp2_parse_error grpc_chttp2_ping_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { - gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice); - gpr_uint8 *const end = GPR_SLICE_END_PTR(slice); +grpc_chttp2_parse_error +grpc_chttp2_ping_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ + gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice); + gpr_uint8 *const end = GPR_SLICE_END_PTR (slice); gpr_uint8 *cur = beg; grpc_chttp2_ping_parser *p = parser; grpc_chttp2_outstanding_ping *ping; - while (p->byte != 8 && cur != end) { - p->opaque_8bytes[p->byte] = *cur; - cur++; - p->byte++; - } + while (p->byte != 8 && cur != end) + { + p->opaque_8bytes[p->byte] = *cur; + cur++; + p->byte++; + } - if (p->byte == 8) { - GPR_ASSERT(is_last); - if (p->is_ack) { - for (ping = transport_parsing->pings.next; - ping != &transport_parsing->pings; ping = ping->next) { - if (0 == memcmp(p->opaque_8bytes, ping->id, 8)) { - grpc_closure_list_add(closure_list, ping->on_recv, 1); - } - ping->next->prev = ping->prev; - ping->prev->next = ping->next; - gpr_free(ping); - } - } else { - gpr_slice_buffer_add(&transport_parsing->qbuf, - grpc_chttp2_ping_create(1, p->opaque_8bytes)); + if (p->byte == 8) + { + GPR_ASSERT (is_last); + if (p->is_ack) + { + for (ping = transport_parsing->pings.next; ping != &transport_parsing->pings; ping = ping->next) + { + if (0 == memcmp (p->opaque_8bytes, ping->id, 8)) + { + grpc_closure_list_add (closure_list, ping->on_recv, 1); + } + ping->next->prev = ping->prev; + ping->prev->next = ping->next; + gpr_free (ping); + } + } + else + { + gpr_slice_buffer_add (&transport_parsing->qbuf, grpc_chttp2_ping_create (1, p->opaque_8bytes)); + } } - } return GRPC_CHTTP2_PARSE_OK; } diff --git a/src/core/transport/chttp2/frame_ping.h b/src/core/transport/chttp2/frame_ping.h index 4224002904..65a666bc18 100644 --- a/src/core/transport/chttp2/frame_ping.h +++ b/src/core/transport/chttp2/frame_ping.h @@ -38,19 +38,16 @@ #include <grpc/support/slice.h> #include "src/core/transport/chttp2/frame.h" -typedef struct { +typedef struct +{ gpr_uint8 byte; gpr_uint8 is_ack; gpr_uint8 opaque_8bytes[8]; } grpc_chttp2_ping_parser; -gpr_slice grpc_chttp2_ping_create(gpr_uint8 ack, gpr_uint8 *opaque_8bytes); +gpr_slice grpc_chttp2_ping_create (gpr_uint8 ack, gpr_uint8 * opaque_8bytes); -grpc_chttp2_parse_error grpc_chttp2_ping_parser_begin_frame( - grpc_chttp2_ping_parser *parser, gpr_uint32 length, gpr_uint8 flags); -grpc_chttp2_parse_error grpc_chttp2_ping_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list); +grpc_chttp2_parse_error grpc_chttp2_ping_parser_begin_frame (grpc_chttp2_ping_parser * parser, gpr_uint32 length, gpr_uint8 flags); +grpc_chttp2_parse_error grpc_chttp2_ping_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_PING_H */ diff --git a/src/core/transport/chttp2/frame_rst_stream.c b/src/core/transport/chttp2/frame_rst_stream.c index 4d8323c11d..c4bca3e680 100644 --- a/src/core/transport/chttp2/frame_rst_stream.c +++ b/src/core/transport/chttp2/frame_rst_stream.c @@ -38,63 +38,63 @@ #include "src/core/transport/chttp2/frame.h" -gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 id, gpr_uint32 code) { - gpr_slice slice = gpr_slice_malloc(13); - gpr_uint8 *p = GPR_SLICE_START_PTR(slice); +gpr_slice +grpc_chttp2_rst_stream_create (gpr_uint32 id, gpr_uint32 code) +{ + gpr_slice slice = gpr_slice_malloc (13); + gpr_uint8 *p = GPR_SLICE_START_PTR (slice); *p++ = 0; *p++ = 0; *p++ = 4; *p++ = GRPC_CHTTP2_FRAME_RST_STREAM; *p++ = 0; - *p++ = (gpr_uint8)(id >> 24); - *p++ = (gpr_uint8)(id >> 16); - *p++ = (gpr_uint8)(id >> 8); - *p++ = (gpr_uint8)(id); - *p++ = (gpr_uint8)(code >> 24); - *p++ = (gpr_uint8)(code >> 16); - *p++ = (gpr_uint8)(code >> 8); - *p++ = (gpr_uint8)(code); + *p++ = (gpr_uint8) (id >> 24); + *p++ = (gpr_uint8) (id >> 16); + *p++ = (gpr_uint8) (id >> 8); + *p++ = (gpr_uint8) (id); + *p++ = (gpr_uint8) (code >> 24); + *p++ = (gpr_uint8) (code >> 16); + *p++ = (gpr_uint8) (code >> 8); + *p++ = (gpr_uint8) (code); return slice; } -grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_begin_frame( - grpc_chttp2_rst_stream_parser *parser, gpr_uint32 length, gpr_uint8 flags) { - if (length != 4) { - gpr_log(GPR_ERROR, "invalid rst_stream: length=%d, flags=%02x", length, - flags); - return GRPC_CHTTP2_CONNECTION_ERROR; - } +grpc_chttp2_parse_error +grpc_chttp2_rst_stream_parser_begin_frame (grpc_chttp2_rst_stream_parser * parser, gpr_uint32 length, gpr_uint8 flags) +{ + if (length != 4) + { + gpr_log (GPR_ERROR, "invalid rst_stream: length=%d, flags=%02x", length, flags); + return GRPC_CHTTP2_CONNECTION_ERROR; + } parser->byte = 0; return GRPC_CHTTP2_PARSE_OK; } -grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { - gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice); - gpr_uint8 *const end = GPR_SLICE_END_PTR(slice); +grpc_chttp2_parse_error +grpc_chttp2_rst_stream_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ + gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice); + gpr_uint8 *const end = GPR_SLICE_END_PTR (slice); gpr_uint8 *cur = beg; grpc_chttp2_rst_stream_parser *p = parser; - while (p->byte != 4 && cur != end) { - p->reason_bytes[p->byte] = *cur; - cur++; - p->byte++; - } + while (p->byte != 4 && cur != end) + { + p->reason_bytes[p->byte] = *cur; + cur++; + p->byte++; + } - if (p->byte == 4) { - GPR_ASSERT(is_last); - stream_parsing->received_close = 1; - stream_parsing->saw_rst_stream = 1; - stream_parsing->rst_stream_reason = - (((gpr_uint32)p->reason_bytes[0]) << 24) | - (((gpr_uint32)p->reason_bytes[1]) << 16) | - (((gpr_uint32)p->reason_bytes[2]) << 8) | - (((gpr_uint32)p->reason_bytes[3])); - } + if (p->byte == 4) + { + GPR_ASSERT (is_last); + stream_parsing->received_close = 1; + stream_parsing->saw_rst_stream = 1; + stream_parsing->rst_stream_reason = (((gpr_uint32) p->reason_bytes[0]) << 24) | (((gpr_uint32) p->reason_bytes[1]) << 16) | (((gpr_uint32) p->reason_bytes[2]) << 8) | (((gpr_uint32) p->reason_bytes[3])); + } return GRPC_CHTTP2_PARSE_OK; } diff --git a/src/core/transport/chttp2/frame_rst_stream.h b/src/core/transport/chttp2/frame_rst_stream.h index 5d660968ad..781f4e5743 100644 --- a/src/core/transport/chttp2/frame_rst_stream.h +++ b/src/core/transport/chttp2/frame_rst_stream.h @@ -38,18 +38,15 @@ #include "src/core/transport/chttp2/frame.h" #include "src/core/iomgr/exec_ctx.h" -typedef struct { +typedef struct +{ gpr_uint8 byte; gpr_uint8 reason_bytes[4]; } grpc_chttp2_rst_stream_parser; -gpr_slice grpc_chttp2_rst_stream_create(gpr_uint32 stream_id, gpr_uint32 code); +gpr_slice grpc_chttp2_rst_stream_create (gpr_uint32 stream_id, gpr_uint32 code); -grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_begin_frame( - grpc_chttp2_rst_stream_parser *parser, gpr_uint32 length, gpr_uint8 flags); -grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list); +grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_begin_frame (grpc_chttp2_rst_stream_parser * parser, gpr_uint32 length, gpr_uint8 flags); +grpc_chttp2_parse_error grpc_chttp2_rst_stream_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_RST_STREAM_H */ diff --git a/src/core/transport/chttp2/frame_settings.c b/src/core/transport/chttp2/frame_settings.c index 235ff5a352..7f2d5ba3fe 100644 --- a/src/core/transport/chttp2/frame_settings.c +++ b/src/core/transport/chttp2/frame_settings.c @@ -43,27 +43,27 @@ #include <grpc/support/useful.h> /* HTTP/2 mandated initial connection settings */ -const grpc_chttp2_setting_parameters - grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS] = { - {NULL, 0, 0, 0, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, - {"HEADER_TABLE_SIZE", 4096, 0, 0xffffffff, - GRPC_CHTTP2_CLAMP_INVALID_VALUE}, - {"ENABLE_PUSH", 1, 0, 1, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, - {"MAX_CONCURRENT_STREAMS", 0xffffffffu, 0, 0xffffffffu, - GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, - {"INITIAL_WINDOW_SIZE", 65535, 0, 0xffffffffu, - GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, - {"MAX_FRAME_SIZE", 16384, 16384, 16777215, - GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, - {"MAX_HEADER_LIST_SIZE", 0xffffffffu, 0, 0xffffffffu, - GRPC_CHTTP2_CLAMP_INVALID_VALUE}, +const grpc_chttp2_setting_parameters grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS] = { + {NULL, 0, 0, 0, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, + {"HEADER_TABLE_SIZE", 4096, 0, 0xffffffff, + GRPC_CHTTP2_CLAMP_INVALID_VALUE}, + {"ENABLE_PUSH", 1, 0, 1, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, + {"MAX_CONCURRENT_STREAMS", 0xffffffffu, 0, 0xffffffffu, + GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, + {"INITIAL_WINDOW_SIZE", 65535, 0, 0xffffffffu, + GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, + {"MAX_FRAME_SIZE", 16384, 16384, 16777215, + GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE}, + {"MAX_HEADER_LIST_SIZE", 0xffffffffu, 0, 0xffffffffu, + GRPC_CHTTP2_CLAMP_INVALID_VALUE}, }; -static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length, - gpr_uint8 flags) { - *out++ = (gpr_uint8)(length >> 16); - *out++ = (gpr_uint8)(length >> 8); - *out++ = (gpr_uint8)(length); +static gpr_uint8 * +fill_header (gpr_uint8 * out, gpr_uint32 length, gpr_uint8 flags) +{ + *out++ = (gpr_uint8) (length >> 16); + *out++ = (gpr_uint8) (length >> 8); + *out++ = (gpr_uint8) (length); *out++ = GRPC_CHTTP2_FRAME_SETTINGS; *out++ = flags; *out++ = 0; @@ -73,175 +73,194 @@ static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length, return out; } -gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new, - gpr_uint32 force_mask, size_t count) { +gpr_slice +grpc_chttp2_settings_create (gpr_uint32 * old, const gpr_uint32 * new, gpr_uint32 force_mask, size_t count) +{ size_t i; gpr_uint32 n = 0; gpr_slice output; gpr_uint8 *p; - for (i = 0; i < count; i++) { - n += (new[i] != old[i] || (force_mask & (1u << i)) != 0); - } - - output = gpr_slice_malloc(9 + 6 * n); - p = fill_header(GPR_SLICE_START_PTR(output), 6 * n, 0); - - for (i = 0; i < count; i++) { - if (new[i] != old[i] || (force_mask & (1u << i)) != 0) { - GPR_ASSERT(i); - *p++ = (gpr_uint8)(i >> 8); - *p++ = (gpr_uint8)(i); - *p++ = (gpr_uint8)(new[i] >> 24); - *p++ = (gpr_uint8)(new[i] >> 16); - *p++ = (gpr_uint8)(new[i] >> 8); - *p++ = (gpr_uint8)(new[i]); - old[i] = new[i]; + for (i = 0; i < count; i++) + { + n += (new[i] != old[i] || (force_mask & (1u << i)) != 0); } - } - GPR_ASSERT(p == GPR_SLICE_END_PTR(output)); + output = gpr_slice_malloc (9 + 6 * n); + p = fill_header (GPR_SLICE_START_PTR (output), 6 * n, 0); + + for (i = 0; i < count; i++) + { + if (new[i] != old[i] || (force_mask & (1u << i)) != 0) + { + GPR_ASSERT (i); + *p++ = (gpr_uint8) (i >> 8); + *p++ = (gpr_uint8) (i); + *p++ = (gpr_uint8) (new[i] >> 24); + *p++ = (gpr_uint8) (new[i] >> 16); + *p++ = (gpr_uint8) (new[i] >> 8); + *p++ = (gpr_uint8) (new[i]); + old[i] = new[i]; + } + } + + GPR_ASSERT (p == GPR_SLICE_END_PTR (output)); return output; } -gpr_slice grpc_chttp2_settings_ack_create(void) { - gpr_slice output = gpr_slice_malloc(9); - fill_header(GPR_SLICE_START_PTR(output), 0, GRPC_CHTTP2_FLAG_ACK); +gpr_slice +grpc_chttp2_settings_ack_create (void) +{ + gpr_slice output = gpr_slice_malloc (9); + fill_header (GPR_SLICE_START_PTR (output), 0, GRPC_CHTTP2_FLAG_ACK); return output; } -grpc_chttp2_parse_error grpc_chttp2_settings_parser_begin_frame( - grpc_chttp2_settings_parser *parser, gpr_uint32 length, gpr_uint8 flags, - gpr_uint32 *settings) { +grpc_chttp2_parse_error +grpc_chttp2_settings_parser_begin_frame (grpc_chttp2_settings_parser * parser, gpr_uint32 length, gpr_uint8 flags, gpr_uint32 * settings) +{ parser->target_settings = settings; - memcpy(parser->incoming_settings, settings, - GRPC_CHTTP2_NUM_SETTINGS * sizeof(gpr_uint32)); + memcpy (parser->incoming_settings, settings, GRPC_CHTTP2_NUM_SETTINGS * sizeof (gpr_uint32)); parser->is_ack = 0; parser->state = GRPC_CHTTP2_SPS_ID0; - if (flags == GRPC_CHTTP2_FLAG_ACK) { - parser->is_ack = 1; - if (length != 0) { - gpr_log(GPR_ERROR, "non-empty settings ack frame received"); + if (flags == GRPC_CHTTP2_FLAG_ACK) + { + parser->is_ack = 1; + if (length != 0) + { + gpr_log (GPR_ERROR, "non-empty settings ack frame received"); + return GRPC_CHTTP2_CONNECTION_ERROR; + } + return GRPC_CHTTP2_PARSE_OK; + } + else if (flags != 0) + { + gpr_log (GPR_ERROR, "invalid flags on settings frame"); + return GRPC_CHTTP2_CONNECTION_ERROR; + } + else if (length % 6 != 0) + { + gpr_log (GPR_ERROR, "settings frames must be a multiple of six bytes"); return GRPC_CHTTP2_CONNECTION_ERROR; } - return GRPC_CHTTP2_PARSE_OK; - } else if (flags != 0) { - gpr_log(GPR_ERROR, "invalid flags on settings frame"); - return GRPC_CHTTP2_CONNECTION_ERROR; - } else if (length % 6 != 0) { - gpr_log(GPR_ERROR, "settings frames must be a multiple of six bytes"); - return GRPC_CHTTP2_CONNECTION_ERROR; - } else { - return GRPC_CHTTP2_PARSE_OK; - } + else + { + return GRPC_CHTTP2_PARSE_OK; + } } -grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse( - void *p, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { +grpc_chttp2_parse_error +grpc_chttp2_settings_parser_parse (void *p, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ grpc_chttp2_settings_parser *parser = p; - const gpr_uint8 *cur = GPR_SLICE_START_PTR(slice); - const gpr_uint8 *end = GPR_SLICE_END_PTR(slice); - - if (parser->is_ack) { - return GRPC_CHTTP2_PARSE_OK; - } - - for (;;) { - switch (parser->state) { - case GRPC_CHTTP2_SPS_ID0: - if (cur == end) { - parser->state = GRPC_CHTTP2_SPS_ID0; - if (is_last) { - transport_parsing->settings_updated = 1; - memcpy(parser->target_settings, parser->incoming_settings, - GRPC_CHTTP2_NUM_SETTINGS * sizeof(gpr_uint32)); - gpr_slice_buffer_add(&transport_parsing->qbuf, - grpc_chttp2_settings_ack_create()); - } - return GRPC_CHTTP2_PARSE_OK; - } - parser->id = (gpr_uint16)(((gpr_uint16)*cur) << 8); - cur++; - /* fallthrough */ - case GRPC_CHTTP2_SPS_ID1: - if (cur == end) { - parser->state = GRPC_CHTTP2_SPS_ID1; - return GRPC_CHTTP2_PARSE_OK; - } - parser->id = (gpr_uint16)(parser->id | (*cur)); - cur++; - /* fallthrough */ - case GRPC_CHTTP2_SPS_VAL0: - if (cur == end) { - parser->state = GRPC_CHTTP2_SPS_VAL0; - return GRPC_CHTTP2_PARSE_OK; - } - parser->value = ((gpr_uint32)*cur) << 24; - cur++; - /* fallthrough */ - case GRPC_CHTTP2_SPS_VAL1: - if (cur == end) { - parser->state = GRPC_CHTTP2_SPS_VAL1; - return GRPC_CHTTP2_PARSE_OK; - } - parser->value |= ((gpr_uint32)*cur) << 16; - cur++; - /* fallthrough */ - case GRPC_CHTTP2_SPS_VAL2: - if (cur == end) { - parser->state = GRPC_CHTTP2_SPS_VAL2; - return GRPC_CHTTP2_PARSE_OK; - } - parser->value |= ((gpr_uint32)*cur) << 8; - cur++; - /* fallthrough */ - case GRPC_CHTTP2_SPS_VAL3: - if (cur == end) { - parser->state = GRPC_CHTTP2_SPS_VAL3; - return GRPC_CHTTP2_PARSE_OK; - } else { - parser->state = GRPC_CHTTP2_SPS_ID0; - } - parser->value |= *cur; - cur++; - - if (parser->id > 0 && parser->id < GRPC_CHTTP2_NUM_SETTINGS) { - const grpc_chttp2_setting_parameters *sp = - &grpc_chttp2_settings_parameters[parser->id]; - if (parser->value < sp->min_value || parser->value > sp->max_value) { - switch (sp->invalid_value_behavior) { - case GRPC_CHTTP2_CLAMP_INVALID_VALUE: - parser->value = - GPR_CLAMP(parser->value, sp->min_value, sp->max_value); - break; - case GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE: - gpr_log(GPR_ERROR, "invalid value %u passed for %s", - parser->value, sp->name); - return GRPC_CHTTP2_CONNECTION_ERROR; - } - } - if (parser->id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE && - parser->incoming_settings[parser->id] != parser->value) { - transport_parsing->initial_window_update = - (gpr_int64)parser->value - - parser->incoming_settings[parser->id]; - gpr_log(GPR_DEBUG, "adding %d for initial_window change", - (int)transport_parsing->initial_window_update); - } - parser->incoming_settings[parser->id] = parser->value; - if (grpc_http_trace) { - gpr_log(GPR_DEBUG, "CHTTP2:%s: got setting %d = %d", - transport_parsing->is_client ? "CLI" : "SVR", parser->id, - parser->value); - } - } else { - gpr_log(GPR_ERROR, "CHTTP2: Ignoring unknown setting %d (value %d)", - parser->id, parser->value); - } - break; + const gpr_uint8 *cur = GPR_SLICE_START_PTR (slice); + const gpr_uint8 *end = GPR_SLICE_END_PTR (slice); + + if (parser->is_ack) + { + return GRPC_CHTTP2_PARSE_OK; + } + + for (;;) + { + switch (parser->state) + { + case GRPC_CHTTP2_SPS_ID0: + if (cur == end) + { + parser->state = GRPC_CHTTP2_SPS_ID0; + if (is_last) + { + transport_parsing->settings_updated = 1; + memcpy (parser->target_settings, parser->incoming_settings, GRPC_CHTTP2_NUM_SETTINGS * sizeof (gpr_uint32)); + gpr_slice_buffer_add (&transport_parsing->qbuf, grpc_chttp2_settings_ack_create ()); + } + return GRPC_CHTTP2_PARSE_OK; + } + parser->id = (gpr_uint16) (((gpr_uint16) * cur) << 8); + cur++; + /* fallthrough */ + case GRPC_CHTTP2_SPS_ID1: + if (cur == end) + { + parser->state = GRPC_CHTTP2_SPS_ID1; + return GRPC_CHTTP2_PARSE_OK; + } + parser->id = (gpr_uint16) (parser->id | (*cur)); + cur++; + /* fallthrough */ + case GRPC_CHTTP2_SPS_VAL0: + if (cur == end) + { + parser->state = GRPC_CHTTP2_SPS_VAL0; + return GRPC_CHTTP2_PARSE_OK; + } + parser->value = ((gpr_uint32) * cur) << 24; + cur++; + /* fallthrough */ + case GRPC_CHTTP2_SPS_VAL1: + if (cur == end) + { + parser->state = GRPC_CHTTP2_SPS_VAL1; + return GRPC_CHTTP2_PARSE_OK; + } + parser->value |= ((gpr_uint32) * cur) << 16; + cur++; + /* fallthrough */ + case GRPC_CHTTP2_SPS_VAL2: + if (cur == end) + { + parser->state = GRPC_CHTTP2_SPS_VAL2; + return GRPC_CHTTP2_PARSE_OK; + } + parser->value |= ((gpr_uint32) * cur) << 8; + cur++; + /* fallthrough */ + case GRPC_CHTTP2_SPS_VAL3: + if (cur == end) + { + parser->state = GRPC_CHTTP2_SPS_VAL3; + return GRPC_CHTTP2_PARSE_OK; + } + else + { + parser->state = GRPC_CHTTP2_SPS_ID0; + } + parser->value |= *cur; + cur++; + + if (parser->id > 0 && parser->id < GRPC_CHTTP2_NUM_SETTINGS) + { + const grpc_chttp2_setting_parameters *sp = &grpc_chttp2_settings_parameters[parser->id]; + if (parser->value < sp->min_value || parser->value > sp->max_value) + { + switch (sp->invalid_value_behavior) + { + case GRPC_CHTTP2_CLAMP_INVALID_VALUE: + parser->value = GPR_CLAMP (parser->value, sp->min_value, sp->max_value); + break; + case GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE: + gpr_log (GPR_ERROR, "invalid value %u passed for %s", parser->value, sp->name); + return GRPC_CHTTP2_CONNECTION_ERROR; + } + } + if (parser->id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE && parser->incoming_settings[parser->id] != parser->value) + { + transport_parsing->initial_window_update = (gpr_int64) parser->value - parser->incoming_settings[parser->id]; + gpr_log (GPR_DEBUG, "adding %d for initial_window change", (int) transport_parsing->initial_window_update); + } + parser->incoming_settings[parser->id] = parser->value; + if (grpc_http_trace) + { + gpr_log (GPR_DEBUG, "CHTTP2:%s: got setting %d = %d", transport_parsing->is_client ? "CLI" : "SVR", parser->id, parser->value); + } + } + else + { + gpr_log (GPR_ERROR, "CHTTP2: Ignoring unknown setting %d (value %d)", parser->id, parser->value); + } + break; + } } - } } diff --git a/src/core/transport/chttp2/frame_settings.h b/src/core/transport/chttp2/frame_settings.h index f08d527d38..36c2c1d6d4 100644 --- a/src/core/transport/chttp2/frame_settings.h +++ b/src/core/transport/chttp2/frame_settings.h @@ -39,7 +39,8 @@ #include "src/core/transport/chttp2/frame.h" #include "src/core/iomgr/exec_ctx.h" -typedef enum { +typedef enum +{ GRPC_CHTTP2_SPS_ID0, GRPC_CHTTP2_SPS_ID1, GRPC_CHTTP2_SPS_VAL0, @@ -49,7 +50,8 @@ typedef enum { } grpc_chttp2_settings_parse_state; /* The things HTTP/2 defines as connection level settings */ -typedef enum { +typedef enum +{ GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE = 1, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH = 2, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 3, @@ -59,7 +61,8 @@ typedef enum { GRPC_CHTTP2_NUM_SETTINGS } grpc_chttp2_setting_id; -typedef struct { +typedef struct +{ grpc_chttp2_settings_parse_state state; gpr_uint32 *target_settings; gpr_uint8 is_ack; @@ -68,12 +71,14 @@ typedef struct { gpr_uint32 incoming_settings[GRPC_CHTTP2_NUM_SETTINGS]; } grpc_chttp2_settings_parser; -typedef enum { +typedef enum +{ GRPC_CHTTP2_CLAMP_INVALID_VALUE, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE } grpc_chttp2_invalid_value_behavior; -typedef struct { +typedef struct +{ const char *name; gpr_uint32 default_value; gpr_uint32 min_value; @@ -82,21 +87,14 @@ typedef struct { } grpc_chttp2_setting_parameters; /* HTTP/2 mandated connection setting parameters */ -extern const grpc_chttp2_setting_parameters - grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS]; +extern const grpc_chttp2_setting_parameters grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS]; /* Create a settings frame by diffing old & new, and updating old to be new */ -gpr_slice grpc_chttp2_settings_create(gpr_uint32 *old, const gpr_uint32 *new, - gpr_uint32 force_mask, size_t count); +gpr_slice grpc_chttp2_settings_create (gpr_uint32 * old, const gpr_uint32 * new, gpr_uint32 force_mask, size_t count); /* Create an ack settings frame */ -gpr_slice grpc_chttp2_settings_ack_create(void); +gpr_slice grpc_chttp2_settings_ack_create (void); -grpc_chttp2_parse_error grpc_chttp2_settings_parser_begin_frame( - grpc_chttp2_settings_parser *parser, gpr_uint32 length, gpr_uint8 flags, - gpr_uint32 *settings); -grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list); +grpc_chttp2_parse_error grpc_chttp2_settings_parser_begin_frame (grpc_chttp2_settings_parser * parser, gpr_uint32 length, gpr_uint8 flags, gpr_uint32 * settings); +grpc_chttp2_parse_error grpc_chttp2_settings_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_SETTINGS_H */ diff --git a/src/core/transport/chttp2/frame_window_update.c b/src/core/transport/chttp2/frame_window_update.c index b0f5f8698b..e18fc1f694 100644 --- a/src/core/transport/chttp2/frame_window_update.c +++ b/src/core/transport/chttp2/frame_window_update.c @@ -36,80 +36,83 @@ #include <grpc/support/log.h> -gpr_slice grpc_chttp2_window_update_create(gpr_uint32 id, - gpr_uint32 window_update) { - gpr_slice slice = gpr_slice_malloc(13); - gpr_uint8 *p = GPR_SLICE_START_PTR(slice); +gpr_slice +grpc_chttp2_window_update_create (gpr_uint32 id, gpr_uint32 window_update) +{ + gpr_slice slice = gpr_slice_malloc (13); + gpr_uint8 *p = GPR_SLICE_START_PTR (slice); - GPR_ASSERT(window_update); + GPR_ASSERT (window_update); *p++ = 0; *p++ = 0; *p++ = 4; *p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE; *p++ = 0; - *p++ = (gpr_uint8)(id >> 24); - *p++ = (gpr_uint8)(id >> 16); - *p++ = (gpr_uint8)(id >> 8); - *p++ = (gpr_uint8)(id); - *p++ = (gpr_uint8)(window_update >> 24); - *p++ = (gpr_uint8)(window_update >> 16); - *p++ = (gpr_uint8)(window_update >> 8); - *p++ = (gpr_uint8)(window_update); + *p++ = (gpr_uint8) (id >> 24); + *p++ = (gpr_uint8) (id >> 16); + *p++ = (gpr_uint8) (id >> 8); + *p++ = (gpr_uint8) (id); + *p++ = (gpr_uint8) (window_update >> 24); + *p++ = (gpr_uint8) (window_update >> 16); + *p++ = (gpr_uint8) (window_update >> 8); + *p++ = (gpr_uint8) (window_update); return slice; } -grpc_chttp2_parse_error grpc_chttp2_window_update_parser_begin_frame( - grpc_chttp2_window_update_parser *parser, gpr_uint32 length, - gpr_uint8 flags) { - if (flags || length != 4) { - gpr_log(GPR_ERROR, "invalid window update: length=%d, flags=%02x", length, - flags); - return GRPC_CHTTP2_CONNECTION_ERROR; - } +grpc_chttp2_parse_error +grpc_chttp2_window_update_parser_begin_frame (grpc_chttp2_window_update_parser * parser, gpr_uint32 length, gpr_uint8 flags) +{ + if (flags || length != 4) + { + gpr_log (GPR_ERROR, "invalid window update: length=%d, flags=%02x", length, flags); + return GRPC_CHTTP2_CONNECTION_ERROR; + } parser->byte = 0; parser->amount = 0; return GRPC_CHTTP2_PARSE_OK; } -grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { - gpr_uint8 *const beg = GPR_SLICE_START_PTR(slice); - gpr_uint8 *const end = GPR_SLICE_END_PTR(slice); +grpc_chttp2_parse_error +grpc_chttp2_window_update_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ + gpr_uint8 *const beg = GPR_SLICE_START_PTR (slice); + gpr_uint8 *const end = GPR_SLICE_END_PTR (slice); gpr_uint8 *cur = beg; grpc_chttp2_window_update_parser *p = parser; - while (p->byte != 4 && cur != end) { - p->amount |= ((gpr_uint32)*cur) << (8 * (3 - p->byte)); - cur++; - p->byte++; - } - - if (p->byte == 4) { - if (p->amount == 0 || (p->amount & 0x80000000u)) { - gpr_log(GPR_ERROR, "invalid window update bytes: %d", p->amount); - return GRPC_CHTTP2_CONNECTION_ERROR; + while (p->byte != 4 && cur != end) + { + p->amount |= ((gpr_uint32) * cur) << (8 * (3 - p->byte)); + cur++; + p->byte++; } - GPR_ASSERT(is_last); - if (transport_parsing->incoming_stream_id != 0) { - if (stream_parsing != NULL) { - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("update", transport_parsing, - stream_parsing, outgoing_window_update, - p->amount); - stream_parsing->outgoing_window_update += p->amount; - grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, - stream_parsing); - } - } else { - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT("update", transport_parsing, - outgoing_window_update, p->amount); - transport_parsing->outgoing_window_update += p->amount; + if (p->byte == 4) + { + if (p->amount == 0 || (p->amount & 0x80000000u)) + { + gpr_log (GPR_ERROR, "invalid window update bytes: %d", p->amount); + return GRPC_CHTTP2_CONNECTION_ERROR; + } + GPR_ASSERT (is_last); + + if (transport_parsing->incoming_stream_id != 0) + { + if (stream_parsing != NULL) + { + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("update", transport_parsing, stream_parsing, outgoing_window_update, p->amount); + stream_parsing->outgoing_window_update += p->amount; + grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing); + } + } + else + { + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("update", transport_parsing, outgoing_window_update, p->amount); + transport_parsing->outgoing_window_update += p->amount; + } } - } return GRPC_CHTTP2_PARSE_OK; } diff --git a/src/core/transport/chttp2/frame_window_update.h b/src/core/transport/chttp2/frame_window_update.h index b8fe9095b7..57d77b41cf 100644 --- a/src/core/transport/chttp2/frame_window_update.h +++ b/src/core/transport/chttp2/frame_window_update.h @@ -38,21 +38,16 @@ #include <grpc/support/slice.h> #include "src/core/transport/chttp2/frame.h" -typedef struct { +typedef struct +{ gpr_uint8 byte; gpr_uint8 is_connection_update; gpr_uint32 amount; } grpc_chttp2_window_update_parser; -gpr_slice grpc_chttp2_window_update_create(gpr_uint32 id, - gpr_uint32 window_delta); +gpr_slice grpc_chttp2_window_update_create (gpr_uint32 id, gpr_uint32 window_delta); -grpc_chttp2_parse_error grpc_chttp2_window_update_parser_begin_frame( - grpc_chttp2_window_update_parser *parser, gpr_uint32 length, - gpr_uint8 flags); -grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list); +grpc_chttp2_parse_error grpc_chttp2_window_update_parser_begin_frame (grpc_chttp2_window_update_parser * parser, gpr_uint32 length, gpr_uint8 flags); +grpc_chttp2_parse_error grpc_chttp2_window_update_parser_parse (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_FRAME_WINDOW_UPDATE_H */ diff --git a/src/core/transport/chttp2/hpack_parser.c b/src/core/transport/chttp2/hpack_parser.c index e66a918fcd..f3af6d91d2 100644 --- a/src/core/transport/chttp2/hpack_parser.c +++ b/src/core/transport/chttp2/hpack_parser.c @@ -45,7 +45,8 @@ #include <grpc/support/port_platform.h> #include <grpc/support/useful.h> -typedef enum { +typedef enum +{ NOT_BINARY, B64_BYTE0, B64_BYTE1, @@ -68,61 +69,34 @@ typedef enum { a set of indirect jumps, and so not waste stack space. */ /* forward declarations for parsing states */ -static int parse_begin(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_error(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); - -static int parse_string_prefix(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_key_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_value_string_with_indexed_key(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_value_string_with_literal_key(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, - const gpr_uint8 *end); - -static int parse_value0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_value1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_value2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_value3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_value4(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_value5up(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); - -static int parse_indexed_field(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_indexed_field_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_incidx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_incidx_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_incidx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_notidx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_notidx_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_notidx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_nvridx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); -static int parse_max_tbl_size(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end); -static int parse_max_tbl_size_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end); +static int parse_begin (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_error (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); + +static int parse_string_prefix (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_key_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_value_string_with_indexed_key (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_value_string_with_literal_key (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); + +static int parse_value0 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_value1 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_value2 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_value3 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_value4 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_value5up (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); + +static int parse_indexed_field (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_indexed_field_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_incidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_incidx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_incidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_notidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_notidx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_notidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_nvridx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_nvridx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_lithdr_nvridx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_max_tbl_size (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); +static int parse_max_tbl_size_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end); /* we translate the first byte of a hpack field into one of these decoding cases, then use a lookup table to jump directly to the appropriate parser. @@ -130,7 +104,8 @@ static int parse_max_tbl_size_x(grpc_chttp2_hpack_parser *p, _X => the integer index is all ones, meaning we need to do varint decoding _V => the integer index is all zeros, meaning we need to decode an additional string value */ -typedef enum { +typedef enum +{ INDEXED_FIELD, INDEXED_FIELD_X, LITHDR_INCIDX, @@ -150,81 +125,82 @@ typedef enum { /* jump table of parse state functions -- order must match first_byte_type above */ static const grpc_chttp2_hpack_parser_state first_byte_action[] = { - parse_indexed_field, parse_indexed_field_x, - parse_lithdr_incidx, parse_lithdr_incidx_x, - parse_lithdr_incidx_v, parse_lithdr_notidx, - parse_lithdr_notidx_x, parse_lithdr_notidx_v, - parse_lithdr_nvridx, parse_lithdr_nvridx_x, - parse_lithdr_nvridx_v, parse_max_tbl_size, - parse_max_tbl_size_x, parse_error}; + parse_indexed_field, parse_indexed_field_x, + parse_lithdr_incidx, parse_lithdr_incidx_x, + parse_lithdr_incidx_v, parse_lithdr_notidx, + parse_lithdr_notidx_x, parse_lithdr_notidx_v, + parse_lithdr_nvridx, parse_lithdr_nvridx_x, + parse_lithdr_nvridx_v, parse_max_tbl_size, + parse_max_tbl_size_x, parse_error +}; /* indexes the first byte to a parse state function - generated by gen_hpack_tables.c */ static const gpr_uint8 first_byte_lut[256] = { - LITHDR_NOTIDX_V, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, - LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, - LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, - LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX_X, - LITHDR_NVRIDX_V, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, - LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, - LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, - LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX_X, - ILLEGAL, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, - MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, - MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, - MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, - MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, - MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, - MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, - MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE_X, - LITHDR_INCIDX_V, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, - LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX_X, - ILLEGAL, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, - INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X, + LITHDR_NOTIDX_V, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, + LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, + LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, + LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX_X, + LITHDR_NVRIDX_V, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, + LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, + LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, + LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX_X, + ILLEGAL, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, + MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, + MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, + MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, + MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, + MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, + MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, + MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE_X, + LITHDR_INCIDX_V, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, + LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX_X, + ILLEGAL, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, + INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X, }; /* state table for huffman decoding: given a state, gives an index/16 into @@ -233,1118 +209,1217 @@ static const gpr_uint8 first_byte_lut[256] = { generated by gen_hpack_tables.c */ static const gpr_uint8 next_tbl[256] = { - 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8, 1, 3, 3, 9, 10, 11, 1, 1, - 1, 12, 1, 2, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, - 14, 1, 15, 16, 1, 17, 1, 15, 2, 7, 3, 18, 19, 1, 1, 1, 1, 20, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 7, 21, 1, 22, 1, 1, 1, 1, 1, - 1, 1, 1, 15, 2, 2, 2, 2, 2, 2, 23, 24, 25, 1, 1, 1, 1, 2, 2, 2, - 26, 3, 3, 27, 10, 28, 1, 1, 1, 1, 1, 1, 2, 3, 29, 10, 30, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 31, 1, 1, 1, 1, 1, 1, 1, 2, - 2, 2, 2, 2, 2, 2, 2, 32, 1, 1, 15, 33, 1, 34, 35, 9, 36, 1, 1, 1, - 1, 1, 1, 1, 37, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 26, 9, - 38, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 2, 2, 26, 3, 3, 39, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 40, 2, - 41, 1, 1, 1, 42, 43, 1, 1, 44, 1, 1, 1, 1, 15, 2, 2, 2, 2, 2, 2, - 3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2, + 0, 1, 2, 3, 4, 1, 2, 5, 6, 1, 7, 8, 1, 3, 3, 9, 10, 11, 1, 1, + 1, 12, 1, 2, 13, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 14, 1, 15, 16, 1, 17, 1, 15, 2, 7, 3, 18, 19, 1, 1, 1, 1, 20, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 7, 21, 1, 22, 1, 1, 1, 1, 1, + 1, 1, 1, 15, 2, 2, 2, 2, 2, 2, 23, 24, 25, 1, 1, 1, 1, 2, 2, 2, + 26, 3, 3, 27, 10, 28, 1, 1, 1, 1, 1, 1, 2, 3, 29, 10, 30, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 31, 1, 1, 1, 1, 1, 1, 1, 2, + 2, 2, 2, 2, 2, 2, 2, 32, 1, 1, 15, 33, 1, 34, 35, 9, 36, 1, 1, 1, + 1, 1, 1, 1, 37, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 26, 9, + 38, 1, 1, 1, 1, 1, 1, 1, 15, 2, 2, 2, 2, 26, 3, 3, 39, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 7, 3, 3, 3, 40, 2, + 41, 1, 1, 1, 42, 43, 1, 1, 44, 1, 1, 1, 1, 15, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 45, 46, 1, 1, 2, 2, 2, 35, 3, 3, 18, 47, 2, }; + /* next state, based upon current state and the current nibble: see above. generated by gen_hpack_tables.c */ static const gpr_int16 next_sub_tbl[48 * 16] = { - 1, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, - 218, 2, 6, 10, 13, 14, 15, 16, 17, 2, 6, 10, 13, 14, 15, - 16, 17, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11, 24, 3, - 7, 11, 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, - 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, - 199, 200, 201, 202, 203, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 9, 133, 134, 135, 136, 137, 138, 139, 140, - 141, 142, 143, 144, 145, 146, 147, 3, 7, 11, 24, 3, 7, 11, 24, - 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 12, 132, 4, 8, 4, 8, 4, 8, - 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 18, 19, 20, 21, 4, 8, 4, - 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 22, 23, 91, 25, 26, - 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 3, - 7, 11, 24, 3, 7, 11, 24, 0, 0, 0, 0, 0, 41, 42, 43, - 2, 6, 10, 13, 14, 15, 16, 17, 3, 7, 11, 24, 3, 7, 11, - 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, - 44, 45, 2, 6, 10, 13, 14, 15, 16, 17, 46, 47, 48, 49, 50, - 51, 52, 57, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, - 68, 69, 70, 71, 72, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 73, 75, 76, 77, 78, 79, 80, 81, 82, - 83, 84, 85, 86, 87, 88, 89, 90, 3, 7, 11, 24, 3, 7, 11, - 24, 3, 7, 11, 24, 0, 0, 0, 0, 3, 7, 11, 24, 3, 7, - 11, 24, 4, 8, 4, 8, 0, 0, 0, 92, 0, 0, 0, 93, 94, - 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 3, 7, 11, 24, - 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, - 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 4, - 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, - 0, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, - 131, 2, 6, 10, 13, 14, 15, 16, 17, 4, 8, 4, 8, 4, 8, - 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 148, - 149, 150, 151, 3, 7, 11, 24, 4, 8, 4, 8, 0, 0, 0, 0, - 0, 0, 152, 153, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11, - 24, 154, 155, 156, 164, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, - 11, 24, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 157, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 171, 172, - 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, - 188, 189, 190, 191, 192, 193, 194, 195, 196, 4, 8, 4, 8, 4, 8, - 4, 8, 4, 8, 4, 8, 4, 8, 197, 198, 4, 8, 4, 8, 4, - 8, 4, 8, 0, 0, 0, 0, 0, 0, 219, 220, 3, 7, 11, 24, - 4, 8, 4, 8, 4, 8, 0, 0, 221, 222, 223, 224, 3, 7, 11, - 24, 3, 7, 11, 24, 4, 8, 4, 8, 4, 8, 225, 228, 4, 8, - 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 226, 227, 229, - 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, - 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 245, 246, 247, 248, 249, 250, 251, 252, - 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 255, + 1, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, + 218, 2, 6, 10, 13, 14, 15, 16, 17, 2, 6, 10, 13, 14, 15, + 16, 17, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11, 24, 3, + 7, 11, 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, + 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, + 199, 200, 201, 202, 203, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 9, 133, 134, 135, 136, 137, 138, 139, 140, + 141, 142, 143, 144, 145, 146, 147, 3, 7, 11, 24, 3, 7, 11, 24, + 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 12, 132, 4, 8, 4, 8, 4, 8, + 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 18, 19, 20, 21, 4, 8, 4, + 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 22, 23, 91, 25, 26, + 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 3, + 7, 11, 24, 3, 7, 11, 24, 0, 0, 0, 0, 0, 41, 42, 43, + 2, 6, 10, 13, 14, 15, 16, 17, 3, 7, 11, 24, 3, 7, 11, + 24, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, + 44, 45, 2, 6, 10, 13, 14, 15, 16, 17, 46, 47, 48, 49, 50, + 51, 52, 57, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 53, 54, 55, 56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, + 68, 69, 70, 71, 72, 74, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 73, 75, 76, 77, 78, 79, 80, 81, 82, + 83, 84, 85, 86, 87, 88, 89, 90, 3, 7, 11, 24, 3, 7, 11, + 24, 3, 7, 11, 24, 0, 0, 0, 0, 3, 7, 11, 24, 3, 7, + 11, 24, 4, 8, 4, 8, 0, 0, 0, 92, 0, 0, 0, 93, 94, + 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 3, 7, 11, 24, + 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, + 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 4, + 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, + 0, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, + 131, 2, 6, 10, 13, 14, 15, 16, 17, 4, 8, 4, 8, 4, 8, + 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 148, + 149, 150, 151, 3, 7, 11, 24, 4, 8, 4, 8, 0, 0, 0, 0, + 0, 0, 152, 153, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, 11, + 24, 154, 155, 156, 164, 3, 7, 11, 24, 3, 7, 11, 24, 3, 7, + 11, 24, 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 157, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 171, 172, + 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, + 188, 189, 190, 191, 192, 193, 194, 195, 196, 4, 8, 4, 8, 4, 8, + 4, 8, 4, 8, 4, 8, 4, 8, 197, 198, 4, 8, 4, 8, 4, + 8, 4, 8, 0, 0, 0, 0, 0, 0, 219, 220, 3, 7, 11, 24, + 4, 8, 4, 8, 4, 8, 0, 0, 221, 222, 223, 224, 3, 7, 11, + 24, 3, 7, 11, 24, 4, 8, 4, 8, 4, 8, 225, 228, 4, 8, + 4, 8, 4, 8, 0, 0, 0, 0, 0, 0, 0, 0, 226, 227, 229, + 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, + 4, 8, 4, 8, 4, 8, 4, 8, 4, 8, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 245, 246, 247, 248, 249, 250, 251, 252, + 253, 254, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 255, }; + /* emission table: indexed like next_tbl, ultimately gives the byte to be emitted, or -1 for no byte, or 256 for end of stream generated by gen_hpack_tables.c */ static const gpr_uint16 emit_tbl[256] = { - 0, 1, 2, 3, 4, 5, 6, 7, 0, 8, 9, 10, 11, 12, 13, - 14, 15, 16, 17, 18, 19, 20, 21, 22, 0, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, - 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0, 55, 56, - 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 0, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, - 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, - 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, - 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, - 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, - 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 0, - 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, - 0, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, - 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, - 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, - 219, 220, 221, 0, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, - 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, - 248, + 0, 1, 2, 3, 4, 5, 6, 7, 0, 8, 9, 10, 11, 12, 13, + 14, 15, 16, 17, 18, 19, 20, 21, 22, 0, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, + 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 0, 55, 56, + 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 0, + 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, + 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, + 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, + 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, + 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, + 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 0, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, + 0, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, + 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, + 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, + 219, 220, 221, 0, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, + 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, + 248, }; + /* generated by gen_hpack_tables.c */ static const gpr_int16 emit_sub_tbl[249 * 16] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, - 49, 49, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 97, - 97, 97, 97, 48, 48, 49, 49, 50, 50, 97, 97, 99, 99, 101, 101, - 105, 105, 111, 111, 48, 49, 50, 97, 99, 101, 105, 111, 115, 116, -1, - -1, -1, -1, -1, -1, 32, 32, 32, 32, 32, 32, 32, 32, 37, 37, - 37, 37, 37, 37, 37, 37, 99, 99, 99, 99, 101, 101, 101, 101, 105, - 105, 105, 105, 111, 111, 111, 111, 115, 115, 116, 116, 32, 37, 45, 46, - 47, 51, 52, 53, 54, 55, 56, 57, 61, 61, 61, 61, 61, 61, 61, - 61, 65, 65, 65, 65, 65, 65, 65, 65, 115, 115, 115, 115, 116, 116, - 116, 116, 32, 32, 37, 37, 45, 45, 46, 46, 61, 65, 95, 98, 100, - 102, 103, 104, 108, 109, 110, 112, 114, 117, -1, -1, 58, 58, 58, 58, - 58, 58, 58, 58, 66, 66, 66, 66, 66, 66, 66, 66, 47, 47, 51, - 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 61, 61, - 65, 65, 95, 95, 98, 98, 100, 100, 102, 102, 103, 103, 104, 104, 108, - 108, 109, 109, 110, 110, 112, 112, 114, 114, 117, 117, 58, 66, 67, 68, - 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, - 84, 85, 86, 87, 89, 106, 107, 113, 118, 119, 120, 121, 122, -1, -1, - -1, -1, 38, 38, 38, 38, 38, 38, 38, 38, 42, 42, 42, 42, 42, - 42, 42, 42, 44, 44, 44, 44, 44, 44, 44, 44, 59, 59, 59, 59, - 59, 59, 59, 59, 88, 88, 88, 88, 88, 88, 88, 88, 90, 90, 90, - 90, 90, 90, 90, 90, 33, 33, 34, 34, 40, 40, 41, 41, 63, 63, - 39, 43, 124, -1, -1, -1, 35, 35, 35, 35, 35, 35, 35, 35, 62, - 62, 62, 62, 62, 62, 62, 62, 0, 0, 0, 0, 36, 36, 36, 36, - 64, 64, 64, 64, 91, 91, 91, 91, 69, 69, 69, 69, 69, 69, 69, - 69, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, - 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73, - 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, - 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, - 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79, - 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 81, - 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82, - 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84, - 84, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, - 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, 89, - 89, 89, 89, 106, 106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107, - 107, 107, 107, 107, 113, 113, 113, 113, 113, 113, 113, 113, 118, 118, 118, - 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 120, 120, - 120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 121, 122, - 122, 122, 122, 122, 122, 122, 122, 38, 38, 38, 38, 42, 42, 42, 42, - 44, 44, 44, 44, 59, 59, 59, 59, 88, 88, 88, 88, 90, 90, 90, - 90, 33, 34, 40, 41, 63, -1, -1, -1, 39, 39, 39, 39, 39, 39, - 39, 39, 43, 43, 43, 43, 43, 43, 43, 43, 124, 124, 124, 124, 124, - 124, 124, 124, 35, 35, 35, 35, 62, 62, 62, 62, 0, 0, 36, 36, - 64, 64, 91, 91, 93, 93, 126, 126, 94, 125, -1, -1, 60, 60, 60, - 60, 60, 60, 60, 60, 96, 96, 96, 96, 96, 96, 96, 96, 123, 123, - 123, 123, 123, 123, 123, 123, -1, -1, -1, -1, -1, -1, -1, -1, 92, - 92, 92, 92, 92, 92, 92, 92, 195, 195, 195, 195, 195, 195, 195, 195, - 208, 208, 208, 208, 208, 208, 208, 208, 128, 128, 128, 128, 130, 130, 130, - 130, 131, 131, 131, 131, 162, 162, 162, 162, 184, 184, 184, 184, 194, 194, - 194, 194, 224, 224, 224, 224, 226, 226, 226, 226, 153, 153, 161, 161, 167, - 167, 172, 172, 176, 176, 177, 177, 179, 179, 209, 209, 216, 216, 217, 217, - 227, 227, 229, 229, 230, 230, 129, 132, 133, 134, 136, 146, 154, 156, 160, - 163, 164, 169, 170, 173, 178, 181, 185, 186, 187, 189, 190, 196, 198, 228, - 232, 233, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 135, - 135, 135, 135, 135, 135, 135, 135, 137, 137, 137, 137, 137, 137, 137, 137, - 138, 138, 138, 138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 139, 139, - 139, 140, 140, 140, 140, 140, 140, 140, 140, 141, 141, 141, 141, 141, 141, - 141, 141, 143, 143, 143, 143, 143, 143, 143, 143, 147, 147, 147, 147, 147, - 147, 147, 147, 149, 149, 149, 149, 149, 149, 149, 149, 150, 150, 150, 150, - 150, 150, 150, 150, 151, 151, 151, 151, 151, 151, 151, 151, 152, 152, 152, - 152, 152, 152, 152, 152, 155, 155, 155, 155, 155, 155, 155, 155, 157, 157, - 157, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 158, 158, 158, 165, - 165, 165, 165, 165, 165, 165, 165, 166, 166, 166, 166, 166, 166, 166, 166, - 168, 168, 168, 168, 168, 168, 168, 168, 174, 174, 174, 174, 174, 174, 174, - 174, 175, 175, 175, 175, 175, 175, 175, 175, 180, 180, 180, 180, 180, 180, - 180, 180, 182, 182, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183, - 183, 183, 183, 188, 188, 188, 188, 188, 188, 188, 188, 191, 191, 191, 191, - 191, 191, 191, 191, 197, 197, 197, 197, 197, 197, 197, 197, 231, 231, 231, - 231, 231, 231, 231, 231, 239, 239, 239, 239, 239, 239, 239, 239, 9, 9, - 9, 9, 142, 142, 142, 142, 144, 144, 144, 144, 145, 145, 145, 145, 148, - 148, 148, 148, 159, 159, 159, 159, 171, 171, 171, 171, 206, 206, 206, 206, - 215, 215, 215, 215, 225, 225, 225, 225, 236, 236, 236, 236, 237, 237, 237, - 237, 199, 199, 207, 207, 234, 234, 235, 235, 192, 193, 200, 201, 202, 205, - 210, 213, 218, 219, 238, 240, 242, 243, 255, -1, 203, 203, 203, 203, 203, - 203, 203, 203, 204, 204, 204, 204, 204, 204, 204, 204, 211, 211, 211, 211, - 211, 211, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 214, 214, 214, - 214, 214, 214, 214, 214, 221, 221, 221, 221, 221, 221, 221, 221, 222, 222, - 222, 222, 222, 222, 222, 222, 223, 223, 223, 223, 223, 223, 223, 223, 241, - 241, 241, 241, 241, 241, 241, 241, 244, 244, 244, 244, 244, 244, 244, 244, - 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, - 246, 247, 247, 247, 247, 247, 247, 247, 247, 248, 248, 248, 248, 248, 248, - 248, 248, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251, - 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253, - 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 2, 2, 2, - 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, - 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 11, 11, 11, 11, 12, - 12, 12, 12, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, - 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, - 20, 21, 21, 21, 21, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, - 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, - 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 127, 127, 127, 127, - 220, 220, 220, 220, 249, 249, 249, 249, 10, 13, 22, 256, 93, 93, 93, - 93, 126, 126, 126, 126, 94, 94, 125, 125, 60, 96, 123, -1, 92, 195, - 208, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 128, - 128, 128, 128, 128, 128, 128, 128, 130, 130, 130, 130, 130, 130, 130, 130, - 131, 131, 131, 131, 131, 131, 131, 131, 162, 162, 162, 162, 162, 162, 162, - 162, 184, 184, 184, 184, 184, 184, 184, 184, 194, 194, 194, 194, 194, 194, - 194, 194, 224, 224, 224, 224, 224, 224, 224, 224, 226, 226, 226, 226, 226, - 226, 226, 226, 153, 153, 153, 153, 161, 161, 161, 161, 167, 167, 167, 167, - 172, 172, 172, 172, 176, 176, 176, 176, 177, 177, 177, 177, 179, 179, 179, - 179, 209, 209, 209, 209, 216, 216, 216, 216, 217, 217, 217, 217, 227, 227, - 227, 227, 229, 229, 229, 229, 230, 230, 230, 230, 129, 129, 132, 132, 133, - 133, 134, 134, 136, 136, 146, 146, 154, 154, 156, 156, 160, 160, 163, 163, - 164, 164, 169, 169, 170, 170, 173, 173, 178, 178, 181, 181, 185, 185, 186, - 186, 187, 187, 189, 189, 190, 190, 196, 196, 198, 198, 228, 228, 232, 232, - 233, 233, 1, 135, 137, 138, 139, 140, 141, 143, 147, 149, 150, 151, 152, - 155, 157, 158, 165, 166, 168, 174, 175, 180, 182, 183, 188, 191, 197, 231, - 239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 9, 9, - 9, 9, 9, 9, 9, 142, 142, 142, 142, 142, 142, 142, 142, 144, 144, - 144, 144, 144, 144, 144, 144, 145, 145, 145, 145, 145, 145, 145, 145, 148, - 148, 148, 148, 148, 148, 148, 148, 159, 159, 159, 159, 159, 159, 159, 159, - 171, 171, 171, 171, 171, 171, 171, 171, 206, 206, 206, 206, 206, 206, 206, - 206, 215, 215, 215, 215, 215, 215, 215, 215, 225, 225, 225, 225, 225, 225, - 225, 225, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237, - 237, 237, 237, 199, 199, 199, 199, 207, 207, 207, 207, 234, 234, 234, 234, - 235, 235, 235, 235, 192, 192, 193, 193, 200, 200, 201, 201, 202, 202, 205, - 205, 210, 210, 213, 213, 218, 218, 219, 219, 238, 238, 240, 240, 242, 242, - 243, 243, 255, 255, 203, 204, 211, 212, 214, 221, 222, 223, 241, 244, 245, - 246, 247, 248, 250, 251, 252, 253, 254, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, - 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, - 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, - 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, - 8, 8, 8, 8, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, - 12, 12, 12, 12, 12, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, - 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17, - 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, - 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, - 20, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23, - 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, - 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, - 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, - 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, - 31, 31, 31, 31, 31, 31, 127, 127, 127, 127, 127, 127, 127, 127, 220, - 220, 220, 220, 220, 220, 220, 220, 249, 249, 249, 249, 249, 249, 249, 249, - 10, 10, 13, 13, 22, 22, 256, 256, 67, 67, 67, 67, 67, 67, 67, - 67, 68, 68, 68, 68, 68, 68, 68, 68, 95, 95, 95, 95, 95, 95, - 95, 95, 98, 98, 98, 98, 98, 98, 98, 98, 100, 100, 100, 100, 100, - 100, 100, 100, 102, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103, - 103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 108, 108, 108, - 108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109, 109, 109, 110, 110, - 110, 110, 110, 110, 110, 110, 112, 112, 112, 112, 112, 112, 112, 112, 114, - 114, 114, 114, 114, 114, 114, 114, 117, 117, 117, 117, 117, 117, 117, 117, - 58, 58, 58, 58, 66, 66, 66, 66, 67, 67, 67, 67, 68, 68, 68, - 68, 69, 69, 69, 69, 70, 70, 70, 70, 71, 71, 71, 71, 72, 72, - 72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 75, 76, - 76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 79, - 80, 80, 80, 80, 81, 81, 81, 81, 82, 82, 82, 82, 83, 83, 83, - 83, 84, 84, 84, 84, 85, 85, 85, 85, 86, 86, 86, 86, 87, 87, - 87, 87, 89, 89, 89, 89, 106, 106, 106, 106, 107, 107, 107, 107, 113, - 113, 113, 113, 118, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 120, - 121, 121, 121, 121, 122, 122, 122, 122, 38, 38, 42, 42, 44, 44, 59, - 59, 88, 88, 90, 90, -1, -1, -1, -1, 33, 33, 33, 33, 33, 33, - 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 40, 40, 40, 40, 40, - 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 63, 63, 63, 63, - 63, 63, 63, 63, 39, 39, 39, 39, 43, 43, 43, 43, 124, 124, 124, - 124, 35, 35, 62, 62, 0, 36, 64, 91, 93, 126, -1, -1, 94, 94, - 94, 94, 94, 94, 94, 94, 125, 125, 125, 125, 125, 125, 125, 125, 60, - 60, 60, 60, 96, 96, 96, 96, 123, 123, 123, 123, -1, -1, -1, -1, - 92, 92, 92, 92, 195, 195, 195, 195, 208, 208, 208, 208, 128, 128, 130, - 130, 131, 131, 162, 162, 184, 184, 194, 194, 224, 224, 226, 226, 153, 161, - 167, 172, 176, 177, 179, 209, 216, 217, 227, 229, 230, -1, -1, -1, -1, - -1, -1, -1, 129, 129, 129, 129, 129, 129, 129, 129, 132, 132, 132, 132, - 132, 132, 132, 132, 133, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134, - 134, 134, 134, 134, 134, 136, 136, 136, 136, 136, 136, 136, 136, 146, 146, - 146, 146, 146, 146, 146, 146, 154, 154, 154, 154, 154, 154, 154, 154, 156, - 156, 156, 156, 156, 156, 156, 156, 160, 160, 160, 160, 160, 160, 160, 160, - 163, 163, 163, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 164, 164, - 164, 169, 169, 169, 169, 169, 169, 169, 169, 170, 170, 170, 170, 170, 170, - 170, 170, 173, 173, 173, 173, 173, 173, 173, 173, 178, 178, 178, 178, 178, - 178, 178, 178, 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, 185, 185, - 185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187, - 187, 187, 187, 187, 187, 189, 189, 189, 189, 189, 189, 189, 189, 190, 190, - 190, 190, 190, 190, 190, 190, 196, 196, 196, 196, 196, 196, 196, 196, 198, - 198, 198, 198, 198, 198, 198, 198, 228, 228, 228, 228, 228, 228, 228, 228, - 232, 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 233, 233, 233, 233, - 233, 1, 1, 1, 1, 135, 135, 135, 135, 137, 137, 137, 137, 138, 138, - 138, 138, 139, 139, 139, 139, 140, 140, 140, 140, 141, 141, 141, 141, 143, - 143, 143, 143, 147, 147, 147, 147, 149, 149, 149, 149, 150, 150, 150, 150, - 151, 151, 151, 151, 152, 152, 152, 152, 155, 155, 155, 155, 157, 157, 157, - 157, 158, 158, 158, 158, 165, 165, 165, 165, 166, 166, 166, 166, 168, 168, - 168, 168, 174, 174, 174, 174, 175, 175, 175, 175, 180, 180, 180, 180, 182, - 182, 182, 182, 183, 183, 183, 183, 188, 188, 188, 188, 191, 191, 191, 191, - 197, 197, 197, 197, 231, 231, 231, 231, 239, 239, 239, 239, 9, 9, 142, - 142, 144, 144, 145, 145, 148, 148, 159, 159, 171, 171, 206, 206, 215, 215, - 225, 225, 236, 236, 237, 237, 199, 207, 234, 235, 192, 192, 192, 192, 192, - 192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 200, 200, 200, 200, - 200, 200, 200, 200, 201, 201, 201, 201, 201, 201, 201, 201, 202, 202, 202, - 202, 202, 202, 202, 202, 205, 205, 205, 205, 205, 205, 205, 205, 210, 210, - 210, 210, 210, 210, 210, 210, 213, 213, 213, 213, 213, 213, 213, 213, 218, - 218, 218, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 219, - 238, 238, 238, 238, 238, 238, 238, 238, 240, 240, 240, 240, 240, 240, 240, - 240, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243, 243, - 243, 243, 255, 255, 255, 255, 255, 255, 255, 255, 203, 203, 203, 203, 204, - 204, 204, 204, 211, 211, 211, 211, 212, 212, 212, 212, 214, 214, 214, 214, - 221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 241, 241, 241, - 241, 244, 244, 244, 244, 245, 245, 245, 245, 246, 246, 246, 246, 247, 247, - 247, 247, 248, 248, 248, 248, 250, 250, 250, 250, 251, 251, 251, 251, 252, - 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 2, 2, 3, 3, - 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 11, 11, 12, 12, 14, - 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, - 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, - 30, 31, 31, 127, 127, 220, 220, 249, 249, -1, -1, 10, 10, 10, 10, - 10, 10, 10, 10, 13, 13, 13, 13, 13, 13, 13, 13, 22, 22, 22, - 22, 22, 22, 22, 22, 256, 256, 256, 256, 256, 256, 256, 256, 45, 45, - 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 47, - 47, 47, 47, 47, 47, 47, 47, 51, 51, 51, 51, 51, 51, 51, 51, - 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, - 53, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55, - 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, - 57, 57, 57, 50, 50, 50, 50, 50, 50, 50, 50, 97, 97, 97, 97, - 97, 97, 97, 97, 99, 99, 99, 99, 99, 99, 99, 99, 101, 101, 101, - 101, 101, 101, 101, 101, 105, 105, 105, 105, 105, 105, 105, 105, 111, 111, - 111, 111, 111, 111, 111, 111, 115, 115, 115, 115, 115, 115, 115, 115, 116, - 116, 116, 116, 116, 116, 116, 116, 32, 32, 32, 32, 37, 37, 37, 37, - 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 51, 51, 51, - 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, - 55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 61, 61, 61, 61, 65, - 65, 65, 65, 95, 95, 95, 95, 98, 98, 98, 98, 100, 100, 100, 100, - 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, 104, 104, 108, 108, 108, - 108, 109, 109, 109, 109, 110, 110, 110, 110, 112, 112, 112, 112, 114, 114, - 114, 114, 117, 117, 117, 117, 58, 58, 66, 66, 67, 67, 68, 68, 69, - 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76, - 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 82, 82, 83, 83, 84, - 84, 85, 85, 86, 86, 87, 87, 89, 89, 106, 106, 107, 107, 113, 113, - 118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 38, 42, 44, 59, 88, - 90, -1, -1, 33, 33, 33, 33, 34, 34, 34, 34, 40, 40, 40, 40, - 41, 41, 41, 41, 63, 63, 63, 63, 39, 39, 43, 43, 124, 124, 35, - 62, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36, - 36, 36, 36, 36, 36, 36, 64, 64, 64, 64, 64, 64, 64, 64, 91, - 91, 91, 91, 91, 91, 91, 91, 93, 93, 93, 93, 93, 93, 93, 93, - 126, 126, 126, 126, 126, 126, 126, 126, 94, 94, 94, 94, 125, 125, 125, - 125, 60, 60, 96, 96, 123, 123, -1, -1, 92, 92, 195, 195, 208, 208, - 128, 130, 131, 162, 184, 194, 224, 226, -1, -1, 153, 153, 153, 153, 153, - 153, 153, 153, 161, 161, 161, 161, 161, 161, 161, 161, 167, 167, 167, 167, - 167, 167, 167, 167, 172, 172, 172, 172, 172, 172, 172, 172, 176, 176, 176, - 176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 177, 177, 177, 179, 179, - 179, 179, 179, 179, 179, 179, 209, 209, 209, 209, 209, 209, 209, 209, 216, - 216, 216, 216, 216, 216, 216, 216, 217, 217, 217, 217, 217, 217, 217, 217, - 227, 227, 227, 227, 227, 227, 227, 227, 229, 229, 229, 229, 229, 229, 229, - 229, 230, 230, 230, 230, 230, 230, 230, 230, 129, 129, 129, 129, 132, 132, - 132, 132, 133, 133, 133, 133, 134, 134, 134, 134, 136, 136, 136, 136, 146, - 146, 146, 146, 154, 154, 154, 154, 156, 156, 156, 156, 160, 160, 160, 160, - 163, 163, 163, 163, 164, 164, 164, 164, 169, 169, 169, 169, 170, 170, 170, - 170, 173, 173, 173, 173, 178, 178, 178, 178, 181, 181, 181, 181, 185, 185, - 185, 185, 186, 186, 186, 186, 187, 187, 187, 187, 189, 189, 189, 189, 190, - 190, 190, 190, 196, 196, 196, 196, 198, 198, 198, 198, 228, 228, 228, 228, - 232, 232, 232, 232, 233, 233, 233, 233, 1, 1, 135, 135, 137, 137, 138, - 138, 139, 139, 140, 140, 141, 141, 143, 143, 147, 147, 149, 149, 150, 150, - 151, 151, 152, 152, 155, 155, 157, 157, 158, 158, 165, 165, 166, 166, 168, - 168, 174, 174, 175, 175, 180, 180, 182, 182, 183, 183, 188, 188, 191, 191, - 197, 197, 231, 231, 239, 239, 9, 142, 144, 145, 148, 159, 171, 206, 215, - 225, 236, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 199, 199, - 199, 199, 199, 199, 199, 199, 207, 207, 207, 207, 207, 207, 207, 207, 234, - 234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235, - 192, 192, 192, 192, 193, 193, 193, 193, 200, 200, 200, 200, 201, 201, 201, - 201, 202, 202, 202, 202, 205, 205, 205, 205, 210, 210, 210, 210, 213, 213, - 213, 213, 218, 218, 218, 218, 219, 219, 219, 219, 238, 238, 238, 238, 240, - 240, 240, 240, 242, 242, 242, 242, 243, 243, 243, 243, 255, 255, 255, 255, - 203, 203, 204, 204, 211, 211, 212, 212, 214, 214, 221, 221, 222, 222, 223, - 223, 241, 241, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 250, 250, - 251, 251, 252, 252, 253, 253, 254, 254, 2, 3, 4, 5, 6, 7, 8, - 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, - 28, 29, 30, 31, 127, 220, 249, -1, 10, 10, 10, 10, 13, 13, 13, - 13, 22, 22, 22, 22, 256, 256, 256, 256, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, 48, 48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, + 49, 49, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 97, + 97, 97, 97, 48, 48, 49, 49, 50, 50, 97, 97, 99, 99, 101, 101, + 105, 105, 111, 111, 48, 49, 50, 97, 99, 101, 105, 111, 115, 116, -1, + -1, -1, -1, -1, -1, 32, 32, 32, 32, 32, 32, 32, 32, 37, 37, + 37, 37, 37, 37, 37, 37, 99, 99, 99, 99, 101, 101, 101, 101, 105, + 105, 105, 105, 111, 111, 111, 111, 115, 115, 116, 116, 32, 37, 45, 46, + 47, 51, 52, 53, 54, 55, 56, 57, 61, 61, 61, 61, 61, 61, 61, + 61, 65, 65, 65, 65, 65, 65, 65, 65, 115, 115, 115, 115, 116, 116, + 116, 116, 32, 32, 37, 37, 45, 45, 46, 46, 61, 65, 95, 98, 100, + 102, 103, 104, 108, 109, 110, 112, 114, 117, -1, -1, 58, 58, 58, 58, + 58, 58, 58, 58, 66, 66, 66, 66, 66, 66, 66, 66, 47, 47, 51, + 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 56, 57, 57, 61, 61, + 65, 65, 95, 95, 98, 98, 100, 100, 102, 102, 103, 103, 104, 104, 108, + 108, 109, 109, 110, 110, 112, 112, 114, 114, 117, 117, 58, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, + 84, 85, 86, 87, 89, 106, 107, 113, 118, 119, 120, 121, 122, -1, -1, + -1, -1, 38, 38, 38, 38, 38, 38, 38, 38, 42, 42, 42, 42, 42, + 42, 42, 42, 44, 44, 44, 44, 44, 44, 44, 44, 59, 59, 59, 59, + 59, 59, 59, 59, 88, 88, 88, 88, 88, 88, 88, 88, 90, 90, 90, + 90, 90, 90, 90, 90, 33, 33, 34, 34, 40, 40, 41, 41, 63, 63, + 39, 43, 124, -1, -1, -1, 35, 35, 35, 35, 35, 35, 35, 35, 62, + 62, 62, 62, 62, 62, 62, 62, 0, 0, 0, 0, 36, 36, 36, 36, + 64, 64, 64, 64, 91, 91, 91, 91, 69, 69, 69, 69, 69, 69, 69, + 69, 70, 70, 70, 70, 70, 70, 70, 70, 71, 71, 71, 71, 71, 71, + 71, 71, 72, 72, 72, 72, 72, 72, 72, 72, 73, 73, 73, 73, 73, + 73, 73, 73, 74, 74, 74, 74, 74, 74, 74, 74, 75, 75, 75, 75, + 75, 75, 75, 75, 76, 76, 76, 76, 76, 76, 76, 76, 77, 77, 77, + 77, 77, 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, 78, 79, 79, + 79, 79, 79, 79, 79, 79, 80, 80, 80, 80, 80, 80, 80, 80, 81, + 81, 81, 81, 81, 81, 81, 81, 82, 82, 82, 82, 82, 82, 82, 82, + 83, 83, 83, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 84, 84, + 84, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, + 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 89, 89, 89, 89, 89, + 89, 89, 89, 106, 106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107, + 107, 107, 107, 107, 113, 113, 113, 113, 113, 113, 113, 113, 118, 118, 118, + 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 119, 120, 120, + 120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 121, 122, + 122, 122, 122, 122, 122, 122, 122, 38, 38, 38, 38, 42, 42, 42, 42, + 44, 44, 44, 44, 59, 59, 59, 59, 88, 88, 88, 88, 90, 90, 90, + 90, 33, 34, 40, 41, 63, -1, -1, -1, 39, 39, 39, 39, 39, 39, + 39, 39, 43, 43, 43, 43, 43, 43, 43, 43, 124, 124, 124, 124, 124, + 124, 124, 124, 35, 35, 35, 35, 62, 62, 62, 62, 0, 0, 36, 36, + 64, 64, 91, 91, 93, 93, 126, 126, 94, 125, -1, -1, 60, 60, 60, + 60, 60, 60, 60, 60, 96, 96, 96, 96, 96, 96, 96, 96, 123, 123, + 123, 123, 123, 123, 123, 123, -1, -1, -1, -1, -1, -1, -1, -1, 92, + 92, 92, 92, 92, 92, 92, 92, 195, 195, 195, 195, 195, 195, 195, 195, + 208, 208, 208, 208, 208, 208, 208, 208, 128, 128, 128, 128, 130, 130, 130, + 130, 131, 131, 131, 131, 162, 162, 162, 162, 184, 184, 184, 184, 194, 194, + 194, 194, 224, 224, 224, 224, 226, 226, 226, 226, 153, 153, 161, 161, 167, + 167, 172, 172, 176, 176, 177, 177, 179, 179, 209, 209, 216, 216, 217, 217, + 227, 227, 229, 229, 230, 230, 129, 132, 133, 134, 136, 146, 154, 156, 160, + 163, 164, 169, 170, 173, 178, 181, 185, 186, 187, 189, 190, 196, 198, 228, + 232, 233, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 135, + 135, 135, 135, 135, 135, 135, 135, 137, 137, 137, 137, 137, 137, 137, 137, + 138, 138, 138, 138, 138, 138, 138, 138, 139, 139, 139, 139, 139, 139, 139, + 139, 140, 140, 140, 140, 140, 140, 140, 140, 141, 141, 141, 141, 141, 141, + 141, 141, 143, 143, 143, 143, 143, 143, 143, 143, 147, 147, 147, 147, 147, + 147, 147, 147, 149, 149, 149, 149, 149, 149, 149, 149, 150, 150, 150, 150, + 150, 150, 150, 150, 151, 151, 151, 151, 151, 151, 151, 151, 152, 152, 152, + 152, 152, 152, 152, 152, 155, 155, 155, 155, 155, 155, 155, 155, 157, 157, + 157, 157, 157, 157, 157, 157, 158, 158, 158, 158, 158, 158, 158, 158, 165, + 165, 165, 165, 165, 165, 165, 165, 166, 166, 166, 166, 166, 166, 166, 166, + 168, 168, 168, 168, 168, 168, 168, 168, 174, 174, 174, 174, 174, 174, 174, + 174, 175, 175, 175, 175, 175, 175, 175, 175, 180, 180, 180, 180, 180, 180, + 180, 180, 182, 182, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183, + 183, 183, 183, 188, 188, 188, 188, 188, 188, 188, 188, 191, 191, 191, 191, + 191, 191, 191, 191, 197, 197, 197, 197, 197, 197, 197, 197, 231, 231, 231, + 231, 231, 231, 231, 231, 239, 239, 239, 239, 239, 239, 239, 239, 9, 9, + 9, 9, 142, 142, 142, 142, 144, 144, 144, 144, 145, 145, 145, 145, 148, + 148, 148, 148, 159, 159, 159, 159, 171, 171, 171, 171, 206, 206, 206, 206, + 215, 215, 215, 215, 225, 225, 225, 225, 236, 236, 236, 236, 237, 237, 237, + 237, 199, 199, 207, 207, 234, 234, 235, 235, 192, 193, 200, 201, 202, 205, + 210, 213, 218, 219, 238, 240, 242, 243, 255, -1, 203, 203, 203, 203, 203, + 203, 203, 203, 204, 204, 204, 204, 204, 204, 204, 204, 211, 211, 211, 211, + 211, 211, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 214, 214, 214, + 214, 214, 214, 214, 214, 221, 221, 221, 221, 221, 221, 221, 221, 222, 222, + 222, 222, 222, 222, 222, 222, 223, 223, 223, 223, 223, 223, 223, 223, 241, + 241, 241, 241, 241, 241, 241, 241, 244, 244, 244, 244, 244, 244, 244, 244, + 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, + 246, 247, 247, 247, 247, 247, 247, 247, 247, 248, 248, 248, 248, 248, 248, + 248, 248, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251, + 251, 251, 251, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253, + 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 2, 2, 2, + 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, + 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 11, 11, 11, 11, 12, + 12, 12, 12, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, + 17, 17, 17, 17, 18, 18, 18, 18, 19, 19, 19, 19, 20, 20, 20, + 20, 21, 21, 21, 21, 23, 23, 23, 23, 24, 24, 24, 24, 25, 25, + 25, 25, 26, 26, 26, 26, 27, 27, 27, 27, 28, 28, 28, 28, 29, + 29, 29, 29, 30, 30, 30, 30, 31, 31, 31, 31, 127, 127, 127, 127, + 220, 220, 220, 220, 249, 249, 249, 249, 10, 13, 22, 256, 93, 93, 93, + 93, 126, 126, 126, 126, 94, 94, 125, 125, 60, 96, 123, -1, 92, 195, + 208, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 128, + 128, 128, 128, 128, 128, 128, 128, 130, 130, 130, 130, 130, 130, 130, 130, + 131, 131, 131, 131, 131, 131, 131, 131, 162, 162, 162, 162, 162, 162, 162, + 162, 184, 184, 184, 184, 184, 184, 184, 184, 194, 194, 194, 194, 194, 194, + 194, 194, 224, 224, 224, 224, 224, 224, 224, 224, 226, 226, 226, 226, 226, + 226, 226, 226, 153, 153, 153, 153, 161, 161, 161, 161, 167, 167, 167, 167, + 172, 172, 172, 172, 176, 176, 176, 176, 177, 177, 177, 177, 179, 179, 179, + 179, 209, 209, 209, 209, 216, 216, 216, 216, 217, 217, 217, 217, 227, 227, + 227, 227, 229, 229, 229, 229, 230, 230, 230, 230, 129, 129, 132, 132, 133, + 133, 134, 134, 136, 136, 146, 146, 154, 154, 156, 156, 160, 160, 163, 163, + 164, 164, 169, 169, 170, 170, 173, 173, 178, 178, 181, 181, 185, 185, 186, + 186, 187, 187, 189, 189, 190, 190, 196, 196, 198, 198, 228, 228, 232, 232, + 233, 233, 1, 135, 137, 138, 139, 140, 141, 143, 147, 149, 150, 151, 152, + 155, 157, 158, 165, 166, 168, 174, 175, 180, 182, 183, 188, 191, 197, 231, + 239, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 9, 9, 9, + 9, 9, 9, 9, 9, 142, 142, 142, 142, 142, 142, 142, 142, 144, 144, + 144, 144, 144, 144, 144, 144, 145, 145, 145, 145, 145, 145, 145, 145, 148, + 148, 148, 148, 148, 148, 148, 148, 159, 159, 159, 159, 159, 159, 159, 159, + 171, 171, 171, 171, 171, 171, 171, 171, 206, 206, 206, 206, 206, 206, 206, + 206, 215, 215, 215, 215, 215, 215, 215, 215, 225, 225, 225, 225, 225, 225, + 225, 225, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237, + 237, 237, 237, 199, 199, 199, 199, 207, 207, 207, 207, 234, 234, 234, 234, + 235, 235, 235, 235, 192, 192, 193, 193, 200, 200, 201, 201, 202, 202, 205, + 205, 210, 210, 213, 213, 218, 218, 219, 219, 238, 238, 240, 240, 242, 242, + 243, 243, 255, 255, 203, 204, 211, 212, 214, 221, 222, 223, 241, 244, 245, + 246, 247, 248, 250, 251, 252, 253, 254, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 2, 2, + 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, + 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, + 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, + 8, 8, 8, 8, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, + 12, 12, 12, 12, 12, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, + 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 17, + 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, + 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, + 20, 21, 21, 21, 21, 21, 21, 21, 21, 23, 23, 23, 23, 23, 23, + 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, + 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, + 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, + 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 31, 31, + 31, 31, 31, 31, 31, 31, 127, 127, 127, 127, 127, 127, 127, 127, 220, + 220, 220, 220, 220, 220, 220, 220, 249, 249, 249, 249, 249, 249, 249, 249, + 10, 10, 13, 13, 22, 22, 256, 256, 67, 67, 67, 67, 67, 67, 67, + 67, 68, 68, 68, 68, 68, 68, 68, 68, 95, 95, 95, 95, 95, 95, + 95, 95, 98, 98, 98, 98, 98, 98, 98, 98, 100, 100, 100, 100, 100, + 100, 100, 100, 102, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103, + 103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 104, 108, 108, 108, + 108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109, 109, 109, 110, 110, + 110, 110, 110, 110, 110, 110, 112, 112, 112, 112, 112, 112, 112, 112, 114, + 114, 114, 114, 114, 114, 114, 114, 117, 117, 117, 117, 117, 117, 117, 117, + 58, 58, 58, 58, 66, 66, 66, 66, 67, 67, 67, 67, 68, 68, 68, + 68, 69, 69, 69, 69, 70, 70, 70, 70, 71, 71, 71, 71, 72, 72, + 72, 72, 73, 73, 73, 73, 74, 74, 74, 74, 75, 75, 75, 75, 76, + 76, 76, 76, 77, 77, 77, 77, 78, 78, 78, 78, 79, 79, 79, 79, + 80, 80, 80, 80, 81, 81, 81, 81, 82, 82, 82, 82, 83, 83, 83, + 83, 84, 84, 84, 84, 85, 85, 85, 85, 86, 86, 86, 86, 87, 87, + 87, 87, 89, 89, 89, 89, 106, 106, 106, 106, 107, 107, 107, 107, 113, + 113, 113, 113, 118, 118, 118, 118, 119, 119, 119, 119, 120, 120, 120, 120, + 121, 121, 121, 121, 122, 122, 122, 122, 38, 38, 42, 42, 44, 44, 59, + 59, 88, 88, 90, 90, -1, -1, -1, -1, 33, 33, 33, 33, 33, 33, + 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 40, 40, 40, 40, 40, + 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 63, 63, 63, 63, + 63, 63, 63, 63, 39, 39, 39, 39, 43, 43, 43, 43, 124, 124, 124, + 124, 35, 35, 62, 62, 0, 36, 64, 91, 93, 126, -1, -1, 94, 94, + 94, 94, 94, 94, 94, 94, 125, 125, 125, 125, 125, 125, 125, 125, 60, + 60, 60, 60, 96, 96, 96, 96, 123, 123, 123, 123, -1, -1, -1, -1, + 92, 92, 92, 92, 195, 195, 195, 195, 208, 208, 208, 208, 128, 128, 130, + 130, 131, 131, 162, 162, 184, 184, 194, 194, 224, 224, 226, 226, 153, 161, + 167, 172, 176, 177, 179, 209, 216, 217, 227, 229, 230, -1, -1, -1, -1, + -1, -1, -1, 129, 129, 129, 129, 129, 129, 129, 129, 132, 132, 132, 132, + 132, 132, 132, 132, 133, 133, 133, 133, 133, 133, 133, 133, 134, 134, 134, + 134, 134, 134, 134, 134, 136, 136, 136, 136, 136, 136, 136, 136, 146, 146, + 146, 146, 146, 146, 146, 146, 154, 154, 154, 154, 154, 154, 154, 154, 156, + 156, 156, 156, 156, 156, 156, 156, 160, 160, 160, 160, 160, 160, 160, 160, + 163, 163, 163, 163, 163, 163, 163, 163, 164, 164, 164, 164, 164, 164, 164, + 164, 169, 169, 169, 169, 169, 169, 169, 169, 170, 170, 170, 170, 170, 170, + 170, 170, 173, 173, 173, 173, 173, 173, 173, 173, 178, 178, 178, 178, 178, + 178, 178, 178, 181, 181, 181, 181, 181, 181, 181, 181, 185, 185, 185, 185, + 185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187, + 187, 187, 187, 187, 187, 189, 189, 189, 189, 189, 189, 189, 189, 190, 190, + 190, 190, 190, 190, 190, 190, 196, 196, 196, 196, 196, 196, 196, 196, 198, + 198, 198, 198, 198, 198, 198, 198, 228, 228, 228, 228, 228, 228, 228, 228, + 232, 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 233, 233, 233, 233, + 233, 1, 1, 1, 1, 135, 135, 135, 135, 137, 137, 137, 137, 138, 138, + 138, 138, 139, 139, 139, 139, 140, 140, 140, 140, 141, 141, 141, 141, 143, + 143, 143, 143, 147, 147, 147, 147, 149, 149, 149, 149, 150, 150, 150, 150, + 151, 151, 151, 151, 152, 152, 152, 152, 155, 155, 155, 155, 157, 157, 157, + 157, 158, 158, 158, 158, 165, 165, 165, 165, 166, 166, 166, 166, 168, 168, + 168, 168, 174, 174, 174, 174, 175, 175, 175, 175, 180, 180, 180, 180, 182, + 182, 182, 182, 183, 183, 183, 183, 188, 188, 188, 188, 191, 191, 191, 191, + 197, 197, 197, 197, 231, 231, 231, 231, 239, 239, 239, 239, 9, 9, 142, + 142, 144, 144, 145, 145, 148, 148, 159, 159, 171, 171, 206, 206, 215, 215, + 225, 225, 236, 236, 237, 237, 199, 207, 234, 235, 192, 192, 192, 192, 192, + 192, 192, 192, 193, 193, 193, 193, 193, 193, 193, 193, 200, 200, 200, 200, + 200, 200, 200, 200, 201, 201, 201, 201, 201, 201, 201, 201, 202, 202, 202, + 202, 202, 202, 202, 202, 205, 205, 205, 205, 205, 205, 205, 205, 210, 210, + 210, 210, 210, 210, 210, 210, 213, 213, 213, 213, 213, 213, 213, 213, 218, + 218, 218, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 219, + 238, 238, 238, 238, 238, 238, 238, 238, 240, 240, 240, 240, 240, 240, 240, + 240, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243, 243, + 243, 243, 255, 255, 255, 255, 255, 255, 255, 255, 203, 203, 203, 203, 204, + 204, 204, 204, 211, 211, 211, 211, 212, 212, 212, 212, 214, 214, 214, 214, + 221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 241, 241, 241, + 241, 244, 244, 244, 244, 245, 245, 245, 245, 246, 246, 246, 246, 247, 247, + 247, 247, 248, 248, 248, 248, 250, 250, 250, 250, 251, 251, 251, 251, 252, + 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 2, 2, 3, 3, + 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 11, 11, 12, 12, 14, + 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, + 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, + 30, 31, 31, 127, 127, 220, 220, 249, 249, -1, -1, 10, 10, 10, 10, + 10, 10, 10, 10, 13, 13, 13, 13, 13, 13, 13, 13, 22, 22, 22, + 22, 22, 22, 22, 22, 256, 256, 256, 256, 256, 256, 256, 256, 45, 45, + 45, 45, 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, 46, 46, 47, + 47, 47, 47, 47, 47, 47, 47, 51, 51, 51, 51, 51, 51, 51, 51, + 52, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, + 53, 54, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55, + 55, 55, 56, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, + 57, 57, 57, 50, 50, 50, 50, 50, 50, 50, 50, 97, 97, 97, 97, + 97, 97, 97, 97, 99, 99, 99, 99, 99, 99, 99, 99, 101, 101, 101, + 101, 101, 101, 101, 101, 105, 105, 105, 105, 105, 105, 105, 105, 111, 111, + 111, 111, 111, 111, 111, 111, 115, 115, 115, 115, 115, 115, 115, 115, 116, + 116, 116, 116, 116, 116, 116, 116, 32, 32, 32, 32, 37, 37, 37, 37, + 45, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 47, 51, 51, 51, + 51, 52, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, + 55, 55, 56, 56, 56, 56, 57, 57, 57, 57, 61, 61, 61, 61, 65, + 65, 65, 65, 95, 95, 95, 95, 98, 98, 98, 98, 100, 100, 100, 100, + 102, 102, 102, 102, 103, 103, 103, 103, 104, 104, 104, 104, 108, 108, 108, + 108, 109, 109, 109, 109, 110, 110, 110, 110, 112, 112, 112, 112, 114, 114, + 114, 114, 117, 117, 117, 117, 58, 58, 66, 66, 67, 67, 68, 68, 69, + 69, 70, 70, 71, 71, 72, 72, 73, 73, 74, 74, 75, 75, 76, 76, + 77, 77, 78, 78, 79, 79, 80, 80, 81, 81, 82, 82, 83, 83, 84, + 84, 85, 85, 86, 86, 87, 87, 89, 89, 106, 106, 107, 107, 113, 113, + 118, 118, 119, 119, 120, 120, 121, 121, 122, 122, 38, 42, 44, 59, 88, + 90, -1, -1, 33, 33, 33, 33, 34, 34, 34, 34, 40, 40, 40, 40, + 41, 41, 41, 41, 63, 63, 63, 63, 39, 39, 43, 43, 124, 124, 35, + 62, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 36, 36, + 36, 36, 36, 36, 36, 36, 64, 64, 64, 64, 64, 64, 64, 64, 91, + 91, 91, 91, 91, 91, 91, 91, 93, 93, 93, 93, 93, 93, 93, 93, + 126, 126, 126, 126, 126, 126, 126, 126, 94, 94, 94, 94, 125, 125, 125, + 125, 60, 60, 96, 96, 123, 123, -1, -1, 92, 92, 195, 195, 208, 208, + 128, 130, 131, 162, 184, 194, 224, 226, -1, -1, 153, 153, 153, 153, 153, + 153, 153, 153, 161, 161, 161, 161, 161, 161, 161, 161, 167, 167, 167, 167, + 167, 167, 167, 167, 172, 172, 172, 172, 172, 172, 172, 172, 176, 176, 176, + 176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 177, 177, 177, 179, 179, + 179, 179, 179, 179, 179, 179, 209, 209, 209, 209, 209, 209, 209, 209, 216, + 216, 216, 216, 216, 216, 216, 216, 217, 217, 217, 217, 217, 217, 217, 217, + 227, 227, 227, 227, 227, 227, 227, 227, 229, 229, 229, 229, 229, 229, 229, + 229, 230, 230, 230, 230, 230, 230, 230, 230, 129, 129, 129, 129, 132, 132, + 132, 132, 133, 133, 133, 133, 134, 134, 134, 134, 136, 136, 136, 136, 146, + 146, 146, 146, 154, 154, 154, 154, 156, 156, 156, 156, 160, 160, 160, 160, + 163, 163, 163, 163, 164, 164, 164, 164, 169, 169, 169, 169, 170, 170, 170, + 170, 173, 173, 173, 173, 178, 178, 178, 178, 181, 181, 181, 181, 185, 185, + 185, 185, 186, 186, 186, 186, 187, 187, 187, 187, 189, 189, 189, 189, 190, + 190, 190, 190, 196, 196, 196, 196, 198, 198, 198, 198, 228, 228, 228, 228, + 232, 232, 232, 232, 233, 233, 233, 233, 1, 1, 135, 135, 137, 137, 138, + 138, 139, 139, 140, 140, 141, 141, 143, 143, 147, 147, 149, 149, 150, 150, + 151, 151, 152, 152, 155, 155, 157, 157, 158, 158, 165, 165, 166, 166, 168, + 168, 174, 174, 175, 175, 180, 180, 182, 182, 183, 183, 188, 188, 191, 191, + 197, 197, 231, 231, 239, 239, 9, 142, 144, 145, 148, 159, 171, 206, 215, + 225, 236, 237, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 199, 199, + 199, 199, 199, 199, 199, 199, 207, 207, 207, 207, 207, 207, 207, 207, 234, + 234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235, + 192, 192, 192, 192, 193, 193, 193, 193, 200, 200, 200, 200, 201, 201, 201, + 201, 202, 202, 202, 202, 205, 205, 205, 205, 210, 210, 210, 210, 213, 213, + 213, 213, 218, 218, 218, 218, 219, 219, 219, 219, 238, 238, 238, 238, 240, + 240, 240, 240, 242, 242, 242, 242, 243, 243, 243, 243, 255, 255, 255, 255, + 203, 203, 204, 204, 211, 211, 212, 212, 214, 214, 221, 221, 222, 222, 223, + 223, 241, 241, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 250, 250, + 251, 251, 252, 252, 253, 253, 254, 254, 2, 3, 4, 5, 6, 7, 8, + 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, + 28, 29, 30, 31, 127, 220, 249, -1, 10, 10, 10, 10, 13, 13, 13, + 13, 22, 22, 22, 22, 256, 256, 256, 256, }; static const gpr_uint8 inverse_base64[256] = { - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, - 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, - 255, 64, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, - 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, - 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255, + 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255, + 255, 64, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, + 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, }; /* emission helpers */ -static void on_hdr(grpc_chttp2_hpack_parser *p, grpc_mdelem *md, - int add_to_table) { - if (add_to_table) { - GRPC_MDELEM_REF(md); - grpc_chttp2_hptbl_add(&p->table, md); - } - p->on_header(p->on_header_user_data, md); +static void +on_hdr (grpc_chttp2_hpack_parser * p, grpc_mdelem * md, int add_to_table) +{ + if (add_to_table) + { + GRPC_MDELEM_REF (md); + grpc_chttp2_hptbl_add (&p->table, md); + } + p->on_header (p->on_header_user_data, md); } -static grpc_mdstr *take_string(grpc_chttp2_hpack_parser *p, - grpc_chttp2_hpack_parser_string *str) { - grpc_mdstr *s = grpc_mdstr_from_buffer(p->table.mdctx, (gpr_uint8 *)str->str, - str->length); +static grpc_mdstr * +take_string (grpc_chttp2_hpack_parser * p, grpc_chttp2_hpack_parser_string * str) +{ + grpc_mdstr *s = grpc_mdstr_from_buffer (p->table.mdctx, (gpr_uint8 *) str->str, + str->length); str->length = 0; return s; } /* jump to the next state */ -static int parse_next(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { +static int +parse_next (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ p->state = *p->next_state++; - return p->state(p, cur, end); + return p->state (p, cur, end); } /* begin parsing a header: all functionality is encoded into lookup tables above */ -static int parse_begin(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_begin; - return 1; - } - - return first_byte_action[first_byte_lut[*cur]](p, cur, end); +static int +parse_begin (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_begin; + return 1; + } + + return first_byte_action[first_byte_lut[*cur]] (p, cur, end); } /* stream dependency and prioritization data: we just skip it */ -static int parse_stream_weight(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_stream_weight; - return 1; - } - - return p->after_prioritization(p, cur + 1, end); +static int +parse_stream_weight (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_stream_weight; + return 1; + } + + return p->after_prioritization (p, cur + 1, end); } -static int parse_stream_dep3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_stream_dep3; - return 1; - } +static int +parse_stream_dep3 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_stream_dep3; + return 1; + } - return parse_stream_weight(p, cur + 1, end); + return parse_stream_weight (p, cur + 1, end); } -static int parse_stream_dep2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_stream_dep2; - return 1; - } +static int +parse_stream_dep2 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_stream_dep2; + return 1; + } - return parse_stream_dep3(p, cur + 1, end); + return parse_stream_dep3 (p, cur + 1, end); } -static int parse_stream_dep1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_stream_dep1; - return 1; - } +static int +parse_stream_dep1 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_stream_dep1; + return 1; + } - return parse_stream_dep2(p, cur + 1, end); + return parse_stream_dep2 (p, cur + 1, end); } -static int parse_stream_dep0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_stream_dep0; - return 1; - } +static int +parse_stream_dep0 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_stream_dep0; + return 1; + } - return parse_stream_dep1(p, cur + 1, end); + return parse_stream_dep1 (p, cur + 1, end); } /* emit an indexed field; for now just logs it to console; jumps to begin the next field on completion */ -static int finish_indexed_field(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); - GRPC_MDELEM_REF(md); - on_hdr(p, md, 0); - return parse_begin(p, cur, end); +static int +finish_indexed_field (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + grpc_mdelem *md = grpc_chttp2_hptbl_lookup (&p->table, p->index); + GRPC_MDELEM_REF (md); + on_hdr (p, md, 0); + return parse_begin (p, cur, end); } /* parse an indexed field with index < 127 */ -static int parse_indexed_field(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_indexed_field (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ p->index = (*cur) & 0x7f; - return finish_indexed_field(p, cur + 1, end); + return finish_indexed_field (p, cur + 1, end); } /* parse an indexed field with index >= 127 */ -static int parse_indexed_field_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_indexed_field_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - finish_indexed_field}; + finish_indexed_field + }; p->next_state = and_then; p->index = 0x7f; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0 (p, cur + 1, end); } /* finish a literal header with incremental indexing: just log, and jump to ' begin */ -static int finish_lithdr_incidx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); - on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx, - GRPC_MDSTR_REF(md->key), - take_string(p, &p->value)), - 1); - return parse_begin(p, cur, end); +static int +finish_lithdr_incidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + grpc_mdelem *md = grpc_chttp2_hptbl_lookup (&p->table, p->index); + on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, GRPC_MDSTR_REF (md->key), take_string (p, &p->value)), 1); + return parse_begin (p, cur, end); } /* finish a literal header with incremental indexing with no index */ -static int finish_lithdr_incidx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx, - take_string(p, &p->key), - take_string(p, &p->value)), - 1); - return parse_begin(p, cur, end); +static int +finish_lithdr_incidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, take_string (p, &p->key), take_string (p, &p->value)), 1); + return parse_begin (p, cur, end); } /* parse a literal header with incremental indexing; index < 63 */ -static int parse_lithdr_incidx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_incidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_value_string_with_indexed_key, finish_lithdr_incidx}; + parse_value_string_with_indexed_key, finish_lithdr_incidx + }; p->next_state = and_then; p->index = (*cur) & 0x3f; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix (p, cur + 1, end); } /* parse a literal header with incremental indexing; index >= 63 */ -static int parse_lithdr_incidx_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_incidx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_string_prefix, parse_value_string_with_indexed_key, - finish_lithdr_incidx}; + parse_string_prefix, parse_value_string_with_indexed_key, + finish_lithdr_incidx + }; p->next_state = and_then; p->index = 0x3f; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0 (p, cur + 1, end); } /* parse a literal header with incremental indexing; index = 0 */ -static int parse_lithdr_incidx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_incidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_key_string, parse_string_prefix, - parse_value_string_with_literal_key, finish_lithdr_incidx_v}; + parse_key_string, parse_string_prefix, + parse_value_string_with_literal_key, finish_lithdr_incidx_v + }; p->next_state = and_then; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix (p, cur + 1, end); } /* finish a literal header without incremental indexing */ -static int finish_lithdr_notidx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); - on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx, - GRPC_MDSTR_REF(md->key), - take_string(p, &p->value)), - 0); - return parse_begin(p, cur, end); +static int +finish_lithdr_notidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + grpc_mdelem *md = grpc_chttp2_hptbl_lookup (&p->table, p->index); + on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, GRPC_MDSTR_REF (md->key), take_string (p, &p->value)), 0); + return parse_begin (p, cur, end); } /* finish a literal header without incremental indexing with index = 0 */ -static int finish_lithdr_notidx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx, - take_string(p, &p->key), - take_string(p, &p->value)), - 0); - return parse_begin(p, cur, end); +static int +finish_lithdr_notidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, take_string (p, &p->key), take_string (p, &p->value)), 0); + return parse_begin (p, cur, end); } /* parse a literal header without incremental indexing; index < 15 */ -static int parse_lithdr_notidx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_notidx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_value_string_with_indexed_key, finish_lithdr_notidx}; + parse_value_string_with_indexed_key, finish_lithdr_notidx + }; p->next_state = and_then; p->index = (*cur) & 0xf; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix (p, cur + 1, end); } /* parse a literal header without incremental indexing; index >= 15 */ -static int parse_lithdr_notidx_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_notidx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_string_prefix, parse_value_string_with_indexed_key, - finish_lithdr_notidx}; + parse_string_prefix, parse_value_string_with_indexed_key, + finish_lithdr_notidx + }; p->next_state = and_then; p->index = 0xf; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0 (p, cur + 1, end); } /* parse a literal header without incremental indexing; index == 0 */ -static int parse_lithdr_notidx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_notidx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_key_string, parse_string_prefix, - parse_value_string_with_literal_key, finish_lithdr_notidx_v}; + parse_key_string, parse_string_prefix, + parse_value_string_with_literal_key, finish_lithdr_notidx_v + }; p->next_state = and_then; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix (p, cur + 1, end); } /* finish a literal header that is never indexed */ -static int finish_lithdr_nvridx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); - on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx, - GRPC_MDSTR_REF(md->key), - take_string(p, &p->value)), - 0); - return parse_begin(p, cur, end); +static int +finish_lithdr_nvridx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + grpc_mdelem *md = grpc_chttp2_hptbl_lookup (&p->table, p->index); + on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, GRPC_MDSTR_REF (md->key), take_string (p, &p->value)), 0); + return parse_begin (p, cur, end); } /* finish a literal header that is never indexed with an extra value */ -static int finish_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - on_hdr(p, grpc_mdelem_from_metadata_strings(p->table.mdctx, - take_string(p, &p->key), - take_string(p, &p->value)), - 0); - return parse_begin(p, cur, end); +static int +finish_lithdr_nvridx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + on_hdr (p, grpc_mdelem_from_metadata_strings (p->table.mdctx, take_string (p, &p->key), take_string (p, &p->value)), 0); + return parse_begin (p, cur, end); } /* parse a literal header that is never indexed; index < 15 */ -static int parse_lithdr_nvridx(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_nvridx (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_value_string_with_indexed_key, finish_lithdr_nvridx}; + parse_value_string_with_indexed_key, finish_lithdr_nvridx + }; p->next_state = and_then; p->index = (*cur) & 0xf; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix (p, cur + 1, end); } /* parse a literal header that is never indexed; index >= 15 */ -static int parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_nvridx_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_string_prefix, parse_value_string_with_indexed_key, - finish_lithdr_nvridx}; + parse_string_prefix, parse_value_string_with_indexed_key, + finish_lithdr_nvridx + }; p->next_state = and_then; p->index = 0xf; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0 (p, cur + 1, end); } /* parse a literal header that is never indexed; index == 0 */ -static int parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_lithdr_nvridx_v (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - parse_key_string, parse_string_prefix, - parse_value_string_with_literal_key, finish_lithdr_nvridx_v}; + parse_key_string, parse_string_prefix, + parse_value_string_with_literal_key, finish_lithdr_nvridx_v + }; p->next_state = and_then; - return parse_string_prefix(p, cur + 1, end); + return parse_string_prefix (p, cur + 1, end); } /* finish parsing a max table size change */ -static int finish_max_tbl_size(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index); - abort(); /* not implemented */ - return parse_begin(p, cur, end); +static int +finish_max_tbl_size (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + gpr_log (GPR_INFO, "MAX TABLE SIZE: %d", p->index); + abort (); /* not implemented */ + return parse_begin (p, cur, end); } /* parse a max table size change, max size < 15 */ -static int parse_max_tbl_size(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { +static int +parse_max_tbl_size (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ p->index = (*cur) & 0xf; - return finish_max_tbl_size(p, cur + 1, end); + return finish_max_tbl_size (p, cur + 1, end); } /* parse a max table size change, max size >= 15 */ -static int parse_max_tbl_size_x(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { +static int +parse_max_tbl_size_x (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ static const grpc_chttp2_hpack_parser_state and_then[] = { - finish_max_tbl_size}; + finish_max_tbl_size + }; p->next_state = and_then; p->index = 0xf; p->parsing.value = &p->index; - return parse_value0(p, cur + 1, end); + return parse_value0 (p, cur + 1, end); } /* a parse error: jam the parse state into parse_error, and return error */ -static int parse_error(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { +static int +parse_error (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ p->state = parse_error; return 0; } /* parse the 1st byte of a varint into p->parsing.value no overflow is possible */ -static int parse_value0(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_value0; - return 1; - } +static int +parse_value0 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_value0; + return 1; + } *p->parsing.value += (*cur) & 0x7f; - if ((*cur) & 0x80) { - return parse_value1(p, cur + 1, end); - } else { - return parse_next(p, cur + 1, end); - } + if ((*cur) & 0x80) + { + return parse_value1 (p, cur + 1, end); + } + else + { + return parse_next (p, cur + 1, end); + } } /* parse the 2nd byte of a varint into p->parsing.value no overflow is possible */ -static int parse_value1(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_value1; - return 1; - } - - *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 7; - - if ((*cur) & 0x80) { - return parse_value2(p, cur + 1, end); - } else { - return parse_next(p, cur + 1, end); - } +static int +parse_value1 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_value1; + return 1; + } + + *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 7; + + if ((*cur) & 0x80) + { + return parse_value2 (p, cur + 1, end); + } + else + { + return parse_next (p, cur + 1, end); + } } /* parse the 3rd byte of a varint into p->parsing.value no overflow is possible */ -static int parse_value2(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_value2; - return 1; - } - - *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 14; - - if ((*cur) & 0x80) { - return parse_value3(p, cur + 1, end); - } else { - return parse_next(p, cur + 1, end); - } +static int +parse_value2 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_value2; + return 1; + } + + *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 14; + + if ((*cur) & 0x80) + { + return parse_value3 (p, cur + 1, end); + } + else + { + return parse_next (p, cur + 1, end); + } } /* parse the 4th byte of a varint into p->parsing.value no overflow is possible */ -static int parse_value3(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_value3; - return 1; - } - - *p->parsing.value += (((gpr_uint32)*cur) & 0x7f) << 21; - - if ((*cur) & 0x80) { - return parse_value4(p, cur + 1, end); - } else { - return parse_next(p, cur + 1, end); - } +static int +parse_value3 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_value3; + return 1; + } + + *p->parsing.value += (((gpr_uint32) * cur) & 0x7f) << 21; + + if ((*cur) & 0x80) + { + return parse_value4 (p, cur + 1, end); + } + else + { + return parse_next (p, cur + 1, end); + } } /* parse the 5th byte of a varint into p->parsing.value depending on the byte, we may overflow, and care must be taken */ -static int parse_value4(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { +static int +parse_value4 (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ gpr_uint8 c; gpr_uint32 cur_value; gpr_uint32 add_value; - if (cur == end) { - p->state = parse_value4; - return 1; - } + if (cur == end) + { + p->state = parse_value4; + return 1; + } c = (*cur) & 0x7f; - if (c > 0xf) { - goto error; - } + if (c > 0xf) + { + goto error; + } cur_value = *p->parsing.value; - add_value = ((gpr_uint32)c) << 28; - if (add_value > 0xffffffffu - cur_value) { - goto error; - } + add_value = ((gpr_uint32) c) << 28; + if (add_value > 0xffffffffu - cur_value) + { + goto error; + } *p->parsing.value = cur_value + add_value; - if ((*cur) & 0x80) { - return parse_value5up(p, cur + 1, end); - } else { - return parse_next(p, cur + 1, end); - } + if ((*cur) & 0x80) + { + return parse_value5up (p, cur + 1, end); + } + else + { + return parse_next (p, cur + 1, end); + } error: - gpr_log(GPR_ERROR, - "integer overflow in hpack integer decoding: have 0x%08x, " - "got byte 0x%02x", - *p->parsing.value, *cur); - return parse_error(p, cur, end); + gpr_log (GPR_ERROR, "integer overflow in hpack integer decoding: have 0x%08x, " "got byte 0x%02x", *p->parsing.value, *cur); + return parse_error (p, cur, end); } /* parse any trailing bytes in a varint: it's possible to append an arbitrary number of 0x80's and not affect the value - a zero will terminate - and anything else will overflow */ -static int parse_value5up(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - while (cur != end && *cur == 0x80) { - ++cur; - } - - if (cur == end) { - p->state = parse_value5up; - return 1; - } - - if (*cur == 0) { - return parse_next(p, cur + 1, end); - } - - gpr_log(GPR_ERROR, - "integer overflow in hpack integer decoding: have 0x%08x, " - "got byte 0x%02x sometime after byte 4"); - return parse_error(p, cur, end); +static int +parse_value5up (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + while (cur != end && *cur == 0x80) + { + ++cur; + } + + if (cur == end) + { + p->state = parse_value5up; + return 1; + } + + if (*cur == 0) + { + return parse_next (p, cur + 1, end); + } + + gpr_log (GPR_ERROR, "integer overflow in hpack integer decoding: have 0x%08x, " "got byte 0x%02x sometime after byte 4"); + return parse_error (p, cur, end); } /* parse a string prefix */ -static int parse_string_prefix(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, const gpr_uint8 *end) { - if (cur == end) { - p->state = parse_string_prefix; - return 1; - } +static int +parse_string_prefix (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (cur == end) + { + p->state = parse_string_prefix; + return 1; + } p->strlen = (*cur) & 0x7f; p->huff = (*cur) >> 7; - if (p->strlen == 0x7f) { - p->parsing.value = &p->strlen; - return parse_value0(p, cur + 1, end); - } else { - return parse_next(p, cur + 1, end); - } + if (p->strlen == 0x7f) + { + p->parsing.value = &p->strlen; + return parse_value0 (p, cur + 1, end); + } + else + { + return parse_next (p, cur + 1, end); + } } /* append some bytes to a string */ -static void append_bytes(grpc_chttp2_hpack_parser_string *str, - const gpr_uint8 *data, size_t length) { - if (length + str->length > str->capacity) { - GPR_ASSERT(str->length + length <= GPR_UINT32_MAX); - str->capacity = (gpr_uint32)(str->length + length); - str->str = gpr_realloc(str->str, str->capacity); - } - memcpy(str->str + str->length, data, length); - GPR_ASSERT(length <= GPR_UINT32_MAX - str->length); - str->length += (gpr_uint32)length; +static void +append_bytes (grpc_chttp2_hpack_parser_string * str, const gpr_uint8 * data, size_t length) +{ + if (length + str->length > str->capacity) + { + GPR_ASSERT (str->length + length <= GPR_UINT32_MAX); + str->capacity = (gpr_uint32) (str->length + length); + str->str = gpr_realloc (str->str, str->capacity); + } + memcpy (str->str + str->length, data, length); + GPR_ASSERT (length <= GPR_UINT32_MAX - str->length); + str->length += (gpr_uint32) length; } -static int append_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { +static int +append_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ grpc_chttp2_hpack_parser_string *str = p->parsing.str; gpr_uint32 bits; gpr_uint8 decoded[3]; - switch ((binary_state)p->binary) { + switch ((binary_state) p->binary) + { case NOT_BINARY: - append_bytes(str, cur, (size_t)(end - cur)); + append_bytes (str, cur, (size_t) (end - cur)); return 1; b64_byte0: case B64_BYTE0: - if (cur == end) { - p->binary = B64_BYTE0; - return 1; - } + if (cur == end) + { + p->binary = B64_BYTE0; + return 1; + } bits = inverse_base64[*cur]; ++cur; if (bits == 255) - return 0; + return 0; else if (bits == 64) - goto b64_byte0; + goto b64_byte0; p->base64_buffer = bits << 18; - /* fallthrough */ + /* fallthrough */ b64_byte1: case B64_BYTE1: - if (cur == end) { - p->binary = B64_BYTE1; - return 1; - } + if (cur == end) + { + p->binary = B64_BYTE1; + return 1; + } bits = inverse_base64[*cur]; ++cur; if (bits == 255) - return 0; + return 0; else if (bits == 64) - goto b64_byte1; + goto b64_byte1; p->base64_buffer |= bits << 12; - /* fallthrough */ + /* fallthrough */ b64_byte2: case B64_BYTE2: - if (cur == end) { - p->binary = B64_BYTE2; - return 1; - } + if (cur == end) + { + p->binary = B64_BYTE2; + return 1; + } bits = inverse_base64[*cur]; ++cur; if (bits == 255) - return 0; + return 0; else if (bits == 64) - goto b64_byte2; + goto b64_byte2; p->base64_buffer |= bits << 6; - /* fallthrough */ + /* fallthrough */ b64_byte3: case B64_BYTE3: - if (cur == end) { - p->binary = B64_BYTE3; - return 1; - } + if (cur == end) + { + p->binary = B64_BYTE3; + return 1; + } bits = inverse_base64[*cur]; ++cur; if (bits == 255) - return 0; + return 0; else if (bits == 64) - goto b64_byte3; + goto b64_byte3; p->base64_buffer |= bits; bits = p->base64_buffer; - decoded[0] = (gpr_uint8)(bits >> 16); - decoded[1] = (gpr_uint8)(bits >> 8); - decoded[2] = (gpr_uint8)(bits); - append_bytes(str, decoded, 3); + decoded[0] = (gpr_uint8) (bits >> 16); + decoded[1] = (gpr_uint8) (bits >> 8); + decoded[2] = (gpr_uint8) (bits); + append_bytes (str, decoded, 3); goto b64_byte0; - } - gpr_log(GPR_ERROR, "should never reach here"); - abort(); + } + gpr_log (GPR_ERROR, "should never reach here"); + abort (); return 1; } /* append a null terminator to a string */ -static int finish_str(grpc_chttp2_hpack_parser *p) { +static int +finish_str (grpc_chttp2_hpack_parser * p) +{ gpr_uint8 terminator = 0; gpr_uint8 decoded[2]; gpr_uint32 bits; grpc_chttp2_hpack_parser_string *str = p->parsing.str; - switch ((binary_state)p->binary) { + switch ((binary_state) p->binary) + { case NOT_BINARY: break; case B64_BYTE0: break; case B64_BYTE1: - gpr_log(GPR_ERROR, "illegal base64 encoding"); - return 0; /* illegal encoding */ + gpr_log (GPR_ERROR, "illegal base64 encoding"); + return 0; /* illegal encoding */ case B64_BYTE2: bits = p->base64_buffer; - if (bits & 0xffff) { - gpr_log(GPR_ERROR, "trailing bits in base64 encoding: 0x%04x", - bits & 0xffff); - return 0; - } - decoded[0] = (gpr_uint8)(bits >> 16); - append_bytes(str, decoded, 1); + if (bits & 0xffff) + { + gpr_log (GPR_ERROR, "trailing bits in base64 encoding: 0x%04x", bits & 0xffff); + return 0; + } + decoded[0] = (gpr_uint8) (bits >> 16); + append_bytes (str, decoded, 1); break; case B64_BYTE3: bits = p->base64_buffer; - if (bits & 0xff) { - gpr_log(GPR_ERROR, "trailing bits in base64 encoding: 0x%02x", - bits & 0xff); - return 0; - } - decoded[0] = (gpr_uint8)(bits >> 16); - decoded[1] = (gpr_uint8)(bits >> 8); - append_bytes(str, decoded, 2); + if (bits & 0xff) + { + gpr_log (GPR_ERROR, "trailing bits in base64 encoding: 0x%02x", bits & 0xff); + return 0; + } + decoded[0] = (gpr_uint8) (bits >> 16); + decoded[1] = (gpr_uint8) (bits >> 8); + append_bytes (str, decoded, 2); break; - } - append_bytes(str, &terminator, 1); - p->parsing.str->length--; /* don't actually count the null terminator */ + } + append_bytes (str, &terminator, 1); + p->parsing.str->length--; /* don't actually count the null terminator */ return 1; } /* decode a nibble from a huffman encoded stream */ -static int huff_nibble(grpc_chttp2_hpack_parser *p, gpr_uint8 nibble) { +static int +huff_nibble (grpc_chttp2_hpack_parser * p, gpr_uint8 nibble) +{ gpr_int16 emit = emit_sub_tbl[16 * emit_tbl[p->huff_state] + nibble]; gpr_int16 next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble]; - if (emit != -1) { - if (emit >= 0 && emit < 256) { - gpr_uint8 c = (gpr_uint8)emit; - if (!append_string(p, &c, (&c) + 1)) return 0; - } else { - assert(emit == 256); + if (emit != -1) + { + if (emit >= 0 && emit < 256) + { + gpr_uint8 c = (gpr_uint8) emit; + if (!append_string (p, &c, (&c) + 1)) + return 0; + } + else + { + assert (emit == 256); + } } - } p->huff_state = next; return 1; } /* decode full bytes from a huffman encoded stream */ -static int add_huff_bytes(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - for (; cur != end; ++cur) { - if (!huff_nibble(p, *cur >> 4) || !huff_nibble(p, *cur & 0xf)) return 0; - } +static int +add_huff_bytes (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + for (; cur != end; ++cur) + { + if (!huff_nibble (p, *cur >> 4) || !huff_nibble (p, *cur & 0xf)) + return 0; + } return 1; } /* decode some string bytes based on the current decoding mode (huffman or not) */ -static int add_str_bytes(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - if (p->huff) { - return add_huff_bytes(p, cur, end); - } else { - return append_string(p, cur, end); - } +static int +add_str_bytes (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + if (p->huff) + { + return add_huff_bytes (p, cur, end); + } + else + { + return append_string (p, cur, end); + } } /* parse a string - tries to do large chunks at a time */ -static int parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { +static int +parse_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ size_t remaining = p->strlen - p->strgot; - size_t given = (size_t)(end - cur); - if (remaining <= given) { - return add_str_bytes(p, cur, cur + remaining) && finish_str(p) && - parse_next(p, cur + remaining, end); - } else { - if (!add_str_bytes(p, cur, cur + given)) return 0; - GPR_ASSERT(given <= GPR_UINT32_MAX - p->strgot); - p->strgot += (gpr_uint32)given; - p->state = parse_string; - return 1; - } + size_t given = (size_t) (end - cur); + if (remaining <= given) + { + return add_str_bytes (p, cur, cur + remaining) && finish_str (p) && parse_next (p, cur + remaining, end); + } + else + { + if (!add_str_bytes (p, cur, cur + given)) + return 0; + GPR_ASSERT (given <= GPR_UINT32_MAX - p->strgot); + p->strgot += (gpr_uint32) given; + p->state = parse_string; + return 1; + } } /* begin parsing a string - performs setup, calls parse_string */ -static int begin_parse_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end, gpr_uint8 binary, - grpc_chttp2_hpack_parser_string *str) { +static int +begin_parse_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end, gpr_uint8 binary, grpc_chttp2_hpack_parser_string * str) +{ p->strgot = 0; str->length = 0; p->parsing.str = str; p->huff_state = 0; p->binary = binary; - return parse_string(p, cur, end); + return parse_string (p, cur, end); } /* parse the key string */ -static int parse_key_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end) { - return begin_parse_string(p, cur, end, NOT_BINARY, &p->key); +static int +parse_key_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + return begin_parse_string (p, cur, end, NOT_BINARY, &p->key); } /* check if a key represents a binary header or not */ -typedef enum { BINARY_HEADER, PLAINTEXT_HEADER, ERROR_HEADER } is_binary_header; +typedef enum +{ BINARY_HEADER, PLAINTEXT_HEADER, ERROR_HEADER } is_binary_header; -static is_binary_header is_binary_literal_header(grpc_chttp2_hpack_parser *p) { - return grpc_is_binary_header(p->key.str, p->key.length) ? BINARY_HEADER - : PLAINTEXT_HEADER; +static is_binary_header +is_binary_literal_header (grpc_chttp2_hpack_parser * p) +{ + return grpc_is_binary_header (p->key.str, p->key.length) ? BINARY_HEADER : PLAINTEXT_HEADER; } -static is_binary_header is_binary_indexed_header(grpc_chttp2_hpack_parser *p) { - grpc_mdelem *elem = grpc_chttp2_hptbl_lookup(&p->table, p->index); - if (!elem) return ERROR_HEADER; - return grpc_is_binary_header( - (const char *)GPR_SLICE_START_PTR(elem->key->slice), - GPR_SLICE_LENGTH(elem->key->slice)) - ? BINARY_HEADER - : PLAINTEXT_HEADER; +static is_binary_header +is_binary_indexed_header (grpc_chttp2_hpack_parser * p) +{ + grpc_mdelem *elem = grpc_chttp2_hptbl_lookup (&p->table, p->index); + if (!elem) + return ERROR_HEADER; + return grpc_is_binary_header ((const char *) GPR_SLICE_START_PTR (elem->key->slice), GPR_SLICE_LENGTH (elem->key->slice)) ? BINARY_HEADER : PLAINTEXT_HEADER; } /* parse the value string */ -static int parse_value_string(grpc_chttp2_hpack_parser *p, const gpr_uint8 *cur, - const gpr_uint8 *end, is_binary_header type) { - switch (type) { +static int +parse_value_string (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end, is_binary_header type) +{ + switch (type) + { case BINARY_HEADER: - return begin_parse_string(p, cur, end, B64_BYTE0, &p->value); + return begin_parse_string (p, cur, end, B64_BYTE0, &p->value); case PLAINTEXT_HEADER: - return begin_parse_string(p, cur, end, NOT_BINARY, &p->value); + return begin_parse_string (p, cur, end, NOT_BINARY, &p->value); case ERROR_HEADER: return 0; - } + } /* Add code to prevent return without value error */ - gpr_log(GPR_ERROR, "Should never reach beyond switch in parse_value_string"); - abort(); + gpr_log (GPR_ERROR, "Should never reach beyond switch in parse_value_string"); + abort (); return 0; } -static int parse_value_string_with_indexed_key(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, - const gpr_uint8 *end) { - return parse_value_string(p, cur, end, is_binary_indexed_header(p)); +static int +parse_value_string_with_indexed_key (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + return parse_value_string (p, cur, end, is_binary_indexed_header (p)); } -static int parse_value_string_with_literal_key(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *cur, - const gpr_uint8 *end) { - return parse_value_string(p, cur, end, is_binary_literal_header(p)); +static int +parse_value_string_with_literal_key (grpc_chttp2_hpack_parser * p, const gpr_uint8 * cur, const gpr_uint8 * end) +{ + return parse_value_string (p, cur, end, is_binary_literal_header (p)); } /* PUBLIC INTERFACE */ -static void on_header_not_set(void *user_data, grpc_mdelem *md) { - char *keyhex = gpr_dump_slice(md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); - char *valuehex = - gpr_dump_slice(md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, "on_header callback not set; key=%s value=%s", keyhex, - valuehex); - gpr_free(keyhex); - gpr_free(valuehex); - GRPC_MDELEM_UNREF(md); - abort(); +static void +on_header_not_set (void *user_data, grpc_mdelem * md) +{ + char *keyhex = gpr_dump_slice (md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); + char *valuehex = gpr_dump_slice (md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log (GPR_ERROR, "on_header callback not set; key=%s value=%s", keyhex, valuehex); + gpr_free (keyhex); + gpr_free (valuehex); + GRPC_MDELEM_UNREF (md); + abort (); } -void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p, - grpc_mdctx *mdctx) { +void +grpc_chttp2_hpack_parser_init (grpc_chttp2_hpack_parser * p, grpc_mdctx * mdctx) +{ p->on_header = on_header_not_set; p->on_header_user_data = NULL; p->state = parse_begin; @@ -1354,58 +1429,62 @@ void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p, p->value.str = NULL; p->value.capacity = 0; p->value.length = 0; - grpc_chttp2_hptbl_init(&p->table, mdctx); + grpc_chttp2_hptbl_init (&p->table, mdctx); } -void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p) { +void +grpc_chttp2_hpack_parser_set_has_priority (grpc_chttp2_hpack_parser * p) +{ p->after_prioritization = p->state; p->state = parse_stream_dep0; } -void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p) { - grpc_chttp2_hptbl_destroy(&p->table); - gpr_free(p->key.str); - gpr_free(p->value.str); +void +grpc_chttp2_hpack_parser_destroy (grpc_chttp2_hpack_parser * p) +{ + grpc_chttp2_hptbl_destroy (&p->table); + gpr_free (p->key.str); + gpr_free (p->value.str); } -int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *beg, const gpr_uint8 *end) { +int +grpc_chttp2_hpack_parser_parse (grpc_chttp2_hpack_parser * p, const gpr_uint8 * beg, const gpr_uint8 * end) +{ /* TODO(ctiller): limit the distance of end from beg, and perform multiple - steps in the event of a large chunk of data to limit - stack space usage when no tail call optimization is - available */ - return p->state(p, beg, end); + steps in the event of a large chunk of data to limit + stack space usage when no tail call optimization is + available */ + return p->state (p, beg, end); } -grpc_chttp2_parse_error grpc_chttp2_header_parser_parse( - void *hpack_parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { +grpc_chttp2_parse_error +grpc_chttp2_header_parser_parse (void *hpack_parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ grpc_chttp2_hpack_parser *parser = hpack_parser; - if (!grpc_chttp2_hpack_parser_parse(parser, GPR_SLICE_START_PTR(slice), - GPR_SLICE_END_PTR(slice))) { - return GRPC_CHTTP2_CONNECTION_ERROR; - } - if (is_last) { - if (parser->is_boundary && parser->state != parse_begin) { - gpr_log(GPR_ERROR, - "end of header frame not aligned with a hpack record boundary"); + if (!grpc_chttp2_hpack_parser_parse (parser, GPR_SLICE_START_PTR (slice), GPR_SLICE_END_PTR (slice))) + { return GRPC_CHTTP2_CONNECTION_ERROR; } - if (parser->is_boundary) { - grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into( - &stream_parsing->incoming_metadata, - &stream_parsing->data_parser.incoming_sopb); - grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, - stream_parsing); - } - if (parser->is_eof) { - stream_parsing->received_close = 1; + if (is_last) + { + if (parser->is_boundary && parser->state != parse_begin) + { + gpr_log (GPR_ERROR, "end of header frame not aligned with a hpack record boundary"); + return GRPC_CHTTP2_CONNECTION_ERROR; + } + if (parser->is_boundary) + { + grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into (&stream_parsing->incoming_metadata, &stream_parsing->data_parser.incoming_sopb); + grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing); + } + if (parser->is_eof) + { + stream_parsing->received_close = 1; + } + parser->on_header = on_header_not_set; + parser->on_header_user_data = NULL; + parser->is_boundary = 0xde; + parser->is_eof = 0xde; } - parser->on_header = on_header_not_set; - parser->on_header_user_data = NULL; - parser->is_boundary = 0xde; - parser->is_eof = 0xde; - } return GRPC_CHTTP2_PARSE_OK; } diff --git a/src/core/transport/chttp2/hpack_parser.h b/src/core/transport/chttp2/hpack_parser.h index 0d6d268a06..6d21202d4d 100644 --- a/src/core/transport/chttp2/hpack_parser.h +++ b/src/core/transport/chttp2/hpack_parser.h @@ -44,19 +44,19 @@ typedef struct grpc_chttp2_hpack_parser grpc_chttp2_hpack_parser; -typedef int (*grpc_chttp2_hpack_parser_state)(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *beg, - const gpr_uint8 *end); +typedef int (*grpc_chttp2_hpack_parser_state) (grpc_chttp2_hpack_parser * p, const gpr_uint8 * beg, const gpr_uint8 * end); -typedef struct { +typedef struct +{ char *str; gpr_uint32 length; gpr_uint32 capacity; } grpc_chttp2_hpack_parser_string; -struct grpc_chttp2_hpack_parser { +struct grpc_chttp2_hpack_parser +{ /* user specified callback for each header output */ - void (*on_header)(void *user_data, grpc_mdelem *md); + void (*on_header) (void *user_data, grpc_mdelem * md); void *on_header_user_data; /* current parse state - or a function that implements it */ @@ -66,7 +66,8 @@ struct grpc_chttp2_hpack_parser { /* what to do after skipping prioritization data */ grpc_chttp2_hpack_parser_state after_prioritization; /* the value we're currently parsing */ - union { + union + { gpr_uint32 *value; grpc_chttp2_hpack_parser_string *str; } parsing; @@ -95,21 +96,16 @@ struct grpc_chttp2_hpack_parser { grpc_chttp2_hptbl table; }; -void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser *p, - grpc_mdctx *mdctx); -void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p); +void grpc_chttp2_hpack_parser_init (grpc_chttp2_hpack_parser * p, grpc_mdctx * mdctx); +void grpc_chttp2_hpack_parser_destroy (grpc_chttp2_hpack_parser * p); -void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p); +void grpc_chttp2_hpack_parser_set_has_priority (grpc_chttp2_hpack_parser * p); /* returns 1 on success, 0 on error */ -int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p, - const gpr_uint8 *beg, const gpr_uint8 *end); +int grpc_chttp2_hpack_parser_parse (grpc_chttp2_hpack_parser * p, const gpr_uint8 * beg, const gpr_uint8 * end); /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for the transport */ -grpc_chttp2_parse_error grpc_chttp2_header_parser_parse( - void *hpack_parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list); +grpc_chttp2_parse_error grpc_chttp2_header_parser_parse (void *hpack_parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HPACK_PARSER_H */ diff --git a/src/core/transport/chttp2/hpack_table.c b/src/core/transport/chttp2/hpack_table.c index e18778ab0b..099766c85e 100644 --- a/src/core/transport/chttp2/hpack_table.c +++ b/src/core/transport/chttp2/hpack_table.c @@ -39,191 +39,329 @@ #include <grpc/support/log.h> #include "src/core/support/murmur_hash.h" -static struct { +static struct +{ const char *key; const char *value; -} static_table[] = { - /* 0: */ {NULL, NULL}, - /* 1: */ {":authority", ""}, - /* 2: */ {":method", "GET"}, - /* 3: */ {":method", "POST"}, - /* 4: */ {":path", "/"}, - /* 5: */ {":path", "/index.html"}, - /* 6: */ {":scheme", "http"}, - /* 7: */ {":scheme", "https"}, - /* 8: */ {":status", "200"}, - /* 9: */ {":status", "204"}, - /* 10: */ {":status", "206"}, - /* 11: */ {":status", "304"}, - /* 12: */ {":status", "400"}, - /* 13: */ {":status", "404"}, - /* 14: */ {":status", "500"}, - /* 15: */ {"accept-charset", ""}, - /* 16: */ {"accept-encoding", "gzip, deflate"}, - /* 17: */ {"accept-language", ""}, - /* 18: */ {"accept-ranges", ""}, - /* 19: */ {"accept", ""}, - /* 20: */ {"access-control-allow-origin", ""}, - /* 21: */ {"age", ""}, - /* 22: */ {"allow", ""}, - /* 23: */ {"authorization", ""}, - /* 24: */ {"cache-control", ""}, - /* 25: */ {"content-disposition", ""}, - /* 26: */ {"content-encoding", ""}, - /* 27: */ {"content-language", ""}, - /* 28: */ {"content-length", ""}, - /* 29: */ {"content-location", ""}, - /* 30: */ {"content-range", ""}, - /* 31: */ {"content-type", ""}, - /* 32: */ {"cookie", ""}, - /* 33: */ {"date", ""}, - /* 34: */ {"etag", ""}, - /* 35: */ {"expect", ""}, - /* 36: */ {"expires", ""}, - /* 37: */ {"from", ""}, - /* 38: */ {"host", ""}, - /* 39: */ {"if-match", ""}, - /* 40: */ {"if-modified-since", ""}, - /* 41: */ {"if-none-match", ""}, - /* 42: */ {"if-range", ""}, - /* 43: */ {"if-unmodified-since", ""}, - /* 44: */ {"last-modified", ""}, - /* 45: */ {"link", ""}, - /* 46: */ {"location", ""}, - /* 47: */ {"max-forwards", ""}, - /* 48: */ {"proxy-authenticate", ""}, - /* 49: */ {"proxy-authorization", ""}, - /* 50: */ {"range", ""}, - /* 51: */ {"referer", ""}, - /* 52: */ {"refresh", ""}, - /* 53: */ {"retry-after", ""}, - /* 54: */ {"server", ""}, - /* 55: */ {"set-cookie", ""}, - /* 56: */ {"strict-transport-security", ""}, - /* 57: */ {"transfer-encoding", ""}, - /* 58: */ {"user-agent", ""}, - /* 59: */ {"vary", ""}, - /* 60: */ {"via", ""}, - /* 61: */ {"www-authenticate", ""}, -}; - -void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx) { +} static_table[] = +{ + /* 0: */ + { + NULL, NULL}, + /* 1: */ + { + ":authority", ""}, + /* 2: */ + { + ":method", "GET"}, + /* 3: */ + { + ":method", "POST"}, + /* 4: */ + { + ":path", "/"}, + /* 5: */ + { + ":path", "/index.html"}, + /* 6: */ + { + ":scheme", "http"}, + /* 7: */ + { + ":scheme", "https"}, + /* 8: */ + { + ":status", "200"}, + /* 9: */ + { + ":status", "204"}, + /* 10: */ + { + ":status", "206"}, + /* 11: */ + { + ":status", "304"}, + /* 12: */ + { + ":status", "400"}, + /* 13: */ + { + ":status", "404"}, + /* 14: */ + { + ":status", "500"}, + /* 15: */ + { + "accept-charset", ""}, + /* 16: */ + { + "accept-encoding", "gzip, deflate"}, + /* 17: */ + { + "accept-language", ""}, + /* 18: */ + { + "accept-ranges", ""}, + /* 19: */ + { + "accept", ""}, + /* 20: */ + { + "access-control-allow-origin", ""}, + /* 21: */ + { + "age", ""}, + /* 22: */ + { + "allow", ""}, + /* 23: */ + { + "authorization", ""}, + /* 24: */ + { + "cache-control", ""}, + /* 25: */ + { + "content-disposition", ""}, + /* 26: */ + { + "content-encoding", ""}, + /* 27: */ + { + "content-language", ""}, + /* 28: */ + { + "content-length", ""}, + /* 29: */ + { + "content-location", ""}, + /* 30: */ + { + "content-range", ""}, + /* 31: */ + { + "content-type", ""}, + /* 32: */ + { + "cookie", ""}, + /* 33: */ + { + "date", ""}, + /* 34: */ + { + "etag", ""}, + /* 35: */ + { + "expect", ""}, + /* 36: */ + { + "expires", ""}, + /* 37: */ + { + "from", ""}, + /* 38: */ + { + "host", ""}, + /* 39: */ + { + "if-match", ""}, + /* 40: */ + { + "if-modified-since", ""}, + /* 41: */ + { + "if-none-match", ""}, + /* 42: */ + { + "if-range", ""}, + /* 43: */ + { + "if-unmodified-since", ""}, + /* 44: */ + { + "last-modified", ""}, + /* 45: */ + { + "link", ""}, + /* 46: */ + { + "location", ""}, + /* 47: */ + { + "max-forwards", ""}, + /* 48: */ + { + "proxy-authenticate", ""}, + /* 49: */ + { + "proxy-authorization", ""}, + /* 50: */ + { + "range", ""}, + /* 51: */ + { + "referer", ""}, + /* 52: */ + { + "refresh", ""}, + /* 53: */ + { + "retry-after", ""}, + /* 54: */ + { + "server", ""}, + /* 55: */ + { + "set-cookie", ""}, + /* 56: */ + { + "strict-transport-security", ""}, + /* 57: */ + { + "transfer-encoding", ""}, + /* 58: */ + { + "user-agent", ""}, + /* 59: */ + { + "vary", ""}, + /* 60: */ + { + "via", ""}, + /* 61: */ + { +"www-authenticate", ""},}; + +void +grpc_chttp2_hptbl_init (grpc_chttp2_hptbl * tbl, grpc_mdctx * mdctx) +{ size_t i; - memset(tbl, 0, sizeof(*tbl)); + memset (tbl, 0, sizeof (*tbl)); tbl->mdctx = mdctx; tbl->max_bytes = GRPC_CHTTP2_INITIAL_HPACK_TABLE_SIZE; - for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - tbl->static_ents[i - 1] = grpc_mdelem_from_strings( - mdctx, static_table[i].key, static_table[i].value); - } + for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) + { + tbl->static_ents[i - 1] = grpc_mdelem_from_strings (mdctx, static_table[i].key, static_table[i].value); + } } -void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl *tbl) { +void +grpc_chttp2_hptbl_destroy (grpc_chttp2_hptbl * tbl) +{ size_t i; - for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - GRPC_MDELEM_UNREF(tbl->static_ents[i]); - } - for (i = 0; i < tbl->num_ents; i++) { - GRPC_MDELEM_UNREF( - tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]); - } + for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) + { + GRPC_MDELEM_UNREF (tbl->static_ents[i]); + } + for (i = 0; i < tbl->num_ents; i++) + { + GRPC_MDELEM_UNREF (tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]); + } } -grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, - gpr_uint32 index) { +grpc_mdelem * +grpc_chttp2_hptbl_lookup (const grpc_chttp2_hptbl * tbl, gpr_uint32 index) +{ /* Static table comes first, just return an entry from it */ - if (index <= GRPC_CHTTP2_LAST_STATIC_ENTRY) { - return tbl->static_ents[index - 1]; - } + if (index <= GRPC_CHTTP2_LAST_STATIC_ENTRY) + { + return tbl->static_ents[index - 1]; + } /* Otherwise, find the value in the list of valid entries */ index -= (GRPC_CHTTP2_LAST_STATIC_ENTRY + 1); - if (index < tbl->num_ents) { - gpr_uint32 offset = (tbl->num_ents - 1u - index + tbl->first_ent) % - GRPC_CHTTP2_MAX_TABLE_COUNT; - return tbl->ents[offset]; - } + if (index < tbl->num_ents) + { + gpr_uint32 offset = (tbl->num_ents - 1u - index + tbl->first_ent) % GRPC_CHTTP2_MAX_TABLE_COUNT; + return tbl->ents[offset]; + } /* Invalid entry: return error */ return NULL; } /* Evict one element from the table */ -static void evict1(grpc_chttp2_hptbl *tbl) { +static void +evict1 (grpc_chttp2_hptbl * tbl) +{ grpc_mdelem *first_ent = tbl->ents[tbl->first_ent]; - size_t elem_bytes = GPR_SLICE_LENGTH(first_ent->key->slice) + - GPR_SLICE_LENGTH(first_ent->value->slice) + - GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; - GPR_ASSERT(elem_bytes <= tbl->mem_used); - tbl->mem_used = (gpr_uint16)(tbl->mem_used - elem_bytes); - tbl->first_ent = - (gpr_uint16)((tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT); + size_t elem_bytes = GPR_SLICE_LENGTH (first_ent->key->slice) + GPR_SLICE_LENGTH (first_ent->value->slice) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; + GPR_ASSERT (elem_bytes <= tbl->mem_used); + tbl->mem_used = (gpr_uint16) (tbl->mem_used - elem_bytes); + tbl->first_ent = (gpr_uint16) ((tbl->first_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT); tbl->num_ents--; - GRPC_MDELEM_UNREF(first_ent); + GRPC_MDELEM_UNREF (first_ent); } -void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { +void +grpc_chttp2_hptbl_add (grpc_chttp2_hptbl * tbl, grpc_mdelem * md) +{ /* determine how many bytes of buffer this entry represents */ - size_t elem_bytes = GPR_SLICE_LENGTH(md->key->slice) + - GPR_SLICE_LENGTH(md->value->slice) + - GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; + size_t elem_bytes = GPR_SLICE_LENGTH (md->key->slice) + GPR_SLICE_LENGTH (md->value->slice) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; /* we can't add elements bigger than the max table size */ - if (elem_bytes > tbl->max_bytes) { - /* HPACK draft 10 section 4.4 states: - * If the size of the new entry is less than or equal to the maximum - * size, that entry is added to the table. It is not an error to - * attempt to add an entry that is larger than the maximum size; an - * attempt to add an entry larger than the entire table causes - * the table - * to be emptied of all existing entries, and results in an - * empty table. - */ - while (tbl->num_ents) { - evict1(tbl); + if (elem_bytes > tbl->max_bytes) + { + /* HPACK draft 10 section 4.4 states: + * If the size of the new entry is less than or equal to the maximum + * size, that entry is added to the table. It is not an error to + * attempt to add an entry that is larger than the maximum size; an + * attempt to add an entry larger than the entire table causes + * the table + * to be emptied of all existing entries, and results in an + * empty table. + */ + while (tbl->num_ents) + { + evict1 (tbl); + } + return; } - return; - } /* evict entries to ensure no overflow */ - while (elem_bytes > (size_t)tbl->max_bytes - tbl->mem_used) { - evict1(tbl); - } + while (elem_bytes > (size_t) tbl->max_bytes - tbl->mem_used) + { + evict1 (tbl); + } /* copy the finalized entry in */ tbl->ents[tbl->last_ent] = md; /* update accounting values */ - tbl->last_ent = - (gpr_uint16)((tbl->last_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT); + tbl->last_ent = (gpr_uint16) ((tbl->last_ent + 1) % GRPC_CHTTP2_MAX_TABLE_COUNT); tbl->num_ents++; - tbl->mem_used = (gpr_uint16)(tbl->mem_used + elem_bytes); + tbl->mem_used = (gpr_uint16) (tbl->mem_used + elem_bytes); } -grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( - const grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { - grpc_chttp2_hptbl_find_result r = {0, 0}; +grpc_chttp2_hptbl_find_result +grpc_chttp2_hptbl_find (const grpc_chttp2_hptbl * tbl, grpc_mdelem * md) +{ + grpc_chttp2_hptbl_find_result r = { 0, 0 }; gpr_uint16 i; /* See if the string is in the static table */ - for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - grpc_mdelem *ent = tbl->static_ents[i]; - if (md->key != ent->key) continue; - r.index = (gpr_uint16)(i + 1); - r.has_value = md->value == ent->value; - if (r.has_value) return r; - } + for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) + { + grpc_mdelem *ent = tbl->static_ents[i]; + if (md->key != ent->key) + continue; + r.index = (gpr_uint16) (i + 1); + r.has_value = md->value == ent->value; + if (r.has_value) + return r; + } /* Scan the dynamic table */ - for (i = 0; i < tbl->num_ents; i++) { - gpr_uint16 idx = - (gpr_uint16)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); - grpc_mdelem *ent = - tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]; - if (md->key != ent->key) continue; - r.index = idx; - r.has_value = md->value == ent->value; - if (r.has_value) return r; - } + for (i = 0; i < tbl->num_ents; i++) + { + gpr_uint16 idx = (gpr_uint16) (tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); + grpc_mdelem *ent = tbl->ents[(tbl->first_ent + i) % GRPC_CHTTP2_MAX_TABLE_COUNT]; + if (md->key != ent->key) + continue; + r.index = idx; + r.has_value = md->value == ent->value; + if (r.has_value) + return r; + } return r; } diff --git a/src/core/transport/chttp2/hpack_table.h b/src/core/transport/chttp2/hpack_table.h index 4f882e2e03..5c58a35186 100644 --- a/src/core/transport/chttp2/hpack_table.h +++ b/src/core/transport/chttp2/hpack_table.h @@ -56,7 +56,8 @@ GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD) /* hpack decoder table */ -typedef struct { +typedef struct +{ grpc_mdctx *mdctx; /* the first used entry in ents */ gpr_uint16 first_ent; @@ -77,21 +78,20 @@ typedef struct { } grpc_chttp2_hptbl; /* initialize a hpack table */ -void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl, grpc_mdctx *mdctx); -void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl *tbl); +void grpc_chttp2_hptbl_init (grpc_chttp2_hptbl * tbl, grpc_mdctx * mdctx); +void grpc_chttp2_hptbl_destroy (grpc_chttp2_hptbl * tbl); /* lookup a table entry based on its hpack index */ -grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, - gpr_uint32 index); +grpc_mdelem *grpc_chttp2_hptbl_lookup (const grpc_chttp2_hptbl * tbl, gpr_uint32 index); /* add a table entry to the index */ -void grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md); +void grpc_chttp2_hptbl_add (grpc_chttp2_hptbl * tbl, grpc_mdelem * md); /* Find a key/value pair in the table... returns the index in the table of the most similar entry, or 0 if the value was not found */ -typedef struct { +typedef struct +{ gpr_uint16 index; gpr_uint8 has_value; } grpc_chttp2_hptbl_find_result; -grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( - const grpc_chttp2_hptbl *tbl, grpc_mdelem *md); +grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find (const grpc_chttp2_hptbl * tbl, grpc_mdelem * md); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HPACK_TABLE_H */ diff --git a/src/core/transport/chttp2/http2_errors.h b/src/core/transport/chttp2/http2_errors.h index a4f309e056..8385d6ba44 100644 --- a/src/core/transport/chttp2/http2_errors.h +++ b/src/core/transport/chttp2/http2_errors.h @@ -35,7 +35,8 @@ #define GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_HTTP2_ERRORS_H /* error codes for RST_STREAM from http2 draft 14 section 7 */ -typedef enum { +typedef enum +{ GRPC_CHTTP2_NO_ERROR = 0x0, GRPC_CHTTP2_PROTOCOL_ERROR = 0x1, GRPC_CHTTP2_INTERNAL_ERROR = 0x2, diff --git a/src/core/transport/chttp2/huffsyms.c b/src/core/transport/chttp2/huffsyms.c index 6f5cf6a2a9..058c6ee61e 100644 --- a/src/core/transport/chttp2/huffsyms.c +++ b/src/core/transport/chttp2/huffsyms.c @@ -37,69 +37,69 @@ command: :%s/.* \([0-9a-f]\+\) \[ *\([0-9]\+\)\]/{0x\1, \2},/g */ const grpc_chttp2_huffsym grpc_chttp2_huffsyms[GRPC_CHTTP2_NUM_HUFFSYMS] = { - {0x1ff8, 13}, {0x7fffd8, 23}, {0xfffffe2, 28}, {0xfffffe3, 28}, - {0xfffffe4, 28}, {0xfffffe5, 28}, {0xfffffe6, 28}, {0xfffffe7, 28}, - {0xfffffe8, 28}, {0xffffea, 24}, {0x3ffffffc, 30}, {0xfffffe9, 28}, - {0xfffffea, 28}, {0x3ffffffd, 30}, {0xfffffeb, 28}, {0xfffffec, 28}, - {0xfffffed, 28}, {0xfffffee, 28}, {0xfffffef, 28}, {0xffffff0, 28}, - {0xffffff1, 28}, {0xffffff2, 28}, {0x3ffffffe, 30}, {0xffffff3, 28}, - {0xffffff4, 28}, {0xffffff5, 28}, {0xffffff6, 28}, {0xffffff7, 28}, - {0xffffff8, 28}, {0xffffff9, 28}, {0xffffffa, 28}, {0xffffffb, 28}, - {0x14, 6}, {0x3f8, 10}, {0x3f9, 10}, {0xffa, 12}, - {0x1ff9, 13}, {0x15, 6}, {0xf8, 8}, {0x7fa, 11}, - {0x3fa, 10}, {0x3fb, 10}, {0xf9, 8}, {0x7fb, 11}, - {0xfa, 8}, {0x16, 6}, {0x17, 6}, {0x18, 6}, - {0x0, 5}, {0x1, 5}, {0x2, 5}, {0x19, 6}, - {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6}, - {0x1e, 6}, {0x1f, 6}, {0x5c, 7}, {0xfb, 8}, - {0x7ffc, 15}, {0x20, 6}, {0xffb, 12}, {0x3fc, 10}, - {0x1ffa, 13}, {0x21, 6}, {0x5d, 7}, {0x5e, 7}, - {0x5f, 7}, {0x60, 7}, {0x61, 7}, {0x62, 7}, - {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7}, - {0x67, 7}, {0x68, 7}, {0x69, 7}, {0x6a, 7}, - {0x6b, 7}, {0x6c, 7}, {0x6d, 7}, {0x6e, 7}, - {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7}, - {0xfc, 8}, {0x73, 7}, {0xfd, 8}, {0x1ffb, 13}, - {0x7fff0, 19}, {0x1ffc, 13}, {0x3ffc, 14}, {0x22, 6}, - {0x7ffd, 15}, {0x3, 5}, {0x23, 6}, {0x4, 5}, - {0x24, 6}, {0x5, 5}, {0x25, 6}, {0x26, 6}, - {0x27, 6}, {0x6, 5}, {0x74, 7}, {0x75, 7}, - {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5}, - {0x2b, 6}, {0x76, 7}, {0x2c, 6}, {0x8, 5}, - {0x9, 5}, {0x2d, 6}, {0x77, 7}, {0x78, 7}, - {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x7ffe, 15}, - {0x7fc, 11}, {0x3ffd, 14}, {0x1ffd, 13}, {0xffffffc, 28}, - {0xfffe6, 20}, {0x3fffd2, 22}, {0xfffe7, 20}, {0xfffe8, 20}, - {0x3fffd3, 22}, {0x3fffd4, 22}, {0x3fffd5, 22}, {0x7fffd9, 23}, - {0x3fffd6, 22}, {0x7fffda, 23}, {0x7fffdb, 23}, {0x7fffdc, 23}, - {0x7fffdd, 23}, {0x7fffde, 23}, {0xffffeb, 24}, {0x7fffdf, 23}, - {0xffffec, 24}, {0xffffed, 24}, {0x3fffd7, 22}, {0x7fffe0, 23}, - {0xffffee, 24}, {0x7fffe1, 23}, {0x7fffe2, 23}, {0x7fffe3, 23}, - {0x7fffe4, 23}, {0x1fffdc, 21}, {0x3fffd8, 22}, {0x7fffe5, 23}, - {0x3fffd9, 22}, {0x7fffe6, 23}, {0x7fffe7, 23}, {0xffffef, 24}, - {0x3fffda, 22}, {0x1fffdd, 21}, {0xfffe9, 20}, {0x3fffdb, 22}, - {0x3fffdc, 22}, {0x7fffe8, 23}, {0x7fffe9, 23}, {0x1fffde, 21}, - {0x7fffea, 23}, {0x3fffdd, 22}, {0x3fffde, 22}, {0xfffff0, 24}, - {0x1fffdf, 21}, {0x3fffdf, 22}, {0x7fffeb, 23}, {0x7fffec, 23}, - {0x1fffe0, 21}, {0x1fffe1, 21}, {0x3fffe0, 22}, {0x1fffe2, 21}, - {0x7fffed, 23}, {0x3fffe1, 22}, {0x7fffee, 23}, {0x7fffef, 23}, - {0xfffea, 20}, {0x3fffe2, 22}, {0x3fffe3, 22}, {0x3fffe4, 22}, - {0x7ffff0, 23}, {0x3fffe5, 22}, {0x3fffe6, 22}, {0x7ffff1, 23}, - {0x3ffffe0, 26}, {0x3ffffe1, 26}, {0xfffeb, 20}, {0x7fff1, 19}, - {0x3fffe7, 22}, {0x7ffff2, 23}, {0x3fffe8, 22}, {0x1ffffec, 25}, - {0x3ffffe2, 26}, {0x3ffffe3, 26}, {0x3ffffe4, 26}, {0x7ffffde, 27}, - {0x7ffffdf, 27}, {0x3ffffe5, 26}, {0xfffff1, 24}, {0x1ffffed, 25}, - {0x7fff2, 19}, {0x1fffe3, 21}, {0x3ffffe6, 26}, {0x7ffffe0, 27}, - {0x7ffffe1, 27}, {0x3ffffe7, 26}, {0x7ffffe2, 27}, {0xfffff2, 24}, - {0x1fffe4, 21}, {0x1fffe5, 21}, {0x3ffffe8, 26}, {0x3ffffe9, 26}, - {0xffffffd, 28}, {0x7ffffe3, 27}, {0x7ffffe4, 27}, {0x7ffffe5, 27}, - {0xfffec, 20}, {0xfffff3, 24}, {0xfffed, 20}, {0x1fffe6, 21}, - {0x3fffe9, 22}, {0x1fffe7, 21}, {0x1fffe8, 21}, {0x7ffff3, 23}, - {0x3fffea, 22}, {0x3fffeb, 22}, {0x1ffffee, 25}, {0x1ffffef, 25}, - {0xfffff4, 24}, {0xfffff5, 24}, {0x3ffffea, 26}, {0x7ffff4, 23}, - {0x3ffffeb, 26}, {0x7ffffe6, 27}, {0x3ffffec, 26}, {0x3ffffed, 26}, - {0x7ffffe7, 27}, {0x7ffffe8, 27}, {0x7ffffe9, 27}, {0x7ffffea, 27}, - {0x7ffffeb, 27}, {0xffffffe, 28}, {0x7ffffec, 27}, {0x7ffffed, 27}, - {0x7ffffee, 27}, {0x7ffffef, 27}, {0x7fffff0, 27}, {0x3ffffee, 26}, - {0x3fffffff, 30}, + {0x1ff8, 13}, {0x7fffd8, 23}, {0xfffffe2, 28}, {0xfffffe3, 28}, + {0xfffffe4, 28}, {0xfffffe5, 28}, {0xfffffe6, 28}, {0xfffffe7, 28}, + {0xfffffe8, 28}, {0xffffea, 24}, {0x3ffffffc, 30}, {0xfffffe9, 28}, + {0xfffffea, 28}, {0x3ffffffd, 30}, {0xfffffeb, 28}, {0xfffffec, 28}, + {0xfffffed, 28}, {0xfffffee, 28}, {0xfffffef, 28}, {0xffffff0, 28}, + {0xffffff1, 28}, {0xffffff2, 28}, {0x3ffffffe, 30}, {0xffffff3, 28}, + {0xffffff4, 28}, {0xffffff5, 28}, {0xffffff6, 28}, {0xffffff7, 28}, + {0xffffff8, 28}, {0xffffff9, 28}, {0xffffffa, 28}, {0xffffffb, 28}, + {0x14, 6}, {0x3f8, 10}, {0x3f9, 10}, {0xffa, 12}, + {0x1ff9, 13}, {0x15, 6}, {0xf8, 8}, {0x7fa, 11}, + {0x3fa, 10}, {0x3fb, 10}, {0xf9, 8}, {0x7fb, 11}, + {0xfa, 8}, {0x16, 6}, {0x17, 6}, {0x18, 6}, + {0x0, 5}, {0x1, 5}, {0x2, 5}, {0x19, 6}, + {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6}, + {0x1e, 6}, {0x1f, 6}, {0x5c, 7}, {0xfb, 8}, + {0x7ffc, 15}, {0x20, 6}, {0xffb, 12}, {0x3fc, 10}, + {0x1ffa, 13}, {0x21, 6}, {0x5d, 7}, {0x5e, 7}, + {0x5f, 7}, {0x60, 7}, {0x61, 7}, {0x62, 7}, + {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7}, + {0x67, 7}, {0x68, 7}, {0x69, 7}, {0x6a, 7}, + {0x6b, 7}, {0x6c, 7}, {0x6d, 7}, {0x6e, 7}, + {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7}, + {0xfc, 8}, {0x73, 7}, {0xfd, 8}, {0x1ffb, 13}, + {0x7fff0, 19}, {0x1ffc, 13}, {0x3ffc, 14}, {0x22, 6}, + {0x7ffd, 15}, {0x3, 5}, {0x23, 6}, {0x4, 5}, + {0x24, 6}, {0x5, 5}, {0x25, 6}, {0x26, 6}, + {0x27, 6}, {0x6, 5}, {0x74, 7}, {0x75, 7}, + {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5}, + {0x2b, 6}, {0x76, 7}, {0x2c, 6}, {0x8, 5}, + {0x9, 5}, {0x2d, 6}, {0x77, 7}, {0x78, 7}, + {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x7ffe, 15}, + {0x7fc, 11}, {0x3ffd, 14}, {0x1ffd, 13}, {0xffffffc, 28}, + {0xfffe6, 20}, {0x3fffd2, 22}, {0xfffe7, 20}, {0xfffe8, 20}, + {0x3fffd3, 22}, {0x3fffd4, 22}, {0x3fffd5, 22}, {0x7fffd9, 23}, + {0x3fffd6, 22}, {0x7fffda, 23}, {0x7fffdb, 23}, {0x7fffdc, 23}, + {0x7fffdd, 23}, {0x7fffde, 23}, {0xffffeb, 24}, {0x7fffdf, 23}, + {0xffffec, 24}, {0xffffed, 24}, {0x3fffd7, 22}, {0x7fffe0, 23}, + {0xffffee, 24}, {0x7fffe1, 23}, {0x7fffe2, 23}, {0x7fffe3, 23}, + {0x7fffe4, 23}, {0x1fffdc, 21}, {0x3fffd8, 22}, {0x7fffe5, 23}, + {0x3fffd9, 22}, {0x7fffe6, 23}, {0x7fffe7, 23}, {0xffffef, 24}, + {0x3fffda, 22}, {0x1fffdd, 21}, {0xfffe9, 20}, {0x3fffdb, 22}, + {0x3fffdc, 22}, {0x7fffe8, 23}, {0x7fffe9, 23}, {0x1fffde, 21}, + {0x7fffea, 23}, {0x3fffdd, 22}, {0x3fffde, 22}, {0xfffff0, 24}, + {0x1fffdf, 21}, {0x3fffdf, 22}, {0x7fffeb, 23}, {0x7fffec, 23}, + {0x1fffe0, 21}, {0x1fffe1, 21}, {0x3fffe0, 22}, {0x1fffe2, 21}, + {0x7fffed, 23}, {0x3fffe1, 22}, {0x7fffee, 23}, {0x7fffef, 23}, + {0xfffea, 20}, {0x3fffe2, 22}, {0x3fffe3, 22}, {0x3fffe4, 22}, + {0x7ffff0, 23}, {0x3fffe5, 22}, {0x3fffe6, 22}, {0x7ffff1, 23}, + {0x3ffffe0, 26}, {0x3ffffe1, 26}, {0xfffeb, 20}, {0x7fff1, 19}, + {0x3fffe7, 22}, {0x7ffff2, 23}, {0x3fffe8, 22}, {0x1ffffec, 25}, + {0x3ffffe2, 26}, {0x3ffffe3, 26}, {0x3ffffe4, 26}, {0x7ffffde, 27}, + {0x7ffffdf, 27}, {0x3ffffe5, 26}, {0xfffff1, 24}, {0x1ffffed, 25}, + {0x7fff2, 19}, {0x1fffe3, 21}, {0x3ffffe6, 26}, {0x7ffffe0, 27}, + {0x7ffffe1, 27}, {0x3ffffe7, 26}, {0x7ffffe2, 27}, {0xfffff2, 24}, + {0x1fffe4, 21}, {0x1fffe5, 21}, {0x3ffffe8, 26}, {0x3ffffe9, 26}, + {0xffffffd, 28}, {0x7ffffe3, 27}, {0x7ffffe4, 27}, {0x7ffffe5, 27}, + {0xfffec, 20}, {0xfffff3, 24}, {0xfffed, 20}, {0x1fffe6, 21}, + {0x3fffe9, 22}, {0x1fffe7, 21}, {0x1fffe8, 21}, {0x7ffff3, 23}, + {0x3fffea, 22}, {0x3fffeb, 22}, {0x1ffffee, 25}, {0x1ffffef, 25}, + {0xfffff4, 24}, {0xfffff5, 24}, {0x3ffffea, 26}, {0x7ffff4, 23}, + {0x3ffffeb, 26}, {0x7ffffe6, 27}, {0x3ffffec, 26}, {0x3ffffed, 26}, + {0x7ffffe7, 27}, {0x7ffffe8, 27}, {0x7ffffe9, 27}, {0x7ffffea, 27}, + {0x7ffffeb, 27}, {0xffffffe, 28}, {0x7ffffec, 27}, {0x7ffffed, 27}, + {0x7ffffee, 27}, {0x7ffffef, 27}, {0x7fffff0, 27}, {0x3ffffee, 26}, + {0x3fffffff, 30}, }; diff --git a/src/core/transport/chttp2/huffsyms.h b/src/core/transport/chttp2/huffsyms.h index a3cdba8235..04f062dd5e 100644 --- a/src/core/transport/chttp2/huffsyms.h +++ b/src/core/transport/chttp2/huffsyms.h @@ -38,7 +38,8 @@ #define GRPC_CHTTP2_NUM_HUFFSYMS 257 -typedef struct { +typedef struct +{ unsigned bits; unsigned length; } grpc_chttp2_huffsym; diff --git a/src/core/transport/chttp2/incoming_metadata.c b/src/core/transport/chttp2/incoming_metadata.c index d216c42113..93eee0be3f 100644 --- a/src/core/transport/chttp2/incoming_metadata.c +++ b/src/core/transport/chttp2/incoming_metadata.c @@ -40,43 +40,50 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -void grpc_chttp2_incoming_metadata_buffer_init( - grpc_chttp2_incoming_metadata_buffer *buffer) { - buffer->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); +void +grpc_chttp2_incoming_metadata_buffer_init (grpc_chttp2_incoming_metadata_buffer * buffer) +{ + buffer->deadline = gpr_inf_future (GPR_CLOCK_REALTIME); } -void grpc_chttp2_incoming_metadata_buffer_destroy( - grpc_chttp2_incoming_metadata_buffer *buffer) { +void +grpc_chttp2_incoming_metadata_buffer_destroy (grpc_chttp2_incoming_metadata_buffer * buffer) +{ size_t i; - for (i = 0; i < buffer->count; i++) { - GRPC_MDELEM_UNREF(buffer->elems[i].md); - } - gpr_free(buffer->elems); + for (i = 0; i < buffer->count; i++) + { + GRPC_MDELEM_UNREF (buffer->elems[i].md); + } + gpr_free (buffer->elems); } -void grpc_chttp2_incoming_metadata_buffer_add( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem) { - if (buffer->capacity == buffer->count) { - buffer->capacity = GPR_MAX(8, 2 * buffer->capacity); - buffer->elems = - gpr_realloc(buffer->elems, sizeof(*buffer->elems) * buffer->capacity); - } +void +grpc_chttp2_incoming_metadata_buffer_add (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_mdelem * elem) +{ + if (buffer->capacity == buffer->count) + { + buffer->capacity = GPR_MAX (8, 2 * buffer->capacity); + buffer->elems = gpr_realloc (buffer->elems, sizeof (*buffer->elems) * buffer->capacity); + } buffer->elems[buffer->count++].md = elem; } -void grpc_chttp2_incoming_metadata_buffer_set_deadline( - grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline) { +void +grpc_chttp2_incoming_metadata_buffer_set_deadline (grpc_chttp2_incoming_metadata_buffer * buffer, gpr_timespec deadline) +{ buffer->deadline = deadline; } -void grpc_chttp2_incoming_metadata_live_op_buffer_end( - grpc_chttp2_incoming_metadata_live_op_buffer *buffer) { - gpr_free(buffer->elems); +void +grpc_chttp2_incoming_metadata_live_op_buffer_end (grpc_chttp2_incoming_metadata_live_op_buffer * buffer) +{ + gpr_free (buffer->elems); buffer->elems = NULL; } -void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_stream_op_buffer *sopb) { +void +grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_stream_op_buffer * sopb) +{ grpc_metadata_batch b; b.list.head = NULL; @@ -84,52 +91,56 @@ void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into( we can reconstitute the list. We can't do list building here as later incoming metadata may reallocate the underlying array. */ - b.list.tail = (void *)(gpr_intptr)buffer->count; + b.list.tail = (void *) (gpr_intptr) buffer->count; b.garbage.head = b.garbage.tail = NULL; b.deadline = buffer->deadline; - buffer->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); + buffer->deadline = gpr_inf_future (GPR_CLOCK_REALTIME); - grpc_sopb_add_metadata(sopb, b); + grpc_sopb_add_metadata (sopb, b); } -void grpc_chttp2_incoming_metadata_buffer_swap( - grpc_chttp2_incoming_metadata_buffer *a, - grpc_chttp2_incoming_metadata_buffer *b) { - GPR_SWAP(grpc_chttp2_incoming_metadata_buffer, *a, *b); +void +grpc_chttp2_incoming_metadata_buffer_swap (grpc_chttp2_incoming_metadata_buffer * a, grpc_chttp2_incoming_metadata_buffer * b) +{ + GPR_SWAP (grpc_chttp2_incoming_metadata_buffer, *a, *b); } -void grpc_incoming_metadata_buffer_move_to_referencing_sopb( - grpc_chttp2_incoming_metadata_buffer *src, - grpc_chttp2_incoming_metadata_buffer *dst, grpc_stream_op_buffer *sopb) { +void +grpc_incoming_metadata_buffer_move_to_referencing_sopb (grpc_chttp2_incoming_metadata_buffer * src, grpc_chttp2_incoming_metadata_buffer * dst, grpc_stream_op_buffer * sopb) +{ size_t delta; size_t i; - dst->deadline = gpr_time_min(src->deadline, dst->deadline); - - if (src->count == 0) { - return; - } - if (dst->count == 0) { - grpc_chttp2_incoming_metadata_buffer_swap(src, dst); - return; - } + dst->deadline = gpr_time_min (src->deadline, dst->deadline); + + if (src->count == 0) + { + return; + } + if (dst->count == 0) + { + grpc_chttp2_incoming_metadata_buffer_swap (src, dst); + return; + } delta = dst->count; - if (dst->capacity < src->count + dst->count) { - dst->capacity = GPR_MAX(dst->capacity * 2, src->count + dst->count); - dst->elems = gpr_realloc(dst->elems, dst->capacity * sizeof(*dst->elems)); - } - memcpy(dst->elems + dst->count, src->elems, src->count * sizeof(*src->elems)); + if (dst->capacity < src->count + dst->count) + { + dst->capacity = GPR_MAX (dst->capacity * 2, src->count + dst->count); + dst->elems = gpr_realloc (dst->elems, dst->capacity * sizeof (*dst->elems)); + } + memcpy (dst->elems + dst->count, src->elems, src->count * sizeof (*src->elems)); dst->count += src->count; - for (i = 0; i < sopb->nops; i++) { - if (sopb->ops[i].type != GRPC_OP_METADATA) continue; - sopb->ops[i].data.metadata.list.tail = - (void *)(delta + (gpr_uintptr)sopb->ops[i].data.metadata.list.tail); - } + for (i = 0; i < sopb->nops; i++) + { + if (sopb->ops[i].type != GRPC_OP_METADATA) + continue; + sopb->ops[i].data.metadata.list.tail = (void *) (delta + (gpr_uintptr) sopb->ops[i].data.metadata.list.tail); + } src->count = 0; } -void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_stream_op_buffer *sopb, - grpc_chttp2_incoming_metadata_live_op_buffer *live_op_buffer) { +void +grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_stream_op_buffer * sopb, grpc_chttp2_incoming_metadata_live_op_buffer * live_op_buffer) +{ grpc_stream_op *ops = sopb->ops; size_t nops = sopb->nops; size_t i; @@ -141,42 +152,49 @@ void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op( /* rework the array of metadata into a linked list, making use of the breadcrumbs we left in metadata batches during add_metadata_batch */ - for (i = 0; i < nops; i++) { - grpc_stream_op *op = &ops[i]; - if (op->type != GRPC_OP_METADATA) continue; - found_metadata = 1; - /* we left a breadcrumb indicating where the end of this list is, - and since we add sequentially, we know from the end of the last - segment where this segment begins */ - last_mdidx = (size_t)(gpr_intptr)(op->data.metadata.list.tail); - GPR_ASSERT(last_mdidx > mdidx); - GPR_ASSERT(last_mdidx <= buffer->count); - /* turn the array into a doubly linked list */ - op->data.metadata.list.head = &buffer->elems[mdidx]; - op->data.metadata.list.tail = &buffer->elems[last_mdidx - 1]; - for (j = mdidx + 1; j < last_mdidx; j++) { - buffer->elems[j].prev = &buffer->elems[j - 1]; - buffer->elems[j - 1].next = &buffer->elems[j]; + for (i = 0; i < nops; i++) + { + grpc_stream_op *op = &ops[i]; + if (op->type != GRPC_OP_METADATA) + continue; + found_metadata = 1; + /* we left a breadcrumb indicating where the end of this list is, + and since we add sequentially, we know from the end of the last + segment where this segment begins */ + last_mdidx = (size_t) (gpr_intptr) (op->data.metadata.list.tail); + GPR_ASSERT (last_mdidx > mdidx); + GPR_ASSERT (last_mdidx <= buffer->count); + /* turn the array into a doubly linked list */ + op->data.metadata.list.head = &buffer->elems[mdidx]; + op->data.metadata.list.tail = &buffer->elems[last_mdidx - 1]; + for (j = mdidx + 1; j < last_mdidx; j++) + { + buffer->elems[j].prev = &buffer->elems[j - 1]; + buffer->elems[j - 1].next = &buffer->elems[j]; + } + buffer->elems[mdidx].prev = NULL; + buffer->elems[last_mdidx - 1].next = NULL; + /* track where we're up to */ + mdidx = last_mdidx; } - buffer->elems[mdidx].prev = NULL; - buffer->elems[last_mdidx - 1].next = NULL; - /* track where we're up to */ - mdidx = last_mdidx; - } - if (found_metadata) { - live_op_buffer->elems = buffer->elems; - if (mdidx != buffer->count) { - /* we have a partially read metadata batch still in incoming_metadata */ - size_t new_count = buffer->count - mdidx; - size_t copy_bytes = sizeof(*buffer->elems) * new_count; - GPR_ASSERT(mdidx < buffer->count); - buffer->elems = gpr_malloc(copy_bytes); - memcpy(live_op_buffer->elems + mdidx, buffer->elems, copy_bytes); - buffer->count = buffer->capacity = new_count; - } else { - buffer->elems = NULL; - buffer->count = 0; - buffer->capacity = 0; + if (found_metadata) + { + live_op_buffer->elems = buffer->elems; + if (mdidx != buffer->count) + { + /* we have a partially read metadata batch still in incoming_metadata */ + size_t new_count = buffer->count - mdidx; + size_t copy_bytes = sizeof (*buffer->elems) * new_count; + GPR_ASSERT (mdidx < buffer->count); + buffer->elems = gpr_malloc (copy_bytes); + memcpy (live_op_buffer->elems + mdidx, buffer->elems, copy_bytes); + buffer->count = buffer->capacity = new_count; + } + else + { + buffer->elems = NULL; + buffer->count = 0; + buffer->capacity = 0; + } } - } } diff --git a/src/core/transport/chttp2/incoming_metadata.h b/src/core/transport/chttp2/incoming_metadata.h index 2f1de411ba..7ca0f722c3 100644 --- a/src/core/transport/chttp2/incoming_metadata.h +++ b/src/core/transport/chttp2/incoming_metadata.h @@ -36,45 +36,36 @@ #include "src/core/transport/transport.h" -typedef struct { +typedef struct +{ grpc_linked_mdelem *elems; size_t count; size_t capacity; gpr_timespec deadline; } grpc_chttp2_incoming_metadata_buffer; -typedef struct { +typedef struct +{ grpc_linked_mdelem *elems; } grpc_chttp2_incoming_metadata_live_op_buffer; /** assumes everything initially zeroed */ -void grpc_chttp2_incoming_metadata_buffer_init( - grpc_chttp2_incoming_metadata_buffer *buffer); -void grpc_chttp2_incoming_metadata_buffer_destroy( - grpc_chttp2_incoming_metadata_buffer *buffer); -void grpc_chttp2_incoming_metadata_buffer_reset( - grpc_chttp2_incoming_metadata_buffer *buffer); +void grpc_chttp2_incoming_metadata_buffer_init (grpc_chttp2_incoming_metadata_buffer * buffer); +void grpc_chttp2_incoming_metadata_buffer_destroy (grpc_chttp2_incoming_metadata_buffer * buffer); +void grpc_chttp2_incoming_metadata_buffer_reset (grpc_chttp2_incoming_metadata_buffer * buffer); -void grpc_chttp2_incoming_metadata_buffer_add( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem); -void grpc_chttp2_incoming_metadata_buffer_set_deadline( - grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline); +void grpc_chttp2_incoming_metadata_buffer_add (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_mdelem * elem); +void grpc_chttp2_incoming_metadata_buffer_set_deadline (grpc_chttp2_incoming_metadata_buffer * buffer, gpr_timespec deadline); /** extend sopb with a metadata batch; this must be post-processed by grpc_chttp2_incoming_metadata_buffer_postprocess_sopb before being handed out of the transport */ -void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_stream_op_buffer *sopb); +void grpc_chttp2_incoming_metadata_buffer_place_metadata_batch_into (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_stream_op_buffer * sopb); -void grpc_incoming_metadata_buffer_move_to_referencing_sopb( - grpc_chttp2_incoming_metadata_buffer *src, - grpc_chttp2_incoming_metadata_buffer *dst, grpc_stream_op_buffer *sopb); +void grpc_incoming_metadata_buffer_move_to_referencing_sopb (grpc_chttp2_incoming_metadata_buffer * src, grpc_chttp2_incoming_metadata_buffer * dst, grpc_stream_op_buffer * sopb); -void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_stream_op_buffer *sopb, - grpc_chttp2_incoming_metadata_live_op_buffer *live_op_buffer); +void grpc_chttp2_incoming_metadata_buffer_postprocess_sopb_and_begin_live_op (grpc_chttp2_incoming_metadata_buffer * buffer, grpc_stream_op_buffer * sopb, grpc_chttp2_incoming_metadata_live_op_buffer * live_op_buffer); -void grpc_chttp2_incoming_metadata_live_op_buffer_end( - grpc_chttp2_incoming_metadata_live_op_buffer *live_op_buffer); +void grpc_chttp2_incoming_metadata_live_op_buffer_end (grpc_chttp2_incoming_metadata_live_op_buffer * live_op_buffer); #endif /* GRPC_INTERNAL_CORE_CHTTP2_INCOMING_METADATA_H */ diff --git a/src/core/transport/chttp2/internal.h b/src/core/transport/chttp2/internal.h index 14a6c909ee..1ef9c1af87 100644 --- a/src/core/transport/chttp2/internal.h +++ b/src/core/transport/chttp2/internal.h @@ -54,7 +54,8 @@ typedef struct grpc_chttp2_stream grpc_chttp2_stream; /* streams are kept in various linked lists depending on what things need to happen to them... this enum labels each list */ -typedef enum { +typedef enum +{ GRPC_CHTTP2_LIST_ALL_STREAMS, GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED, GRPC_CHTTP2_LIST_WRITABLE, @@ -67,11 +68,12 @@ typedef enum { /** streams that are waiting to start because there are too many concurrent streams on the connection */ GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY, - STREAM_LIST_COUNT /* must be last */ + STREAM_LIST_COUNT /* must be last */ } grpc_chttp2_stream_list_id; /* deframer state for the overall http2 stream of bytes */ -typedef enum { +typedef enum +{ /* prefix: one entry per http2 connection prefix byte */ GRPC_DTS_CLIENT_PREFIX_0 = 0, GRPC_DTS_CLIENT_PREFIX_1, @@ -113,7 +115,8 @@ typedef enum { GRPC_DTS_FRAME } grpc_chttp2_deframe_transport_state; -typedef enum { +typedef enum +{ GRPC_WRITE_STATE_OPEN, GRPC_WRITE_STATE_QUEUED_CLOSE, GRPC_WRITE_STATE_SENT_CLOSE @@ -123,24 +126,28 @@ typedef enum { #define GRPC_CHTTP2_WRITING_DATA 1 #define GRPC_CHTTP2_WRITING_WINDOW 2 -typedef enum { +typedef enum +{ GRPC_DONT_SEND_CLOSED = 0, GRPC_SEND_CLOSED, GRPC_SEND_CLOSED_WITH_RST_STREAM } grpc_chttp2_send_closed; -typedef struct { +typedef struct +{ grpc_chttp2_stream *head; grpc_chttp2_stream *tail; } grpc_chttp2_stream_list; -typedef struct { +typedef struct +{ grpc_chttp2_stream *next; grpc_chttp2_stream *prev; } grpc_chttp2_stream_link; /* We keep several sets of connection wide parameters */ -typedef enum { +typedef enum +{ /* The settings our peer has asked for (and we have acked) */ GRPC_PEER_SETTINGS = 0, /* The settings we'd like to have */ @@ -153,14 +160,16 @@ typedef enum { } grpc_chttp2_setting_set; /* Outstanding ping request data */ -typedef struct grpc_chttp2_outstanding_ping { +typedef struct grpc_chttp2_outstanding_ping +{ gpr_uint8 id[8]; grpc_closure *on_recv; struct grpc_chttp2_outstanding_ping *next; struct grpc_chttp2_outstanding_ping *prev; } grpc_chttp2_outstanding_ping; -typedef struct { +typedef struct +{ /** data to write next write */ gpr_slice_buffer qbuf; @@ -204,7 +213,8 @@ typedef struct { gpr_uint32 concurrent_stream_count; } grpc_chttp2_transport_global; -typedef struct { +typedef struct +{ /** data to write now */ gpr_slice_buffer outbuf; /** hpack encoding */ @@ -215,7 +225,8 @@ typedef struct { grpc_closure done_cb; } grpc_chttp2_transport_writing; -struct grpc_chttp2_transport_parsing { +struct grpc_chttp2_transport_parsing +{ /** is this transport a client? (boolean) */ gpr_uint8 is_client; @@ -236,7 +247,8 @@ struct grpc_chttp2_transport_parsing { /** parser for headers */ grpc_chttp2_hpack_parser hpack_parser; /** simple one shot parsers */ - union { + union + { grpc_chttp2_window_update_parser window_update; grpc_chttp2_settings_parser settings; grpc_chttp2_ping_parser ping; @@ -265,10 +277,7 @@ struct grpc_chttp2_transport_parsing { /* active parser */ void *parser_data; grpc_chttp2_stream_parsing *incoming_stream; - grpc_chttp2_parse_error (*parser)( - void *parser_user_data, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list); + grpc_chttp2_parse_error (*parser) (void *parser_user_data, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); /* received settings */ gpr_uint32 settings[GRPC_CHTTP2_NUM_SETTINGS]; @@ -284,8 +293,9 @@ struct grpc_chttp2_transport_parsing { grpc_chttp2_outstanding_ping pings; }; -struct grpc_chttp2_transport { - grpc_transport base; /* must be first */ +struct grpc_chttp2_transport +{ + grpc_transport base; /* must be first */ grpc_endpoint *ep; grpc_mdctx *metadata_context; gpr_refcount refs; @@ -343,10 +353,10 @@ struct grpc_chttp2_transport { publish the accepted server stream */ grpc_chttp2_stream **accepting_stream; - struct { + struct + { /* accept stream callback */ - void (*accept_stream)(void *user_data, grpc_transport *transport, - const void *server_data); + void (*accept_stream) (void *user_data, grpc_transport * transport, const void *server_data); void *accept_stream_user_data; /** connectivity tracking */ @@ -354,7 +364,8 @@ struct grpc_chttp2_transport { } channel_callback; }; -typedef struct { +typedef struct +{ /** HTTP2 stream id for this stream, or zero if one has not been assigned */ gpr_uint32 id; @@ -410,7 +421,8 @@ typedef struct { grpc_chttp2_incoming_metadata_live_op_buffer outstanding_metadata; } grpc_chttp2_stream_global; -typedef struct { +typedef struct +{ /** HTTP2 stream id for this stream, or zero if one has not been assigned */ gpr_uint32 id; /** sops that have passed flow control to be written */ @@ -421,7 +433,8 @@ typedef struct { gpr_uint32 announce_window; } grpc_chttp2_stream_writing; -struct grpc_chttp2_stream_parsing { +struct grpc_chttp2_stream_parsing +{ /** HTTP2 stream id for this stream, or zero if one has not been assigned */ gpr_uint32 id; /** has this stream received a close */ @@ -443,7 +456,8 @@ struct grpc_chttp2_stream_parsing { grpc_chttp2_incoming_metadata_buffer incoming_metadata; }; -struct grpc_chttp2_stream { +struct grpc_chttp2_stream +{ grpc_chttp2_stream_global global; grpc_chttp2_stream_writing writing; grpc_chttp2_stream_parsing parsing; @@ -465,140 +479,71 @@ struct grpc_chttp2_stream { /** Someone is unlocking the transport mutex: check to see if writes are required, and schedule them if so */ -int grpc_chttp2_unlocking_check_writes(grpc_chttp2_transport_global *global, - grpc_chttp2_transport_writing *writing); -void grpc_chttp2_perform_writes( - grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint, - grpc_closure_list *closure_list); -void grpc_chttp2_terminate_writing(void *transport_writing, int success, - grpc_closure_list *closure_list); -void grpc_chttp2_cleanup_writing(grpc_chttp2_transport_global *global, - grpc_chttp2_transport_writing *writing, - grpc_closure_list *closure_list); - -void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global, - grpc_chttp2_transport_parsing *parsing); +int grpc_chttp2_unlocking_check_writes (grpc_chttp2_transport_global * global, grpc_chttp2_transport_writing * writing); +void grpc_chttp2_perform_writes (grpc_chttp2_transport_writing * transport_writing, grpc_endpoint * endpoint, grpc_closure_list * closure_list); +void grpc_chttp2_terminate_writing (void *transport_writing, int success, grpc_closure_list * closure_list); +void grpc_chttp2_cleanup_writing (grpc_chttp2_transport_global * global, grpc_chttp2_transport_writing * writing, grpc_closure_list * closure_list); + +void grpc_chttp2_prepare_to_read (grpc_chttp2_transport_global * global, grpc_chttp2_transport_parsing * parsing); /** Process one slice of incoming data; return 1 if the connection is still viable after reading, or 0 if the connection should be torn down */ -int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, - gpr_slice slice, grpc_closure_list *closure_list); -void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *global, - grpc_chttp2_transport_parsing *parsing, - grpc_closure_list *closure_list); +int grpc_chttp2_perform_read (grpc_chttp2_transport_parsing * transport_parsing, gpr_slice slice, grpc_closure_list * closure_list); +void grpc_chttp2_publish_reads (grpc_chttp2_transport_global * global, grpc_chttp2_transport_parsing * parsing, grpc_closure_list * closure_list); /** Get a writable stream returns non-zero if there was a stream available */ -void grpc_chttp2_list_add_writable_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); -void grpc_chttp2_list_add_first_writable_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); -int grpc_chttp2_list_pop_writable_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_global **stream_global, - grpc_chttp2_stream_writing **stream_writing); -void grpc_chttp2_list_remove_writable_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); - -void grpc_chttp2_list_add_incoming_window_updated( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); -int grpc_chttp2_list_pop_incoming_window_updated( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_global **stream_global, - grpc_chttp2_stream_parsing **stream_parsing); -void grpc_chttp2_list_remove_incoming_window_updated( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); - -void grpc_chttp2_list_add_writing_stream( - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_writing *stream_writing); -int grpc_chttp2_list_have_writing_streams( - grpc_chttp2_transport_writing *transport_writing); -int grpc_chttp2_list_pop_writing_stream( - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_writing **stream_writing); - -void grpc_chttp2_list_add_written_stream( - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_writing *stream_writing); -int grpc_chttp2_list_pop_written_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_global **stream_global, - grpc_chttp2_stream_writing **stream_writing); - -void grpc_chttp2_list_add_parsing_seen_stream( - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing); -int grpc_chttp2_list_pop_parsing_seen_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_global **stream_global, - grpc_chttp2_stream_parsing **stream_parsing); - -void grpc_chttp2_list_add_waiting_for_concurrency( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); -int grpc_chttp2_list_pop_waiting_for_concurrency( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global **stream_global); - -void grpc_chttp2_list_add_closed_waiting_for_parsing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); -int grpc_chttp2_list_pop_closed_waiting_for_parsing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global **stream_global); - -void grpc_chttp2_list_add_cancelled_waiting_for_writing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); -int grpc_chttp2_list_pop_cancelled_waiting_for_writing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global **stream_global); - -void grpc_chttp2_list_add_read_write_state_changed( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global); -int grpc_chttp2_list_pop_read_write_state_changed( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global **stream_global); - -grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream( - grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); -grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream( - grpc_chttp2_transport_parsing *transport_parsing, gpr_uint32 id); - -void grpc_chttp2_add_incoming_goaway( - grpc_chttp2_transport_global *transport_global, gpr_uint32 goaway_error, - gpr_slice goaway_text, grpc_closure_list *closure_list); - -void grpc_chttp2_register_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s); +void grpc_chttp2_list_add_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); +void grpc_chttp2_list_add_first_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); +int grpc_chttp2_list_pop_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_writing ** stream_writing); +void grpc_chttp2_list_remove_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); + +void grpc_chttp2_list_add_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); +int grpc_chttp2_list_pop_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_parsing ** stream_parsing); +void grpc_chttp2_list_remove_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); + +void grpc_chttp2_list_add_writing_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing * stream_writing); +int grpc_chttp2_list_have_writing_streams (grpc_chttp2_transport_writing * transport_writing); +int grpc_chttp2_list_pop_writing_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing ** stream_writing); + +void grpc_chttp2_list_add_written_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing * stream_writing); +int grpc_chttp2_list_pop_written_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_writing ** stream_writing); + +void grpc_chttp2_list_add_parsing_seen_stream (grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing); +int grpc_chttp2_list_pop_parsing_seen_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_parsing ** stream_parsing); + +void grpc_chttp2_list_add_waiting_for_concurrency (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); +int grpc_chttp2_list_pop_waiting_for_concurrency (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global); + +void grpc_chttp2_list_add_closed_waiting_for_parsing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); +int grpc_chttp2_list_pop_closed_waiting_for_parsing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global); + +void grpc_chttp2_list_add_cancelled_waiting_for_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); +int grpc_chttp2_list_pop_cancelled_waiting_for_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global); + +void grpc_chttp2_list_add_read_write_state_changed (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global); +int grpc_chttp2_list_pop_read_write_state_changed (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global); + +grpc_chttp2_stream_parsing *grpc_chttp2_parsing_lookup_stream (grpc_chttp2_transport_parsing * transport_parsing, gpr_uint32 id); +grpc_chttp2_stream_parsing *grpc_chttp2_parsing_accept_stream (grpc_chttp2_transport_parsing * transport_parsing, gpr_uint32 id); + +void grpc_chttp2_add_incoming_goaway (grpc_chttp2_transport_global * transport_global, gpr_uint32 goaway_error, gpr_slice goaway_text, grpc_closure_list * closure_list); + +void grpc_chttp2_register_stream (grpc_chttp2_transport * t, grpc_chttp2_stream * s); /* returns 1 if this is the last stream, 0 otherwise */ -int grpc_chttp2_unregister_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) GRPC_MUST_USE_RESULT; -int grpc_chttp2_has_streams(grpc_chttp2_transport *t); -void grpc_chttp2_for_all_streams( - grpc_chttp2_transport_global *transport_global, void *user_data, - void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data, - grpc_chttp2_stream_global *stream_global)); +int +grpc_chttp2_unregister_stream (grpc_chttp2_transport * t, grpc_chttp2_stream * s) + GRPC_MUST_USE_RESULT; + int grpc_chttp2_has_streams (grpc_chttp2_transport * t); + void grpc_chttp2_for_all_streams (grpc_chttp2_transport_global * transport_global, void *user_data, void (*cb) (grpc_chttp2_transport_global * transport_global, void *user_data, grpc_chttp2_stream_global * stream_global)); -void grpc_chttp2_parsing_become_skip_parser( - grpc_chttp2_transport_parsing *transport_parsing); + void grpc_chttp2_parsing_become_skip_parser (grpc_chttp2_transport_parsing * transport_parsing); #define GRPC_CHTTP2_CLIENT_CONNECT_STRING "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" #define GRPC_CHTTP2_CLIENT_CONNECT_STRLEN \ (sizeof(GRPC_CHTTP2_CLIENT_CONNECT_STRING) - 1) -extern int grpc_http_trace; -extern int grpc_flowctl_trace; + extern int grpc_http_trace; + extern int grpc_flowctl_trace; #define GRPC_CHTTP2_IF_TRACING(stmt) \ if (!(grpc_http_trace)) \ @@ -623,9 +568,6 @@ extern int grpc_flowctl_trace; (gpr_int64)(context->var), (gpr_int64)(delta)); \ } -void grpc_chttp2_flowctl_trace(const char *file, int line, const char *reason, - const char *context, const char *var, - int is_client, gpr_uint32 stream_id, - gpr_int64 current_value, gpr_int64 delta); + void grpc_chttp2_flowctl_trace (const char *file, int line, const char *reason, const char *context, const char *var, int is_client, gpr_uint32 stream_id, gpr_int64 current_value, gpr_int64 delta); #endif diff --git a/src/core/transport/chttp2/parsing.c b/src/core/transport/chttp2/parsing.c index f6ce35f9ac..944066eab3 100644 --- a/src/core/transport/chttp2/parsing.c +++ b/src/core/transport/chttp2/parsing.c @@ -42,58 +42,46 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> -static int init_frame_parser(grpc_chttp2_transport_parsing *transport_parsing); -static int init_header_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing, int is_continuation); -static int init_data_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing); -static int init_rst_stream_parser( - grpc_chttp2_transport_parsing *transport_parsing); -static int init_settings_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing); -static int init_window_update_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing); -static int init_ping_parser(grpc_chttp2_transport_parsing *transport_parsing); -static int init_goaway_parser(grpc_chttp2_transport_parsing *transport_parsing); -static int init_skip_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing, int is_header); - -static int parse_frame_slice(grpc_chttp2_transport_parsing *transport_parsing, - gpr_slice slice, int is_last, - grpc_closure_list *closure_list); - -void grpc_chttp2_prepare_to_read( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_parsing *transport_parsing) { +static int init_frame_parser (grpc_chttp2_transport_parsing * transport_parsing); +static int init_header_frame_parser (grpc_chttp2_transport_parsing * transport_parsing, int is_continuation); +static int init_data_frame_parser (grpc_chttp2_transport_parsing * transport_parsing); +static int init_rst_stream_parser (grpc_chttp2_transport_parsing * transport_parsing); +static int init_settings_frame_parser (grpc_chttp2_transport_parsing * transport_parsing); +static int init_window_update_frame_parser (grpc_chttp2_transport_parsing * transport_parsing); +static int init_ping_parser (grpc_chttp2_transport_parsing * transport_parsing); +static int init_goaway_parser (grpc_chttp2_transport_parsing * transport_parsing); +static int init_skip_frame_parser (grpc_chttp2_transport_parsing * transport_parsing, int is_header); + +static int parse_frame_slice (grpc_chttp2_transport_parsing * transport_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list); + +void +grpc_chttp2_prepare_to_read (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing) +{ grpc_chttp2_stream_global *stream_global; grpc_chttp2_stream_parsing *stream_parsing; transport_parsing->next_stream_id = transport_global->next_stream_id; /* update the parsing view of incoming window */ - if (transport_parsing->incoming_window != transport_global->incoming_window) { - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( - "parse", transport_parsing, incoming_window, - (gpr_int64)transport_global->incoming_window - - (gpr_int64)transport_parsing->incoming_window); - transport_parsing->incoming_window = transport_global->incoming_window; - } - while (grpc_chttp2_list_pop_incoming_window_updated( - transport_global, transport_parsing, &stream_global, &stream_parsing)) { - stream_parsing->id = stream_global->id; - if (stream_parsing->incoming_window != stream_global->incoming_window) { - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "parse", transport_parsing, stream_parsing, incoming_window, - (gpr_int64)stream_global->incoming_window - - (gpr_int64)stream_parsing->incoming_window); - stream_parsing->incoming_window = stream_global->incoming_window; - } - } + if (transport_parsing->incoming_window != transport_global->incoming_window) + { + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parse", transport_parsing, incoming_window, (gpr_int64) transport_global->incoming_window - (gpr_int64) transport_parsing->incoming_window); + transport_parsing->incoming_window = transport_global->incoming_window; + } + while (grpc_chttp2_list_pop_incoming_window_updated (transport_global, transport_parsing, &stream_global, &stream_parsing)) + { + stream_parsing->id = stream_global->id; + if (stream_parsing->incoming_window != stream_global->incoming_window) + { + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parse", transport_parsing, stream_parsing, incoming_window, (gpr_int64) stream_global->incoming_window - (gpr_int64) stream_parsing->incoming_window); + stream_parsing->incoming_window = stream_global->incoming_window; + } + } } -void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_parsing *transport_parsing, - grpc_closure_list *closure_list) { +void +grpc_chttp2_publish_reads (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_closure_list * closure_list) +{ grpc_chttp2_stream_global *stream_global; grpc_chttp2_stream_parsing *stream_parsing; @@ -105,145 +93,126 @@ void grpc_chttp2_publish_reads(grpc_chttp2_transport_global *transport_global, ID. So, since we don't have server pushed streams, client should send GOAWAY last-grpc_chttp2_stream-id=0 in this case. */ - if (!transport_parsing->is_client) { - transport_global->last_incoming_stream_id = - transport_parsing->incoming_stream_id; - } + if (!transport_parsing->is_client) + { + transport_global->last_incoming_stream_id = transport_parsing->incoming_stream_id; + } /* copy parsing qbuf to global qbuf */ - gpr_slice_buffer_move_into(&transport_parsing->qbuf, &transport_global->qbuf); + gpr_slice_buffer_move_into (&transport_parsing->qbuf, &transport_global->qbuf); /* update global settings */ - if (transport_parsing->settings_updated) { - memcpy(transport_global->settings[GRPC_PEER_SETTINGS], - transport_parsing->settings, sizeof(transport_parsing->settings)); - transport_parsing->settings_updated = 0; - } + if (transport_parsing->settings_updated) + { + memcpy (transport_global->settings[GRPC_PEER_SETTINGS], transport_parsing->settings, sizeof (transport_parsing->settings)); + transport_parsing->settings_updated = 0; + } /* update settings based on ack if received */ - if (transport_parsing->settings_ack_received) { - memcpy(transport_global->settings[GRPC_ACKED_SETTINGS], - transport_global->settings[GRPC_SENT_SETTINGS], - GRPC_CHTTP2_NUM_SETTINGS * sizeof(gpr_uint32)); - transport_parsing->settings_ack_received = 0; - } + if (transport_parsing->settings_ack_received) + { + memcpy (transport_global->settings[GRPC_ACKED_SETTINGS], transport_global->settings[GRPC_SENT_SETTINGS], GRPC_CHTTP2_NUM_SETTINGS * sizeof (gpr_uint32)); + transport_parsing->settings_ack_received = 0; + } /* move goaway to the global state if we received one (it will be published later */ - if (transport_parsing->goaway_received) { - grpc_chttp2_add_incoming_goaway( - transport_global, (gpr_uint32)transport_parsing->goaway_error, - transport_parsing->goaway_text, closure_list); - transport_parsing->goaway_text = gpr_empty_slice(); - transport_parsing->goaway_received = 0; - } + if (transport_parsing->goaway_received) + { + grpc_chttp2_add_incoming_goaway (transport_global, (gpr_uint32) transport_parsing->goaway_error, transport_parsing->goaway_text, closure_list); + transport_parsing->goaway_text = gpr_empty_slice (); + transport_parsing->goaway_received = 0; + } /* propagate flow control tokens to global state */ - if (transport_parsing->outgoing_window_update) { - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( - "parsed", transport_global, outgoing_window, - transport_parsing->outgoing_window_update); - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( - "parsed", transport_parsing, outgoing_window_update, - -(gpr_int64)transport_parsing->outgoing_window_update); - transport_global->outgoing_window += - transport_parsing->outgoing_window_update; - transport_parsing->outgoing_window_update = 0; - } - - if (transport_parsing->incoming_window_delta) { - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( - "parsed", transport_global, incoming_window, - -(gpr_int64)transport_parsing->incoming_window_delta); - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( - "parsed", transport_parsing, incoming_window_delta, - -(gpr_int64)transport_parsing->incoming_window_delta); - transport_global->incoming_window -= - transport_parsing->incoming_window_delta; - transport_parsing->incoming_window_delta = 0; - } + if (transport_parsing->outgoing_window_update) + { + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parsed", transport_global, outgoing_window, transport_parsing->outgoing_window_update); + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parsed", transport_parsing, outgoing_window_update, -(gpr_int64) transport_parsing->outgoing_window_update); + transport_global->outgoing_window += transport_parsing->outgoing_window_update; + transport_parsing->outgoing_window_update = 0; + } + + if (transport_parsing->incoming_window_delta) + { + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parsed", transport_global, incoming_window, -(gpr_int64) transport_parsing->incoming_window_delta); + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("parsed", transport_parsing, incoming_window_delta, -(gpr_int64) transport_parsing->incoming_window_delta); + transport_global->incoming_window -= transport_parsing->incoming_window_delta; + transport_parsing->incoming_window_delta = 0; + } /* for each stream that saw an update, fixup global state */ - while (grpc_chttp2_list_pop_parsing_seen_stream( - transport_global, transport_parsing, &stream_global, &stream_parsing)) { - /* update incoming flow control window */ - if (stream_parsing->incoming_window_delta) { - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "parsed", transport_parsing, stream_global, incoming_window, - -(gpr_int64)stream_parsing->incoming_window_delta); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "parsed", transport_parsing, stream_parsing, incoming_window_delta, - -(gpr_int64)stream_parsing->incoming_window_delta); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "parsed", transport_parsing, stream_global, max_recv_bytes, - -(gpr_int64)stream_parsing->incoming_window_delta); - stream_global->incoming_window -= stream_parsing->incoming_window_delta; - GPR_ASSERT(stream_global->max_recv_bytes >= - stream_parsing->incoming_window_delta); - stream_global->max_recv_bytes -= stream_parsing->incoming_window_delta; - stream_parsing->incoming_window_delta = 0; - grpc_chttp2_list_add_writable_stream(transport_global, stream_global); - } - - /* update outgoing flow control window */ - if (stream_parsing->outgoing_window_update) { - int was_zero = stream_global->outgoing_window <= 0; - int is_zero; - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("parsed", transport_parsing, - stream_global, outgoing_window, - stream_parsing->outgoing_window_update); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "parsed", transport_parsing, stream_parsing, outgoing_window_update, - -(gpr_int64)stream_parsing->outgoing_window_update); - GPR_ASSERT(stream_parsing->outgoing_window_update <= GPR_UINT32_MAX); - stream_global->outgoing_window += - (gpr_uint32)stream_parsing->outgoing_window_update; - stream_parsing->outgoing_window_update = 0; - is_zero = stream_global->outgoing_window <= 0; - if (was_zero && !is_zero) { - grpc_chttp2_list_add_writable_stream(transport_global, stream_global); - } - } - - /* updating closed status */ - if (stream_parsing->received_close) { - stream_global->read_closed = 1; - grpc_chttp2_list_add_read_write_state_changed(transport_global, - stream_global); - } - if (stream_parsing->saw_rst_stream) { - stream_global->cancelled = 1; - stream_global->cancelled_status = grpc_chttp2_http2_error_to_grpc_status( - (grpc_chttp2_error_code)stream_parsing->rst_stream_reason); - if (stream_parsing->rst_stream_reason == GRPC_CHTTP2_NO_ERROR) { - stream_global->published_cancelled = 1; - } - grpc_chttp2_list_add_read_write_state_changed(transport_global, - stream_global); - } - - /* publish incoming stream ops */ - if (stream_parsing->data_parser.incoming_sopb.nops > 0) { - grpc_incoming_metadata_buffer_move_to_referencing_sopb( - &stream_parsing->incoming_metadata, &stream_global->incoming_metadata, - &stream_parsing->data_parser.incoming_sopb); - grpc_sopb_move_to(&stream_parsing->data_parser.incoming_sopb, - &stream_global->incoming_sopb); - grpc_chttp2_list_add_read_write_state_changed(transport_global, - stream_global); - } - } + while (grpc_chttp2_list_pop_parsing_seen_stream (transport_global, transport_parsing, &stream_global, &stream_parsing)) + { + /* update incoming flow control window */ + if (stream_parsing->incoming_window_delta) + { + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_global, incoming_window, -(gpr_int64) stream_parsing->incoming_window_delta); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_parsing, incoming_window_delta, -(gpr_int64) stream_parsing->incoming_window_delta); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_global, max_recv_bytes, -(gpr_int64) stream_parsing->incoming_window_delta); + stream_global->incoming_window -= stream_parsing->incoming_window_delta; + GPR_ASSERT (stream_global->max_recv_bytes >= stream_parsing->incoming_window_delta); + stream_global->max_recv_bytes -= stream_parsing->incoming_window_delta; + stream_parsing->incoming_window_delta = 0; + grpc_chttp2_list_add_writable_stream (transport_global, stream_global); + } + + /* update outgoing flow control window */ + if (stream_parsing->outgoing_window_update) + { + int was_zero = stream_global->outgoing_window <= 0; + int is_zero; + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_global, outgoing_window, stream_parsing->outgoing_window_update); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("parsed", transport_parsing, stream_parsing, outgoing_window_update, -(gpr_int64) stream_parsing->outgoing_window_update); + GPR_ASSERT (stream_parsing->outgoing_window_update <= GPR_UINT32_MAX); + stream_global->outgoing_window += (gpr_uint32) stream_parsing->outgoing_window_update; + stream_parsing->outgoing_window_update = 0; + is_zero = stream_global->outgoing_window <= 0; + if (was_zero && !is_zero) + { + grpc_chttp2_list_add_writable_stream (transport_global, stream_global); + } + } + + /* updating closed status */ + if (stream_parsing->received_close) + { + stream_global->read_closed = 1; + grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global); + } + if (stream_parsing->saw_rst_stream) + { + stream_global->cancelled = 1; + stream_global->cancelled_status = grpc_chttp2_http2_error_to_grpc_status ((grpc_chttp2_error_code) stream_parsing->rst_stream_reason); + if (stream_parsing->rst_stream_reason == GRPC_CHTTP2_NO_ERROR) + { + stream_global->published_cancelled = 1; + } + grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global); + } + + /* publish incoming stream ops */ + if (stream_parsing->data_parser.incoming_sopb.nops > 0) + { + grpc_incoming_metadata_buffer_move_to_referencing_sopb (&stream_parsing->incoming_metadata, &stream_global->incoming_metadata, &stream_parsing->data_parser.incoming_sopb); + grpc_sopb_move_to (&stream_parsing->data_parser.incoming_sopb, &stream_global->incoming_sopb); + grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global); + } + } } -int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, - gpr_slice slice, grpc_closure_list *closure_list) { - gpr_uint8 *beg = GPR_SLICE_START_PTR(slice); - gpr_uint8 *end = GPR_SLICE_END_PTR(slice); +int +grpc_chttp2_perform_read (grpc_chttp2_transport_parsing * transport_parsing, gpr_slice slice, grpc_closure_list * closure_list) +{ + gpr_uint8 *beg = GPR_SLICE_START_PTR (slice); + gpr_uint8 *end = GPR_SLICE_END_PTR (slice); gpr_uint8 *cur = beg; - if (cur == end) return 1; + if (cur == end) + return 1; - switch (transport_parsing->deframe_state) { + switch (transport_parsing->deframe_state) + { case GRPC_DTS_CLIENT_PREFIX_0: case GRPC_DTS_CLIENT_PREFIX_1: case GRPC_DTS_CLIENT_PREFIX_2: @@ -268,300 +237,294 @@ int grpc_chttp2_perform_read(grpc_chttp2_transport_parsing *transport_parsing, case GRPC_DTS_CLIENT_PREFIX_21: case GRPC_DTS_CLIENT_PREFIX_22: case GRPC_DTS_CLIENT_PREFIX_23: - while (cur != end && transport_parsing->deframe_state != GRPC_DTS_FH_0) { - if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing - ->deframe_state]) { - gpr_log(GPR_INFO, - "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " - "at byte %d", - GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing - ->deframe_state], - (int)(gpr_uint8)GRPC_CHTTP2_CLIENT_CONNECT_STRING - [transport_parsing->deframe_state], - *cur, (int)*cur, transport_parsing->deframe_state); - return 0; - } - ++cur; - ++transport_parsing->deframe_state; - } - if (cur == end) { - return 1; - } - /* fallthrough */ + while (cur != end && transport_parsing->deframe_state != GRPC_DTS_FH_0) + { + if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing->deframe_state]) + { + gpr_log (GPR_INFO, "Connect string mismatch: expected '%c' (%d) got '%c' (%d) " "at byte %d", GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing->deframe_state], (int) (gpr_uint8) GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing->deframe_state], *cur, (int) *cur, transport_parsing->deframe_state); + return 0; + } + ++cur; + ++transport_parsing->deframe_state; + } + if (cur == end) + { + return 1; + } + /* fallthrough */ dts_fh_0: case GRPC_DTS_FH_0: - GPR_ASSERT(cur < end); - transport_parsing->incoming_frame_size = ((gpr_uint32)*cur) << 16; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_1; - return 1; - } - /* fallthrough */ + GPR_ASSERT (cur < end); + transport_parsing->incoming_frame_size = ((gpr_uint32) * cur) << 16; + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_1; + return 1; + } + /* fallthrough */ case GRPC_DTS_FH_1: - GPR_ASSERT(cur < end); - transport_parsing->incoming_frame_size |= ((gpr_uint32)*cur) << 8; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_2; - return 1; - } - /* fallthrough */ + GPR_ASSERT (cur < end); + transport_parsing->incoming_frame_size |= ((gpr_uint32) * cur) << 8; + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_2; + return 1; + } + /* fallthrough */ case GRPC_DTS_FH_2: - GPR_ASSERT(cur < end); + GPR_ASSERT (cur < end); transport_parsing->incoming_frame_size |= *cur; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_3; - return 1; - } - /* fallthrough */ + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_3; + return 1; + } + /* fallthrough */ case GRPC_DTS_FH_3: - GPR_ASSERT(cur < end); + GPR_ASSERT (cur < end); transport_parsing->incoming_frame_type = *cur; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_4; - return 1; - } - /* fallthrough */ + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_4; + return 1; + } + /* fallthrough */ case GRPC_DTS_FH_4: - GPR_ASSERT(cur < end); + GPR_ASSERT (cur < end); transport_parsing->incoming_frame_flags = *cur; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_5; - return 1; - } - /* fallthrough */ + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_5; + return 1; + } + /* fallthrough */ case GRPC_DTS_FH_5: - GPR_ASSERT(cur < end); - transport_parsing->incoming_stream_id = (((gpr_uint32)*cur) & 0x7f) << 24; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_6; - return 1; - } - /* fallthrough */ + GPR_ASSERT (cur < end); + transport_parsing->incoming_stream_id = (((gpr_uint32) * cur) & 0x7f) << 24; + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_6; + return 1; + } + /* fallthrough */ case GRPC_DTS_FH_6: - GPR_ASSERT(cur < end); - transport_parsing->incoming_stream_id |= ((gpr_uint32)*cur) << 16; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_7; - return 1; - } - /* fallthrough */ + GPR_ASSERT (cur < end); + transport_parsing->incoming_stream_id |= ((gpr_uint32) * cur) << 16; + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_7; + return 1; + } + /* fallthrough */ case GRPC_DTS_FH_7: - GPR_ASSERT(cur < end); - transport_parsing->incoming_stream_id |= ((gpr_uint32)*cur) << 8; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_8; - return 1; - } - /* fallthrough */ + GPR_ASSERT (cur < end); + transport_parsing->incoming_stream_id |= ((gpr_uint32) * cur) << 8; + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_8; + return 1; + } + /* fallthrough */ case GRPC_DTS_FH_8: - GPR_ASSERT(cur < end); - transport_parsing->incoming_stream_id |= ((gpr_uint32)*cur); + GPR_ASSERT (cur < end); + transport_parsing->incoming_stream_id |= ((gpr_uint32) * cur); transport_parsing->deframe_state = GRPC_DTS_FRAME; - if (!init_frame_parser(transport_parsing)) { - return 0; - } - if (transport_parsing->incoming_stream_id) { - transport_parsing->last_incoming_stream_id = - transport_parsing->incoming_stream_id; - } - if (transport_parsing->incoming_frame_size == 0) { - if (!parse_frame_slice(transport_parsing, gpr_empty_slice(), 1, - closure_list)) { - return 0; - } - transport_parsing->incoming_stream = NULL; - if (++cur == end) { - transport_parsing->deframe_state = GRPC_DTS_FH_0; - return 1; - } - goto dts_fh_0; /* loop */ - } - if (++cur == end) { - return 1; - } - /* fallthrough */ + if (!init_frame_parser (transport_parsing)) + { + return 0; + } + if (transport_parsing->incoming_stream_id) + { + transport_parsing->last_incoming_stream_id = transport_parsing->incoming_stream_id; + } + if (transport_parsing->incoming_frame_size == 0) + { + if (!parse_frame_slice (transport_parsing, gpr_empty_slice (), 1, closure_list)) + { + return 0; + } + transport_parsing->incoming_stream = NULL; + if (++cur == end) + { + transport_parsing->deframe_state = GRPC_DTS_FH_0; + return 1; + } + goto dts_fh_0; /* loop */ + } + if (++cur == end) + { + return 1; + } + /* fallthrough */ case GRPC_DTS_FRAME: - GPR_ASSERT(cur < end); - if ((gpr_uint32)(end - cur) == transport_parsing->incoming_frame_size) { - if (!parse_frame_slice(transport_parsing, - gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - 1, closure_list)) { - return 0; - } - transport_parsing->deframe_state = GRPC_DTS_FH_0; - transport_parsing->incoming_stream = NULL; - return 1; - } else if ((gpr_uint32)(end - cur) > - transport_parsing->incoming_frame_size) { - size_t cur_offset = (size_t)(cur - beg); - if (!parse_frame_slice( - transport_parsing, - gpr_slice_sub_no_ref( - slice, cur_offset, - cur_offset + transport_parsing->incoming_frame_size), - 1, closure_list)) { - return 0; - } - cur += transport_parsing->incoming_frame_size; - transport_parsing->incoming_stream = NULL; - goto dts_fh_0; /* loop */ - } else { - if (!parse_frame_slice(transport_parsing, - gpr_slice_sub_no_ref(slice, (size_t)(cur - beg), - (size_t)(end - beg)), - 0, closure_list)) { - return 0; - } - transport_parsing->incoming_frame_size -= (gpr_uint32)(end - cur); - return 1; - } - gpr_log(GPR_ERROR, "should never reach here"); - abort(); - } - - gpr_log(GPR_ERROR, "should never reach here"); - abort(); + GPR_ASSERT (cur < end); + if ((gpr_uint32) (end - cur) == transport_parsing->incoming_frame_size) + { + if (!parse_frame_slice (transport_parsing, gpr_slice_sub_no_ref (slice, (size_t) (cur - beg), (size_t) (end - beg)), 1, closure_list)) + { + return 0; + } + transport_parsing->deframe_state = GRPC_DTS_FH_0; + transport_parsing->incoming_stream = NULL; + return 1; + } + else if ((gpr_uint32) (end - cur) > transport_parsing->incoming_frame_size) + { + size_t cur_offset = (size_t) (cur - beg); + if (!parse_frame_slice (transport_parsing, gpr_slice_sub_no_ref (slice, cur_offset, cur_offset + transport_parsing->incoming_frame_size), 1, closure_list)) + { + return 0; + } + cur += transport_parsing->incoming_frame_size; + transport_parsing->incoming_stream = NULL; + goto dts_fh_0; /* loop */ + } + else + { + if (!parse_frame_slice (transport_parsing, gpr_slice_sub_no_ref (slice, (size_t) (cur - beg), (size_t) (end - beg)), 0, closure_list)) + { + return 0; + } + transport_parsing->incoming_frame_size -= (gpr_uint32) (end - cur); + return 1; + } + gpr_log (GPR_ERROR, "should never reach here"); + abort (); + } + + gpr_log (GPR_ERROR, "should never reach here"); + abort (); return 0; } -static int init_frame_parser(grpc_chttp2_transport_parsing *transport_parsing) { - if (transport_parsing->expect_continuation_stream_id != 0) { - if (transport_parsing->incoming_frame_type != - GRPC_CHTTP2_FRAME_CONTINUATION) { - gpr_log(GPR_ERROR, "Expected CONTINUATION frame, got frame type %02x", - transport_parsing->incoming_frame_type); - return 0; - } - if (transport_parsing->expect_continuation_stream_id != - transport_parsing->incoming_stream_id) { - gpr_log(GPR_ERROR, - "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got " - "grpc_chttp2_stream %08x", - transport_parsing->expect_continuation_stream_id, - transport_parsing->incoming_stream_id); - return 0; +static int +init_frame_parser (grpc_chttp2_transport_parsing * transport_parsing) +{ + if (transport_parsing->expect_continuation_stream_id != 0) + { + if (transport_parsing->incoming_frame_type != GRPC_CHTTP2_FRAME_CONTINUATION) + { + gpr_log (GPR_ERROR, "Expected CONTINUATION frame, got frame type %02x", transport_parsing->incoming_frame_type); + return 0; + } + if (transport_parsing->expect_continuation_stream_id != transport_parsing->incoming_stream_id) + { + gpr_log (GPR_ERROR, "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got " "grpc_chttp2_stream %08x", transport_parsing->expect_continuation_stream_id, transport_parsing->incoming_stream_id); + return 0; + } + return init_header_frame_parser (transport_parsing, 1); } - return init_header_frame_parser(transport_parsing, 1); - } - switch (transport_parsing->incoming_frame_type) { + switch (transport_parsing->incoming_frame_type) + { case GRPC_CHTTP2_FRAME_DATA: - return init_data_frame_parser(transport_parsing); + return init_data_frame_parser (transport_parsing); case GRPC_CHTTP2_FRAME_HEADER: - return init_header_frame_parser(transport_parsing, 0); + return init_header_frame_parser (transport_parsing, 0); case GRPC_CHTTP2_FRAME_CONTINUATION: - gpr_log(GPR_ERROR, "Unexpected CONTINUATION frame"); + gpr_log (GPR_ERROR, "Unexpected CONTINUATION frame"); return 0; case GRPC_CHTTP2_FRAME_RST_STREAM: - return init_rst_stream_parser(transport_parsing); + return init_rst_stream_parser (transport_parsing); case GRPC_CHTTP2_FRAME_SETTINGS: - return init_settings_frame_parser(transport_parsing); + return init_settings_frame_parser (transport_parsing); case GRPC_CHTTP2_FRAME_WINDOW_UPDATE: - return init_window_update_frame_parser(transport_parsing); + return init_window_update_frame_parser (transport_parsing); case GRPC_CHTTP2_FRAME_PING: - return init_ping_parser(transport_parsing); + return init_ping_parser (transport_parsing); case GRPC_CHTTP2_FRAME_GOAWAY: - return init_goaway_parser(transport_parsing); + return init_goaway_parser (transport_parsing); default: - gpr_log(GPR_ERROR, "Unknown frame type %02x", - transport_parsing->incoming_frame_type); - return init_skip_frame_parser(transport_parsing, 0); - } + gpr_log (GPR_ERROR, "Unknown frame type %02x", transport_parsing->incoming_frame_type); + return init_skip_frame_parser (transport_parsing, 0); + } } -static grpc_chttp2_parse_error skip_parser( - void *parser, grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { +static grpc_chttp2_parse_error +skip_parser (void *parser, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ return GRPC_CHTTP2_PARSE_OK; } -static void skip_header(void *tp, grpc_mdelem *md) { GRPC_MDELEM_UNREF(md); } - -static int init_skip_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing, int is_header) { - if (is_header) { - gpr_uint8 is_eoh = transport_parsing->expect_continuation_stream_id != 0; - transport_parsing->parser = grpc_chttp2_header_parser_parse; - transport_parsing->parser_data = &transport_parsing->hpack_parser; - transport_parsing->hpack_parser.on_header = skip_header; - transport_parsing->hpack_parser.on_header_user_data = NULL; - transport_parsing->hpack_parser.is_boundary = is_eoh; - transport_parsing->hpack_parser.is_eof = - (gpr_uint8)(is_eoh ? transport_parsing->header_eof : 0); - } else { - transport_parsing->parser = skip_parser; - } +static void +skip_header (void *tp, grpc_mdelem * md) +{ + GRPC_MDELEM_UNREF (md); +} + +static int +init_skip_frame_parser (grpc_chttp2_transport_parsing * transport_parsing, int is_header) +{ + if (is_header) + { + gpr_uint8 is_eoh = transport_parsing->expect_continuation_stream_id != 0; + transport_parsing->parser = grpc_chttp2_header_parser_parse; + transport_parsing->parser_data = &transport_parsing->hpack_parser; + transport_parsing->hpack_parser.on_header = skip_header; + transport_parsing->hpack_parser.on_header_user_data = NULL; + transport_parsing->hpack_parser.is_boundary = is_eoh; + transport_parsing->hpack_parser.is_eof = (gpr_uint8) (is_eoh ? transport_parsing->header_eof : 0); + } + else + { + transport_parsing->parser = skip_parser; + } return 1; } -void grpc_chttp2_parsing_become_skip_parser( - grpc_chttp2_transport_parsing *transport_parsing) { - init_skip_frame_parser( - transport_parsing, - transport_parsing->parser == grpc_chttp2_header_parser_parse); +void +grpc_chttp2_parsing_become_skip_parser (grpc_chttp2_transport_parsing * transport_parsing) +{ + init_skip_frame_parser (transport_parsing, transport_parsing->parser == grpc_chttp2_header_parser_parse); } -static grpc_chttp2_parse_error update_incoming_window( - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing) { - if (transport_parsing->incoming_frame_size > - transport_parsing->incoming_window) { - gpr_log(GPR_ERROR, "frame of size %d overflows incoming window of %d", - transport_parsing->incoming_frame_size, - transport_parsing->incoming_window); - return GRPC_CHTTP2_CONNECTION_ERROR; - } - - if (transport_parsing->incoming_frame_size > - stream_parsing->incoming_window) { - gpr_log(GPR_ERROR, "frame of size %d overflows incoming window of %d", - transport_parsing->incoming_frame_size, - stream_parsing->incoming_window); - return GRPC_CHTTP2_CONNECTION_ERROR; - } - - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( - "data", transport_parsing, incoming_window, - -(gpr_int64)transport_parsing->incoming_frame_size); - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT("data", transport_parsing, - incoming_window_delta, - transport_parsing->incoming_frame_size); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "data", transport_parsing, stream_parsing, incoming_window, - -(gpr_int64)transport_parsing->incoming_frame_size); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("data", transport_parsing, stream_parsing, - incoming_window_delta, - transport_parsing->incoming_frame_size); +static grpc_chttp2_parse_error +update_incoming_window (grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing) +{ + if (transport_parsing->incoming_frame_size > transport_parsing->incoming_window) + { + gpr_log (GPR_ERROR, "frame of size %d overflows incoming window of %d", transport_parsing->incoming_frame_size, transport_parsing->incoming_window); + return GRPC_CHTTP2_CONNECTION_ERROR; + } + + if (transport_parsing->incoming_frame_size > stream_parsing->incoming_window) + { + gpr_log (GPR_ERROR, "frame of size %d overflows incoming window of %d", transport_parsing->incoming_frame_size, stream_parsing->incoming_window); + return GRPC_CHTTP2_CONNECTION_ERROR; + } + + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("data", transport_parsing, incoming_window, -(gpr_int64) transport_parsing->incoming_frame_size); + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("data", transport_parsing, incoming_window_delta, transport_parsing->incoming_frame_size); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("data", transport_parsing, stream_parsing, incoming_window, -(gpr_int64) transport_parsing->incoming_frame_size); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("data", transport_parsing, stream_parsing, incoming_window_delta, transport_parsing->incoming_frame_size); transport_parsing->incoming_window -= transport_parsing->incoming_frame_size; - transport_parsing->incoming_window_delta += - transport_parsing->incoming_frame_size; + transport_parsing->incoming_window_delta += transport_parsing->incoming_frame_size; stream_parsing->incoming_window -= transport_parsing->incoming_frame_size; - stream_parsing->incoming_window_delta += - transport_parsing->incoming_frame_size; - grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, stream_parsing); + stream_parsing->incoming_window_delta += transport_parsing->incoming_frame_size; + grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing); return GRPC_CHTTP2_PARSE_OK; } -static int init_data_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing) { - grpc_chttp2_stream_parsing *stream_parsing = - grpc_chttp2_parsing_lookup_stream(transport_parsing, - transport_parsing->incoming_stream_id); +static int +init_data_frame_parser (grpc_chttp2_transport_parsing * transport_parsing) +{ + grpc_chttp2_stream_parsing *stream_parsing = grpc_chttp2_parsing_lookup_stream (transport_parsing, + transport_parsing->incoming_stream_id); grpc_chttp2_parse_error err = GRPC_CHTTP2_PARSE_OK; if (!stream_parsing || stream_parsing->received_close) - return init_skip_frame_parser(transport_parsing, 0); - if (err == GRPC_CHTTP2_PARSE_OK) { - err = update_incoming_window(transport_parsing, stream_parsing); - } - if (err == GRPC_CHTTP2_PARSE_OK) { - err = grpc_chttp2_data_parser_begin_frame( - &stream_parsing->data_parser, transport_parsing->incoming_frame_flags); - } - switch (err) { + return init_skip_frame_parser (transport_parsing, 0); + if (err == GRPC_CHTTP2_PARSE_OK) + { + err = update_incoming_window (transport_parsing, stream_parsing); + } + if (err == GRPC_CHTTP2_PARSE_OK) + { + err = grpc_chttp2_data_parser_begin_frame (&stream_parsing->data_parser, transport_parsing->incoming_frame_flags); + } + switch (err) + { case GRPC_CHTTP2_PARSE_OK: transport_parsing->incoming_stream = stream_parsing; transport_parsing->parser = grpc_chttp2_data_parser_parse; @@ -571,215 +534,214 @@ static int init_data_frame_parser( stream_parsing->received_close = 1; stream_parsing->saw_rst_stream = 1; stream_parsing->rst_stream_reason = GRPC_CHTTP2_PROTOCOL_ERROR; - gpr_slice_buffer_add( - &transport_parsing->qbuf, - grpc_chttp2_rst_stream_create(transport_parsing->incoming_stream_id, - GRPC_CHTTP2_PROTOCOL_ERROR)); - return init_skip_frame_parser(transport_parsing, 0); + gpr_slice_buffer_add (&transport_parsing->qbuf, grpc_chttp2_rst_stream_create (transport_parsing->incoming_stream_id, GRPC_CHTTP2_PROTOCOL_ERROR)); + return init_skip_frame_parser (transport_parsing, 0); case GRPC_CHTTP2_CONNECTION_ERROR: return 0; - } - gpr_log(GPR_ERROR, "should never reach here"); - abort(); + } + gpr_log (GPR_ERROR, "should never reach here"); + abort (); return 0; } -static void free_timeout(void *p) { gpr_free(p); } +static void +free_timeout (void *p) +{ + gpr_free (p); +} -static void on_header(void *tp, grpc_mdelem *md) { +static void +on_header (void *tp, grpc_mdelem * md) +{ grpc_chttp2_transport_parsing *transport_parsing = tp; - grpc_chttp2_stream_parsing *stream_parsing = - transport_parsing->incoming_stream; - - GPR_ASSERT(stream_parsing); - - GRPC_CHTTP2_IF_TRACING(gpr_log( - GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", stream_parsing->id, - transport_parsing->is_client ? "CLI" : "SVR", - grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value))); - - if (md->key == transport_parsing->str_grpc_timeout) { - gpr_timespec *cached_timeout = grpc_mdelem_get_user_data(md, free_timeout); - if (!cached_timeout) { - /* not already parsed: parse it now, and store the result away */ - cached_timeout = gpr_malloc(sizeof(gpr_timespec)); - if (!grpc_chttp2_decode_timeout(grpc_mdstr_as_c_string(md->value), - cached_timeout)) { - gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", - grpc_mdstr_as_c_string(md->value)); - *cached_timeout = gpr_inf_future(GPR_CLOCK_REALTIME); - } - grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); - } - grpc_chttp2_incoming_metadata_buffer_set_deadline( - &stream_parsing->incoming_metadata, - gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), *cached_timeout)); - GRPC_MDELEM_UNREF(md); - } else { - grpc_chttp2_incoming_metadata_buffer_add(&stream_parsing->incoming_metadata, - md); - } - - grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, stream_parsing); + grpc_chttp2_stream_parsing *stream_parsing = transport_parsing->incoming_stream; + + GPR_ASSERT (stream_parsing); + + GRPC_CHTTP2_IF_TRACING (gpr_log (GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", stream_parsing->id, transport_parsing->is_client ? "CLI" : "SVR", grpc_mdstr_as_c_string (md->key), grpc_mdstr_as_c_string (md->value))); + + if (md->key == transport_parsing->str_grpc_timeout) + { + gpr_timespec *cached_timeout = grpc_mdelem_get_user_data (md, free_timeout); + if (!cached_timeout) + { + /* not already parsed: parse it now, and store the result away */ + cached_timeout = gpr_malloc (sizeof (gpr_timespec)); + if (!grpc_chttp2_decode_timeout (grpc_mdstr_as_c_string (md->value), cached_timeout)) + { + gpr_log (GPR_ERROR, "Ignoring bad timeout value '%s'", grpc_mdstr_as_c_string (md->value)); + *cached_timeout = gpr_inf_future (GPR_CLOCK_REALTIME); + } + grpc_mdelem_set_user_data (md, free_timeout, cached_timeout); + } + grpc_chttp2_incoming_metadata_buffer_set_deadline (&stream_parsing->incoming_metadata, gpr_time_add (gpr_now (GPR_CLOCK_MONOTONIC), *cached_timeout)); + GRPC_MDELEM_UNREF (md); + } + else + { + grpc_chttp2_incoming_metadata_buffer_add (&stream_parsing->incoming_metadata, md); + } + + grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing); } -static int init_header_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing, int is_continuation) { - gpr_uint8 is_eoh = (transport_parsing->incoming_frame_flags & - GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; +static int +init_header_frame_parser (grpc_chttp2_transport_parsing * transport_parsing, int is_continuation) +{ + gpr_uint8 is_eoh = (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_DATA_FLAG_END_HEADERS) != 0; int via_accept = 0; grpc_chttp2_stream_parsing *stream_parsing; - if (is_eoh) { - transport_parsing->expect_continuation_stream_id = 0; - } else { - transport_parsing->expect_continuation_stream_id = - transport_parsing->incoming_stream_id; - } + if (is_eoh) + { + transport_parsing->expect_continuation_stream_id = 0; + } + else + { + transport_parsing->expect_continuation_stream_id = transport_parsing->incoming_stream_id; + } - if (!is_continuation) { - transport_parsing->header_eof = (transport_parsing->incoming_frame_flags & - GRPC_CHTTP2_DATA_FLAG_END_STREAM) != 0; - } + if (!is_continuation) + { + transport_parsing->header_eof = (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_DATA_FLAG_END_STREAM) != 0; + } /* could be a new grpc_chttp2_stream or an existing grpc_chttp2_stream */ - stream_parsing = grpc_chttp2_parsing_lookup_stream( - transport_parsing, transport_parsing->incoming_stream_id); - if (stream_parsing == NULL) { - if (is_continuation) { - gpr_log(GPR_ERROR, - "grpc_chttp2_stream disbanded before CONTINUATION received"); - return init_skip_frame_parser(transport_parsing, 1); - } - if (transport_parsing->is_client) { - if ((transport_parsing->incoming_stream_id & 1) && - transport_parsing->incoming_stream_id < - transport_parsing->next_stream_id) { - /* this is an old (probably cancelled) grpc_chttp2_stream */ - } else { - gpr_log(GPR_ERROR, - "ignoring new grpc_chttp2_stream creation on client"); - } - return init_skip_frame_parser(transport_parsing, 1); - } else if (transport_parsing->last_incoming_stream_id > - transport_parsing->incoming_stream_id) { - gpr_log(GPR_ERROR, - "ignoring out of order new grpc_chttp2_stream request on server; " - "last grpc_chttp2_stream " - "id=%d, new grpc_chttp2_stream id=%d", - transport_parsing->last_incoming_stream_id, - transport_parsing->incoming_stream_id); - return init_skip_frame_parser(transport_parsing, 1); - } else if ((transport_parsing->incoming_stream_id & 1) == 0) { - gpr_log(GPR_ERROR, - "ignoring grpc_chttp2_stream with non-client generated index %d", - transport_parsing->incoming_stream_id); - return init_skip_frame_parser(transport_parsing, 1); - } - stream_parsing = transport_parsing->incoming_stream = - grpc_chttp2_parsing_accept_stream( - transport_parsing, transport_parsing->incoming_stream_id); - if (stream_parsing == NULL) { - gpr_log(GPR_ERROR, "grpc_chttp2_stream not accepted"); - return init_skip_frame_parser(transport_parsing, 1); - } - via_accept = 1; - } else { - transport_parsing->incoming_stream = stream_parsing; - } - GPR_ASSERT(stream_parsing != NULL && (via_accept == 0 || via_accept == 1)); - if (stream_parsing->received_close) { - gpr_log(GPR_ERROR, "skipping already closed grpc_chttp2_stream header"); - transport_parsing->incoming_stream = NULL; - return init_skip_frame_parser(transport_parsing, 1); - } + stream_parsing = grpc_chttp2_parsing_lookup_stream (transport_parsing, transport_parsing->incoming_stream_id); + if (stream_parsing == NULL) + { + if (is_continuation) + { + gpr_log (GPR_ERROR, "grpc_chttp2_stream disbanded before CONTINUATION received"); + return init_skip_frame_parser (transport_parsing, 1); + } + if (transport_parsing->is_client) + { + if ((transport_parsing->incoming_stream_id & 1) && transport_parsing->incoming_stream_id < transport_parsing->next_stream_id) + { + /* this is an old (probably cancelled) grpc_chttp2_stream */ + } + else + { + gpr_log (GPR_ERROR, "ignoring new grpc_chttp2_stream creation on client"); + } + return init_skip_frame_parser (transport_parsing, 1); + } + else if (transport_parsing->last_incoming_stream_id > transport_parsing->incoming_stream_id) + { + gpr_log (GPR_ERROR, "ignoring out of order new grpc_chttp2_stream request on server; " "last grpc_chttp2_stream " "id=%d, new grpc_chttp2_stream id=%d", transport_parsing->last_incoming_stream_id, transport_parsing->incoming_stream_id); + return init_skip_frame_parser (transport_parsing, 1); + } + else if ((transport_parsing->incoming_stream_id & 1) == 0) + { + gpr_log (GPR_ERROR, "ignoring grpc_chttp2_stream with non-client generated index %d", transport_parsing->incoming_stream_id); + return init_skip_frame_parser (transport_parsing, 1); + } + stream_parsing = transport_parsing->incoming_stream = grpc_chttp2_parsing_accept_stream (transport_parsing, transport_parsing->incoming_stream_id); + if (stream_parsing == NULL) + { + gpr_log (GPR_ERROR, "grpc_chttp2_stream not accepted"); + return init_skip_frame_parser (transport_parsing, 1); + } + via_accept = 1; + } + else + { + transport_parsing->incoming_stream = stream_parsing; + } + GPR_ASSERT (stream_parsing != NULL && (via_accept == 0 || via_accept == 1)); + if (stream_parsing->received_close) + { + gpr_log (GPR_ERROR, "skipping already closed grpc_chttp2_stream header"); + transport_parsing->incoming_stream = NULL; + return init_skip_frame_parser (transport_parsing, 1); + } transport_parsing->parser = grpc_chttp2_header_parser_parse; transport_parsing->parser_data = &transport_parsing->hpack_parser; transport_parsing->hpack_parser.on_header = on_header; transport_parsing->hpack_parser.on_header_user_data = transport_parsing; transport_parsing->hpack_parser.is_boundary = is_eoh; - transport_parsing->hpack_parser.is_eof = - (gpr_uint8)(is_eoh ? transport_parsing->header_eof : 0); - if (!is_continuation && (transport_parsing->incoming_frame_flags & - GRPC_CHTTP2_FLAG_HAS_PRIORITY)) { - grpc_chttp2_hpack_parser_set_has_priority(&transport_parsing->hpack_parser); - } + transport_parsing->hpack_parser.is_eof = (gpr_uint8) (is_eoh ? transport_parsing->header_eof : 0); + if (!is_continuation && (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_HAS_PRIORITY)) + { + grpc_chttp2_hpack_parser_set_has_priority (&transport_parsing->hpack_parser); + } return 1; } -static int init_window_update_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing) { - int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_window_update_parser_begin_frame( - &transport_parsing->simple.window_update, - transport_parsing->incoming_frame_size, - transport_parsing->incoming_frame_flags); - if (transport_parsing->incoming_stream_id) { - transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream( - transport_parsing, transport_parsing->incoming_stream_id); - } +static int +init_window_update_frame_parser (grpc_chttp2_transport_parsing * transport_parsing) +{ + int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_window_update_parser_begin_frame (&transport_parsing->simple.window_update, + transport_parsing->incoming_frame_size, + transport_parsing->incoming_frame_flags); + if (transport_parsing->incoming_stream_id) + { + transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream (transport_parsing, transport_parsing->incoming_stream_id); + } transport_parsing->parser = grpc_chttp2_window_update_parser_parse; transport_parsing->parser_data = &transport_parsing->simple.window_update; return ok; } -static int init_ping_parser(grpc_chttp2_transport_parsing *transport_parsing) { - int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_ping_parser_begin_frame( - &transport_parsing->simple.ping, - transport_parsing->incoming_frame_size, - transport_parsing->incoming_frame_flags); +static int +init_ping_parser (grpc_chttp2_transport_parsing * transport_parsing) +{ + int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_ping_parser_begin_frame (&transport_parsing->simple.ping, + transport_parsing->incoming_frame_size, + transport_parsing->incoming_frame_flags); transport_parsing->parser = grpc_chttp2_ping_parser_parse; transport_parsing->parser_data = &transport_parsing->simple.ping; return ok; } -static int init_rst_stream_parser( - grpc_chttp2_transport_parsing *transport_parsing) { - int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_rst_stream_parser_begin_frame( - &transport_parsing->simple.rst_stream, - transport_parsing->incoming_frame_size, - transport_parsing->incoming_frame_flags); - transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream( - transport_parsing, transport_parsing->incoming_stream_id); - if (!transport_parsing->incoming_stream) { - return init_skip_frame_parser(transport_parsing, 0); - } +static int +init_rst_stream_parser (grpc_chttp2_transport_parsing * transport_parsing) +{ + int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_rst_stream_parser_begin_frame (&transport_parsing->simple.rst_stream, + transport_parsing->incoming_frame_size, + transport_parsing->incoming_frame_flags); + transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream (transport_parsing, transport_parsing->incoming_stream_id); + if (!transport_parsing->incoming_stream) + { + return init_skip_frame_parser (transport_parsing, 0); + } transport_parsing->parser = grpc_chttp2_rst_stream_parser_parse; transport_parsing->parser_data = &transport_parsing->simple.rst_stream; return ok; } -static int init_goaway_parser( - grpc_chttp2_transport_parsing *transport_parsing) { - int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_goaway_parser_begin_frame( - &transport_parsing->goaway_parser, - transport_parsing->incoming_frame_size, - transport_parsing->incoming_frame_flags); +static int +init_goaway_parser (grpc_chttp2_transport_parsing * transport_parsing) +{ + int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_goaway_parser_begin_frame (&transport_parsing->goaway_parser, + transport_parsing->incoming_frame_size, + transport_parsing->incoming_frame_flags); transport_parsing->parser = grpc_chttp2_goaway_parser_parse; transport_parsing->parser_data = &transport_parsing->goaway_parser; return ok; } -static int init_settings_frame_parser( - grpc_chttp2_transport_parsing *transport_parsing) { +static int +init_settings_frame_parser (grpc_chttp2_transport_parsing * transport_parsing) +{ int ok; - if (transport_parsing->incoming_stream_id != 0) { - gpr_log(GPR_ERROR, "settings frame received for grpc_chttp2_stream %d", - transport_parsing->incoming_stream_id); - return 0; - } - - ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_settings_parser_begin_frame( - &transport_parsing->simple.settings, - transport_parsing->incoming_frame_size, - transport_parsing->incoming_frame_flags, - transport_parsing->settings); - if (!ok) { - return 0; - } - if (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_ACK) { - transport_parsing->settings_ack_received = 1; - } + if (transport_parsing->incoming_stream_id != 0) + { + gpr_log (GPR_ERROR, "settings frame received for grpc_chttp2_stream %d", transport_parsing->incoming_stream_id); + return 0; + } + + ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_settings_parser_begin_frame (&transport_parsing->simple.settings, transport_parsing->incoming_frame_size, transport_parsing->incoming_frame_flags, transport_parsing->settings); + if (!ok) + { + return 0; + } + if (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_ACK) + { + transport_parsing->settings_ack_received = 1; + } transport_parsing->parser = grpc_chttp2_settings_parser_parse; transport_parsing->parser_data = &transport_parsing->simple.settings; return ok; @@ -791,35 +753,31 @@ static int is_window_update_legal(gpr_int64 window_update, gpr_int64 window) { } */ -static int parse_frame_slice(grpc_chttp2_transport_parsing *transport_parsing, - gpr_slice slice, int is_last, - grpc_closure_list *closure_list) { - grpc_chttp2_stream_parsing *stream_parsing = - transport_parsing->incoming_stream; - switch (transport_parsing->parser(transport_parsing->parser_data, - transport_parsing, stream_parsing, slice, - is_last, closure_list)) { +static int +parse_frame_slice (grpc_chttp2_transport_parsing * transport_parsing, gpr_slice slice, int is_last, grpc_closure_list * closure_list) +{ + grpc_chttp2_stream_parsing *stream_parsing = transport_parsing->incoming_stream; + switch (transport_parsing->parser (transport_parsing->parser_data, transport_parsing, stream_parsing, slice, is_last, closure_list)) + { case GRPC_CHTTP2_PARSE_OK: - if (stream_parsing) { - grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, - stream_parsing); - } + if (stream_parsing) + { + grpc_chttp2_list_add_parsing_seen_stream (transport_parsing, stream_parsing); + } return 1; case GRPC_CHTTP2_STREAM_ERROR: - grpc_chttp2_parsing_become_skip_parser(transport_parsing); - if (stream_parsing) { - stream_parsing->saw_rst_stream = 1; - stream_parsing->rst_stream_reason = GRPC_CHTTP2_PROTOCOL_ERROR; - gpr_slice_buffer_add( - &transport_parsing->qbuf, - grpc_chttp2_rst_stream_create(transport_parsing->incoming_stream_id, - GRPC_CHTTP2_PROTOCOL_ERROR)); - } + grpc_chttp2_parsing_become_skip_parser (transport_parsing); + if (stream_parsing) + { + stream_parsing->saw_rst_stream = 1; + stream_parsing->rst_stream_reason = GRPC_CHTTP2_PROTOCOL_ERROR; + gpr_slice_buffer_add (&transport_parsing->qbuf, grpc_chttp2_rst_stream_create (transport_parsing->incoming_stream_id, GRPC_CHTTP2_PROTOCOL_ERROR)); + } return 1; case GRPC_CHTTP2_CONNECTION_ERROR: return 0; - } - gpr_log(GPR_ERROR, "should never reach here"); - abort(); + } + gpr_log (GPR_ERROR, "should never reach here"); + abort (); return 0; } diff --git a/src/core/transport/chttp2/status_conversion.c b/src/core/transport/chttp2/status_conversion.c index bf214b017a..8be4dc6150 100644 --- a/src/core/transport/chttp2/status_conversion.c +++ b/src/core/transport/chttp2/status_conversion.c @@ -33,8 +33,11 @@ #include "src/core/transport/chttp2/status_conversion.h" -int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) { - switch (status) { +int +grpc_chttp2_grpc_status_to_http2_error (grpc_status_code status) +{ + switch (status) + { case GRPC_STATUS_OK: return GRPC_CHTTP2_NO_ERROR; case GRPC_STATUS_CANCELLED: @@ -47,12 +50,14 @@ int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) { return GRPC_CHTTP2_REFUSED_STREAM; default: return GRPC_CHTTP2_INTERNAL_ERROR; - } + } } -grpc_status_code grpc_chttp2_http2_error_to_grpc_status( - grpc_chttp2_error_code error) { - switch (error) { +grpc_status_code +grpc_chttp2_http2_error_to_grpc_status (grpc_chttp2_error_code error) +{ + switch (error) + { case GRPC_CHTTP2_NO_ERROR: /* should never be received */ return GRPC_STATUS_INTERNAL; @@ -66,12 +71,15 @@ grpc_status_code grpc_chttp2_http2_error_to_grpc_status( return GRPC_STATUS_UNAVAILABLE; default: return GRPC_STATUS_INTERNAL; - } + } } -grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) { - switch (status) { - /* these HTTP2 status codes are called out explicitly in status.proto */ +grpc_status_code +grpc_chttp2_http2_status_to_grpc_status (int status) +{ + switch (status) + { + /* these HTTP2 status codes are called out explicitly in status.proto */ case 200: return GRPC_STATUS_OK; case 400: @@ -98,12 +106,14 @@ grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) { return GRPC_STATUS_UNAVAILABLE; case 504: return GRPC_STATUS_DEADLINE_EXCEEDED; - /* everything else is unknown */ + /* everything else is unknown */ default: return GRPC_STATUS_UNKNOWN; - } + } } -int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status) { +int +grpc_chttp2_grpc_status_to_http2_status (grpc_status_code status) +{ return 200; } diff --git a/src/core/transport/chttp2/status_conversion.h b/src/core/transport/chttp2/status_conversion.h index 0ec5b560b8..ae5b4960df 100644 --- a/src/core/transport/chttp2/status_conversion.h +++ b/src/core/transport/chttp2/status_conversion.h @@ -38,13 +38,11 @@ #include "src/core/transport/chttp2/http2_errors.h" /* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */ -grpc_chttp2_error_code grpc_chttp2_grpc_status_to_http2_error( - grpc_status_code status); -grpc_status_code grpc_chttp2_http2_error_to_grpc_status( - grpc_chttp2_error_code error); +grpc_chttp2_error_code grpc_chttp2_grpc_status_to_http2_error (grpc_status_code status); +grpc_status_code grpc_chttp2_http2_error_to_grpc_status (grpc_chttp2_error_code error); /* Conversion of HTTP status codes (:status) to grpc status codes */ -grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status); -int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status); +grpc_status_code grpc_chttp2_http2_status_to_grpc_status (int status); +int grpc_chttp2_grpc_status_to_http2_status (grpc_status_code status); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STATUS_CONVERSION_H */ diff --git a/src/core/transport/chttp2/stream_encoder.c b/src/core/transport/chttp2/stream_encoder.c index eb02ccdec3..cafd735ba2 100644 --- a/src/core/transport/chttp2/stream_encoder.c +++ b/src/core/transport/chttp2/stream_encoder.c @@ -55,9 +55,11 @@ #define MAX_DECODER_SPACE_USAGE 512 /* what kind of frame our we encoding? */ -typedef enum { HEADER, DATA, NONE } frame_type; +typedef enum +{ HEADER, DATA, NONE } frame_type; -typedef struct { +typedef struct +{ frame_type cur_frame_type; /* number of bytes in 'output' when we started the frame - used to calculate frame length */ @@ -74,28 +76,30 @@ typedef struct { } framer_state; /* fills p (which is expected to be 9 bytes long) with a data frame header */ -static void fill_header(gpr_uint8 *p, gpr_uint8 type, gpr_uint32 id, size_t len, - gpr_uint8 flags) { - GPR_ASSERT(len < 16777316); - *p++ = (gpr_uint8)(len >> 16); - *p++ = (gpr_uint8)(len >> 8); - *p++ = (gpr_uint8)(len); +static void +fill_header (gpr_uint8 * p, gpr_uint8 type, gpr_uint32 id, size_t len, gpr_uint8 flags) +{ + GPR_ASSERT (len < 16777316); + *p++ = (gpr_uint8) (len >> 16); + *p++ = (gpr_uint8) (len >> 8); + *p++ = (gpr_uint8) (len); *p++ = type; *p++ = flags; - *p++ = (gpr_uint8)(id >> 24); - *p++ = (gpr_uint8)(id >> 16); - *p++ = (gpr_uint8)(id >> 8); - *p++ = (gpr_uint8)(id); + *p++ = (gpr_uint8) (id >> 24); + *p++ = (gpr_uint8) (id >> 16); + *p++ = (gpr_uint8) (id >> 8); + *p++ = (gpr_uint8) (id); } /* finish a frame - fill in the previously reserved header */ -static void finish_frame(framer_state *st, int is_header_boundary, - int is_last_in_stream) { +static void +finish_frame (framer_state * st, int is_header_boundary, int is_last_in_stream) +{ gpr_uint8 type = 0xff; - switch (st->cur_frame_type) { + switch (st->cur_frame_type) + { case HEADER: - type = st->last_was_header ? GRPC_CHTTP2_FRAME_CONTINUATION - : GRPC_CHTTP2_FRAME_HEADER; + type = st->last_was_header ? GRPC_CHTTP2_FRAME_CONTINUATION : GRPC_CHTTP2_FRAME_HEADER; st->last_was_header = 1; break; case DATA: @@ -105,397 +109,435 @@ static void finish_frame(framer_state *st, int is_header_boundary, break; case NONE: return; - } - fill_header( - GPR_SLICE_START_PTR(st->output->slices[st->header_idx]), type, - st->stream_id, st->output->length - st->output_length_at_start_of_frame, - (gpr_uint8)( - (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | - (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0))); + } + fill_header (GPR_SLICE_START_PTR (st->output->slices[st->header_idx]), type, st->stream_id, st->output->length - st->output_length_at_start_of_frame, (gpr_uint8) ((is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) | (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0))); st->cur_frame_type = NONE; } /* begin a new frame: reserve off header space, remember how many bytes we'd output before beginning */ -static void begin_frame(framer_state *st, frame_type type) { - GPR_ASSERT(type != NONE); - GPR_ASSERT(st->cur_frame_type == NONE); +static void +begin_frame (framer_state * st, frame_type type) +{ + GPR_ASSERT (type != NONE); + GPR_ASSERT (st->cur_frame_type == NONE); st->cur_frame_type = type; - st->header_idx = - gpr_slice_buffer_add_indexed(st->output, gpr_slice_malloc(9)); + st->header_idx = gpr_slice_buffer_add_indexed (st->output, gpr_slice_malloc (9)); st->output_length_at_start_of_frame = st->output->length; } -static void begin_new_frame(framer_state *st, frame_type type) { - finish_frame(st, 1, 0); +static void +begin_new_frame (framer_state * st, frame_type type) +{ + finish_frame (st, 1, 0); st->last_was_header = 0; - begin_frame(st, type); + begin_frame (st, type); } /* make sure that the current frame is of the type desired, and has sufficient space to add at least about_to_add bytes -- finishes the current frame if needed */ -static void ensure_frame_type(framer_state *st, frame_type type, - size_t need_bytes) { - if (st->cur_frame_type == type && - st->output->length - st->output_length_at_start_of_frame + need_bytes <= - GRPC_CHTTP2_MAX_PAYLOAD_LENGTH) { - return; - } - finish_frame(st, type != HEADER, 0); - begin_frame(st, type); +static void +ensure_frame_type (framer_state * st, frame_type type, size_t need_bytes) +{ + if (st->cur_frame_type == type && st->output->length - st->output_length_at_start_of_frame + need_bytes <= GRPC_CHTTP2_MAX_PAYLOAD_LENGTH) + { + return; + } + finish_frame (st, type != HEADER, 0); + begin_frame (st, type); } /* increment a filter count, halve all counts if one element reaches max */ -static void inc_filter(gpr_uint8 idx, gpr_uint32 *sum, gpr_uint8 *elems) { +static void +inc_filter (gpr_uint8 idx, gpr_uint32 * sum, gpr_uint8 * elems) +{ elems[idx]++; - if (elems[idx] < 255) { - (*sum)++; - } else { - int i; - *sum = 0; - for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_FILTERS; i++) { - elems[i] /= 2; - (*sum) += elems[i]; - } - } + if (elems[idx] < 255) + { + (*sum)++; + } + else + { + int i; + *sum = 0; + for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_FILTERS; i++) + { + elems[i] /= 2; + (*sum) += elems[i]; + } + } } -static void add_header_data(framer_state *st, gpr_slice slice) { - size_t len = GPR_SLICE_LENGTH(slice); +static void +add_header_data (framer_state * st, gpr_slice slice) +{ + size_t len = GPR_SLICE_LENGTH (slice); size_t remaining; - if (len == 0) return; - ensure_frame_type(st, HEADER, 1); - remaining = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH + - st->output_length_at_start_of_frame - st->output->length; - if (len <= remaining) { - gpr_slice_buffer_add(st->output, slice); - } else { - gpr_slice_buffer_add(st->output, gpr_slice_split_head(&slice, remaining)); - add_header_data(st, slice); - } + if (len == 0) + return; + ensure_frame_type (st, HEADER, 1); + remaining = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH + st->output_length_at_start_of_frame - st->output->length; + if (len <= remaining) + { + gpr_slice_buffer_add (st->output, slice); + } + else + { + gpr_slice_buffer_add (st->output, gpr_slice_split_head (&slice, remaining)); + add_header_data (st, slice); + } } -static gpr_uint8 *add_tiny_header_data(framer_state *st, size_t len) { - ensure_frame_type(st, HEADER, len); - return gpr_slice_buffer_tiny_add(st->output, len); +static gpr_uint8 * +add_tiny_header_data (framer_state * st, size_t len) +{ + ensure_frame_type (st, HEADER, len); + return gpr_slice_buffer_tiny_add (st->output, len); } /* add an element to the decoder table: returns metadata element to unref */ -static grpc_mdelem *add_elem(grpc_chttp2_hpack_compressor *c, - grpc_mdelem *elem) { +static grpc_mdelem * +add_elem (grpc_chttp2_hpack_compressor * c, grpc_mdelem * elem) +{ gpr_uint32 key_hash = elem->key->hash; - gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); + gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH (key_hash, elem->value->hash); gpr_uint32 new_index = c->tail_remote_index + c->table_elems + 1; - size_t elem_size = 32 + GPR_SLICE_LENGTH(elem->key->slice) + - GPR_SLICE_LENGTH(elem->value->slice); + size_t elem_size = 32 + GPR_SLICE_LENGTH (elem->key->slice) + GPR_SLICE_LENGTH (elem->value->slice); grpc_mdelem *elem_to_unref; - GPR_ASSERT(elem_size < 65536); + GPR_ASSERT (elem_size < 65536); /* Reserve space for this element in the remote table: if this overflows the current table, drop elements until it fits, matching the decompressor algorithm */ /* TODO(ctiller): constant */ - while (c->table_size + elem_size > 4096) { - c->tail_remote_index++; - GPR_ASSERT(c->tail_remote_index > 0); - GPR_ASSERT(c->table_size >= - c->table_elem_size[c->tail_remote_index % - GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); - GPR_ASSERT(c->table_elems > 0); - c->table_size = - (gpr_uint16)(c->table_size - - c->table_elem_size[c->tail_remote_index % - GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); - c->table_elems--; - } - GPR_ASSERT(c->table_elems < GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS); - c->table_elem_size[new_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS] = - (gpr_uint16)elem_size; - c->table_size = (gpr_uint16)(c->table_size + elem_size); + while (c->table_size + elem_size > 4096) + { + c->tail_remote_index++; + GPR_ASSERT (c->tail_remote_index > 0); + GPR_ASSERT (c->table_size >= c->table_elem_size[c->tail_remote_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); + GPR_ASSERT (c->table_elems > 0); + c->table_size = (gpr_uint16) (c->table_size - c->table_elem_size[c->tail_remote_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]); + c->table_elems--; + } + GPR_ASSERT (c->table_elems < GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS); + c->table_elem_size[new_index % GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS] = (gpr_uint16) elem_size; + c->table_size = (gpr_uint16) (c->table_size + elem_size); c->table_elems++; /* Store this element into {entries,indices}_elem */ - if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == elem) { - /* already there: update with new index */ - c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index; - elem_to_unref = elem; - } else if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == elem) { - /* already there (cuckoo): update with new index */ - c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index; - elem_to_unref = elem; - } else if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == NULL) { - /* not there, but a free element: add */ - c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = elem; - c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index; - elem_to_unref = NULL; - } else if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == NULL) { - /* not there (cuckoo), but a free element: add */ - c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = elem; - c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index; - elem_to_unref = NULL; - } else if (c->indices_elems[HASH_FRAGMENT_2(elem_hash)] < - c->indices_elems[HASH_FRAGMENT_3(elem_hash)]) { - /* not there: replace oldest */ - elem_to_unref = c->entries_elems[HASH_FRAGMENT_2(elem_hash)]; - c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = elem; - c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index; - } else { - /* not there: replace oldest */ - elem_to_unref = c->entries_elems[HASH_FRAGMENT_3(elem_hash)]; - c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = elem; - c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index; - } + if (c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] == elem) + { + /* already there: update with new index */ + c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] = new_index; + elem_to_unref = elem; + } + else if (c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] == elem) + { + /* already there (cuckoo): update with new index */ + c->indices_elems[HASH_FRAGMENT_3 (elem_hash)] = new_index; + elem_to_unref = elem; + } + else if (c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] == NULL) + { + /* not there, but a free element: add */ + c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] = elem; + c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] = new_index; + elem_to_unref = NULL; + } + else if (c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] == NULL) + { + /* not there (cuckoo), but a free element: add */ + c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] = elem; + c->indices_elems[HASH_FRAGMENT_3 (elem_hash)] = new_index; + elem_to_unref = NULL; + } + else if (c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] < c->indices_elems[HASH_FRAGMENT_3 (elem_hash)]) + { + /* not there: replace oldest */ + elem_to_unref = c->entries_elems[HASH_FRAGMENT_2 (elem_hash)]; + c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] = elem; + c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] = new_index; + } + else + { + /* not there: replace oldest */ + elem_to_unref = c->entries_elems[HASH_FRAGMENT_3 (elem_hash)]; + c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] = elem; + c->indices_elems[HASH_FRAGMENT_3 (elem_hash)] = new_index; + } /* do exactly the same for the key (so we can find by that again too) */ - if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == elem->key) { - c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; - } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == elem->key) { - c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; - } else if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == NULL) { - c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key); - c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; - } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == NULL) { - c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key); - c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; - } else if (c->indices_keys[HASH_FRAGMENT_2(key_hash)] < - c->indices_keys[HASH_FRAGMENT_3(key_hash)]) { - GRPC_MDSTR_UNREF(c->entries_keys[HASH_FRAGMENT_2(key_hash)]); - c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key); - c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; - } else { - GRPC_MDSTR_UNREF(c->entries_keys[HASH_FRAGMENT_3(key_hash)]); - c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key); - c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; - } + if (c->entries_keys[HASH_FRAGMENT_2 (key_hash)] == elem->key) + { + c->indices_keys[HASH_FRAGMENT_2 (key_hash)] = new_index; + } + else if (c->entries_keys[HASH_FRAGMENT_3 (key_hash)] == elem->key) + { + c->indices_keys[HASH_FRAGMENT_3 (key_hash)] = new_index; + } + else if (c->entries_keys[HASH_FRAGMENT_2 (key_hash)] == NULL) + { + c->entries_keys[HASH_FRAGMENT_2 (key_hash)] = GRPC_MDSTR_REF (elem->key); + c->indices_keys[HASH_FRAGMENT_2 (key_hash)] = new_index; + } + else if (c->entries_keys[HASH_FRAGMENT_3 (key_hash)] == NULL) + { + c->entries_keys[HASH_FRAGMENT_3 (key_hash)] = GRPC_MDSTR_REF (elem->key); + c->indices_keys[HASH_FRAGMENT_3 (key_hash)] = new_index; + } + else if (c->indices_keys[HASH_FRAGMENT_2 (key_hash)] < c->indices_keys[HASH_FRAGMENT_3 (key_hash)]) + { + GRPC_MDSTR_UNREF (c->entries_keys[HASH_FRAGMENT_2 (key_hash)]); + c->entries_keys[HASH_FRAGMENT_2 (key_hash)] = GRPC_MDSTR_REF (elem->key); + c->indices_keys[HASH_FRAGMENT_2 (key_hash)] = new_index; + } + else + { + GRPC_MDSTR_UNREF (c->entries_keys[HASH_FRAGMENT_3 (key_hash)]); + c->entries_keys[HASH_FRAGMENT_3 (key_hash)] = GRPC_MDSTR_REF (elem->key); + c->indices_keys[HASH_FRAGMENT_3 (key_hash)] = new_index; + } return elem_to_unref; } -static void emit_indexed(grpc_chttp2_hpack_compressor *c, gpr_uint32 index, - framer_state *st) { - gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH(index, 1); - GRPC_CHTTP2_WRITE_VARINT(index, 1, 0x80, add_tiny_header_data(st, len), len); +static void +emit_indexed (grpc_chttp2_hpack_compressor * c, gpr_uint32 index, framer_state * st) +{ + gpr_uint32 len = GRPC_CHTTP2_VARINT_LENGTH (index, 1); + GRPC_CHTTP2_WRITE_VARINT (index, 1, 0x80, add_tiny_header_data (st, len), len); } -static gpr_slice get_wire_value(grpc_mdelem *elem, gpr_uint8 *huffman_prefix) { - if (grpc_is_binary_header((const char *)GPR_SLICE_START_PTR(elem->key->slice), - GPR_SLICE_LENGTH(elem->key->slice))) { - *huffman_prefix = 0x80; - return grpc_mdstr_as_base64_encoded_and_huffman_compressed(elem->value); - } +static gpr_slice +get_wire_value (grpc_mdelem * elem, gpr_uint8 * huffman_prefix) +{ + if (grpc_is_binary_header ((const char *) GPR_SLICE_START_PTR (elem->key->slice), GPR_SLICE_LENGTH (elem->key->slice))) + { + *huffman_prefix = 0x80; + return grpc_mdstr_as_base64_encoded_and_huffman_compressed (elem->value); + } /* TODO(ctiller): opportunistically compress non-binary headers */ *huffman_prefix = 0x00; return elem->value->slice; } -static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, - gpr_uint32 key_index, grpc_mdelem *elem, - framer_state *st) { - gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); +static void +emit_lithdr_incidx (grpc_chttp2_hpack_compressor * c, gpr_uint32 key_index, grpc_mdelem * elem, framer_state * st) +{ + gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH (key_index, 2); gpr_uint8 huffman_prefix; - gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - size_t len_val = GPR_SLICE_LENGTH(value_slice); + gpr_slice value_slice = get_wire_value (elem, &huffman_prefix); + size_t len_val = GPR_SLICE_LENGTH (value_slice); gpr_uint32 len_val_len; - GPR_ASSERT(len_val <= GPR_UINT32_MAX); - len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1); - GRPC_CHTTP2_WRITE_VARINT(key_index, 2, 0x40, - add_tiny_header_data(st, len_pfx), len_pfx); - GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00, - add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, gpr_slice_ref(value_slice)); + GPR_ASSERT (len_val <= GPR_UINT32_MAX); + len_val_len = GRPC_CHTTP2_VARINT_LENGTH ((gpr_uint32) len_val, 1); + GRPC_CHTTP2_WRITE_VARINT (key_index, 2, 0x40, add_tiny_header_data (st, len_pfx), len_pfx); + GRPC_CHTTP2_WRITE_VARINT ((gpr_uint32) len_val, 1, 0x00, add_tiny_header_data (st, len_val_len), len_val_len); + add_header_data (st, gpr_slice_ref (value_slice)); } -static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, - gpr_uint32 key_index, grpc_mdelem *elem, - framer_state *st) { - gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); +static void +emit_lithdr_noidx (grpc_chttp2_hpack_compressor * c, gpr_uint32 key_index, grpc_mdelem * elem, framer_state * st) +{ + gpr_uint32 len_pfx = GRPC_CHTTP2_VARINT_LENGTH (key_index, 4); gpr_uint8 huffman_prefix; - gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - size_t len_val = GPR_SLICE_LENGTH(value_slice); + gpr_slice value_slice = get_wire_value (elem, &huffman_prefix); + size_t len_val = GPR_SLICE_LENGTH (value_slice); gpr_uint32 len_val_len; - GPR_ASSERT(len_val <= GPR_UINT32_MAX); - len_val_len = GRPC_CHTTP2_VARINT_LENGTH((gpr_uint32)len_val, 1); - GRPC_CHTTP2_WRITE_VARINT(key_index, 4, 0x00, - add_tiny_header_data(st, len_pfx), len_pfx); - GRPC_CHTTP2_WRITE_VARINT((gpr_uint32)len_val, 1, 0x00, - add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, gpr_slice_ref(value_slice)); + GPR_ASSERT (len_val <= GPR_UINT32_MAX); + len_val_len = GRPC_CHTTP2_VARINT_LENGTH ((gpr_uint32) len_val, 1); + GRPC_CHTTP2_WRITE_VARINT (key_index, 4, 0x00, add_tiny_header_data (st, len_pfx), len_pfx); + GRPC_CHTTP2_WRITE_VARINT ((gpr_uint32) len_val, 1, 0x00, add_tiny_header_data (st, len_val_len), len_val_len); + add_header_data (st, gpr_slice_ref (value_slice)); } -static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, - grpc_mdelem *elem, framer_state *st) { - gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice); +static void +emit_lithdr_incidx_v (grpc_chttp2_hpack_compressor * c, grpc_mdelem * elem, framer_state * st) +{ + gpr_uint32 len_key = (gpr_uint32) GPR_SLICE_LENGTH (elem->key->slice); gpr_uint8 huffman_prefix; - gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice); - gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); - gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); - GPR_ASSERT(len_key <= GPR_UINT32_MAX); - GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX); - *add_tiny_header_data(st, 1) = 0x40; - GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, - add_tiny_header_data(st, len_key_len), len_key_len); - add_header_data(st, gpr_slice_ref(elem->key->slice)); - GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix, - add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, gpr_slice_ref(value_slice)); + gpr_slice value_slice = get_wire_value (elem, &huffman_prefix); + gpr_uint32 len_val = (gpr_uint32) GPR_SLICE_LENGTH (value_slice); + gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH (len_key, 1); + gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH (len_val, 1); + GPR_ASSERT (len_key <= GPR_UINT32_MAX); + GPR_ASSERT (GPR_SLICE_LENGTH (value_slice) <= GPR_UINT32_MAX); + *add_tiny_header_data (st, 1) = 0x40; + GRPC_CHTTP2_WRITE_VARINT (len_key, 1, 0x00, add_tiny_header_data (st, len_key_len), len_key_len); + add_header_data (st, gpr_slice_ref (elem->key->slice)); + GRPC_CHTTP2_WRITE_VARINT (len_val, 1, huffman_prefix, add_tiny_header_data (st, len_val_len), len_val_len); + add_header_data (st, gpr_slice_ref (value_slice)); } -static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, - grpc_mdelem *elem, framer_state *st) { - gpr_uint32 len_key = (gpr_uint32)GPR_SLICE_LENGTH(elem->key->slice); +static void +emit_lithdr_noidx_v (grpc_chttp2_hpack_compressor * c, grpc_mdelem * elem, framer_state * st) +{ + gpr_uint32 len_key = (gpr_uint32) GPR_SLICE_LENGTH (elem->key->slice); gpr_uint8 huffman_prefix; - gpr_slice value_slice = get_wire_value(elem, &huffman_prefix); - gpr_uint32 len_val = (gpr_uint32)GPR_SLICE_LENGTH(value_slice); - gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1); - gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1); - GPR_ASSERT(len_key <= GPR_UINT32_MAX); - GPR_ASSERT(GPR_SLICE_LENGTH(value_slice) <= GPR_UINT32_MAX); - *add_tiny_header_data(st, 1) = 0x00; - GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, - add_tiny_header_data(st, len_key_len), len_key_len); - add_header_data(st, gpr_slice_ref(elem->key->slice)); - GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix, - add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, gpr_slice_ref(value_slice)); + gpr_slice value_slice = get_wire_value (elem, &huffman_prefix); + gpr_uint32 len_val = (gpr_uint32) GPR_SLICE_LENGTH (value_slice); + gpr_uint32 len_key_len = GRPC_CHTTP2_VARINT_LENGTH (len_key, 1); + gpr_uint32 len_val_len = GRPC_CHTTP2_VARINT_LENGTH (len_val, 1); + GPR_ASSERT (len_key <= GPR_UINT32_MAX); + GPR_ASSERT (GPR_SLICE_LENGTH (value_slice) <= GPR_UINT32_MAX); + *add_tiny_header_data (st, 1) = 0x00; + GRPC_CHTTP2_WRITE_VARINT (len_key, 1, 0x00, add_tiny_header_data (st, len_key_len), len_key_len); + add_header_data (st, gpr_slice_ref (elem->key->slice)); + GRPC_CHTTP2_WRITE_VARINT (len_val, 1, huffman_prefix, add_tiny_header_data (st, len_val_len), len_val_len); + add_header_data (st, gpr_slice_ref (value_slice)); } -static gpr_uint32 dynidx(grpc_chttp2_hpack_compressor *c, gpr_uint32 index) { - return 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY + c->tail_remote_index + - c->table_elems - index; +static gpr_uint32 +dynidx (grpc_chttp2_hpack_compressor * c, gpr_uint32 index) +{ + return 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY + c->tail_remote_index + c->table_elems - index; } /* encode an mdelem; returns metadata element to unref */ -static grpc_mdelem *hpack_enc(grpc_chttp2_hpack_compressor *c, - grpc_mdelem *elem, framer_state *st) { +static grpc_mdelem * +hpack_enc (grpc_chttp2_hpack_compressor * c, grpc_mdelem * elem, framer_state * st) +{ gpr_uint32 key_hash = elem->key->hash; - gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); + gpr_uint32 elem_hash = GRPC_MDSTR_KV_HASH (key_hash, elem->value->hash); size_t decoder_space_usage; gpr_uint32 indices_key; int should_add_elem; - GPR_ASSERT(GPR_SLICE_LENGTH(elem->key->slice) > 0); - if (GPR_SLICE_START_PTR(elem->key->slice)[0] != ':') { /* regular header */ - st->seen_regular_header = 1; - } else if (st->seen_regular_header != 0) { /* reserved header */ - gpr_log(GPR_ERROR, - "Reserved header (colon-prefixed) happening after regular ones."); - abort(); - } + GPR_ASSERT (GPR_SLICE_LENGTH (elem->key->slice) > 0); + if (GPR_SLICE_START_PTR (elem->key->slice)[0] != ':') + { /* regular header */ + st->seen_regular_header = 1; + } + else if (st->seen_regular_header != 0) + { /* reserved header */ + gpr_log (GPR_ERROR, "Reserved header (colon-prefixed) happening after regular ones."); + abort (); + } - inc_filter(HASH_FRAGMENT_1(elem_hash), &c->filter_elems_sum, c->filter_elems); + inc_filter (HASH_FRAGMENT_1 (elem_hash), &c->filter_elems_sum, c->filter_elems); /* is this elem currently in the decoders table? */ - if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == elem && - c->indices_elems[HASH_FRAGMENT_2(elem_hash)] > c->tail_remote_index) { - /* HIT: complete element (first cuckoo hash) */ - emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_2(elem_hash)]), - st); - return elem; - } - - if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == elem && - c->indices_elems[HASH_FRAGMENT_3(elem_hash)] > c->tail_remote_index) { - /* HIT: complete element (second cuckoo hash) */ - emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_3(elem_hash)]), - st); - return elem; - } + if (c->entries_elems[HASH_FRAGMENT_2 (elem_hash)] == elem && c->indices_elems[HASH_FRAGMENT_2 (elem_hash)] > c->tail_remote_index) + { + /* HIT: complete element (first cuckoo hash) */ + emit_indexed (c, dynidx (c, c->indices_elems[HASH_FRAGMENT_2 (elem_hash)]), st); + return elem; + } + + if (c->entries_elems[HASH_FRAGMENT_3 (elem_hash)] == elem && c->indices_elems[HASH_FRAGMENT_3 (elem_hash)] > c->tail_remote_index) + { + /* HIT: complete element (second cuckoo hash) */ + emit_indexed (c, dynidx (c, c->indices_elems[HASH_FRAGMENT_3 (elem_hash)]), st); + return elem; + } /* should this elem be in the table? */ - decoder_space_usage = 32 + GPR_SLICE_LENGTH(elem->key->slice) + - GPR_SLICE_LENGTH(elem->value->slice); - should_add_elem = decoder_space_usage < MAX_DECODER_SPACE_USAGE && - c->filter_elems[HASH_FRAGMENT_1(elem_hash)] >= - c->filter_elems_sum / ONE_ON_ADD_PROBABILITY; + decoder_space_usage = 32 + GPR_SLICE_LENGTH (elem->key->slice) + GPR_SLICE_LENGTH (elem->value->slice); + should_add_elem = decoder_space_usage < MAX_DECODER_SPACE_USAGE && c->filter_elems[HASH_FRAGMENT_1 (elem_hash)] >= c->filter_elems_sum / ONE_ON_ADD_PROBABILITY; /* no hits for the elem... maybe there's a key? */ - indices_key = c->indices_keys[HASH_FRAGMENT_2(key_hash)]; - if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == elem->key && - indices_key > c->tail_remote_index) { - /* HIT: key (first cuckoo hash) */ - if (should_add_elem) { - emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st); - return add_elem(c, elem); - } else { - emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st); - return elem; + indices_key = c->indices_keys[HASH_FRAGMENT_2 (key_hash)]; + if (c->entries_keys[HASH_FRAGMENT_2 (key_hash)] == elem->key && indices_key > c->tail_remote_index) + { + /* HIT: key (first cuckoo hash) */ + if (should_add_elem) + { + emit_lithdr_incidx (c, dynidx (c, indices_key), elem, st); + return add_elem (c, elem); + } + else + { + emit_lithdr_noidx (c, dynidx (c, indices_key), elem, st); + return elem; + } + abort (); } - abort(); - } - - indices_key = c->indices_keys[HASH_FRAGMENT_3(key_hash)]; - if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == elem->key && - indices_key > c->tail_remote_index) { - /* HIT: key (first cuckoo hash) */ - if (should_add_elem) { - emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st); - return add_elem(c, elem); - } else { - emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st); - return elem; + + indices_key = c->indices_keys[HASH_FRAGMENT_3 (key_hash)]; + if (c->entries_keys[HASH_FRAGMENT_3 (key_hash)] == elem->key && indices_key > c->tail_remote_index) + { + /* HIT: key (first cuckoo hash) */ + if (should_add_elem) + { + emit_lithdr_incidx (c, dynidx (c, indices_key), elem, st); + return add_elem (c, elem); + } + else + { + emit_lithdr_noidx (c, dynidx (c, indices_key), elem, st); + return elem; + } + abort (); } - abort(); - } /* no elem, key in the table... fall back to literal emission */ - if (should_add_elem) { - emit_lithdr_incidx_v(c, elem, st); - return add_elem(c, elem); - } else { - emit_lithdr_noidx_v(c, elem, st); - return elem; - } - abort(); + if (should_add_elem) + { + emit_lithdr_incidx_v (c, elem, st); + return add_elem (c, elem); + } + else + { + emit_lithdr_noidx_v (c, elem, st); + return elem; + } + abort (); } #define STRLEN_LIT(x) (sizeof(x) - 1) #define TIMEOUT_KEY "grpc-timeout" -static void deadline_enc(grpc_chttp2_hpack_compressor *c, gpr_timespec deadline, - framer_state *st) { +static void +deadline_enc (grpc_chttp2_hpack_compressor * c, gpr_timespec deadline, framer_state * st) +{ char timeout_str[GRPC_CHTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; grpc_mdelem *mdelem; - grpc_chttp2_encode_timeout( - gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str); - mdelem = grpc_mdelem_from_metadata_strings( - c->mdctx, GRPC_MDSTR_REF(c->timeout_key_str), - grpc_mdstr_from_string(c->mdctx, timeout_str, 0)); - mdelem = hpack_enc(c, mdelem, st); - if (mdelem) GRPC_MDELEM_UNREF(mdelem); + grpc_chttp2_encode_timeout (gpr_time_sub (deadline, gpr_now (deadline.clock_type)), timeout_str); + mdelem = grpc_mdelem_from_metadata_strings (c->mdctx, GRPC_MDSTR_REF (c->timeout_key_str), grpc_mdstr_from_string (c->mdctx, timeout_str, 0)); + mdelem = hpack_enc (c, mdelem, st); + if (mdelem) + GRPC_MDELEM_UNREF (mdelem); } -gpr_slice grpc_chttp2_data_frame_create_empty_close(gpr_uint32 id) { - gpr_slice slice = gpr_slice_malloc(9); - fill_header(GPR_SLICE_START_PTR(slice), GRPC_CHTTP2_FRAME_DATA, id, 0, 1); +gpr_slice +grpc_chttp2_data_frame_create_empty_close (gpr_uint32 id) +{ + gpr_slice slice = gpr_slice_malloc (9); + fill_header (GPR_SLICE_START_PTR (slice), GRPC_CHTTP2_FRAME_DATA, id, 0, 1); return slice; } -void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c, - grpc_mdctx *ctx) { - memset(c, 0, sizeof(*c)); +void +grpc_chttp2_hpack_compressor_init (grpc_chttp2_hpack_compressor * c, grpc_mdctx * ctx) +{ + memset (c, 0, sizeof (*c)); c->mdctx = ctx; - c->timeout_key_str = grpc_mdstr_from_string(ctx, "grpc-timeout", 0); + c->timeout_key_str = grpc_mdstr_from_string (ctx, "grpc-timeout", 0); } -void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c) { +void +grpc_chttp2_hpack_compressor_destroy (grpc_chttp2_hpack_compressor * c) +{ int i; - for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) { - if (c->entries_keys[i]) GRPC_MDSTR_UNREF(c->entries_keys[i]); - if (c->entries_elems[i]) GRPC_MDELEM_UNREF(c->entries_elems[i]); - } - GRPC_MDSTR_UNREF(c->timeout_key_str); + for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) + { + if (c->entries_keys[i]) + GRPC_MDSTR_UNREF (c->entries_keys[i]); + if (c->entries_elems[i]) + GRPC_MDELEM_UNREF (c->entries_elems[i]); + } + GRPC_MDSTR_UNREF (c->timeout_key_str); } -gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count, - gpr_uint32 max_flow_controlled_bytes, - grpc_stream_op_buffer *outops) { +gpr_uint32 +grpc_chttp2_preencode (grpc_stream_op * inops, size_t * inops_count, gpr_uint32 max_flow_controlled_bytes, grpc_stream_op_buffer * outops) +{ gpr_slice slice; grpc_stream_op *op; gpr_uint32 max_take_size; @@ -504,78 +546,85 @@ gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count, gpr_uint8 *p; gpr_uint8 compressed_flag_set = 0; - while (curop < *inops_count) { - GPR_ASSERT(flow_controlled_bytes_taken <= max_flow_controlled_bytes); - op = &inops[curop]; - switch (op->type) { - case GRPC_NO_OP: - /* skip */ - curop++; - break; - case GRPC_OP_METADATA: - grpc_metadata_batch_assert_ok(&op->data.metadata); - /* these just get copied as they don't impact the number of flow - controlled bytes */ - grpc_sopb_append(outops, op, 1); - curop++; - break; - case GRPC_OP_BEGIN_MESSAGE: - /* begin op: for now we just convert the op to a slice and fall - through - this lets us reuse the slice framing code below */ - compressed_flag_set = - (op->data.begin_message.flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0; - slice = gpr_slice_malloc(5); - - p = GPR_SLICE_START_PTR(slice); - p[0] = compressed_flag_set; - p[1] = (gpr_uint8)(op->data.begin_message.length >> 24); - p[2] = (gpr_uint8)(op->data.begin_message.length >> 16); - p[3] = (gpr_uint8)(op->data.begin_message.length >> 8); - p[4] = (gpr_uint8)(op->data.begin_message.length); - op->type = GRPC_OP_SLICE; - op->data.slice = slice; - /* fallthrough */ - case GRPC_OP_SLICE: - slice = op->data.slice; - if (!GPR_SLICE_LENGTH(slice)) { - /* skip zero length slices */ - gpr_slice_unref(slice); - curop++; - break; - } - max_take_size = max_flow_controlled_bytes - flow_controlled_bytes_taken; - if (max_take_size == 0) { - goto exit_loop; - } - if (GPR_SLICE_LENGTH(slice) > max_take_size) { - slice = gpr_slice_split_head(&op->data.slice, max_take_size); - grpc_sopb_add_slice(outops, slice); - } else { - /* consume this op immediately */ - grpc_sopb_append(outops, op, 1); - curop++; - } - flow_controlled_bytes_taken += (gpr_uint32)GPR_SLICE_LENGTH(slice); - break; - } - } + while (curop < *inops_count) + { + GPR_ASSERT (flow_controlled_bytes_taken <= max_flow_controlled_bytes); + op = &inops[curop]; + switch (op->type) + { + case GRPC_NO_OP: + /* skip */ + curop++; + break; + case GRPC_OP_METADATA: + grpc_metadata_batch_assert_ok (&op->data.metadata); + /* these just get copied as they don't impact the number of flow + controlled bytes */ + grpc_sopb_append (outops, op, 1); + curop++; + break; + case GRPC_OP_BEGIN_MESSAGE: + /* begin op: for now we just convert the op to a slice and fall + through - this lets us reuse the slice framing code below */ + compressed_flag_set = (op->data.begin_message.flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0; + slice = gpr_slice_malloc (5); + + p = GPR_SLICE_START_PTR (slice); + p[0] = compressed_flag_set; + p[1] = (gpr_uint8) (op->data.begin_message.length >> 24); + p[2] = (gpr_uint8) (op->data.begin_message.length >> 16); + p[3] = (gpr_uint8) (op->data.begin_message.length >> 8); + p[4] = (gpr_uint8) (op->data.begin_message.length); + op->type = GRPC_OP_SLICE; + op->data.slice = slice; + /* fallthrough */ + case GRPC_OP_SLICE: + slice = op->data.slice; + if (!GPR_SLICE_LENGTH (slice)) + { + /* skip zero length slices */ + gpr_slice_unref (slice); + curop++; + break; + } + max_take_size = max_flow_controlled_bytes - flow_controlled_bytes_taken; + if (max_take_size == 0) + { + goto exit_loop; + } + if (GPR_SLICE_LENGTH (slice) > max_take_size) + { + slice = gpr_slice_split_head (&op->data.slice, max_take_size); + grpc_sopb_add_slice (outops, slice); + } + else + { + /* consume this op immediately */ + grpc_sopb_append (outops, op, 1); + curop++; + } + flow_controlled_bytes_taken += (gpr_uint32) GPR_SLICE_LENGTH (slice); + break; + } + } exit_loop: *inops_count -= curop; - memmove(inops, inops + curop, *inops_count * sizeof(grpc_stream_op)); - - for (curop = 0; curop < *inops_count; curop++) { - if (inops[curop].type == GRPC_OP_METADATA) { - grpc_metadata_batch_assert_ok(&inops[curop].data.metadata); + memmove (inops, inops + curop, *inops_count * sizeof (grpc_stream_op)); + + for (curop = 0; curop < *inops_count; curop++) + { + if (inops[curop].type == GRPC_OP_METADATA) + { + grpc_metadata_batch_assert_ok (&inops[curop].data.metadata); + } } - } return flow_controlled_bytes_taken; } -void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof, - gpr_uint32 stream_id, - grpc_chttp2_hpack_compressor *compressor, - gpr_slice_buffer *output) { +void +grpc_chttp2_encode (grpc_stream_op * ops, size_t ops_count, int eof, gpr_uint32 stream_id, grpc_chttp2_hpack_compressor * compressor, gpr_slice_buffer * output) +{ framer_state st; gpr_slice slice; grpc_stream_op *op; @@ -587,7 +636,7 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof, int need_unref = 0; gpr_timespec deadline; - GPR_ASSERT(stream_id != 0); + GPR_ASSERT (stream_id != 0); st.cur_frame_type = NONE; st.last_was_header = 0; @@ -595,70 +644,80 @@ void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof, st.stream_id = stream_id; st.output = output; - while (curop < ops_count) { - op = &ops[curop]; - switch (op->type) { - case GRPC_NO_OP: - case GRPC_OP_BEGIN_MESSAGE: - gpr_log( - GPR_ERROR, - "These stream ops should be filtered out by grpc_chttp2_preencode"); - abort(); - case GRPC_OP_METADATA: - /* Encode a metadata batch; store the returned values, representing - a metadata element that needs to be unreffed back into the metadata - slot. THIS MAY NOT BE THE SAME ELEMENT (if a decoder table slot got - updated). After this loop, we'll do a batch unref of elements. */ - begin_new_frame(&st, HEADER); - need_unref |= op->data.metadata.garbage.head != NULL; - grpc_metadata_batch_assert_ok(&op->data.metadata); - for (l = op->data.metadata.list.head; l; l = l->next) { - l->md = hpack_enc(compressor, l->md, &st); - need_unref |= l->md != NULL; - } - deadline = op->data.metadata.deadline; - if (gpr_time_cmp(deadline, gpr_inf_future(deadline.clock_type)) != 0) { - deadline_enc(compressor, deadline, &st); - } - curop++; - break; - case GRPC_OP_SLICE: - slice = op->data.slice; - if (st.cur_frame_type == DATA && - st.output->length - st.output_length_at_start_of_frame == - GRPC_CHTTP2_MAX_PAYLOAD_LENGTH) { - finish_frame(&st, 0, 0); - } - ensure_frame_type(&st, DATA, 1); - max_take_size = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH + - st.output_length_at_start_of_frame - st.output->length; - if (GPR_SLICE_LENGTH(slice) > max_take_size) { - slice = gpr_slice_split_head(&op->data.slice, max_take_size); - } else { - /* consume this op immediately */ - curop++; - } - gpr_slice_buffer_add(output, slice); - break; - } - } - if (eof && st.cur_frame_type == NONE) { - begin_frame(&st, DATA); - } - finish_frame(&st, 1, eof); - - if (need_unref) { - grpc_mdctx_lock(mdctx); - for (unref_op = 0; unref_op < curop; unref_op++) { - op = &ops[unref_op]; - if (op->type != GRPC_OP_METADATA) continue; - for (l = op->data.metadata.list.head; l; l = l->next) { - if (l->md) GRPC_MDCTX_LOCKED_MDELEM_UNREF(mdctx, l->md); - } - for (l = op->data.metadata.garbage.head; l; l = l->next) { - GRPC_MDCTX_LOCKED_MDELEM_UNREF(mdctx, l->md); - } - } - grpc_mdctx_unlock(mdctx); - } + while (curop < ops_count) + { + op = &ops[curop]; + switch (op->type) + { + case GRPC_NO_OP: + case GRPC_OP_BEGIN_MESSAGE: + gpr_log (GPR_ERROR, "These stream ops should be filtered out by grpc_chttp2_preencode"); + abort (); + case GRPC_OP_METADATA: + /* Encode a metadata batch; store the returned values, representing + a metadata element that needs to be unreffed back into the metadata + slot. THIS MAY NOT BE THE SAME ELEMENT (if a decoder table slot got + updated). After this loop, we'll do a batch unref of elements. */ + begin_new_frame (&st, HEADER); + need_unref |= op->data.metadata.garbage.head != NULL; + grpc_metadata_batch_assert_ok (&op->data.metadata); + for (l = op->data.metadata.list.head; l; l = l->next) + { + l->md = hpack_enc (compressor, l->md, &st); + need_unref |= l->md != NULL; + } + deadline = op->data.metadata.deadline; + if (gpr_time_cmp (deadline, gpr_inf_future (deadline.clock_type)) != 0) + { + deadline_enc (compressor, deadline, &st); + } + curop++; + break; + case GRPC_OP_SLICE: + slice = op->data.slice; + if (st.cur_frame_type == DATA && st.output->length - st.output_length_at_start_of_frame == GRPC_CHTTP2_MAX_PAYLOAD_LENGTH) + { + finish_frame (&st, 0, 0); + } + ensure_frame_type (&st, DATA, 1); + max_take_size = GRPC_CHTTP2_MAX_PAYLOAD_LENGTH + st.output_length_at_start_of_frame - st.output->length; + if (GPR_SLICE_LENGTH (slice) > max_take_size) + { + slice = gpr_slice_split_head (&op->data.slice, max_take_size); + } + else + { + /* consume this op immediately */ + curop++; + } + gpr_slice_buffer_add (output, slice); + break; + } + } + if (eof && st.cur_frame_type == NONE) + { + begin_frame (&st, DATA); + } + finish_frame (&st, 1, eof); + + if (need_unref) + { + grpc_mdctx_lock (mdctx); + for (unref_op = 0; unref_op < curop; unref_op++) + { + op = &ops[unref_op]; + if (op->type != GRPC_OP_METADATA) + continue; + for (l = op->data.metadata.list.head; l; l = l->next) + { + if (l->md) + GRPC_MDCTX_LOCKED_MDELEM_UNREF (mdctx, l->md); + } + for (l = op->data.metadata.garbage.head; l; l = l->next) + { + GRPC_MDCTX_LOCKED_MDELEM_UNREF (mdctx, l->md); + } + } + grpc_mdctx_unlock (mdctx); + } } diff --git a/src/core/transport/chttp2/stream_encoder.h b/src/core/transport/chttp2/stream_encoder.h index db52f2a0f6..32f003d000 100644 --- a/src/core/transport/chttp2/stream_encoder.h +++ b/src/core/transport/chttp2/stream_encoder.h @@ -45,7 +45,8 @@ #define GRPC_CHTTP2_HPACKC_NUM_VALUES 256 #define GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS (4096 / 32) -typedef struct { +typedef struct +{ gpr_uint32 filter_elems_sum; /* one before the lowest usable table index */ gpr_uint32 tail_remote_index; @@ -74,20 +75,14 @@ typedef struct { gpr_uint16 table_elem_size[GRPC_CHTTP2_HPACKC_MAX_TABLE_ELEMS]; } grpc_chttp2_hpack_compressor; -void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c, - grpc_mdctx *mdctx); -void grpc_chttp2_hpack_compressor_destroy(grpc_chttp2_hpack_compressor *c); +void grpc_chttp2_hpack_compressor_init (grpc_chttp2_hpack_compressor * c, grpc_mdctx * mdctx); +void grpc_chttp2_hpack_compressor_destroy (grpc_chttp2_hpack_compressor * c); /* select stream ops to be encoded, moving them from inops to outops, and moving subsequent ops in inops forward in the queue */ -gpr_uint32 grpc_chttp2_preencode(grpc_stream_op *inops, size_t *inops_count, - gpr_uint32 max_flow_controlled_bytes, - grpc_stream_op_buffer *outops); +gpr_uint32 grpc_chttp2_preencode (grpc_stream_op * inops, size_t * inops_count, gpr_uint32 max_flow_controlled_bytes, grpc_stream_op_buffer * outops); /* encode stream ops to output */ -void grpc_chttp2_encode(grpc_stream_op *ops, size_t ops_count, int eof, - gpr_uint32 stream_id, - grpc_chttp2_hpack_compressor *compressor, - gpr_slice_buffer *output); +void grpc_chttp2_encode (grpc_stream_op * ops, size_t ops_count, int eof, gpr_uint32 stream_id, grpc_chttp2_hpack_compressor * compressor, gpr_slice_buffer * output); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STREAM_ENCODER_H */ diff --git a/src/core/transport/chttp2/stream_lists.c b/src/core/transport/chttp2/stream_lists.c index 781db7b0d6..43d7b0b39f 100644 --- a/src/core/transport/chttp2/stream_lists.c +++ b/src/core/transport/chttp2/stream_lists.c @@ -58,346 +58,348 @@ /* core list management */ -static int stream_list_empty(grpc_chttp2_transport *t, - grpc_chttp2_stream_list_id id) { +static int +stream_list_empty (grpc_chttp2_transport * t, grpc_chttp2_stream_list_id id) +{ return t->lists[id].head == NULL; } -static int stream_list_pop(grpc_chttp2_transport *t, - grpc_chttp2_stream **stream, - grpc_chttp2_stream_list_id id) { +static int +stream_list_pop (grpc_chttp2_transport * t, grpc_chttp2_stream ** stream, grpc_chttp2_stream_list_id id) +{ grpc_chttp2_stream *s = t->lists[id].head; - if (s) { - grpc_chttp2_stream *new_head = s->links[id].next; - GPR_ASSERT(s->included[id]); - if (new_head) { - t->lists[id].head = new_head; - new_head->links[id].prev = NULL; - } else { - t->lists[id].head = NULL; - t->lists[id].tail = NULL; + if (s) + { + grpc_chttp2_stream *new_head = s->links[id].next; + GPR_ASSERT (s->included[id]); + if (new_head) + { + t->lists[id].head = new_head; + new_head->links[id].prev = NULL; + } + else + { + t->lists[id].head = NULL; + t->lists[id].tail = NULL; + } + s->included[id] = 0; } - s->included[id] = 0; - } *stream = s; return s != 0; } -static void stream_list_remove(grpc_chttp2_transport *t, grpc_chttp2_stream *s, - grpc_chttp2_stream_list_id id) { - GPR_ASSERT(s->included[id]); +static void +stream_list_remove (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id) +{ + GPR_ASSERT (s->included[id]); s->included[id] = 0; - if (s->links[id].prev) { - s->links[id].prev->links[id].next = s->links[id].next; - } else { - GPR_ASSERT(t->lists[id].head == s); - t->lists[id].head = s->links[id].next; - } - if (s->links[id].next) { - s->links[id].next->links[id].prev = s->links[id].prev; - } else { - t->lists[id].tail = s->links[id].prev; - } -} - -static void stream_list_maybe_remove(grpc_chttp2_transport *t, - grpc_chttp2_stream *s, - grpc_chttp2_stream_list_id id) { - if (s->included[id]) { - stream_list_remove(t, s, id); - } -} - -static void stream_list_add_head(grpc_chttp2_transport *t, - grpc_chttp2_stream *s, - grpc_chttp2_stream_list_id id) { + if (s->links[id].prev) + { + s->links[id].prev->links[id].next = s->links[id].next; + } + else + { + GPR_ASSERT (t->lists[id].head == s); + t->lists[id].head = s->links[id].next; + } + if (s->links[id].next) + { + s->links[id].next->links[id].prev = s->links[id].prev; + } + else + { + t->lists[id].tail = s->links[id].prev; + } +} + +static void +stream_list_maybe_remove (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id) +{ + if (s->included[id]) + { + stream_list_remove (t, s, id); + } +} + +static void +stream_list_add_head (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id) +{ grpc_chttp2_stream *old_head; - GPR_ASSERT(!s->included[id]); + GPR_ASSERT (!s->included[id]); old_head = t->lists[id].head; s->links[id].next = old_head; s->links[id].prev = NULL; - if (old_head) { - old_head->links[id].prev = s; - } else { - t->lists[id].tail = s; - } + if (old_head) + { + old_head->links[id].prev = s; + } + else + { + t->lists[id].tail = s; + } t->lists[id].head = s; s->included[id] = 1; } -static void stream_list_add_tail(grpc_chttp2_transport *t, - grpc_chttp2_stream *s, - grpc_chttp2_stream_list_id id) { +static void +stream_list_add_tail (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id) +{ grpc_chttp2_stream *old_tail; - GPR_ASSERT(!s->included[id]); + GPR_ASSERT (!s->included[id]); old_tail = t->lists[id].tail; s->links[id].next = NULL; s->links[id].prev = old_tail; - if (old_tail) { - old_tail->links[id].next = s; - } else { - t->lists[id].head = s; - } + if (old_tail) + { + old_tail->links[id].next = s; + } + else + { + t->lists[id].head = s; + } t->lists[id].tail = s; s->included[id] = 1; } -static void stream_list_add(grpc_chttp2_transport *t, grpc_chttp2_stream *s, - grpc_chttp2_stream_list_id id) { - if (s->included[id]) { - return; - } - stream_list_add_tail(t, s, id); +static void +stream_list_add (grpc_chttp2_transport * t, grpc_chttp2_stream * s, grpc_chttp2_stream_list_id id) +{ + if (s->included[id]) + { + return; + } + stream_list_add_tail (t, s, id); } /* wrappers for specializations */ -void grpc_chttp2_list_add_writable_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - GPR_ASSERT(stream_global->id != 0); - stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), GRPC_CHTTP2_LIST_WRITABLE); +void +grpc_chttp2_list_add_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + GPR_ASSERT (stream_global->id != 0); + stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_WRITABLE); } -void grpc_chttp2_list_add_first_writable_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - GPR_ASSERT(stream_global->id != 0); - stream_list_add_head(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), - GRPC_CHTTP2_LIST_WRITABLE); +void +grpc_chttp2_list_add_first_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + GPR_ASSERT (stream_global->id != 0); + stream_list_add_head (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_WRITABLE); } -int grpc_chttp2_list_pop_writable_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_global **stream_global, - grpc_chttp2_stream_writing **stream_writing) { +int +grpc_chttp2_list_pop_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_writing ** stream_writing) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream, - GRPC_CHTTP2_LIST_WRITABLE); - if (r != 0) { - *stream_global = &stream->global; - *stream_writing = &stream->writing; - } + int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream, + GRPC_CHTTP2_LIST_WRITABLE); + if (r != 0) + { + *stream_global = &stream->global; + *stream_writing = &stream->writing; + } return r; } -void grpc_chttp2_list_remove_writable_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), - GRPC_CHTTP2_LIST_WRITABLE); +void +grpc_chttp2_list_remove_writable_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + stream_list_maybe_remove (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_WRITABLE); } -void grpc_chttp2_list_add_writing_stream( - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_writing *stream_writing) { - stream_list_add(TRANSPORT_FROM_WRITING(transport_writing), - STREAM_FROM_WRITING(stream_writing), - GRPC_CHTTP2_LIST_WRITING); +void +grpc_chttp2_list_add_writing_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing * stream_writing) +{ + stream_list_add (TRANSPORT_FROM_WRITING (transport_writing), STREAM_FROM_WRITING (stream_writing), GRPC_CHTTP2_LIST_WRITING); } -int grpc_chttp2_list_have_writing_streams( - grpc_chttp2_transport_writing *transport_writing) { - return !stream_list_empty(TRANSPORT_FROM_WRITING(transport_writing), - GRPC_CHTTP2_LIST_WRITING); +int +grpc_chttp2_list_have_writing_streams (grpc_chttp2_transport_writing * transport_writing) +{ + return !stream_list_empty (TRANSPORT_FROM_WRITING (transport_writing), GRPC_CHTTP2_LIST_WRITING); } -int grpc_chttp2_list_pop_writing_stream( - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_writing **stream_writing) { +int +grpc_chttp2_list_pop_writing_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing ** stream_writing) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_WRITING(transport_writing), &stream, - GRPC_CHTTP2_LIST_WRITING); - if (r != 0) { - *stream_writing = &stream->writing; - } + int r = stream_list_pop (TRANSPORT_FROM_WRITING (transport_writing), &stream, + GRPC_CHTTP2_LIST_WRITING); + if (r != 0) + { + *stream_writing = &stream->writing; + } return r; } -void grpc_chttp2_list_add_written_stream( - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_writing *stream_writing) { - stream_list_add(TRANSPORT_FROM_WRITING(transport_writing), - STREAM_FROM_WRITING(stream_writing), - GRPC_CHTTP2_LIST_WRITTEN); +void +grpc_chttp2_list_add_written_stream (grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_writing * stream_writing) +{ + stream_list_add (TRANSPORT_FROM_WRITING (transport_writing), STREAM_FROM_WRITING (stream_writing), GRPC_CHTTP2_LIST_WRITTEN); } -int grpc_chttp2_list_pop_written_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_writing *transport_writing, - grpc_chttp2_stream_global **stream_global, - grpc_chttp2_stream_writing **stream_writing) { +int +grpc_chttp2_list_pop_written_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_writing ** stream_writing) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_WRITING(transport_writing), &stream, - GRPC_CHTTP2_LIST_WRITTEN); - if (r != 0) { - *stream_global = &stream->global; - *stream_writing = &stream->writing; - } + int r = stream_list_pop (TRANSPORT_FROM_WRITING (transport_writing), &stream, + GRPC_CHTTP2_LIST_WRITTEN); + if (r != 0) + { + *stream_global = &stream->global; + *stream_writing = &stream->writing; + } return r; } -void grpc_chttp2_list_add_parsing_seen_stream( - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_parsing *stream_parsing) { - stream_list_add(TRANSPORT_FROM_PARSING(transport_parsing), - STREAM_FROM_PARSING(stream_parsing), - GRPC_CHTTP2_LIST_PARSING_SEEN); +void +grpc_chttp2_list_add_parsing_seen_stream (grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_parsing * stream_parsing) +{ + stream_list_add (TRANSPORT_FROM_PARSING (transport_parsing), STREAM_FROM_PARSING (stream_parsing), GRPC_CHTTP2_LIST_PARSING_SEEN); } -int grpc_chttp2_list_pop_parsing_seen_stream( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_global **stream_global, - grpc_chttp2_stream_parsing **stream_parsing) { +int +grpc_chttp2_list_pop_parsing_seen_stream (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_parsing ** stream_parsing) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_PARSING(transport_parsing), &stream, - GRPC_CHTTP2_LIST_PARSING_SEEN); - if (r != 0) { - *stream_global = &stream->global; - *stream_parsing = &stream->parsing; - } + int r = stream_list_pop (TRANSPORT_FROM_PARSING (transport_parsing), &stream, + GRPC_CHTTP2_LIST_PARSING_SEEN); + if (r != 0) + { + *stream_global = &stream->global; + *stream_parsing = &stream->parsing; + } return r; } -void grpc_chttp2_list_add_waiting_for_concurrency( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), - GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY); +void +grpc_chttp2_list_add_waiting_for_concurrency (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY); } -int grpc_chttp2_list_pop_waiting_for_concurrency( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global **stream_global) { +int +grpc_chttp2_list_pop_waiting_for_concurrency (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream, - GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY); - if (r != 0) { - *stream_global = &stream->global; - } + int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream, + GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY); + if (r != 0) + { + *stream_global = &stream->global; + } return r; } -void grpc_chttp2_list_add_closed_waiting_for_parsing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), - GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING); +void +grpc_chttp2_list_add_closed_waiting_for_parsing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING); } -int grpc_chttp2_list_pop_closed_waiting_for_parsing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global **stream_global) { +int +grpc_chttp2_list_pop_closed_waiting_for_parsing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream, - GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING); - if (r != 0) { - *stream_global = &stream->global; - } + int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream, + GRPC_CHTTP2_LIST_CLOSED_WAITING_FOR_PARSING); + if (r != 0) + { + *stream_global = &stream->global; + } return r; } -void grpc_chttp2_list_add_cancelled_waiting_for_writing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), - GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING); +void +grpc_chttp2_list_add_cancelled_waiting_for_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING); } -int grpc_chttp2_list_pop_cancelled_waiting_for_writing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global **stream_global) { +int +grpc_chttp2_list_pop_cancelled_waiting_for_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream, - GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING); - if (r != 0) { - *stream_global = &stream->global; - } + int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream, + GRPC_CHTTP2_LIST_CANCELLED_WAITING_FOR_WRITING); + if (r != 0) + { + *stream_global = &stream->global; + } return r; } -void grpc_chttp2_list_add_incoming_window_updated( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), - GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED); +void +grpc_chttp2_list_add_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED); } -int grpc_chttp2_list_pop_incoming_window_updated( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_parsing *transport_parsing, - grpc_chttp2_stream_global **stream_global, - grpc_chttp2_stream_parsing **stream_parsing) { +int +grpc_chttp2_list_pop_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_parsing * transport_parsing, grpc_chttp2_stream_global ** stream_global, grpc_chttp2_stream_parsing ** stream_parsing) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream, - GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED); - if (r != 0) { - *stream_global = &stream->global; - *stream_parsing = &stream->parsing; - } + int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream, + GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED); + if (r != 0) + { + *stream_global = &stream->global; + *stream_parsing = &stream->parsing; + } return r; } -void grpc_chttp2_list_remove_incoming_window_updated( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - stream_list_maybe_remove(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), - GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED); +void +grpc_chttp2_list_remove_incoming_window_updated (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + stream_list_maybe_remove (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_INCOMING_WINDOW_UPDATED); } -void grpc_chttp2_list_add_read_write_state_changed( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global *stream_global) { - stream_list_add(TRANSPORT_FROM_GLOBAL(transport_global), - STREAM_FROM_GLOBAL(stream_global), - GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED); +void +grpc_chttp2_list_add_read_write_state_changed (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global * stream_global) +{ + stream_list_add (TRANSPORT_FROM_GLOBAL (transport_global), STREAM_FROM_GLOBAL (stream_global), GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED); } -int grpc_chttp2_list_pop_read_write_state_changed( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_stream_global **stream_global) { +int +grpc_chttp2_list_pop_read_write_state_changed (grpc_chttp2_transport_global * transport_global, grpc_chttp2_stream_global ** stream_global) +{ grpc_chttp2_stream *stream; - int r = stream_list_pop(TRANSPORT_FROM_GLOBAL(transport_global), &stream, - GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED); - if (r != 0) { - *stream_global = &stream->global; - } + int r = stream_list_pop (TRANSPORT_FROM_GLOBAL (transport_global), &stream, + GRPC_CHTTP2_LIST_READ_WRITE_STATE_CHANGED); + if (r != 0) + { + *stream_global = &stream->global; + } return r; } -void grpc_chttp2_register_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { - stream_list_add_tail(t, s, GRPC_CHTTP2_LIST_ALL_STREAMS); +void +grpc_chttp2_register_stream (grpc_chttp2_transport * t, grpc_chttp2_stream * s) +{ + stream_list_add_tail (t, s, GRPC_CHTTP2_LIST_ALL_STREAMS); } -int grpc_chttp2_unregister_stream(grpc_chttp2_transport *t, - grpc_chttp2_stream *s) { - stream_list_maybe_remove(t, s, GRPC_CHTTP2_LIST_ALL_STREAMS); - return stream_list_empty(t, GRPC_CHTTP2_LIST_ALL_STREAMS); +int +grpc_chttp2_unregister_stream (grpc_chttp2_transport * t, grpc_chttp2_stream * s) +{ + stream_list_maybe_remove (t, s, GRPC_CHTTP2_LIST_ALL_STREAMS); + return stream_list_empty (t, GRPC_CHTTP2_LIST_ALL_STREAMS); } -int grpc_chttp2_has_streams(grpc_chttp2_transport *t) { - return !stream_list_empty(t, GRPC_CHTTP2_LIST_ALL_STREAMS); +int +grpc_chttp2_has_streams (grpc_chttp2_transport * t) +{ + return !stream_list_empty (t, GRPC_CHTTP2_LIST_ALL_STREAMS); } -void grpc_chttp2_for_all_streams( - grpc_chttp2_transport_global *transport_global, void *user_data, - void (*cb)(grpc_chttp2_transport_global *transport_global, void *user_data, - grpc_chttp2_stream_global *stream_global)) { +void +grpc_chttp2_for_all_streams (grpc_chttp2_transport_global * transport_global, void *user_data, void (*cb) (grpc_chttp2_transport_global * transport_global, void *user_data, grpc_chttp2_stream_global * stream_global)) +{ grpc_chttp2_stream *s; - grpc_chttp2_transport *t = TRANSPORT_FROM_GLOBAL(transport_global); - for (s = t->lists[GRPC_CHTTP2_LIST_ALL_STREAMS].head; s != NULL; - s = s->links[GRPC_CHTTP2_LIST_ALL_STREAMS].next) { - cb(transport_global, user_data, &s->global); - } + grpc_chttp2_transport *t = TRANSPORT_FROM_GLOBAL (transport_global); + for (s = t->lists[GRPC_CHTTP2_LIST_ALL_STREAMS].head; s != NULL; s = s->links[GRPC_CHTTP2_LIST_ALL_STREAMS].next) + { + cb (transport_global, user_data, &s->global); + } } diff --git a/src/core/transport/chttp2/stream_map.c b/src/core/transport/chttp2/stream_map.c index bd16153ed1..00878c1d2a 100644 --- a/src/core/transport/chttp2/stream_map.c +++ b/src/core/transport/chttp2/stream_map.c @@ -39,98 +39,117 @@ #include <grpc/support/log.h> #include <grpc/support/useful.h> -void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map *map, - size_t initial_capacity) { - GPR_ASSERT(initial_capacity > 1); - map->keys = gpr_malloc(sizeof(gpr_uint32) * initial_capacity); - map->values = gpr_malloc(sizeof(void *) * initial_capacity); +void +grpc_chttp2_stream_map_init (grpc_chttp2_stream_map * map, size_t initial_capacity) +{ + GPR_ASSERT (initial_capacity > 1); + map->keys = gpr_malloc (sizeof (gpr_uint32) * initial_capacity); + map->values = gpr_malloc (sizeof (void *) * initial_capacity); map->count = 0; map->free = 0; map->capacity = initial_capacity; } -void grpc_chttp2_stream_map_destroy(grpc_chttp2_stream_map *map) { - gpr_free(map->keys); - gpr_free(map->values); +void +grpc_chttp2_stream_map_destroy (grpc_chttp2_stream_map * map) +{ + gpr_free (map->keys); + gpr_free (map->values); } -static size_t compact(gpr_uint32 *keys, void **values, size_t count) { +static size_t +compact (gpr_uint32 * keys, void **values, size_t count) +{ size_t i, out; - for (i = 0, out = 0; i < count; i++) { - if (values[i]) { - keys[out] = keys[i]; - values[out] = values[i]; - out++; + for (i = 0, out = 0; i < count; i++) + { + if (values[i]) + { + keys[out] = keys[i]; + values[out] = values[i]; + out++; + } } - } return out; } -void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, gpr_uint32 key, - void *value) { +void +grpc_chttp2_stream_map_add (grpc_chttp2_stream_map * map, gpr_uint32 key, void *value) +{ size_t count = map->count; size_t capacity = map->capacity; gpr_uint32 *keys = map->keys; void **values = map->values; - GPR_ASSERT(count == 0 || keys[count - 1] < key); - GPR_ASSERT(value); - - if (count == capacity) { - if (map->free > capacity / 4) { - count = compact(keys, values, count); - map->free = 0; - } else { - /* resize when less than 25% of the table is free, because compaction - won't help much */ - map->capacity = capacity = 3 * capacity / 2; - map->keys = keys = gpr_realloc(keys, capacity * sizeof(gpr_uint32)); - map->values = values = gpr_realloc(values, capacity * sizeof(void *)); + GPR_ASSERT (count == 0 || keys[count - 1] < key); + GPR_ASSERT (value); + + if (count == capacity) + { + if (map->free > capacity / 4) + { + count = compact (keys, values, count); + map->free = 0; + } + else + { + /* resize when less than 25% of the table is free, because compaction + won't help much */ + map->capacity = capacity = 3 * capacity / 2; + map->keys = keys = gpr_realloc (keys, capacity * sizeof (gpr_uint32)); + map->values = values = gpr_realloc (values, capacity * sizeof (void *)); + } } - } keys[count] = key; values[count] = value; map->count = count + 1; } -void grpc_chttp2_stream_map_move_into(grpc_chttp2_stream_map *src, - grpc_chttp2_stream_map *dst) { +void +grpc_chttp2_stream_map_move_into (grpc_chttp2_stream_map * src, grpc_chttp2_stream_map * dst) +{ /* if src is empty we dont need to do anything */ - if (src->count == src->free) { - return; - } + if (src->count == src->free) + { + return; + } /* if dst is empty we simply need to swap */ - if (dst->count == dst->free) { - GPR_SWAP(grpc_chttp2_stream_map, *src, *dst); - return; - } + if (dst->count == dst->free) + { + GPR_SWAP (grpc_chttp2_stream_map, *src, *dst); + return; + } /* the first element of src must be greater than the last of dst... * however the maps may need compacting for this property to hold */ - if (src->keys[0] <= dst->keys[dst->count - 1]) { - src->count = compact(src->keys, src->values, src->count); - src->free = 0; - dst->count = compact(dst->keys, dst->values, dst->count); - dst->free = 0; - } - GPR_ASSERT(src->keys[0] > dst->keys[dst->count - 1]); + if (src->keys[0] <= dst->keys[dst->count - 1]) + { + src->count = compact (src->keys, src->values, src->count); + src->free = 0; + dst->count = compact (dst->keys, dst->values, dst->count); + dst->free = 0; + } + GPR_ASSERT (src->keys[0] > dst->keys[dst->count - 1]); /* if dst doesn't have capacity, resize */ - if (dst->count + src->count > dst->capacity) { - dst->capacity = GPR_MAX(dst->capacity * 3 / 2, dst->count + src->count); - dst->keys = gpr_realloc(dst->keys, dst->capacity * sizeof(gpr_uint32)); - dst->values = gpr_realloc(dst->values, dst->capacity * sizeof(void *)); - } - memcpy(dst->keys + dst->count, src->keys, src->count * sizeof(gpr_uint32)); - memcpy(dst->values + dst->count, src->values, src->count * sizeof(void *)); + if (dst->count + src->count > dst->capacity) + { + dst->capacity = GPR_MAX (dst->capacity * 3 / 2, dst->count + src->count); + dst->keys = gpr_realloc (dst->keys, dst->capacity * sizeof (gpr_uint32)); + dst->values = gpr_realloc (dst->values, dst->capacity * sizeof (void *)); + } + memcpy (dst->keys + dst->count, src->keys, src->count * sizeof (gpr_uint32)); + memcpy (dst->values + dst->count, src->values, src->count * sizeof (void *)); dst->count += src->count; dst->free += src->free; src->count = 0; src->free = 0; } -static void **find(grpc_chttp2_stream_map *map, gpr_uint32 key) { +static void ** +find (grpc_chttp2_stream_map * map, gpr_uint32 key) +{ size_t min_idx = 0; size_t max_idx = map->count; size_t mid_idx; @@ -138,60 +157,75 @@ static void **find(grpc_chttp2_stream_map *map, gpr_uint32 key) { void **values = map->values; gpr_uint32 mid_key; - if (max_idx == 0) return NULL; - - while (min_idx < max_idx) { - /* find the midpoint, avoiding overflow */ - mid_idx = min_idx + ((max_idx - min_idx) / 2); - mid_key = keys[mid_idx]; - - if (mid_key < key) { - min_idx = mid_idx + 1; - } else if (mid_key > key) { - max_idx = mid_idx; - } else /* mid_key == key */ { - return &values[mid_idx]; + if (max_idx == 0) + return NULL; + + while (min_idx < max_idx) + { + /* find the midpoint, avoiding overflow */ + mid_idx = min_idx + ((max_idx - min_idx) / 2); + mid_key = keys[mid_idx]; + + if (mid_key < key) + { + min_idx = mid_idx + 1; + } + else if (mid_key > key) + { + max_idx = mid_idx; + } + else /* mid_key == key */ + { + return &values[mid_idx]; + } } - } return NULL; } -void *grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map *map, - gpr_uint32 key) { - void **pvalue = find(map, key); +void * +grpc_chttp2_stream_map_delete (grpc_chttp2_stream_map * map, gpr_uint32 key) +{ + void **pvalue = find (map, key); void *out = NULL; - if (pvalue != NULL) { - out = *pvalue; - *pvalue = NULL; - map->free += (out != NULL); - /* recognize complete emptyness and ensure we can skip - * defragmentation later */ - if (map->free == map->count) { - map->free = map->count = 0; + if (pvalue != NULL) + { + out = *pvalue; + *pvalue = NULL; + map->free += (out != NULL); + /* recognize complete emptyness and ensure we can skip + * defragmentation later */ + if (map->free == map->count) + { + map->free = map->count = 0; + } } - } return out; } -void *grpc_chttp2_stream_map_find(grpc_chttp2_stream_map *map, gpr_uint32 key) { - void **pvalue = find(map, key); +void * +grpc_chttp2_stream_map_find (grpc_chttp2_stream_map * map, gpr_uint32 key) +{ + void **pvalue = find (map, key); return pvalue != NULL ? *pvalue : NULL; } -size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map *map) { +size_t +grpc_chttp2_stream_map_size (grpc_chttp2_stream_map * map) +{ return map->count - map->free; } -void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map *map, - void (*f)(void *user_data, gpr_uint32 key, - void *value), - void *user_data) { +void +grpc_chttp2_stream_map_for_each (grpc_chttp2_stream_map * map, void (*f) (void *user_data, gpr_uint32 key, void *value), void *user_data) +{ size_t i; - for (i = 0; i < map->count; i++) { - if (map->values[i]) { - f(user_data, map->keys[i], map->values[i]); + for (i = 0; i < map->count; i++) + { + if (map->values[i]) + { + f (user_data, map->keys[i], map->values[i]); + } } - } } diff --git a/src/core/transport/chttp2/stream_map.h b/src/core/transport/chttp2/stream_map.h index 71b0582054..2af61212da 100644 --- a/src/core/transport/chttp2/stream_map.h +++ b/src/core/transport/chttp2/stream_map.h @@ -44,7 +44,8 @@ Lookups are performed with binary search. Adds are restricted to strictly higher keys than previously seen (this is guaranteed by http2). */ -typedef struct { +typedef struct +{ gpr_uint32 *keys; void **values; size_t count; @@ -52,34 +53,27 @@ typedef struct { size_t capacity; } grpc_chttp2_stream_map; -void grpc_chttp2_stream_map_init(grpc_chttp2_stream_map *map, - size_t initial_capacity); -void grpc_chttp2_stream_map_destroy(grpc_chttp2_stream_map *map); +void grpc_chttp2_stream_map_init (grpc_chttp2_stream_map * map, size_t initial_capacity); +void grpc_chttp2_stream_map_destroy (grpc_chttp2_stream_map * map); /* Add a new key: given http2 semantics, new keys must always be greater than existing keys - this is asserted */ -void grpc_chttp2_stream_map_add(grpc_chttp2_stream_map *map, gpr_uint32 key, - void *value); +void grpc_chttp2_stream_map_add (grpc_chttp2_stream_map * map, gpr_uint32 key, void *value); /* Delete an existing key - returns the previous value of the key if it existed, or NULL otherwise */ -void *grpc_chttp2_stream_map_delete(grpc_chttp2_stream_map *map, - gpr_uint32 key); +void *grpc_chttp2_stream_map_delete (grpc_chttp2_stream_map * map, gpr_uint32 key); /* Move all elements of src into dst */ -void grpc_chttp2_stream_map_move_into(grpc_chttp2_stream_map *src, - grpc_chttp2_stream_map *dst); +void grpc_chttp2_stream_map_move_into (grpc_chttp2_stream_map * src, grpc_chttp2_stream_map * dst); /* Return an existing key, or NULL if it does not exist */ -void *grpc_chttp2_stream_map_find(grpc_chttp2_stream_map *map, gpr_uint32 key); +void *grpc_chttp2_stream_map_find (grpc_chttp2_stream_map * map, gpr_uint32 key); /* How many (populated) entries are in the stream map? */ -size_t grpc_chttp2_stream_map_size(grpc_chttp2_stream_map *map); +size_t grpc_chttp2_stream_map_size (grpc_chttp2_stream_map * map); /* Callback on each stream */ -void grpc_chttp2_stream_map_for_each(grpc_chttp2_stream_map *map, - void (*f)(void *user_data, gpr_uint32 key, - void *value), - void *user_data); +void grpc_chttp2_stream_map_for_each (grpc_chttp2_stream_map * map, void (*f) (void *user_data, gpr_uint32 key, void *value), void *user_data); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_STREAM_MAP_H */ diff --git a/src/core/transport/chttp2/timeout_encoding.c b/src/core/transport/chttp2/timeout_encoding.c index 8a9b290ecb..e241242403 100644 --- a/src/core/transport/chttp2/timeout_encoding.c +++ b/src/core/transport/chttp2/timeout_encoding.c @@ -38,147 +38,215 @@ #include "src/core/support/string.h" -static int round_up(int x, int divisor) { +static int +round_up (int x, int divisor) +{ return (x / divisor + (x % divisor != 0)) * divisor; } /* round an integer up to the next value with three significant figures */ -static int round_up_to_three_sig_figs(int x) { - if (x < 1000) return x; - if (x < 10000) return round_up(x, 10); - if (x < 100000) return round_up(x, 100); - if (x < 1000000) return round_up(x, 1000); - if (x < 10000000) return round_up(x, 10000); - if (x < 100000000) return round_up(x, 100000); - if (x < 1000000000) return round_up(x, 1000000); - return round_up(x, 10000000); +static int +round_up_to_three_sig_figs (int x) +{ + if (x < 1000) + return x; + if (x < 10000) + return round_up (x, 10); + if (x < 100000) + return round_up (x, 100); + if (x < 1000000) + return round_up (x, 1000); + if (x < 10000000) + return round_up (x, 10000); + if (x < 100000000) + return round_up (x, 100000); + if (x < 1000000000) + return round_up (x, 1000000); + return round_up (x, 10000000); } /* encode our minimum viable timeout value */ -static void enc_tiny(char *buffer) { memcpy(buffer, "1n", 3); } +static void +enc_tiny (char *buffer) +{ + memcpy (buffer, "1n", 3); +} -static void enc_ext(char *buffer, long value, char ext) { - int n = gpr_ltoa(value, buffer); +static void +enc_ext (char *buffer, long value, char ext) +{ + int n = gpr_ltoa (value, buffer); buffer[n] = ext; buffer[n + 1] = 0; } -static void enc_seconds(char *buffer, long sec) { - if (sec % 3600 == 0) { - enc_ext(buffer, sec / 3600, 'H'); - } else if (sec % 60 == 0) { - enc_ext(buffer, sec / 60, 'M'); - } else { - enc_ext(buffer, sec, 'S'); - } +static void +enc_seconds (char *buffer, long sec) +{ + if (sec % 3600 == 0) + { + enc_ext (buffer, sec / 3600, 'H'); + } + else if (sec % 60 == 0) + { + enc_ext (buffer, sec / 60, 'M'); + } + else + { + enc_ext (buffer, sec, 'S'); + } } -static void enc_nanos(char *buffer, int x) { - x = round_up_to_three_sig_figs(x); - if (x < 100000) { - if (x % 1000 == 0) { - enc_ext(buffer, x / 1000, 'u'); - } else { - enc_ext(buffer, x, 'n'); - } - } else if (x < 100000000) { - if (x % 1000000 == 0) { - enc_ext(buffer, x / 1000000, 'm'); - } else { - enc_ext(buffer, x / 1000, 'u'); - } - } else if (x < 1000000000) { - enc_ext(buffer, x / 1000000, 'm'); - } else { - /* note that this is only ever called with times of less than one second, - so if we reach here the time must have been rounded up to a whole second - (and no more) */ - memcpy(buffer, "1S", 3); - } +static void +enc_nanos (char *buffer, int x) +{ + x = round_up_to_three_sig_figs (x); + if (x < 100000) + { + if (x % 1000 == 0) + { + enc_ext (buffer, x / 1000, 'u'); + } + else + { + enc_ext (buffer, x, 'n'); + } + } + else if (x < 100000000) + { + if (x % 1000000 == 0) + { + enc_ext (buffer, x / 1000000, 'm'); + } + else + { + enc_ext (buffer, x / 1000, 'u'); + } + } + else if (x < 1000000000) + { + enc_ext (buffer, x / 1000000, 'm'); + } + else + { + /* note that this is only ever called with times of less than one second, + so if we reach here the time must have been rounded up to a whole second + (and no more) */ + memcpy (buffer, "1S", 3); + } } -static void enc_micros(char *buffer, int x) { - x = round_up_to_three_sig_figs(x); - if (x < 100000) { - if (x % 1000 == 0) { - enc_ext(buffer, x / 1000, 'm'); - } else { - enc_ext(buffer, x, 'u'); - } - } else if (x < 100000000) { - if (x % 1000000 == 0) { - enc_ext(buffer, x / 1000000, 'S'); - } else { - enc_ext(buffer, x / 1000, 'm'); - } - } else { - enc_ext(buffer, x / 1000000, 'S'); - } +static void +enc_micros (char *buffer, int x) +{ + x = round_up_to_three_sig_figs (x); + if (x < 100000) + { + if (x % 1000 == 0) + { + enc_ext (buffer, x / 1000, 'm'); + } + else + { + enc_ext (buffer, x, 'u'); + } + } + else if (x < 100000000) + { + if (x % 1000000 == 0) + { + enc_ext (buffer, x / 1000000, 'S'); + } + else + { + enc_ext (buffer, x / 1000, 'm'); + } + } + else + { + enc_ext (buffer, x / 1000000, 'S'); + } } -void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer) { - if (timeout.tv_sec < 0) { - enc_tiny(buffer); - } else if (timeout.tv_sec == 0) { - enc_nanos(buffer, timeout.tv_nsec); - } else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) { - enc_micros(buffer, - (int)(timeout.tv_sec * 1000000) + - (timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0))); - } else { - enc_seconds(buffer, timeout.tv_sec + (timeout.tv_nsec != 0)); - } +void +grpc_chttp2_encode_timeout (gpr_timespec timeout, char *buffer) +{ + if (timeout.tv_sec < 0) + { + enc_tiny (buffer); + } + else if (timeout.tv_sec == 0) + { + enc_nanos (buffer, timeout.tv_nsec); + } + else if (timeout.tv_sec < 1000 && timeout.tv_nsec != 0) + { + enc_micros (buffer, (int) (timeout.tv_sec * 1000000) + (timeout.tv_nsec / 1000 + (timeout.tv_nsec % 1000 != 0))); + } + else + { + enc_seconds (buffer, timeout.tv_sec + (timeout.tv_nsec != 0)); + } } -static int is_all_whitespace(const char *p) { - while (*p == ' ') p++; +static int +is_all_whitespace (const char *p) +{ + while (*p == ' ') + p++; return *p == 0; } -int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout) { +int +grpc_chttp2_decode_timeout (const char *buffer, gpr_timespec * timeout) +{ gpr_uint32 x = 0; - const gpr_uint8 *p = (const gpr_uint8 *)buffer; + const gpr_uint8 *p = (const gpr_uint8 *) buffer; int have_digit = 0; /* skip whitespace */ for (; *p == ' '; p++) ; /* decode numeric part */ - for (; *p >= '0' && *p <= '9'; p++) { - gpr_uint32 xp = x * 10u + (gpr_uint32)*p - (gpr_uint32)'0'; - have_digit = 1; - if (xp < x) { - *timeout = gpr_inf_future(GPR_CLOCK_REALTIME); - return 1; - } - x = xp; - } - if (!have_digit) return 0; + for (; *p >= '0' && *p <= '9'; p++) + { + gpr_uint32 xp = x * 10u + (gpr_uint32) * p - (gpr_uint32) '0'; + have_digit = 1; + if (xp < x) + { + *timeout = gpr_inf_future (GPR_CLOCK_REALTIME); + return 1; + } + x = xp; + } + if (!have_digit) + return 0; /* skip whitespace */ for (; *p == ' '; p++) ; /* decode unit specifier */ - switch (*p) { + switch (*p) + { case 'n': - *timeout = gpr_time_from_nanos(x, GPR_TIMESPAN); + *timeout = gpr_time_from_nanos (x, GPR_TIMESPAN); break; case 'u': - *timeout = gpr_time_from_micros(x, GPR_TIMESPAN); + *timeout = gpr_time_from_micros (x, GPR_TIMESPAN); break; case 'm': - *timeout = gpr_time_from_millis(x, GPR_TIMESPAN); + *timeout = gpr_time_from_millis (x, GPR_TIMESPAN); break; case 'S': - *timeout = gpr_time_from_seconds(x, GPR_TIMESPAN); + *timeout = gpr_time_from_seconds (x, GPR_TIMESPAN); break; case 'M': - *timeout = gpr_time_from_minutes(x, GPR_TIMESPAN); + *timeout = gpr_time_from_minutes (x, GPR_TIMESPAN); break; case 'H': - *timeout = gpr_time_from_hours(x, GPR_TIMESPAN); + *timeout = gpr_time_from_hours (x, GPR_TIMESPAN); break; default: return 0; - } + } p++; - return is_all_whitespace((const char *)p); + return is_all_whitespace ((const char *) p); } diff --git a/src/core/transport/chttp2/timeout_encoding.h b/src/core/transport/chttp2/timeout_encoding.h index 9d8756e799..b68ce2e5d6 100644 --- a/src/core/transport/chttp2/timeout_encoding.h +++ b/src/core/transport/chttp2/timeout_encoding.h @@ -41,7 +41,7 @@ /* Encode/decode timeouts to the GRPC over HTTP2 format; encoding may round up arbitrarily */ -void grpc_chttp2_encode_timeout(gpr_timespec timeout, char *buffer); -int grpc_chttp2_decode_timeout(const char *buffer, gpr_timespec *timeout); +void grpc_chttp2_encode_timeout (gpr_timespec timeout, char *buffer); +int grpc_chttp2_decode_timeout (const char *buffer, gpr_timespec * timeout); #endif /* GRPC_INTERNAL_CORE_TRANSPORT_CHTTP2_TIMEOUT_ENCODING_H */ diff --git a/src/core/transport/chttp2/varint.c b/src/core/transport/chttp2/varint.c index 056f68047b..f478a9d847 100644 --- a/src/core/transport/chttp2/varint.c +++ b/src/core/transport/chttp2/varint.c @@ -33,34 +33,46 @@ #include "src/core/transport/chttp2/varint.h" -gpr_uint32 grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value) { - if (tail_value < (1 << 7)) { - return 2; - } else if (tail_value < (1 << 14)) { - return 3; - } else if (tail_value < (1 << 21)) { - return 4; - } else if (tail_value < (1 << 28)) { - return 5; - } else { - return 6; - } +gpr_uint32 +grpc_chttp2_hpack_varint_length (gpr_uint32 tail_value) +{ + if (tail_value < (1 << 7)) + { + return 2; + } + else if (tail_value < (1 << 14)) + { + return 3; + } + else if (tail_value < (1 << 21)) + { + return 4; + } + else if (tail_value < (1 << 28)) + { + return 5; + } + else + { + return 6; + } } -void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value, - gpr_uint8* target, - gpr_uint32 tail_length) { - switch (tail_length) { +void +grpc_chttp2_hpack_write_varint_tail (gpr_uint32 tail_value, gpr_uint8 * target, gpr_uint32 tail_length) +{ + switch (tail_length) + { case 5: - target[4] = (gpr_uint8)((tail_value >> 28) | 0x80); + target[4] = (gpr_uint8) ((tail_value >> 28) | 0x80); case 4: - target[3] = (gpr_uint8)((tail_value >> 21) | 0x80); + target[3] = (gpr_uint8) ((tail_value >> 21) | 0x80); case 3: - target[2] = (gpr_uint8)((tail_value >> 14) | 0x80); + target[2] = (gpr_uint8) ((tail_value >> 14) | 0x80); case 2: - target[1] = (gpr_uint8)((tail_value >> 7) | 0x80); + target[1] = (gpr_uint8) ((tail_value >> 7) | 0x80); case 1: - target[0] = (gpr_uint8)((tail_value) | 0x80); - } + target[0] = (gpr_uint8) ((tail_value) | 0x80); + } target[tail_length - 1] &= 0x7f; } diff --git a/src/core/transport/chttp2/varint.h b/src/core/transport/chttp2/varint.h index 4dfcc76773..4193305d0f 100644 --- a/src/core/transport/chttp2/varint.h +++ b/src/core/transport/chttp2/varint.h @@ -41,11 +41,9 @@ /* length of a value that needs varint tail encoding (it's bigger than can be bitpacked into the opcode byte) - returned value includes the length of the opcode byte */ -gpr_uint32 grpc_chttp2_hpack_varint_length(gpr_uint32 tail_value); +gpr_uint32 grpc_chttp2_hpack_varint_length (gpr_uint32 tail_value); -void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value, - gpr_uint8* target, - gpr_uint32 tail_length); +void grpc_chttp2_hpack_write_varint_tail (gpr_uint32 tail_value, gpr_uint8 * target, gpr_uint32 tail_length); /* maximum value that can be bitpacked with the opcode if the opcode has a prefix diff --git a/src/core/transport/chttp2/writing.c b/src/core/transport/chttp2/writing.c index e6f169c280..edf40f54fb 100644 --- a/src/core/transport/chttp2/writing.c +++ b/src/core/transport/chttp2/writing.c @@ -39,205 +39,174 @@ #include "src/core/transport/chttp2/http2_errors.h" -static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing); +static void finalize_outbuf (grpc_chttp2_transport_writing * transport_writing); -int grpc_chttp2_unlocking_check_writes( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_writing *transport_writing) { +int +grpc_chttp2_unlocking_check_writes (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing) +{ grpc_chttp2_stream_global *stream_global; grpc_chttp2_stream_writing *stream_writing; grpc_chttp2_stream_global *first_reinserted_stream = NULL; gpr_uint32 window_delta; /* simple writes are queued to qbuf, and flushed here */ - gpr_slice_buffer_swap(&transport_global->qbuf, &transport_writing->outbuf); - GPR_ASSERT(transport_global->qbuf.count == 0); - - if (transport_global->dirtied_local_settings && - !transport_global->sent_local_settings) { - gpr_slice_buffer_add( - &transport_writing->outbuf, - grpc_chttp2_settings_create( - transport_global->settings[GRPC_SENT_SETTINGS], - transport_global->settings[GRPC_LOCAL_SETTINGS], - transport_global->force_send_settings, GRPC_CHTTP2_NUM_SETTINGS)); - transport_global->force_send_settings = 0; - transport_global->dirtied_local_settings = 0; - transport_global->sent_local_settings = 1; - } + gpr_slice_buffer_swap (&transport_global->qbuf, &transport_writing->outbuf); + GPR_ASSERT (transport_global->qbuf.count == 0); + + if (transport_global->dirtied_local_settings && !transport_global->sent_local_settings) + { + gpr_slice_buffer_add (&transport_writing->outbuf, grpc_chttp2_settings_create (transport_global->settings[GRPC_SENT_SETTINGS], transport_global->settings[GRPC_LOCAL_SETTINGS], transport_global->force_send_settings, GRPC_CHTTP2_NUM_SETTINGS)); + transport_global->force_send_settings = 0; + transport_global->dirtied_local_settings = 0; + transport_global->sent_local_settings = 1; + } /* for each grpc_chttp2_stream that's become writable, frame it's data (according to available window sizes) and add to the output buffer */ - while (grpc_chttp2_list_pop_writable_stream( - transport_global, transport_writing, &stream_global, &stream_writing)) { - if (stream_global == first_reinserted_stream) { - /* prevent infinite loop */ - grpc_chttp2_list_add_first_writable_stream(transport_global, - stream_global); - break; - } - - stream_writing->id = stream_global->id; - stream_writing->send_closed = GRPC_DONT_SEND_CLOSED; - - if (stream_global->outgoing_sopb) { - window_delta = grpc_chttp2_preencode( - stream_global->outgoing_sopb->ops, - &stream_global->outgoing_sopb->nops, - (gpr_uint32)GPR_MIN(GPR_MIN(transport_global->outgoing_window, - stream_global->outgoing_window), - GPR_UINT32_MAX), - &stream_writing->sopb); - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT( - "write", transport_global, outgoing_window, -(gpr_int64)window_delta); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM("write", transport_global, stream_global, - outgoing_window, - -(gpr_int64)window_delta); - transport_global->outgoing_window -= window_delta; - stream_global->outgoing_window -= window_delta; - - if (stream_global->write_state == GRPC_WRITE_STATE_QUEUED_CLOSE && - stream_global->outgoing_sopb->nops == 0) { - if (!transport_global->is_client && !stream_global->read_closed) { - stream_writing->send_closed = GRPC_SEND_CLOSED_WITH_RST_STREAM; - } else { - stream_writing->send_closed = GRPC_SEND_CLOSED; - } - } - - if (stream_global->outgoing_window > 0 && - stream_global->outgoing_sopb->nops != 0) { - grpc_chttp2_list_add_writable_stream(transport_global, stream_global); - if (first_reinserted_stream == NULL && - transport_global->outgoing_window == 0) { - first_reinserted_stream = stream_global; - } - } - } - - if (!stream_global->read_closed && - stream_global->unannounced_incoming_window > 0) { - GPR_ASSERT(stream_writing->announce_window == 0); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "write", transport_writing, stream_writing, announce_window, - stream_global->unannounced_incoming_window); - stream_writing->announce_window = - stream_global->unannounced_incoming_window; - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "write", transport_global, stream_global, incoming_window, - stream_global->unannounced_incoming_window); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "write", transport_global, stream_global, unannounced_incoming_window, - -(gpr_int64)stream_global->unannounced_incoming_window); - stream_global->incoming_window += - stream_global->unannounced_incoming_window; - stream_global->unannounced_incoming_window = 0; - grpc_chttp2_list_add_incoming_window_updated(transport_global, - stream_global); - stream_global->writing_now |= GRPC_CHTTP2_WRITING_WINDOW; - } - if (stream_writing->sopb.nops > 0 || - stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) { - stream_global->writing_now |= GRPC_CHTTP2_WRITING_DATA; + while (grpc_chttp2_list_pop_writable_stream (transport_global, transport_writing, &stream_global, &stream_writing)) + { + if (stream_global == first_reinserted_stream) + { + /* prevent infinite loop */ + grpc_chttp2_list_add_first_writable_stream (transport_global, stream_global); + break; + } + + stream_writing->id = stream_global->id; + stream_writing->send_closed = GRPC_DONT_SEND_CLOSED; + + if (stream_global->outgoing_sopb) + { + window_delta = grpc_chttp2_preencode (stream_global->outgoing_sopb->ops, &stream_global->outgoing_sopb->nops, (gpr_uint32) GPR_MIN (GPR_MIN (transport_global->outgoing_window, stream_global->outgoing_window), GPR_UINT32_MAX), &stream_writing->sopb); + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("write", transport_global, outgoing_window, -(gpr_int64) window_delta); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_global, stream_global, outgoing_window, -(gpr_int64) window_delta); + transport_global->outgoing_window -= window_delta; + stream_global->outgoing_window -= window_delta; + + if (stream_global->write_state == GRPC_WRITE_STATE_QUEUED_CLOSE && stream_global->outgoing_sopb->nops == 0) + { + if (!transport_global->is_client && !stream_global->read_closed) + { + stream_writing->send_closed = GRPC_SEND_CLOSED_WITH_RST_STREAM; + } + else + { + stream_writing->send_closed = GRPC_SEND_CLOSED; + } + } + + if (stream_global->outgoing_window > 0 && stream_global->outgoing_sopb->nops != 0) + { + grpc_chttp2_list_add_writable_stream (transport_global, stream_global); + if (first_reinserted_stream == NULL && transport_global->outgoing_window == 0) + { + first_reinserted_stream = stream_global; + } + } + } + + if (!stream_global->read_closed && stream_global->unannounced_incoming_window > 0) + { + GPR_ASSERT (stream_writing->announce_window == 0); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_writing, stream_writing, announce_window, stream_global->unannounced_incoming_window); + stream_writing->announce_window = stream_global->unannounced_incoming_window; + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_global, stream_global, incoming_window, stream_global->unannounced_incoming_window); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_global, stream_global, unannounced_incoming_window, -(gpr_int64) stream_global->unannounced_incoming_window); + stream_global->incoming_window += stream_global->unannounced_incoming_window; + stream_global->unannounced_incoming_window = 0; + grpc_chttp2_list_add_incoming_window_updated (transport_global, stream_global); + stream_global->writing_now |= GRPC_CHTTP2_WRITING_WINDOW; + } + if (stream_writing->sopb.nops > 0 || stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) + { + stream_global->writing_now |= GRPC_CHTTP2_WRITING_DATA; + } + if (stream_global->writing_now != 0) + { + grpc_chttp2_list_add_writing_stream (transport_writing, stream_writing); + } } - if (stream_global->writing_now != 0) { - grpc_chttp2_list_add_writing_stream(transport_writing, stream_writing); - } - } /* if the grpc_chttp2_transport is ready to send a window update, do so here also; 3/4 is a magic number that will likely get tuned soon */ - if (transport_global->incoming_window < - transport_global->connection_window_target * 3 / 4) { - window_delta = transport_global->connection_window_target - - transport_global->incoming_window; - gpr_slice_buffer_add(&transport_writing->outbuf, - grpc_chttp2_window_update_create(0, window_delta)); - GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT("write", transport_global, - incoming_window, window_delta); - transport_global->incoming_window += window_delta; - } - - return transport_writing->outbuf.count > 0 || - grpc_chttp2_list_have_writing_streams(transport_writing); + if (transport_global->incoming_window < transport_global->connection_window_target * 3 / 4) + { + window_delta = transport_global->connection_window_target - transport_global->incoming_window; + gpr_slice_buffer_add (&transport_writing->outbuf, grpc_chttp2_window_update_create (0, window_delta)); + GRPC_CHTTP2_FLOWCTL_TRACE_TRANSPORT ("write", transport_global, incoming_window, window_delta); + transport_global->incoming_window += window_delta; + } + + return transport_writing->outbuf.count > 0 || grpc_chttp2_list_have_writing_streams (transport_writing); } -void grpc_chttp2_perform_writes( - grpc_chttp2_transport_writing *transport_writing, grpc_endpoint *endpoint, - grpc_closure_list *closure_list) { - GPR_ASSERT(transport_writing->outbuf.count > 0 || - grpc_chttp2_list_have_writing_streams(transport_writing)); +void +grpc_chttp2_perform_writes (grpc_chttp2_transport_writing * transport_writing, grpc_endpoint * endpoint, grpc_closure_list * closure_list) +{ + GPR_ASSERT (transport_writing->outbuf.count > 0 || grpc_chttp2_list_have_writing_streams (transport_writing)); - finalize_outbuf(transport_writing); + finalize_outbuf (transport_writing); - GPR_ASSERT(transport_writing->outbuf.count > 0); - GPR_ASSERT(endpoint); + GPR_ASSERT (transport_writing->outbuf.count > 0); + GPR_ASSERT (endpoint); - grpc_endpoint_write(endpoint, &transport_writing->outbuf, - &transport_writing->done_cb, closure_list); + grpc_endpoint_write (endpoint, &transport_writing->outbuf, &transport_writing->done_cb, closure_list); } -static void finalize_outbuf(grpc_chttp2_transport_writing *transport_writing) { +static void +finalize_outbuf (grpc_chttp2_transport_writing * transport_writing) +{ grpc_chttp2_stream_writing *stream_writing; - while ( - grpc_chttp2_list_pop_writing_stream(transport_writing, &stream_writing)) { - if (stream_writing->sopb.nops > 0 || - stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) { - grpc_chttp2_encode(stream_writing->sopb.ops, stream_writing->sopb.nops, - stream_writing->send_closed != GRPC_DONT_SEND_CLOSED, - stream_writing->id, - &transport_writing->hpack_compressor, - &transport_writing->outbuf); - stream_writing->sopb.nops = 0; + while (grpc_chttp2_list_pop_writing_stream (transport_writing, &stream_writing)) + { + if (stream_writing->sopb.nops > 0 || stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) + { + grpc_chttp2_encode (stream_writing->sopb.ops, stream_writing->sopb.nops, stream_writing->send_closed != GRPC_DONT_SEND_CLOSED, stream_writing->id, &transport_writing->hpack_compressor, &transport_writing->outbuf); + stream_writing->sopb.nops = 0; + } + if (stream_writing->announce_window > 0) + { + gpr_slice_buffer_add (&transport_writing->outbuf, grpc_chttp2_window_update_create (stream_writing->id, stream_writing->announce_window)); + GRPC_CHTTP2_FLOWCTL_TRACE_STREAM ("write", transport_writing, stream_writing, announce_window, -(gpr_int64) stream_writing->announce_window); + stream_writing->announce_window = 0; + } + if (stream_writing->send_closed == GRPC_SEND_CLOSED_WITH_RST_STREAM) + { + gpr_slice_buffer_add (&transport_writing->outbuf, grpc_chttp2_rst_stream_create (stream_writing->id, GRPC_CHTTP2_NO_ERROR)); + } + grpc_chttp2_list_add_written_stream (transport_writing, stream_writing); } - if (stream_writing->announce_window > 0) { - gpr_slice_buffer_add( - &transport_writing->outbuf, - grpc_chttp2_window_update_create(stream_writing->id, - stream_writing->announce_window)); - GRPC_CHTTP2_FLOWCTL_TRACE_STREAM( - "write", transport_writing, stream_writing, announce_window, - -(gpr_int64)stream_writing->announce_window); - stream_writing->announce_window = 0; - } - if (stream_writing->send_closed == GRPC_SEND_CLOSED_WITH_RST_STREAM) { - gpr_slice_buffer_add(&transport_writing->outbuf, - grpc_chttp2_rst_stream_create(stream_writing->id, - GRPC_CHTTP2_NO_ERROR)); - } - grpc_chttp2_list_add_written_stream(transport_writing, stream_writing); - } } -void grpc_chttp2_cleanup_writing( - grpc_chttp2_transport_global *transport_global, - grpc_chttp2_transport_writing *transport_writing, - grpc_closure_list *closure_list) { +void +grpc_chttp2_cleanup_writing (grpc_chttp2_transport_global * transport_global, grpc_chttp2_transport_writing * transport_writing, grpc_closure_list * closure_list) +{ grpc_chttp2_stream_writing *stream_writing; grpc_chttp2_stream_global *stream_global; - while (grpc_chttp2_list_pop_written_stream( - transport_global, transport_writing, &stream_global, &stream_writing)) { - GPR_ASSERT(stream_global->writing_now != 0); - if (stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) { - stream_global->write_state = GRPC_WRITE_STATE_SENT_CLOSE; - if (!transport_global->is_client) { - stream_global->read_closed = 1; - } - } - if (stream_global->writing_now & GRPC_CHTTP2_WRITING_DATA) { - if (stream_global->outgoing_sopb != NULL && - stream_global->outgoing_sopb->nops == 0) { - GPR_ASSERT(stream_global->write_state != GRPC_WRITE_STATE_QUEUED_CLOSE); - stream_global->outgoing_sopb = NULL; - grpc_closure_list_add(closure_list, stream_global->send_done_closure, - 1); - } + while (grpc_chttp2_list_pop_written_stream (transport_global, transport_writing, &stream_global, &stream_writing)) + { + GPR_ASSERT (stream_global->writing_now != 0); + if (stream_writing->send_closed != GRPC_DONT_SEND_CLOSED) + { + stream_global->write_state = GRPC_WRITE_STATE_SENT_CLOSE; + if (!transport_global->is_client) + { + stream_global->read_closed = 1; + } + } + if (stream_global->writing_now & GRPC_CHTTP2_WRITING_DATA) + { + if (stream_global->outgoing_sopb != NULL && stream_global->outgoing_sopb->nops == 0) + { + GPR_ASSERT (stream_global->write_state != GRPC_WRITE_STATE_QUEUED_CLOSE); + stream_global->outgoing_sopb = NULL; + grpc_closure_list_add (closure_list, stream_global->send_done_closure, 1); + } + } + stream_global->writing_now = 0; + grpc_chttp2_list_add_read_write_state_changed (transport_global, stream_global); } - stream_global->writing_now = 0; - grpc_chttp2_list_add_read_write_state_changed(transport_global, - stream_global); - } - gpr_slice_buffer_reset_and_unref(&transport_writing->outbuf); + gpr_slice_buffer_reset_and_unref (&transport_writing->outbuf); } |