grpc 1.21.0 → 1.22.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +422 -62
  3. data/include/grpc/grpc_security.h +61 -5
  4. data/include/grpc/grpc_security_constants.h +1 -1
  5. data/include/grpc/impl/codegen/gpr_types.h +1 -1
  6. data/include/grpc/slice.h +2 -2
  7. data/src/core/ext/filters/client_channel/backup_poller.cc +2 -3
  8. data/src/core/ext/filters/client_channel/backup_poller.h +5 -2
  9. data/src/core/ext/filters/client_channel/client_channel.cc +260 -122
  10. data/src/core/ext/filters/client_channel/client_channel.h +0 -8
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +3 -84
  12. data/src/core/ext/filters/client_channel/client_channel_channelz.h +2 -28
  13. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +2 -8
  14. data/src/core/ext/filters/client_channel/health/health_check_client.cc +5 -4
  15. data/src/core/ext/filters/client_channel/lb_policy.cc +16 -2
  16. data/src/core/ext/filters/client_channel/lb_policy.h +92 -98
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +63 -87
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +6 -2
  19. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +35 -87
  20. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +18 -74
  21. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +167 -217
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +216 -190
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +6 -2
  24. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +1 -1
  26. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  27. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +6 -3
  29. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -1
  30. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -0
  31. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +8 -8
  32. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +7 -7
  33. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +28 -64
  34. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +4 -12
  35. data/src/core/ext/filters/client_channel/server_address.cc +4 -6
  36. data/src/core/ext/filters/client_channel/server_address.h +1 -3
  37. data/src/core/ext/filters/client_channel/service_config.cc +20 -22
  38. data/src/core/ext/filters/client_channel/service_config.h +26 -28
  39. data/src/core/ext/filters/client_channel/subchannel.cc +261 -160
  40. data/src/core/ext/filters/client_channel/subchannel.h +97 -23
  41. data/src/core/ext/filters/client_channel/subchannel_interface.h +113 -0
  42. data/src/core/ext/filters/message_size/message_size_filter.cc +12 -12
  43. data/src/core/ext/filters/message_size/message_size_filter.h +2 -2
  44. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +50 -2
  45. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
  46. data/src/core/ext/transport/chttp2/transport/frame_data.cc +31 -36
  47. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +3 -2
  48. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +71 -52
  49. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +18 -3
  50. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +5 -12
  51. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -1
  52. data/src/core/ext/transport/chttp2/transport/internal.h +3 -3
  53. data/src/core/ext/transport/chttp2/transport/parsing.cc +39 -57
  54. data/src/core/lib/channel/channelz.cc +136 -19
  55. data/src/core/lib/channel/channelz.h +36 -40
  56. data/src/core/lib/channel/channelz_registry.cc +74 -106
  57. data/src/core/lib/channel/channelz_registry.h +10 -28
  58. data/src/core/lib/channel/context.h +1 -1
  59. data/src/core/lib/channel/handshaker.cc +6 -0
  60. data/src/core/lib/compression/compression.cc +13 -8
  61. data/src/core/lib/compression/compression_internal.cc +14 -10
  62. data/src/core/lib/compression/compression_internal.h +1 -1
  63. data/src/core/lib/compression/stream_compression.cc +3 -2
  64. data/src/core/lib/compression/stream_compression.h +2 -2
  65. data/src/core/lib/compression/stream_compression_gzip.cc +9 -9
  66. data/src/core/lib/gpr/env.h +1 -1
  67. data/src/core/lib/gpr/string.cc +8 -1
  68. data/src/core/lib/gpr/string.h +6 -1
  69. data/src/core/lib/gprpp/fork.cc +1 -1
  70. data/src/core/lib/gprpp/fork.h +5 -1
  71. data/src/core/lib/gprpp/global_config.h +9 -0
  72. data/src/core/lib/gprpp/global_config_custom.h +1 -1
  73. data/src/core/lib/gprpp/inlined_vector.h +8 -0
  74. data/src/core/lib/gprpp/map.h +38 -21
  75. data/src/core/lib/gprpp/memory.h +2 -2
  76. data/src/core/lib/gprpp/orphanable.h +1 -1
  77. data/src/core/lib/gprpp/ref_counted.h +9 -4
  78. data/src/core/lib/http/httpcli.cc +3 -3
  79. data/src/core/lib/iomgr/buffer_list.h +1 -1
  80. data/src/core/lib/iomgr/call_combiner.cc +1 -1
  81. data/src/core/lib/iomgr/call_combiner.h +1 -1
  82. data/src/core/lib/iomgr/cfstream_handle.cc +3 -2
  83. data/src/core/lib/iomgr/cfstream_handle.h +4 -0
  84. data/src/core/lib/iomgr/error.cc +3 -3
  85. data/src/core/lib/iomgr/error.h +9 -3
  86. data/src/core/lib/iomgr/error_internal.h +1 -1
  87. data/src/core/lib/iomgr/ev_epoll1_linux.cc +1 -1
  88. data/src/core/lib/iomgr/ev_posix.cc +3 -3
  89. data/src/core/lib/iomgr/ev_posix.h +3 -2
  90. data/src/core/lib/iomgr/ev_windows.cc +2 -2
  91. data/src/core/lib/iomgr/iomgr.cc +4 -4
  92. data/src/core/lib/iomgr/lockfree_event.cc +1 -1
  93. data/src/core/lib/iomgr/port.h +5 -1
  94. data/src/core/lib/iomgr/tcp_posix.cc +1 -3
  95. data/src/core/lib/iomgr/tcp_server.cc +5 -0
  96. data/src/core/lib/iomgr/tcp_server.h +24 -0
  97. data/src/core/lib/iomgr/tcp_server_custom.cc +11 -9
  98. data/src/core/lib/iomgr/tcp_server_posix.cc +72 -11
  99. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  100. data/src/core/lib/iomgr/tcp_server_windows.cc +11 -9
  101. data/src/core/lib/iomgr/tcp_uv.cc +5 -6
  102. data/src/core/lib/iomgr/timer.h +2 -1
  103. data/src/core/lib/iomgr/udp_server.cc +2 -2
  104. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -1
  105. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +20 -2
  106. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +2 -2
  107. data/src/core/lib/security/security_connector/security_connector.h +1 -1
  108. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +1 -1
  109. data/src/core/lib/security/transport/auth_filters.h +3 -0
  110. data/src/core/lib/security/transport/client_auth_filter.cc +13 -0
  111. data/src/core/lib/security/transport/security_handshaker.cc +7 -7
  112. data/src/core/lib/slice/b64.h +2 -2
  113. data/src/core/lib/slice/slice.cc +82 -10
  114. data/src/core/lib/slice/slice_buffer.cc +49 -21
  115. data/src/core/lib/slice/slice_hash_table.h +2 -2
  116. data/src/core/lib/slice/slice_intern.cc +15 -16
  117. data/src/core/lib/slice/slice_internal.h +52 -0
  118. data/src/core/lib/slice/slice_string_helpers.cc +10 -1
  119. data/src/core/lib/slice/slice_string_helpers.h +3 -1
  120. data/src/core/lib/slice/slice_utils.h +50 -0
  121. data/src/core/lib/slice/slice_weak_hash_table.h +2 -2
  122. data/src/core/lib/surface/call.cc +14 -8
  123. data/src/core/lib/surface/channel.cc +89 -97
  124. data/src/core/lib/surface/channel.h +60 -6
  125. data/src/core/lib/surface/completion_queue.cc +49 -36
  126. data/src/core/lib/surface/completion_queue.h +2 -1
  127. data/src/core/lib/surface/server.cc +8 -8
  128. data/src/core/lib/surface/validate_metadata.cc +14 -8
  129. data/src/core/lib/surface/validate_metadata.h +13 -2
  130. data/src/core/lib/surface/version.cc +1 -1
  131. data/src/core/lib/transport/metadata.cc +56 -26
  132. data/src/core/lib/transport/metadata.h +91 -75
  133. data/src/core/lib/transport/static_metadata.cc +262 -176
  134. data/src/core/lib/transport/static_metadata.h +272 -180
  135. data/src/core/lib/transport/transport.cc +1 -1
  136. data/src/core/lib/transport/transport.h +8 -2
  137. data/src/core/tsi/alts/handshaker/alts_shared_resource.h +1 -1
  138. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +5 -2
  140. data/src/ruby/lib/grpc/version.rb +1 -1
  141. metadata +37 -35
