grpc 1.15.0 → 1.16.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 (138) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +158 -80
  3. data/etc/roots.pem +23 -0
  4. data/include/grpc/grpc.h +13 -1
  5. data/include/grpc/grpc_security.h +2 -2
  6. data/include/grpc/grpc_security_constants.h +24 -19
  7. data/include/grpc/impl/codegen/grpc_types.h +23 -5
  8. data/include/grpc/impl/codegen/port_platform.h +1 -0
  9. data/src/core/ext/filters/client_channel/client_channel.cc +95 -10
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +71 -0
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +45 -11
  12. data/src/core/ext/filters/client_channel/connector.h +3 -0
  13. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +5 -3
  15. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +12 -32
  16. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +6 -5
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +20 -15
  18. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -4
  19. data/src/core/ext/filters/client_channel/parse_address.cc +27 -4
  20. data/src/core/ext/filters/client_channel/parse_address.h +3 -0
  21. data/src/core/ext/filters/client_channel/resolver.h +1 -12
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -11
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -19
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +9 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +5 -0
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +70 -0
  27. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -11
  28. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -16
  29. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
  30. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +0 -7
  31. data/src/core/ext/filters/client_channel/subchannel.cc +45 -7
  32. data/src/core/ext/filters/client_channel/subchannel.h +16 -1
  33. data/src/core/ext/filters/client_channel/subchannel_index.cc +2 -1
  34. data/src/core/ext/filters/client_channel/subchannel_index.h +1 -4
  35. data/src/core/ext/filters/http/client/http_client_filter.cc +32 -3
  36. data/src/core/ext/filters/http/server/http_server_filter.cc +59 -1
  37. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -2
  38. data/src/core/ext/filters/message_size/message_size_filter.cc +59 -3
  39. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -0
  40. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  41. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  42. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +286 -228
  43. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -0
  44. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -0
  45. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +14 -3
  46. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +29 -0
  47. data/src/core/ext/transport/chttp2/transport/hpack_table.h +9 -0
  48. data/src/core/ext/transport/chttp2/transport/internal.h +10 -0
  49. data/src/core/ext/transport/chttp2/transport/parsing.cc +85 -54
  50. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -0
  51. data/src/core/lib/channel/channel_trace.cc +51 -56
  52. data/src/core/lib/channel/channel_trace.h +30 -25
  53. data/src/core/lib/channel/channelz.cc +235 -61
  54. data/src/core/lib/channel/channelz.h +179 -48
  55. data/src/core/lib/channel/channelz_registry.cc +95 -23
  56. data/src/core/lib/channel/channelz_registry.h +15 -42
  57. data/src/core/lib/gpr/sync_posix.cc +42 -0
  58. data/src/core/lib/http/httpcli.cc +1 -1
  59. data/src/core/lib/iomgr/buffer_list.cc +134 -0
  60. data/src/core/lib/iomgr/buffer_list.h +96 -0
  61. data/src/core/lib/iomgr/endpoint.cc +2 -2
  62. data/src/core/lib/iomgr/endpoint.h +6 -2
  63. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  64. data/src/core/lib/iomgr/error.cc +29 -18
  65. data/src/core/lib/iomgr/error.h +8 -0
  66. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  67. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  68. data/src/core/lib/iomgr/ev_posix.cc +16 -10
  69. data/src/core/lib/iomgr/exec_ctx.h +0 -7
  70. data/src/core/lib/iomgr/{ev_epollsig_linux.h → internal_errqueue.cc} +13 -12
  71. data/src/core/lib/iomgr/internal_errqueue.h +83 -0
  72. data/src/core/lib/iomgr/port.h +11 -2
  73. data/src/core/lib/iomgr/socket_utils_common_posix.cc +90 -0
  74. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  75. data/src/core/lib/iomgr/tcp_client_posix.cc +4 -1
  76. data/src/core/lib/iomgr/tcp_custom.cc +1 -1
  77. data/src/core/lib/iomgr/tcp_posix.cc +306 -13
  78. data/src/core/lib/iomgr/tcp_posix.h +3 -0
  79. data/src/core/lib/iomgr/tcp_server_posix.cc +2 -2
  80. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +4 -1
  81. data/src/core/lib/iomgr/tcp_windows.cc +1 -1
  82. data/src/core/lib/iomgr/timer_generic.cc +13 -12
  83. data/src/core/lib/iomgr/timer_heap.cc +2 -2
  84. data/src/core/lib/iomgr/timer_heap.h +3 -3
  85. data/src/core/lib/iomgr/timer_manager.cc +28 -3
  86. data/src/core/lib/iomgr/timer_manager.h +2 -2
  87. data/src/core/lib/iomgr/udp_server.cc +1 -1
  88. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc +2 -1
  89. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +2 -1
  90. data/src/core/lib/security/security_connector/security_connector.cc +7 -7
  91. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  92. data/src/core/lib/security/transport/security_handshaker.cc +1 -1
  93. data/src/core/lib/security/transport/server_auth_filter.cc +53 -4
  94. data/src/core/lib/slice/slice.cc +8 -0
  95. data/src/core/lib/slice/slice_internal.h +5 -0
  96. data/src/core/lib/surface/call.cc +149 -253
  97. data/src/core/lib/surface/call.h +1 -0
  98. data/src/core/lib/surface/channel.cc +17 -13
  99. data/src/core/lib/surface/completion_queue.cc +21 -17
  100. data/src/core/lib/surface/completion_queue.h +1 -18
  101. data/src/core/lib/surface/completion_queue_factory.cc +3 -3
  102. data/src/core/lib/surface/init_secure.cc +1 -1
  103. data/src/core/lib/surface/server.cc +77 -4
  104. data/src/core/lib/surface/server.h +4 -0
  105. data/src/core/lib/surface/version.cc +2 -2
  106. data/src/core/lib/transport/metadata.cc +0 -18
  107. data/src/core/lib/transport/metadata.h +0 -3
  108. data/src/core/lib/transport/metadata_batch.cc +2 -2
  109. data/src/core/lib/transport/metadata_batch.h +2 -0
  110. data/src/core/lib/transport/static_metadata.cc +220 -249
  111. data/src/core/lib/transport/static_metadata.h +189 -191
  112. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +5 -4
  113. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +3 -1
  114. data/src/core/tsi/alts/handshaker/alts_tsi_event.cc +4 -2
  115. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +6 -5
  116. data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +3 -1
  117. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +2 -2
  118. data/src/core/tsi/alts_transport_security.cc +3 -1
  119. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +2 -1
  120. data/src/ruby/ext/grpc/rb_call.c +1 -0
  121. data/src/ruby/ext/grpc/rb_channel.c +3 -0
  122. data/src/ruby/ext/grpc/rb_grpc.c +31 -1
  123. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  124. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  125. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +12 -3
  126. data/src/ruby/ext/grpc/rb_server.c +2 -0
  127. data/src/ruby/lib/grpc/errors.rb +0 -1
  128. data/src/ruby/lib/grpc/generic/rpc_desc.rb +3 -3
  129. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  130. data/src/ruby/lib/grpc/version.rb +1 -1
  131. data/src/ruby/spec/channel_spec.rb +44 -0
  132. data/src/ruby/spec/client_auth_spec.rb +5 -5
  133. data/src/ruby/spec/generic/client_stub_spec.rb +13 -9
  134. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -3
  135. data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -0
  136. data/src/ruby/spec/support/services.rb +28 -22
  137. metadata +35 -31
  138. data/src/core/lib/iomgr/ev_epollsig_linux.cc +0 -1743