@@ -1720,7 +1720,7 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs,
1720
1720
  }
1721
1721
 
1722
1722
  static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error) {
1723
- /* callback remaining pings: they're not allowed to call into the transpot,
1723
+ /* callback remaining pings: they're not allowed to call into the transport,
1724
1724
  and maybe they hold resources that need to be freed */
1725
1725
  grpc_chttp2_ping_queue* pq = &t->ping_queue;
1726
1726
  GPR_ASSERT(error != GRPC_ERROR_NONE);
@@ -2262,7 +2262,7 @@ void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t,
2262
2262
  if (closed_read) {
2263
2263
  for (int i = 0; i < 2; i++) {
2264
2264
  if (s->published_metadata[i] == GRPC_METADATA_NOT_PUBLISHED) {
2265
- s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE;
2265
+ s->published_metadata[i] = GRPC_METADATA_PUBLISHED_AT_CLOSE;
2266
2266
  }
2267
2267
  }
2268
2268
  grpc_chttp2_maybe_complete_recv_initial_metadata(t, s);
@@ -104,23 +104,21 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
104
104
  uint8_t* end = nullptr;
105
105
  uint8_t* cur = nullptr;
106
106
 
107
- grpc_slice slice = grpc_slice_buffer_take_first(slices);
108
-
109
- beg = GRPC_SLICE_START_PTR(slice);
110
- end = GRPC_SLICE_END_PTR(slice);
107
+ grpc_slice* slice = grpc_slice_buffer_peek_first(slices);
108
+ beg = GRPC_SLICE_START_PTR(*slice);
109
+ end = GRPC_SLICE_END_PTR(*slice);
111
110
  cur = beg;
112
111
  uint32_t message_flags;
113
- char* msg;
114
112
 
115
113
  if (cur == end) {
116
- grpc_slice_unref_internal(slice);
114
+ grpc_slice_buffer_remove_first(slices);
117
115
  continue;
118
116
  }
119
117
 
120
118
  switch (p->state) {
121
119
  case GRPC_CHTTP2_DATA_ERROR:
122
120
  p->state = GRPC_CHTTP2_DATA_ERROR;
123
- grpc_slice_unref_internal(slice);
121
+ grpc_slice_buffer_remove_first(slices);
124
122
  return GRPC_ERROR_REF(p->error);
125
123
  case GRPC_CHTTP2_DATA_FH_0:
126
124
  s->stats.incoming.framing_bytes++;
@@ -133,24 +131,25 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
133
131
  p->is_frame_compressed = true; /* GPR_TRUE */
134
132
  break;
135
133
  default:
134
+ char* msg;
136
135
  gpr_asprintf(&msg, "Bad GRPC frame type 0x%02x", p->frame_type);
137
136
  p->error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
138
137
  p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_STREAM_ID,
139
138
  static_cast<intptr_t>(s->id));
140
139
  gpr_free(msg);
141
- msg = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
142
- p->error = grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES,
143
- grpc_slice_from_copied_string(msg));
144
- gpr_free(msg);
140
+ p->error =
141
+ grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES,
142
+ grpc_dump_slice_to_slice(
143
+ *slice, GPR_DUMP_HEX | GPR_DUMP_ASCII));
145
144
  p->error =
146
145
  grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg);
147
146
  p->state = GRPC_CHTTP2_DATA_ERROR;
148
- grpc_slice_unref_internal(slice);
147
+ grpc_slice_buffer_remove_first(slices);
149
148
  return GRPC_ERROR_REF(p->error);
150
149
  }
151
150
  if (++cur == end) {
152
151
  p->state = GRPC_CHTTP2_DATA_FH_1;
153
- grpc_slice_unref_internal(slice);
152
+ grpc_slice_buffer_remove_first(slices);
154
153
  continue;
155
154
  }
156
155
  /* fallthrough */
@@ -159,7 +158,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
159
158
  p->frame_size = (static_cast<uint32_t>(*cur)) << 24;
160
159
  if (++cur == end) {
161
160
  p->state = GRPC_CHTTP2_DATA_FH_2;
162
- grpc_slice_unref_internal(slice);
161
+ grpc_slice_buffer_remove_first(slices);
163
162
  continue;
164
163
  }
165
164
  /* fallthrough */
@@ -168,7 +167,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
168
167
  p->frame_size |= (static_cast<uint32_t>(*cur)) << 16;
169
168
  if (++cur == end) {
170
169
  p->state = GRPC_CHTTP2_DATA_FH_3;
171
- grpc_slice_unref_internal(slice);
170
+ grpc_slice_buffer_remove_first(slices);
172
171
  continue;
173
172
  }
174
173
  /* fallthrough */
@@ -177,7 +176,7 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
177
176
  p->frame_size |= (static_cast<uint32_t>(*cur)) << 8;
178
177
  if (++cur == end) {
179
178
  p->state = GRPC_CHTTP2_DATA_FH_4;
180
- grpc_slice_unref_internal(slice);
179
+ grpc_slice_buffer_remove_first(slices);
181
180
  continue;
182
181
  }
183
182
  /* fallthrough */
@@ -204,19 +203,18 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
204
203
  p->state = GRPC_CHTTP2_DATA_FH_0;
205
204
  }
206
205
  s->pending_byte_stream = true;
207
-
208
206
  if (cur != end) {
209
- grpc_slice_buffer_undo_take_first(
210
- slices, grpc_slice_sub(slice, static_cast<size_t>(cur - beg),
211
- static_cast<size_t>(end - beg)));
207
+ grpc_slice_buffer_sub_first(slices, static_cast<size_t>(cur - beg),
208
+ static_cast<size_t>(end - beg));
209
+ } else {
210
+ grpc_slice_buffer_remove_first(slices);
212
211
  }
213
- grpc_slice_unref_internal(slice);
214
212
  return GRPC_ERROR_NONE;