@@ -157,6 +157,10 @@ bool g_flow_control_enabled = true;
157
157
  static void destruct_transport(grpc_chttp2_transport* t) {
158
158
  size_t i;
159
159
 
160
+ if (t->channelz_socket != nullptr) {
161
+ t->channelz_socket.reset();
162
+ }
163
+
160
164
  grpc_endpoint_destroy(t->ep);
161
165
 
162
166
  grpc_slice_buffer_destroy_internal(&t->qbuf);
@@ -230,35 +234,174 @@ void grpc_chttp2_ref_transport(grpc_chttp2_transport* t) { gpr_ref(&t->refs); }
230
234
 
231
235
  static const grpc_transport_vtable* get_vtable(void);
232
236
 
233
- static void init_transport(grpc_chttp2_transport* t,
234
- const grpc_channel_args* channel_args,
235
- grpc_endpoint* ep, bool is_client) {
237
+ /* Returns whether bdp is enabled */
238
+ static bool read_channel_args(grpc_chttp2_transport* t,
239
+ const grpc_channel_args* channel_args,
240
+ bool is_client) {
241
+ bool enable_bdp = true;
242
+ bool channelz_enabled = GRPC_ENABLE_CHANNELZ_DEFAULT;
236
243
  size_t i;
237
244
  int j;
238
245
 
239
- GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) ==
240
- GRPC_CHTTP2_CLIENT_CONNECT_STRLEN);
241
-
242
- t->base.vtable = get_vtable();
243
- t->ep = ep;
244
- /* one ref is for destroy */
245
- gpr_ref_init(&t->refs, 1);
246
- t->combiner = grpc_combiner_create();
247
- t->peer_string = grpc_endpoint_get_peer(ep);
248
- t->endpoint_reading = 1;
249
- t->next_stream_id = is_client ? 1 : 2;
250
- t->is_client = is_client;
251
- t->deframe_state = is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0;
252
- t->is_first_frame = true;
253
- grpc_connectivity_state_init(
254
- &t->channel_callback.state_tracker, GRPC_CHANNEL_READY,
255
- is_client ? "client_transport" : "server_transport");
256
-
257
- grpc_slice_buffer_init(&t->qbuf);
258
-
259
- grpc_slice_buffer_init(&t->outbuf);
260
- grpc_chttp2_hpack_compressor_init(&t->hpack_compressor);
246
+ for (i = 0; i < channel_args->num_args; i++) {
247
+ if (0 == strcmp(channel_args->args[i].key,
248
+ GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER)) {
249
+ const grpc_integer_options options = {-1, 0, INT_MAX};
250
+ const int value =
251
+ grpc_channel_arg_get_integer(&channel_args->args[i], options);
252
+ if (value >= 0) {
253
+ if ((t->next_stream_id & 1) != (value & 1)) {
254
+ gpr_log(GPR_ERROR, "%s: low bit must be %d on %s",
255
+ GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER, t->next_stream_id & 1,
256
+ is_client ? "client" : "server");
257
+ } else {
258
+ t->next_stream_id = static_cast<uint32_t>(value);
259
+ }
260
+ }
261
+ } else if (0 == strcmp(channel_args->args[i].key,
262
+ GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER)) {
263
+ const grpc_integer_options options = {-1, 0, INT_MAX};
264
+ const int value =
265
+ grpc_channel_arg_get_integer(&channel_args->args[i], options);
266
+ if (value >= 0) {
267
+ grpc_chttp2_hpack_compressor_set_max_usable_size(
268
+ &t->hpack_compressor, static_cast<uint32_t>(value));
269
+ }
270
+ } else if (0 == strcmp(channel_args->args[i].key,
271
+ GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) {
272
+ t->ping_policy.max_pings_without_data = grpc_channel_arg_get_integer(
273
+ &channel_args->args[i],
274
+ {g_default_max_pings_without_data, 0, INT_MAX});
275
+ } else if (0 == strcmp(channel_args->args[i].key,
276
+ GRPC_ARG_HTTP2_MAX_PING_STRIKES)) {
277
+ t->ping_policy.max_ping_strikes = grpc_channel_arg_get_integer(
278
+ &channel_args->args[i], {g_default_max_ping_strikes, 0, INT_MAX});
279
+ } else if (0 ==
280
+ strcmp(channel_args->args[i].key,
281
+ GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS)) {
282
+ t->ping_policy.min_sent_ping_interval_without_data =
283
+ grpc_channel_arg_get_integer(
284
+ &channel_args->args[i],
285
+ grpc_integer_options{
286
+ g_default_min_sent_ping_interval_without_data_ms, 0,
287
+ INT_MAX});
288
+ } else if (0 ==
289
+ strcmp(channel_args->args[i].key,
290
+ GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS)) {
291
+ t->ping_policy.min_recv_ping_interval_without_data =
292
+ grpc_channel_arg_get_integer(
293
+ &channel_args->args[i],
294
+ grpc_integer_options{
295
+ g_default_min_recv_ping_interval_without_data_ms, 0,
296
+ INT_MAX});
297
+ } else if (0 == strcmp(channel_args->args[i].key,
298
+ GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) {
299
+ t->write_buffer_size = static_cast<uint32_t>(grpc_channel_arg_get_integer(
300
+ &channel_args->args[i], {0, 0, MAX_WRITE_BUFFER_SIZE}));
301
+ } else if (0 ==
302
+ strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_BDP_PROBE)) {
303
+ enable_bdp = grpc_channel_arg_get_bool(&channel_args->args[i], true);
304
+ } else if (0 ==
305
+ strcmp(channel_args->args[i].key, GRPC_ARG_KEEPALIVE_TIME_MS)) {
306
+ const int value = grpc_channel_arg_get_integer(
307
+ &channel_args->args[i],
308
+ grpc_integer_options{t->is_client
309
+ ? g_default_client_keepalive_time_ms
310
+ : g_default_server_keepalive_time_ms,
311
+ 1, INT_MAX});
312
+ t->keepalive_time = value == INT_MAX ? GRPC_MILLIS_INF_FUTURE : value;
313
+ } else if (0 == strcmp(channel_args->args[i].key,
314
+ GRPC_ARG_KEEPALIVE_TIMEOUT_MS)) {
315
+ const int value = grpc_channel_arg_get_integer(
316
+ &channel_args->args[i],
317
+ grpc_integer_options{t->is_client
318
+ ? g_default_client_keepalive_timeout_ms
319
+ : g_default_server_keepalive_timeout_ms,
320
+ 0, INT_MAX});
321
+ t->keepalive_timeout = value == INT_MAX ? GRPC_MILLIS_INF_FUTURE : value;
322
+ } else if (0 == strcmp(channel_args->args[i].key,
323
+ GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) {
324
+ t->keepalive_permit_without_calls = static_cast<uint32_t>(
325
+ grpc_channel_arg_get_integer(&channel_args->args[i], {0, 0, 1}));
326
+ } else if (0 == strcmp(channel_args->args[i].key,
327
+ GRPC_ARG_OPTIMIZATION_TARGET)) {
328
+ if (channel_args->args[i].type != GRPC_ARG_STRING) {
329
+ gpr_log(GPR_ERROR, "%s should be a string",
330
+ GRPC_ARG_OPTIMIZATION_TARGET);
331
+ } else if (0 == strcmp(channel_args->args[i].value.string, "blend")) {
332
+ t->opt_target = GRPC_CHTTP2_OPTIMIZE_FOR_LATENCY;
333
+ } else if (0 == strcmp(channel_args->args[i].value.string, "latency")) {
334
+ t->opt_target = GRPC_CHTTP2_OPTIMIZE_FOR_LATENCY;
335
+ } else if (0 ==
336
+ strcmp(channel_args->args[i].value.string, "throughput")) {
337
+ t->opt_target = GRPC_CHTTP2_OPTIMIZE_FOR_THROUGHPUT;
338
+ } else {
339
+ gpr_log(GPR_ERROR, "%s value '%s' unknown, assuming 'blend'",
340
+ GRPC_ARG_OPTIMIZATION_TARGET,
341
+ channel_args->args[i].value.string);
342
+ }
343
+ } else if (0 ==
344
+ strcmp(channel_args->args[i].key, GRPC_ARG_ENABLE_CHANNELZ)) {
345
+ channelz_enabled = grpc_channel_arg_get_bool(
346
+ &channel_args->args[i], GRPC_ENABLE_CHANNELZ_DEFAULT);
347
+ } else {
348
+ static const struct {
349
+ const char* channel_arg_name;
350
+ grpc_chttp2_setting_id setting_id;
351
+ grpc_integer_options integer_options;
352
+ bool availability[2] /* server, client */;
353
+ } settings_map[] = {{GRPC_ARG_MAX_CONCURRENT_STREAMS,
354
+ GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
355
+ {-1, 0, INT32_MAX},
356
+ {true, false}},
357
+ {GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER,
358
+ GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE,
359
+ {-1, 0, INT32_MAX},
360
+ {true, true}},
361
+ {GRPC_ARG_MAX_METADATA_SIZE,
362
+ GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
363
+ {-1, 0, INT32_MAX},
364
+ {true, true}},
365
+ {GRPC_ARG_HTTP2_MAX_FRAME_SIZE,
366
+ GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE,
367
+ {-1, 16384, 16777215},
368
+ {true, true}},
369
+ {GRPC_ARG_HTTP2_ENABLE_TRUE_BINARY,
370
+ GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA,
371
+ {1, 0, 1},
372
+ {true, true}},
373
+ {GRPC_ARG_HTTP2_STREAM_LOOKAHEAD_BYTES,
374
+ GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
375
+ {-1, 5, INT32_MAX},
376
+ {true, true}}};
377
+ for (j = 0; j < static_cast<int> GPR_ARRAY_SIZE(settings_map); j++) {
378
+ if (0 == strcmp(channel_args->args[i].key,
379
+ settings_map[j].channel_arg_name)) {
380
+ if (!settings_map[j].availability[is_client]) {
381
+ gpr_log(GPR_DEBUG, "%s is not available on %s",
382
+ settings_map[j].channel_arg_name,
383
+ is_client ? "clients" : "servers");
384
+ } else {
385
+ int value = grpc_channel_arg_get_integer(
386
+ &channel_args->args[i], settings_map[j].integer_options);
387
+ if (value >= 0) {
388
+ queue_setting_update(t, settings_map[j].setting_id,
389
+ static_cast<uint32_t>(value));
390
+ }
391
+ }
392
+ break;
393
+ }
394
+ }
395
+ }
396
+ }
397
+ if (channelz_enabled) {
398
+ t->channelz_socket =
399
+ grpc_core::MakeRefCounted<grpc_core::channelz::SocketNode>();
400
+ }
401
+ return enable_bdp;
402
+ }
261
403
 
404
+ static void init_transport_closures(grpc_chttp2_transport* t) {
262
405
  GRPC_CLOSURE_INIT(&t->read_action_locked, read_action_locked, t,
263
406
  grpc_combiner_scheduler(t->combiner));
264
407
  GRPC_CLOSURE_INIT(&t->benign_reclaimer_locked, benign_reclaimer_locked, t,
@@ -286,6 +429,79 @@ static void init_transport(grpc_chttp2_transport* t,
286
429
  GRPC_CLOSURE_INIT(&t->keepalive_watchdog_fired_locked,
287
430
  keepalive_watchdog_fired_locked, t,
288
431
  grpc_combiner_scheduler(t->combiner));
432
+ }
433
+
434
+ static void init_transport_keepalive_settings(grpc_chttp2_transport* t) {
435
+ if (t->is_client) {
436
+ t->keepalive_time = g_default_client_keepalive_time_ms == INT_MAX
437
+ ? GRPC_MILLIS_INF_FUTURE
438
+ : g_default_client_keepalive_time_ms;
439
+ t->keepalive_timeout = g_default_client_keepalive_timeout_ms == INT_MAX
440
+ ? GRPC_MILLIS_INF_FUTURE
441
+ : g_default_client_keepalive_timeout_ms;
442
+ t->keepalive_permit_without_calls =
443
+ g_default_client_keepalive_permit_without_calls;
444
+ } else {
445
+ t->keepalive_time = g_default_server_keepalive_time_ms == INT_MAX
446
+ ? GRPC_MILLIS_INF_FUTURE
447
+ : g_default_server_keepalive_time_ms;
448
+ t->keepalive_timeout = g_default_server_keepalive_timeout_ms == INT_MAX
449
+ ? GRPC_MILLIS_INF_FUTURE
450
+ : g_default_server_keepalive_timeout_ms;
451
+ t->keepalive_permit_without_calls =
452
+ g_default_server_keepalive_permit_without_calls;
453
+ }
454
+ }
455
+
456
+ static void configure_transport_ping_policy(grpc_chttp2_transport* t) {
457
+ t->ping_policy.max_pings_without_data = g_default_max_pings_without_data;
458
+ t->ping_policy.min_sent_ping_interval_without_data =
459
+ g_default_min_sent_ping_interval_without_data_ms;
460
+ t->ping_policy.max_ping_strikes = g_default_max_ping_strikes;
461
+ t->ping_policy.min_recv_ping_interval_without_data =
462
+ g_default_min_recv_ping_interval_without_data_ms;
463
+ }
464
+
465
+ static void init_keepalive_pings_if_enabled(grpc_chttp2_transport* t) {
466
+ if (t->keepalive_time != GRPC_MILLIS_INF_FUTURE) {
467
+ t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
468
+ GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
469
+ grpc_timer_init(&t->keepalive_ping_timer,
470
+ grpc_core::ExecCtx::Get()->Now() + t->keepalive_time,
471
+ &t->init_keepalive_ping_locked);
472
+ } else {
473
+ /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no
474
+ inflight keeaplive timers */
475
+ t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED;
476
+ }
477
+ }
478
+
479
+ static void init_transport(grpc_chttp2_transport* t,
480
+ const grpc_channel_args* channel_args,
481
+ grpc_endpoint* ep, bool is_client) {
482
+ GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) ==
483
+ GRPC_CHTTP2_CLIENT_CONNECT_STRLEN);
484
+
485
+ t->base.vtable = get_vtable();
486
+ t->ep = ep;
487
+ /* one ref is for destroy */
488
+ gpr_ref_init(&t->refs, 1);
489
+ t->combiner = grpc_combiner_create();
490
+ t->peer_string = grpc_endpoint_get_peer(ep);
491
+ t->endpoint_reading = 1;
492
+ t->next_stream_id = is_client ? 1 : 2;
493
+ t->is_client = is_client;
494
+ t->deframe_state = is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0;
495
+ t->is_first_frame = true;
496
+ grpc_connectivity_state_init(
497
+ &t->channel_callback.state_tracker, GRPC_CHANNEL_READY,
498
+ is_client ? "client_transport" : "server_transport");
499
+
500
+ grpc_slice_buffer_init(&t->qbuf);
501
+ grpc_slice_buffer_init(&t->outbuf);
502
+ grpc_chttp2_hpack_compressor_init(&t->hpack_compressor);
503
+
504
+ init_transport_closures(t);
289
505
 
290
506
  t->goaway_error = GRPC_ERROR_NONE;
291
507
  grpc_chttp2_goaway_parser_init(&t->goaway_parser);
@@ -301,6 +517,8 @@ static void init_transport(grpc_chttp2_transport* t,
301
517
  grpc_chttp2_stream_map_init(&t->stream_map, 8);
302
518
 
303
519
  /* copy in initial settings to all setting sets */
520
+ size_t i;
521
+ int j;
304
522
  for (i = 0; i < GRPC_CHTTP2_NUM_SETTINGS; i++) {
305
523
  for (j = 0; j < GRPC_NUM_SETTING_SETS; j++) {
306
524
  t->settings[j][i] = grpc_chttp2_settings_parameters[i].default_value;
@@ -328,191 +546,14 @@ static void init_transport(grpc_chttp2_transport* t,
328
546
  queue_setting_update(t, GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA,
329
547
  1);
330
548
 
331
- t->ping_policy.max_pings_without_data = g_default_max_pings_without_data;
332
- t->ping_policy.min_sent_ping_interval_without_data =
333
- g_default_min_sent_ping_interval_without_data_ms;
334
- t->ping_policy.max_ping_strikes = g_default_max_ping_strikes;
335
- t->ping_policy.min_recv_ping_interval_without_data =
336
- g_default_min_recv_ping_interval_without_data_ms;
337
-
338
- /* Keepalive setting */
339
- if (t->is_client) {
340
- t->keepalive_time = g_default_client_keepalive_time_ms == INT_MAX
341
- ? GRPC_MILLIS_INF_FUTURE
342
- : g_default_client_keepalive_time_ms;
343
- t->keepalive_timeout = g_default_client_keepalive_timeout_ms == INT_MAX
344
- ? GRPC_MILLIS_INF_FUTURE
345
- : g_default_client_keepalive_timeout_ms;
346
- t->keepalive_permit_without_calls =
347
- g_default_client_keepalive_permit_without_calls;
348
- } else {
349
- t->keepalive_time = g_default_server_keepalive_time_ms == INT_MAX
350
- ? GRPC_MILLIS_INF_FUTURE
351
- : g_default_server_keepalive_time_ms;
352
- t->keepalive_timeout = g_default_server_keepalive_timeout_ms == INT_MAX
353
- ? GRPC_MILLIS_INF_FUTURE
354
- : g_default_server_keepalive_timeout_ms;
355
- t->keepalive_permit_without_calls =
356
- g_default_server_keepalive_permit_without_calls;
357
- }
549
+ configure_transport_ping_policy(t);
550
+ init_transport_keepalive_settings(t);
358
551
 
359
552
  t->opt_target = GRPC_CHTTP2_OPTIMIZE_FOR_LATENCY;
360
553
 
361
554
  bool enable_bdp = true;
362
-
363
555
  if (channel_args) {
364
- for (i = 0; i < channel_args->num_args; i++) {
365
- if (0 == strcmp(channel_args->args[i].key,
366
- GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER)) {
367
- const grpc_integer_options options = {-1, 0, INT_MAX};
368
- const int value =
369
- grpc_channel_arg_get_integer(&channel_args->args[i], options);
370
- if (value >= 0) {
371
- if ((t->next_stream_id & 1) != (value & 1)) {
372
- gpr_log(GPR_ERROR, "%s: low bit must be %d on %s",
373
- GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER,
374
- t->next_stream_id & 1, is_client ? "client" : "server");
375
- } else {
376
- t->next_stream_id = static_cast<uint32_t>(value);
377
- }
378
- }
379
- } else if (0 == strcmp(channel_args->args[i].key,
380
- GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER)) {
381
- const grpc_integer_options options = {-1, 0, INT_MAX};
382
- const int value =
383
- grpc_channel_arg_get_integer(&channel_args->args[i], options);
384
- if (value >= 0) {
385
- grpc_chttp2_hpack_compressor_set_max_usable_size(
386
- &t->hpack_compressor, static_cast<uint32_t>(value));
387
- }
388
- } else if (0 == strcmp(channel_args->args[i].key,
389
- GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) {
390
- t->ping_policy.max_pings_without_data = grpc_channel_arg_get_integer(
391
- &channel_args->args[i],
392
- {g_default_max_pings_without_data, 0, INT_MAX});
393
- } else if (0 == strcmp(channel_args->args[i].key,
394
- GRPC_ARG_HTTP2_MAX_PING_STRIKES)) {
395
- t->ping_policy.max_ping_strikes = grpc_channel_arg_get_integer(
396
- &channel_args->args[i], {g_default_max_ping_strikes, 0, INT_MAX});
397
- } else if (0 ==
398
- strcmp(
399
- channel_args->args[i].key,
400
- GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS)) {
401
- t->ping_policy.min_sent_ping_interval_without_data =
402
- grpc_channel_arg_get_integer(
403
- &channel_args->args[i],
404
- grpc_integer_options{
405
- g_default_min_sent_ping_interval_without_data_ms, 0,
406
- INT_MAX});
407
- } else if (0 ==
408
- strcmp(
409
- channel_args->args[i].key,
410
- GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS)) {
411
- t->ping_policy.min_recv_ping_interval_without_data =
412
- grpc_channel_arg_get_integer(
413
- &channel_args->args[i],
414
- grpc_integer_options{
415
- g_default_min_recv_ping_interval_without_data_ms, 0,
416
- INT_MAX});
417
- } else if (0 == strcmp(channel_args->args[i].key,
418
- GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) {
419
- t->write_buffer_size =
420
- static_cast<uint32_t>(grpc_channel_arg_get_integer(
421
- &channel_args->args[i], {0, 0, MAX_WRITE_BUFFER_SIZE}));
422
- } else if (0 ==
423
- strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_BDP_PROBE)) {
424
- enable_bdp = grpc_channel_arg_get_bool(&channel_args->args[i], true);
425
- } else if (0 == strcmp(channel_args->args[i].key,
426
- GRPC_ARG_KEEPALIVE_TIME_MS)) {
427
- const int value = grpc_channel_arg_get_integer(
428
- &channel_args->args[i],
429
- grpc_integer_options{t->is_client
430
- ? g_default_client_keepalive_time_ms
431
- : g_default_server_keepalive_time_ms,
432
- 1, INT_MAX});
433
- t->keepalive_time = value == INT_MAX ? GRPC_MILLIS_INF_FUTURE : value;
434
- } else if (0 == strcmp(channel_args->args[i].key,
435
- GRPC_ARG_KEEPALIVE_TIMEOUT_MS)) {
436
- const int value = grpc_channel_arg_get_integer(
437
- &channel_args->args[i],
438
- grpc_integer_options{t->is_client
439
- ? g_default_client_keepalive_timeout_ms
440
- : g_default_server_keepalive_timeout_ms,
441
- 0, INT_MAX});
442
- t->keepalive_timeout =
443
- value == INT_MAX ? GRPC_MILLIS_INF_FUTURE : value;
444
- } else if (0 == strcmp(channel_args->args[i].key,
445
- GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) {
446
- t->keepalive_permit_without_calls = static_cast<uint32_t>(
447
- grpc_channel_arg_get_integer(&channel_args->args[i], {0, 0, 1}));
448
- } else if (0 == strcmp(channel_args->args[i].key,
449
- GRPC_ARG_OPTIMIZATION_TARGET)) {
450
- if (channel_args->args[i].type != GRPC_ARG_STRING) {
451
- gpr_log(GPR_ERROR, "%s should be a string",
452
- GRPC_ARG_OPTIMIZATION_TARGET);
453
- } else if (0 == strcmp(channel_args->args[i].value.string, "blend")) {
454
- t->opt_target = GRPC_CHTTP2_OPTIMIZE_FOR_LATENCY;
455
- } else if (0 == strcmp(channel_args->args[i].value.string, "latency")) {
456
- t->opt_target = GRPC_CHTTP2_OPTIMIZE_FOR_LATENCY;
457
- } else if (0 ==
458
- strcmp(channel_args->args[i].value.string, "throughput")) {
459
- t->opt_target = GRPC_CHTTP2_OPTIMIZE_FOR_THROUGHPUT;
460
- } else {
461
- gpr_log(GPR_ERROR, "%s value '%s' unknown, assuming 'blend'",
462
- GRPC_ARG_OPTIMIZATION_TARGET,
463
- channel_args->args[i].value.string);
464
- }
465
- } else {
466
- static const struct {
467
- const char* channel_arg_name;
468
- grpc_chttp2_setting_id setting_id;
469
- grpc_integer_options integer_options;
470
- bool availability[2] /* server, client */;
471
- } settings_map[] = {
472
- {GRPC_ARG_MAX_CONCURRENT_STREAMS,
473
- GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
474
- {-1, 0, INT32_MAX},
475
- {true, false}},
476
- {GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER,
477
- GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE,
478
- {-1, 0, INT32_MAX},
479
- {true, true}},
480
- {GRPC_ARG_MAX_METADATA_SIZE,
481
- GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
482
- {-1, 0, INT32_MAX},
483
- {true, true}},
484
- {GRPC_ARG_HTTP2_MAX_FRAME_SIZE,
485
- GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE,
486
- {-1, 16384, 16777215},
487
- {true, true}},
488
- {GRPC_ARG_HTTP2_ENABLE_TRUE_BINARY,
489
- GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA,
490
- {1, 0, 1},
491
- {true, true}},
492
- {GRPC_ARG_HTTP2_STREAM_LOOKAHEAD_BYTES,
493
- GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
494
- {-1, 5, INT32_MAX},
495
- {true, true}}};
496
- for (j = 0; j < static_cast<int> GPR_ARRAY_SIZE(settings_map); j++) {
497
- if (0 == strcmp(channel_args->args[i].key,
498
- settings_map[j].channel_arg_name)) {
499
- if (!settings_map[j].availability[is_client]) {
500
- gpr_log(GPR_DEBUG, "%s is not available on %s",
501
- settings_map[j].channel_arg_name,
502
- is_client ? "clients" : "servers");
503
- } else {
504
- int value = grpc_channel_arg_get_integer(
505
- &channel_args->args[i], settings_map[j].integer_options);
506
- if (value >= 0) {
507
- queue_setting_update(t, settings_map[j].setting_id,
508
- static_cast<uint32_t>(value));
509
- }
510
- }
511
- break;
512
- }
513
- }
514
- }
515
- }
556
+ enable_bdp = read_channel_args(t, channel_args, is_client);
516
557
  }
517
558
 
518
559
  if (g_flow_control_enabled) {
@@ -531,23 +572,11 @@ static void init_transport(grpc_chttp2_transport* t,
531
572
  t->ping_recv_state.last_ping_recv_time = GRPC_MILLIS_INF_PAST;
532
573
  t->ping_recv_state.ping_strikes = 0;
533
574
 
534
- /* Start keepalive pings */
535
- if (t->keepalive_time != GRPC_MILLIS_INF_FUTURE) {
536
- t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
537
- GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
538
- grpc_timer_init(&t->keepalive_ping_timer,
539
- grpc_core::ExecCtx::Get()->Now() + t->keepalive_time,
540
- &t->init_keepalive_ping_locked);
541
- } else {
542
- /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no
543
- inflight keeaplive timers */
544
- t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED;
545
- }
575
+ init_keepalive_pings_if_enabled(t);
546
576
 
547
577
  if (enable_bdp) {
548
578
  GRPC_CHTTP2_REF_TRANSPORT(t, "bdp_ping");
549
579
  schedule_bdp_ping_locked(t);
550
-
551
580
  grpc_chttp2_act_on_flowctl_action(t->flow_control->PeriodicUpdate(), t,
552
581
  nullptr);
553
582
  }
@@ -704,6 +733,14 @@ static void destroy_stream_locked(void* sp, grpc_error* error) {
704
733
  grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(sp);
705
734
  grpc_chttp2_transport* t = s->t;
706
735
 
736
+ if (t->channelz_socket != nullptr) {
737
+ if ((t->is_client && s->eos_received) || (!t->is_client && s->eos_sent)) {
738
+ t->channelz_socket->RecordStreamSucceeded();
739
+ } else {
740
+ t->channelz_socket->RecordStreamFailed();
741
+ }
742
+ }
743
+
707
744
  GPR_ASSERT((s->write_closed && s->read_closed) || s->id == 0);
708
745
  if (s->id != 0) {
709
746
  GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, s->id) == nullptr);
@@ -1029,7 +1066,8 @@ static void write_action(void* gt, grpc_error* error) {
1029
1066
  grpc_endpoint_write(
1030
1067
  t->ep, &t->outbuf,
1031
1068
  GRPC_CLOSURE_INIT(&t->write_action_end_locked, write_action_end_locked, t,
1032
- grpc_combiner_scheduler(t->combiner)));
1069
+ grpc_combiner_scheduler(t->combiner)),
1070
+ nullptr);
1033
1071
  }
1034
1072
 
1035
1073
  /* Callback from the grpc_endpoint after bytes have been written by calling
@@ -1390,6 +1428,9 @@ static void perform_stream_op_locked(void* stream_op,
1390
1428
  }
1391
1429
 
1392
1430
  if (op->send_initial_metadata) {
1431
+ if (t->is_client && t->channelz_socket != nullptr) {
1432
+ t->channelz_socket->RecordStreamStartedFromLocal();
1433
+ }
1393
1434
  GRPC_STATS_INC_HTTP2_OP_SEND_INITIAL_METADATA();
1394
1435
  GPR_ASSERT(s->send_initial_metadata_finished == nullptr);
1395
1436
  on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
@@ -1475,6 +1516,7 @@ static void perform_stream_op_locked(void* stream_op,
1475
1516
 
1476
1517
  if (op->send_message) {
1477
1518
  GRPC_STATS_INC_HTTP2_OP_SEND_MESSAGE();
1519
+ t->num_messages_in_next_write++;
1478
1520
  GRPC_STATS_INC_HTTP2_SEND_MESSAGE_SIZE(
1479
1521
  op->payload->send_message.send_message->length());
1480
1522
  on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
@@ -2690,6 +2732,9 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) {
2690
2732
  if (error != GRPC_ERROR_NONE) {
2691
2733
  return;
2692
2734
  }
2735
+ if (t->channelz_socket != nullptr) {
2736
+ t->channelz_socket->RecordKeepaliveSent();
2737
+ }
2693
2738
  GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog");
2694
2739
  grpc_timer_init(&t->keepalive_watchdog_timer,
2695
2740
  grpc_core::ExecCtx::Get()->Now() + t->keepalive_timeout,
@@ -2717,10 +2762,10 @@ static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) {
2717
2762
  if (error == GRPC_ERROR_NONE) {
2718
2763
  t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING;
2719
2764
  close_transport_locked(
2720
- t,
2721
- grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2722
- "keepalive watchdog timeout"),
2723
- GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL));
2765
+ t, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
2766
+ "keepalive watchdog timeout"),
2767
+ GRPC_ERROR_INT_GRPC_STATUS,
2768
+ GRPC_STATUS_UNAVAILABLE));
2724
2769
  }
2725
2770
  } else {
2726
2771
  /* The watchdog timer should have been cancelled by
@@ -2886,17 +2931,20 @@ bool Chttp2IncomingByteStream::Next(size_t max_size_hint,
2886
2931
  }
2887
2932
  }
2888
2933
 
2934
+ void Chttp2IncomingByteStream::MaybeCreateStreamDecompressionCtx() {
2935
+ if (!stream_->stream_decompression_ctx) {
2936
+ stream_->stream_decompression_ctx = grpc_stream_compression_context_create(
2937
+ stream_->stream_decompression_method);
2938
+ }
2939
+ }
2940
+
2889
2941
  grpc_error* Chttp2IncomingByteStream::Pull(grpc_slice* slice) {
2890
2942
  GPR_TIMER_SCOPE("incoming_byte_stream_pull", 0);
2891
2943
  grpc_error* error;
2892
2944
  if (stream_->unprocessed_incoming_frames_buffer.length > 0) {
2893
2945
  if (!stream_->unprocessed_incoming_frames_decompressed) {
2894
2946
  bool end_of_context;
2895
- if (!stream_->stream_decompression_ctx) {
2896
- stream_->stream_decompression_ctx =
2897
- grpc_stream_compression_context_create(
2898
- stream_->stream_decompression_method);
2899
- }
2947
+ MaybeCreateStreamDecompressionCtx();
2900
2948
  if (!grpc_stream_decompress(stream_->stream_decompression_ctx,
2901
2949
  &stream_->unprocessed_incoming_frames_buffer,
2902
2950
  &stream_->decompressed_data_buffer, nullptr,
@@ -3127,6 +3175,16 @@ static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream),
3127
3175
 
3128
3176
  static const grpc_transport_vtable* get_vtable(void) { return &vtable; }
3129
3177
 
3178
+ intptr_t grpc_chttp2_transport_get_socket_uuid(grpc_transport* transport) {
3179
+ grpc_chttp2_transport* t =
3180
+ reinterpret_cast<grpc_chttp2_transport*>(transport);
3181
+ if (t->channelz_socket != nullptr) {
3182
+ return t->channelz_socket->uuid();
3183
+ } else {
3184
+ return 0;
3185
+ }
3186
+ }
3187
+
3130
3188
  grpc_transport* grpc_create_chttp2_transport(
3131
3189
  const grpc_channel_args* channel_args, grpc_endpoint* ep, bool is_client) {
3132
3190
  grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(