215
213
  case GRPC_CHTTP2_DATA_FRAME: {
216
214
  GPR_ASSERT(p->parsing_frame != nullptr);
217
215
  GPR_ASSERT(slice_out != nullptr);
218
216
  if (cur == end) {
219
- grpc_slice_unref_internal(slice);
217
+ grpc_slice_buffer_remove_first(slices);
220
218
  continue;
221
219
  }
222
220
  uint32_t remaining = static_cast<uint32_t>(end - cur);
@@ -224,32 +222,32 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
224
222
  s->stats.incoming.data_bytes += remaining;
225
223
  if (GRPC_ERROR_NONE !=
226
224
  (error = p->parsing_frame->Push(
227
- grpc_slice_sub(slice, static_cast<size_t>(cur - beg),
225
+ grpc_slice_sub(*slice, static_cast<size_t>(cur - beg),
228
226
  static_cast<size_t>(end - beg)),
229
227
  slice_out))) {
230
- grpc_slice_unref_internal(slice);
228
+ grpc_slice_buffer_remove_first(slices);
231
229
  return error;
232
230
  }
233
231
  if (GRPC_ERROR_NONE !=
234
232
  (error = p->parsing_frame->Finished(GRPC_ERROR_NONE, true))) {
235
- grpc_slice_unref_internal(slice);
233
+ grpc_slice_buffer_remove_first(slices);
236
234
  return error;
237
235
  }
238
236
  p->parsing_frame = nullptr;
239
237
  p->state = GRPC_CHTTP2_DATA_FH_0;
240
- grpc_slice_unref_internal(slice);
238
+ grpc_slice_buffer_remove_first(slices);
241
239
  return GRPC_ERROR_NONE;
242
240
  } else if (remaining < p->frame_size) {
243
241
  s->stats.incoming.data_bytes += remaining;
244
242
  if (GRPC_ERROR_NONE !=
245
243
  (error = p->parsing_frame->Push(
246
- grpc_slice_sub(slice, static_cast<size_t>(cur - beg),
244
+ grpc_slice_sub(*slice, static_cast<size_t>(cur - beg),
247
245
  static_cast<size_t>(end - beg)),
248
246
  slice_out))) {
249
247
  return error;
250
248
  }
251
249
  p->frame_size -= remaining;
252
- grpc_slice_unref_internal(slice);
250
+ grpc_slice_buffer_remove_first(slices);
253
251
  return GRPC_ERROR_NONE;
254
252
  } else {
255
253
  GPR_ASSERT(remaining > p->frame_size);
@@ -257,30 +255,27 @@ grpc_error* grpc_deframe_unprocessed_incoming_frames(
257
255
  if (GRPC_ERROR_NONE !=
258
256
  p->parsing_frame->Push(
259
257
  grpc_slice_sub(
260
- slice, static_cast<size_t>(cur - beg),
258
+ *slice, static_cast<size_t>(cur - beg),
261
259
  static_cast<size_t>(cur + p->frame_size - beg)),
262
260
  slice_out)) {
263
- grpc_slice_unref_internal(slice);
261
+ grpc_slice_buffer_remove_first(slices);
264
262
  return error;
265
263
  }
266
264
  if (GRPC_ERROR_NONE !=
267
265
  (error = p->parsing_frame->Finished(GRPC_ERROR_NONE, true))) {
268
- grpc_slice_unref_internal(slice);
266
+ grpc_slice_buffer_remove_first(slices);
269
267
  return error;
270
268
  }
271
269
  p->parsing_frame = nullptr;
272
270
  p->state = GRPC_CHTTP2_DATA_FH_0;
273
271
  cur += p->frame_size;
274
- grpc_slice_buffer_undo_take_first(
275
- slices, grpc_slice_sub(slice, static_cast<size_t>(cur - beg),
276
- static_cast<size_t>(end - beg)));
277
- grpc_slice_unref_internal(slice);
272
+ grpc_slice_buffer_sub_first(slices, static_cast<size_t>(cur - beg),
273
+ static_cast<size_t>(end - beg));
278
274
  return GRPC_ERROR_NONE;
279
275
  }
280
276
  }
281
277
  }
282
278
  }
283
-
284
279
  return GRPC_ERROR_NONE;
285
280
  }
286
281
 
@@ -26,6 +26,7 @@
26
26
  #include <grpc/support/string_util.h>
27
27
 
28
28
  #include "src/core/ext/transport/chttp2/transport/frame.h"
29
+ #include "src/core/lib/gprpp/memory.h"
29
30
  #include "src/core/lib/transport/http2_errors.h"
30
31
 
31
32
  grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code,
@@ -102,9 +103,9 @@ grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser,
102
103
  error = grpc_error_set_int(
103
104
  grpc_error_set_str(GRPC_ERROR_CREATE_FROM_STATIC_STRING("RST_STREAM"),
104
105
  GRPC_ERROR_STR_GRPC_MESSAGE,
105
- grpc_slice_from_copied_string(message)),
106
+ grpc_slice_from_moved_string(
107
+ grpc_core::UniquePtr<char>(message))),
106
108
  GRPC_ERROR_INT_HTTP2_ERROR, static_cast<intptr_t>(reason));
107
- gpr_free(message);
108
109
  }
109
110
  grpc_chttp2_mark_stream_closed(t, s, true, true, error);
110
111
  }
@@ -37,6 +37,7 @@
37
37
  #include "src/core/lib/debug/stats.h"
38
38
  #include "src/core/lib/slice/slice_internal.h"
39
39
  #include "src/core/lib/slice/slice_string_helpers.h"
40
+ #include "src/core/lib/surface/validate_metadata.h"
40
41
  #include "src/core/lib/transport/metadata.h"
41
42
  #include "src/core/lib/transport/static_metadata.h"
42
43
  #include "src/core/lib/transport/timeout_encoding.h"
@@ -56,7 +57,10 @@
56
57
  /* don't consider adding anything bigger than this to the hpack table */
57
58
  #define MAX_DECODER_SPACE_USAGE 512
58
59
 
59
- static grpc_slice_refcount terminal_slice_refcount;
60
+ #define DATA_FRAME_HEADER_SIZE 9
61
+
62
+ static grpc_slice_refcount terminal_slice_refcount(
63
+ grpc_slice_refcount::Type::STATIC);
60
64
  static const grpc_slice terminal_slice = {
61
65
  &terminal_slice_refcount, /* refcount */
62
66
  {{0, nullptr}} /* data.refcounted */
@@ -80,7 +84,8 @@ typedef struct {
80
84
  bool use_true_binary_metadata;
81
85
  } framer_state;
82
86
 
83
- /* fills p (which is expected to be 9 bytes long) with a data frame header */
87
+ /* fills p (which is expected to be DATA_FRAME_HEADER_SIZE bytes long)
88
+ * with a data frame header */
84
89
  static void fill_header(uint8_t* p, uint8_t type, uint32_t id, size_t len,
85
90
  uint8_t flags) {
86
91
  GPR_ASSERT(len < 16777316);
@@ -107,15 +112,17 @@ static void finish_frame(framer_state* st, int is_header_boundary,
107
112
  static_cast<uint8_t>(
108
113
  (is_last_in_stream ? GRPC_CHTTP2_DATA_FLAG_END_STREAM : 0) |
109
114
  (is_header_boundary ? GRPC_CHTTP2_DATA_FLAG_END_HEADERS : 0)));
110
- st->stats->framing_bytes += 9;
115
+ st->stats->framing_bytes += DATA_FRAME_HEADER_SIZE;
111
116
  st->is_first_frame = 0;
112
117
  }
113
118
 
114
119
  /* begin a new frame: reserve off header space, remember how many bytes we'd
115
120
  output before beginning */
116
121
  static void begin_frame(framer_state* st) {
117
- st->header_idx =
118
- grpc_slice_buffer_add_indexed(st->output, GRPC_SLICE_MALLOC(9));
122
+ grpc_slice reserved;
123
+ reserved.refcount = nullptr;
124
+ reserved.data.inlined.length = DATA_FRAME_HEADER_SIZE;
125
+ st->header_idx = grpc_slice_buffer_add_indexed(st->output, reserved);
119
126
  st->output_length_at_start_of_frame = st->output->length;
120
127
  }
121
128
 
@@ -188,8 +195,9 @@ static void evict_entry(grpc_chttp2_hpack_compressor* c) {
188
195
  static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c,
189
196
  size_t elem_size) {
190
197
  uint32_t new_index = c->tail_remote_index + c->table_elems + 1;
191
- GPR_ASSERT(elem_size < 65536);
198
+ GPR_DEBUG_ASSERT(elem_size < 65536);
192
199
 
200
+ // TODO(arjunroy): Re-examine semantics
193
201
  if (elem_size > c->max_table_size) {
194
202
  while (c->table_size > 0) {
195
203
  evict_entry(c);
@@ -203,6 +211,7 @@ static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c,
203
211
  while (c->table_size + elem_size > c->max_table_size) {
204
212
  evict_entry(c);
205
213
  }
214
+ // TODO(arjunroy): Are we conflating size in bytes vs. membership?
206
215
  GPR_ASSERT(c->table_elems < c->max_table_size);
207
216
  c->table_elem_size[new_index % c->cap_table_elems] =
208
217
  static_cast<uint16_t>(elem_size);
@@ -215,19 +224,19 @@ static uint32_t prepare_space_for_new_elem(grpc_chttp2_hpack_compressor* c,
215
224
  // Add a key to the dynamic table. Both key and value will be added to table at
216
225
  // the decoder.
217
226
  static void add_key_with_index(grpc_chttp2_hpack_compressor* c,
218
- grpc_mdelem elem, uint32_t new_index) {
227
+ grpc_mdelem elem, uint32_t new_index,
228
+ uint32_t key_hash) {
219
229
  if (new_index == 0) {
220
230
  return;
221
231
  }
222
232
 
223
- uint32_t key_hash = grpc_slice_hash(GRPC_MDKEY(elem));
224
-
225
233
  /* Store the key into {entries,indices}_keys */
226
- if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_2(key_hash)],
227
- GRPC_MDKEY(elem))) {
234
+ if (grpc_slice_static_interned_equal(
235
+ c->entries_keys[HASH_FRAGMENT_2(key_hash)], GRPC_MDKEY(elem))) {
228
236
  c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index;
229
- } else if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_3(key_hash)],
230
- GRPC_MDKEY(elem))) {
237
+ } else if (grpc_slice_static_interned_equal(
238
+ c->entries_keys[HASH_FRAGMENT_3(key_hash)],
239
+ GRPC_MDKEY(elem))) {
231
240
  c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index;
232
241
  } else if (c->entries_keys[HASH_FRAGMENT_2(key_hash)].refcount ==
233
242
  &terminal_slice_refcount) {
@@ -255,22 +264,20 @@ static void add_key_with_index(grpc_chttp2_hpack_compressor* c,
255
264
 
256
265
  /* add an element to the decoder table */
257
266
  static void add_elem_with_index(grpc_chttp2_hpack_compressor* c,
258
- grpc_mdelem elem, uint32_t new_index) {
267
+ grpc_mdelem elem, uint32_t new_index,
268
+ uint32_t elem_hash, uint32_t key_hash) {
259
269
  if (new_index == 0) {
260
270
  return;
261
271
  }
262
- GPR_ASSERT(GRPC_MDELEM_IS_INTERNED(elem));
263
-
264
- uint32_t key_hash = grpc_slice_hash(GRPC_MDKEY(elem));
265
- uint32_t value_hash = grpc_slice_hash(GRPC_MDVALUE(elem));
266
- uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash);
272
+ GPR_DEBUG_ASSERT(GRPC_MDELEM_IS_INTERNED(elem));
267
273
 
268
274
  /* Store this element into {entries,indices}_elem */
269
- if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_2(elem_hash)], elem)) {
275
+ if (grpc_mdelem_both_interned_eq(c->entries_elems[HASH_FRAGMENT_2(elem_hash)],
276
+ elem)) {
270
277
  /* already there: update with new index */
271
278
  c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index;
272
- } else if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_3(elem_hash)],
273
- elem)) {
279
+ } else if (grpc_mdelem_both_interned_eq(
280
+ c->entries_elems[HASH_FRAGMENT_3(elem_hash)], elem)) {
274
281
  /* already there (cuckoo): update with new index */
275
282
  c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index;
276
283
  } else if (GRPC_MDISNULL(c->entries_elems[HASH_FRAGMENT_2(elem_hash)])) {
@@ -294,19 +301,19 @@ static void add_elem_with_index(grpc_chttp2_hpack_compressor* c,
294
301
  c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index;
295
302
  }
296
303
 
297
- add_key_with_index(c, elem, new_index);
304
+ add_key_with_index(c, elem, new_index, key_hash);
298
305
  }
299
306
 
300
307
  static void add_elem(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem,
301
- size_t elem_size) {
308
+ size_t elem_size, uint32_t elem_hash, uint32_t key_hash) {
302
309
  uint32_t new_index = prepare_space_for_new_elem(c, elem_size);
303
- add_elem_with_index(c, elem, new_index);
310
+ add_elem_with_index(c, elem, new_index, elem_hash, key_hash);
304
311
  }
305
312
 
306
313
  static void add_key(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem,
307
- size_t elem_size) {
314
+ size_t elem_size, uint32_t key_hash) {
308
315
  uint32_t new_index = prepare_space_for_new_elem(c, elem_size);
309
- add_key_with_index(c, elem, new_index);
316
+ add_key_with_index(c, elem, new_index, key_hash);
310
317
  }
311
318
 
312
319
  static void emit_indexed(grpc_chttp2_hpack_compressor* c, uint32_t elem_index,
@@ -323,9 +330,14 @@ typedef struct {
323
330
  bool insert_null_before_wire_value;
324
331
  } wire_value;
325
332
 
333
+ template <bool mdkey_definitely_interned>
326
334
  static wire_value get_wire_value(grpc_mdelem elem, bool true_binary_enabled) {
327
335
  wire_value wire_val;
328
- if (grpc_is_binary_header(GRPC_MDKEY(elem))) {
336
+ bool is_bin_hdr =
337
+ mdkey_definitely_interned
338
+ ? grpc_is_refcounted_slice_binary_header(GRPC_MDKEY(elem))
339
+ : grpc_is_binary_header_internal(GRPC_MDKEY(elem));
340
+ if (is_bin_hdr) {
329
341
  if (true_binary_enabled) {
330
342
  GRPC_STATS_INC_HPACK_SEND_BINARY();
331
343
  wire_val.huffman_prefix = 0x00;
@@ -363,7 +375,7 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor* c,
363
375
  framer_state* st) {
364
376
  GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX();
365
377
  uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2);
366
- wire_value value = get_wire_value(elem, st->use_true_binary_metadata);
378
+ wire_value value = get_wire_value<true>(elem, st->use_true_binary_metadata);
367
379
  size_t len_val = wire_value_length(value);
368
380
  uint32_t len_val_len;
369
381
  GPR_ASSERT(len_val <= UINT32_MAX);
@@ -380,7 +392,7 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor* c,
380
392
  framer_state* st) {
381
393
  GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX();
382
394
  uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4);
383
- wire_value value = get_wire_value(elem, st->use_true_binary_metadata);
395
+ wire_value value = get_wire_value<false>(elem, st->use_true_binary_metadata);
384
396
  size_t len_val = wire_value_length(value);
385
397
  uint32_t len_val_len;
386
398
  GPR_ASSERT(len_val <= UINT32_MAX);
@@ -399,7 +411,7 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor* c,
399
411
  GRPC_STATS_INC_HPACK_SEND_LITHDR_INCIDX_V();
400
412
  GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED();
401
413
  uint32_t len_key = static_cast<uint32_t> GRPC_SLICE_LENGTH(GRPC_MDKEY(elem));
402
- wire_value value = get_wire_value(elem, st->use_true_binary_metadata);
414
+ wire_value value = get_wire_value<true>(elem, st->use_true_binary_metadata);
403
415
  uint32_t len_val = static_cast<uint32_t>(wire_value_length(value));
404
416
  uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
405
417
  uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
@@ -421,7 +433,7 @@ static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor* c,
421
433
  GRPC_STATS_INC_HPACK_SEND_LITHDR_NOTIDX_V();
422
434
  GRPC_STATS_INC_HPACK_SEND_UNCOMPRESSED();
423
435
  uint32_t len_key = static_cast<uint32_t> GRPC_SLICE_LENGTH(GRPC_MDKEY(elem));
424
- wire_value value = get_wire_value(elem, st->use_true_binary_metadata);
436
+ wire_value value = get_wire_value<false>(elem, st->use_true_binary_metadata);
425
437
  uint32_t len_val = static_cast<uint32_t>(wire_value_length(value));
426
438
  uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
427
439
  uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
@@ -464,7 +476,7 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem,
464
476
  if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) {
465
477
  char* k = grpc_slice_to_c_string(GRPC_MDKEY(elem));
466
478
  char* v = nullptr;
467
- if (grpc_is_binary_header(GRPC_MDKEY(elem))) {
479
+ if (grpc_is_binary_header_internal(GRPC_MDKEY(elem))) {
468
480
  v = grpc_dump_slice(GRPC_MDVALUE(elem), GPR_DUMP_HEX);
469
481
  } else {
470
482
  v = grpc_slice_to_c_string(GRPC_MDVALUE(elem));
@@ -488,27 +500,33 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem,
488
500
  return;
489
501
  }
490
502
 
491
- uint32_t key_hash = grpc_slice_hash(GRPC_MDKEY(elem));
492
503
  uint32_t elem_hash = 0;
493
504
 
494
505
  if (elem_interned) {
495
- uint32_t value_hash = grpc_slice_hash(GRPC_MDVALUE(elem));
496
- elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash);
506
+ if (GRPC_MDELEM_STORAGE(elem) == GRPC_MDELEM_STORAGE_INTERNED) {
507
+ elem_hash =
508
+ reinterpret_cast<grpc_core::InternedMetadata*>(GRPC_MDELEM_DATA(elem))
509
+ ->hash();
510
+ } else {
511
+ elem_hash =
512
+ reinterpret_cast<grpc_core::StaticMetadata*>(GRPC_MDELEM_DATA(elem))
513
+ ->hash();
514
+ }
497
515
 
498
516
  inc_filter(HASH_FRAGMENT_1(elem_hash), &c->filter_elems_sum,
499
517
  c->filter_elems);
500
518
 
501
519
  /* is this elem currently in the decoders table? */
502
-
503
- if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_2(elem_hash)], elem) &&
520
+ if (grpc_mdelem_both_interned_eq(
521
+ c->entries_elems[HASH_FRAGMENT_2(elem_hash)], elem) &&
504
522
  c->indices_elems[HASH_FRAGMENT_2(elem_hash)] > c->tail_remote_index) {
505
523
  /* HIT: complete element (first cuckoo hash) */
506
524
  emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_2(elem_hash)]),
507
525
  st);
508
526
  return;
509
527
  }
510
-
511
- if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_3(elem_hash)], elem) &&
528
+ if (grpc_mdelem_both_interned_eq(
529
+ c->entries_elems[HASH_FRAGMENT_3(elem_hash)], elem) &&
512
530
  c->indices_elems[HASH_FRAGMENT_3(elem_hash)] > c->tail_remote_index) {
513
531
  /* HIT: complete element (second cuckoo hash) */
514
532
  emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_3(elem_hash)]),
@@ -527,11 +545,12 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem,
527
545
  c->filter_elems[HASH_FRAGMENT_1(elem_hash)] >=
528
546
  c->filter_elems_sum / ONE_ON_ADD_PROBABILITY;
529
547
 
548
+ uint32_t key_hash = GRPC_MDKEY(elem).refcount->Hash(GRPC_MDKEY(elem));
530
549
  auto emit_maybe_add = [&should_add_elem, &elem, &st, &c, &indices_key,
531
- &decoder_space_usage] {
550
+ &decoder_space_usage, &elem_hash, &key_hash] {
532
551
  if (should_add_elem) {
533
552
  emit_lithdr_incidx(c, dynidx(c, indices_key), elem, st);
534
- add_elem(c, elem, decoder_space_usage);
553
+ add_elem(c, elem, decoder_space_usage, elem_hash, key_hash);
535
554
  } else {
536
555
  emit_lithdr_noidx(c, dynidx(c, indices_key), elem, st);
537
556
  }
@@ -539,8 +558,8 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem,
539
558
 
540
559
  /* no hits for the elem... maybe there's a key? */
541
560
  indices_key = c->indices_keys[HASH_FRAGMENT_2(key_hash)];
542
- if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_2(key_hash)],
543
- GRPC_MDKEY(elem)) &&
561
+ if (grpc_slice_static_interned_equal(
562
+ c->entries_keys[HASH_FRAGMENT_2(key_hash)], GRPC_MDKEY(elem)) &&
544
563
  indices_key > c->tail_remote_index) {
545
564
  /* HIT: key (first cuckoo hash) */
546
565
  emit_maybe_add();
@@ -548,8 +567,8 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem,
548
567
  }
549
568
 
550
569
  indices_key = c->indices_keys[HASH_FRAGMENT_3(key_hash)];
551
- if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_3(key_hash)],
552
- GRPC_MDKEY(elem)) &&
570
+ if (grpc_slice_static_interned_equal(
571
+ c->entries_keys[HASH_FRAGMENT_3(key_hash)], GRPC_MDKEY(elem)) &&
553
572
  indices_key > c->tail_remote_index) {
554
573
  /* HIT: key (first cuckoo hash) */
555
574
  emit_maybe_add();
@@ -565,9 +584,9 @@ static void hpack_enc(grpc_chttp2_hpack_compressor* c, grpc_mdelem elem,
565
584
  emit_lithdr_noidx_v(c, 0, elem, st);
566
585
  }
567
586
  if (should_add_elem) {
568
- add_elem(c, elem, decoder_space_usage);
587
+ add_elem(c, elem, decoder_space_usage, elem_hash, key_hash);
569
588
  } else if (should_add_key) {
570
- add_key(c, elem, decoder_space_usage);
589
+ add_key(c, elem, decoder_space_usage, key_hash);
571
590
  }
572
591
  }
573
592
 
@@ -692,18 +711,18 @@ void grpc_chttp2_encode_header(grpc_chttp2_hpack_compressor* c,
692
711
  }
693
712
  for (size_t i = 0; i < extra_headers_size; ++i) {
694
713
  grpc_mdelem md = *extra_headers[i];
695
- uint8_t static_index = grpc_chttp2_get_static_hpack_table_index(md);
714
+ uintptr_t static_index = grpc_chttp2_get_static_hpack_table_index(md);
696
715
  if (static_index) {
697
- emit_indexed(c, static_index, &st);
716
+ emit_indexed(c, static_cast<uint32_t>(static_index), &st);
698
717
  } else {
699
718
  hpack_enc(c, md, &st);
700
719
  }
701
720
  }
702
721
  grpc_metadata_batch_assert_ok(metadata);
703
722
  for (grpc_linked_mdelem* l = metadata->list.head; l; l = l->next) {
704
- uint8_t static_index = grpc_chttp2_get_static_hpack_table_index(l->md);
723
+ uintptr_t static_index = grpc_chttp2_get_static_hpack_table_index(l->md);
705
724
  if (static_index) {
706
- emit_indexed(c, static_index, &st);
725
+ emit_indexed(c, static_cast<uint32_t>(static_index), &st);
707
726
  } else {
708
727
  hpack_enc(c, l->md, &st);
709
728
  }