grpc 1.1.2 → 1.2.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 (255) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1257 -404
  3. data/etc/roots.pem +189 -102
  4. data/include/grpc/census.h +7 -7
  5. data/include/grpc/compression.h +4 -4
  6. data/include/grpc/grpc.h +13 -7
  7. data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
  8. data/include/grpc/impl/codegen/grpc_types.h +39 -30
  9. data/include/grpc/impl/codegen/slice.h +24 -6
  10. data/include/grpc/impl/codegen/sync.h +8 -0
  11. data/include/grpc/load_reporting.h +63 -0
  12. data/include/grpc/slice.h +37 -1
  13. data/include/grpc/slice_buffer.h +7 -0
  14. data/include/grpc/support/alloc.h +3 -0
  15. data/include/grpc/support/useful.h +3 -0
  16. data/src/core/ext/census/gen/census.pb.h +1 -1
  17. data/src/core/ext/census/gen/trace_context.pb.c +9 -36
  18. data/src/core/ext/census/gen/trace_context.pb.h +20 -26
  19. data/src/core/ext/census/grpc_filter.c +3 -5
  20. data/src/core/ext/census/trace_context.c +1 -1
  21. data/src/core/ext/census/trace_context.h +3 -0
  22. data/src/core/ext/census/trace_label.h +61 -0
  23. data/src/core/ext/census/trace_propagation.h +63 -0
  24. data/src/core/ext/census/trace_status.h +45 -0
  25. data/src/core/ext/census/trace_string.h +50 -0
  26. data/src/core/ext/census/tracing.c +31 -11
  27. data/src/core/ext/census/tracing.h +124 -0
  28. data/src/core/ext/client_channel/client_channel.c +456 -368
  29. data/src/core/ext/client_channel/client_channel.h +4 -0
  30. data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
  31. data/src/core/ext/client_channel/connector.c +3 -3
  32. data/src/core/ext/client_channel/connector.h +4 -3
  33. data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
  34. data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
  35. data/src/core/ext/client_channel/http_proxy.c +125 -0
  36. data/src/core/ext/client_channel/http_proxy.h +39 -0
  37. data/src/core/ext/client_channel/lb_policy.c +56 -35
  38. data/src/core/ext/client_channel/lb_policy.h +46 -39
  39. data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
  40. data/src/core/ext/client_channel/parse_address.c +32 -6
  41. data/src/core/ext/client_channel/proxy_mapper.c +63 -0
  42. data/src/core/ext/client_channel/proxy_mapper.h +89 -0
  43. data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
  44. data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
  45. data/src/core/ext/client_channel/resolver.c +16 -9
  46. data/src/core/ext/client_channel/resolver.h +23 -12
  47. data/src/core/ext/client_channel/resolver_factory.h +1 -0
  48. data/src/core/ext/client_channel/resolver_registry.c +15 -11
  49. data/src/core/ext/client_channel/resolver_registry.h +5 -3
  50. data/src/core/ext/client_channel/subchannel.c +44 -27
  51. data/src/core/ext/client_channel/subchannel.h +6 -2
  52. data/src/core/ext/client_channel/uri_parser.c +26 -14
  53. data/src/core/ext/client_channel/uri_parser.h +3 -1
  54. data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
  55. data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
  56. data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
  57. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
  58. data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
  59. data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
  60. data/src/core/ext/load_reporting/load_reporting.c +20 -0
  61. data/src/core/ext/load_reporting/load_reporting.h +1 -16
  62. data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
  63. data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
  64. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
  65. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
  67. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
  68. data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
  69. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
  70. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
  71. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
  72. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
  73. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
  74. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
  75. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
  76. data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
  77. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
  78. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
  79. data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
  80. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
  81. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
  84. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
  86. data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
  87. data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
  88. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
  89. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
  90. data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
  91. data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
  92. data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
  93. data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
  94. data/src/core/lib/channel/channel_stack.c +14 -44
  95. data/src/core/lib/channel/channel_stack.h +10 -17
  96. data/src/core/lib/channel/channel_stack_builder.c +2 -3
  97. data/src/core/lib/channel/compress_filter.c +54 -46
  98. data/src/core/lib/channel/connected_channel.c +4 -4
  99. data/src/core/lib/channel/connected_channel.h +5 -0
  100. data/src/core/lib/channel/context.h +3 -0
  101. data/src/core/lib/channel/deadline_filter.c +61 -61
  102. data/src/core/lib/channel/deadline_filter.h +8 -5
  103. data/src/core/lib/channel/handshaker.c +47 -7
  104. data/src/core/lib/channel/handshaker.h +21 -3
  105. data/src/core/lib/channel/http_client_filter.c +149 -99
  106. data/src/core/lib/channel/http_server_filter.c +163 -147
  107. data/src/core/lib/channel/message_size_filter.c +15 -10
  108. data/src/core/lib/compression/algorithm_metadata.h +4 -4
  109. data/src/core/lib/compression/compression.c +17 -23
  110. data/src/core/lib/http/httpcli.c +3 -2
  111. data/src/core/lib/http/httpcli.h +2 -1
  112. data/src/core/lib/http/httpcli_security_connector.c +2 -3
  113. data/src/core/lib/http/parser.c +2 -2
  114. data/src/core/lib/iomgr/closure.c +6 -3
  115. data/src/core/lib/iomgr/closure.h +4 -2
  116. data/src/core/lib/iomgr/combiner.c +35 -5
  117. data/src/core/lib/iomgr/combiner.h +21 -2
  118. data/src/core/lib/iomgr/endpoint.c +3 -2
  119. data/src/core/lib/iomgr/endpoint.h +3 -2
  120. data/src/core/lib/iomgr/error.c +60 -94
  121. data/src/core/lib/iomgr/error.h +7 -10
  122. data/src/core/lib/iomgr/error_internal.h +54 -0
  123. data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
  124. data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
  125. data/src/core/lib/iomgr/ev_posix.c +7 -8
  126. data/src/core/lib/iomgr/ev_posix.h +4 -4
  127. data/src/core/lib/iomgr/exec_ctx.c +11 -6
  128. data/src/core/lib/iomgr/exec_ctx.h +11 -14
  129. data/src/core/lib/iomgr/executor.c +2 -2
  130. data/src/core/lib/iomgr/load_file.c +1 -1
  131. data/src/core/lib/iomgr/network_status_tracker.c +5 -81
  132. data/src/core/lib/iomgr/pollset.h +1 -3
  133. data/src/core/lib/iomgr/pollset_set.h +2 -1
  134. data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
  135. data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
  136. data/src/core/lib/iomgr/pollset_uv.c +25 -11
  137. data/src/core/lib/iomgr/pollset_windows.c +0 -11
  138. data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
  139. data/src/core/lib/iomgr/resource_quota.c +41 -11
  140. data/src/core/lib/iomgr/resource_quota.h +6 -0
  141. data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
  142. data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
  143. data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
  144. data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
  145. data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
  146. data/src/core/lib/iomgr/tcp_posix.c +4 -5
  147. data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
  148. data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
  149. data/src/core/lib/iomgr/tcp_uv.c +11 -5
  150. data/src/core/lib/iomgr/tcp_windows.c +20 -7
  151. data/src/core/lib/iomgr/timer_generic.c +15 -22
  152. data/src/core/lib/iomgr/timer_generic.h +1 -1
  153. data/src/core/lib/iomgr/timer_uv.c +10 -6
  154. data/src/core/lib/iomgr/timer_uv.h +1 -1
  155. data/src/core/lib/iomgr/udp_server.c +45 -6
  156. data/src/core/lib/iomgr/udp_server.h +7 -1
  157. data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
  158. data/src/core/lib/json/json.c +1 -2
  159. data/src/core/lib/profiling/basic_timers.c +17 -3
  160. data/src/core/lib/security/context/security_context.c +3 -10
  161. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
  162. data/src/core/lib/security/credentials/credentials.c +48 -2
  163. data/src/core/lib/security/credentials/credentials.h +13 -0
  164. data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
  165. data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
  166. data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
  167. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
  168. data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
  169. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
  170. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
  171. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  172. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
  173. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
  174. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
  175. data/src/core/lib/security/transport/client_auth_filter.c +72 -47
  176. data/src/core/lib/security/transport/lb_targets_info.c +70 -0
  177. data/src/core/lib/security/transport/lb_targets_info.h +47 -0
  178. data/src/core/lib/security/transport/secure_endpoint.c +3 -3
  179. data/src/core/lib/security/transport/security_connector.c +125 -28
  180. data/src/core/lib/security/transport/security_connector.h +4 -3
  181. data/src/core/lib/security/transport/security_handshaker.c +13 -9
  182. data/src/core/lib/security/transport/server_auth_filter.c +31 -40
  183. data/src/core/lib/security/util/b64.c +1 -1
  184. data/src/core/lib/slice/slice.c +110 -20
  185. data/src/core/lib/slice/slice_buffer.c +92 -39
  186. data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
  187. data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
  188. data/src/core/lib/slice/slice_intern.c +346 -0
  189. data/src/core/lib/slice/slice_internal.h +15 -0
  190. data/src/core/lib/slice/slice_string_helpers.c +5 -0
  191. data/src/core/lib/slice/slice_string_helpers.h +5 -0
  192. data/src/core/lib/support/alloc.c +26 -1
  193. data/src/core/lib/support/cmdline.c +2 -4
  194. data/src/core/lib/support/cpu_posix.c +2 -7
  195. data/src/core/lib/support/histogram.c +1 -2
  196. data/src/core/lib/support/log_posix.c +8 -4
  197. data/src/core/lib/support/spinlock.h +52 -0
  198. data/src/core/lib/support/subprocess_posix.c +1 -2
  199. data/src/core/lib/support/sync.c +7 -1
  200. data/src/core/lib/support/sync_posix.c +9 -0
  201. data/src/core/lib/support/time_windows.c +7 -1
  202. data/src/core/lib/surface/call.c +647 -629
  203. data/src/core/lib/surface/call.h +4 -1
  204. data/src/core/lib/surface/call_details.c +8 -2
  205. data/src/core/lib/surface/call_log_batch.c +17 -6
  206. data/src/core/lib/surface/channel.c +49 -59
  207. data/src/core/lib/surface/channel.h +5 -6
  208. data/src/core/lib/surface/completion_queue.c +16 -45
  209. data/src/core/lib/surface/completion_queue.h +0 -3
  210. data/src/core/lib/surface/init.c +6 -2
  211. data/src/core/lib/surface/init_secure.c +1 -1
  212. data/src/core/lib/surface/lame_client.c +14 -4
  213. data/src/core/lib/surface/server.c +79 -82
  214. data/src/core/lib/surface/validate_metadata.c +46 -15
  215. data/src/core/lib/surface/validate_metadata.h +43 -0
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.c +104 -0
  218. data/src/core/lib/transport/bdp_estimator.h +76 -0
  219. data/src/core/lib/transport/connectivity_state.c +33 -13
  220. data/src/core/lib/transport/connectivity_state.h +15 -5
  221. data/src/core/lib/transport/error_utils.c +124 -0
  222. data/src/core/lib/transport/error_utils.h +56 -0
  223. data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
  224. data/src/core/lib/transport/metadata.c +259 -503
  225. data/src/core/lib/transport/metadata.h +69 -68
  226. data/src/core/lib/transport/metadata_batch.c +183 -63
  227. data/src/core/lib/transport/metadata_batch.h +50 -26
  228. data/src/core/lib/transport/pid_controller.c +28 -8
  229. data/src/core/lib/transport/pid_controller.h +15 -2
  230. data/src/core/lib/transport/service_config.c +21 -18
  231. data/src/core/lib/transport/service_config.h +5 -5
  232. data/src/core/lib/transport/static_metadata.c +753 -112
  233. data/src/core/lib/transport/static_metadata.h +403 -264
  234. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
  235. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
  236. data/src/core/lib/transport/timeout_encoding.c +11 -9
  237. data/src/core/lib/transport/timeout_encoding.h +3 -1
  238. data/src/core/lib/transport/transport.c +47 -87
  239. data/src/core/lib/transport/transport.h +20 -25
  240. data/src/core/lib/transport/transport_op_string.c +7 -19
  241. data/src/core/lib/tsi/fake_transport_security.c +2 -4
  242. data/src/core/lib/tsi/ssl_transport_security.c +7 -16
  243. data/src/core/lib/tsi/transport_security.c +2 -4
  244. data/src/ruby/ext/grpc/extconf.rb +4 -1
  245. data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
  246. data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
  247. data/src/ruby/ext/grpc/rb_call.c +47 -46
  248. data/src/ruby/ext/grpc/rb_channel.c +21 -6
  249. data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
  250. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
  251. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
  252. data/src/ruby/ext/grpc/rb_server.c +6 -4
  253. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  254. data/src/ruby/lib/grpc/version.rb +1 -1
  255. metadata +33 -9
@@ -79,8 +79,8 @@ typedef struct {
79
79
  /* a circular buffer of headers - this is stored in the opposite order to
80
80
  what hpack specifies, in order to simplify table management a little...
81
81
  meaning lookups need to SUBTRACT from the end position */
82
- grpc_mdelem **ents;
83
- grpc_mdelem *static_ents[GRPC_CHTTP2_LAST_STATIC_ENTRY];
82
+ grpc_mdelem *ents;
83
+ grpc_mdelem static_ents[GRPC_CHTTP2_LAST_STATIC_ENTRY];
84
84
  } grpc_chttp2_hptbl;
85
85
 
86
86
  /* initialize a hpack table */
@@ -94,12 +94,12 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx,
94
94
  uint32_t bytes);
95
95
 
96
96
  /* lookup a table entry based on its hpack index */
97
- grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
98
- uint32_t index);
97
+ grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
98
+ uint32_t index);
99
99
  /* add a table entry to the index */
100
100
  grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx,
101
101
  grpc_chttp2_hptbl *tbl,
102
- grpc_mdelem *md) GRPC_MUST_USE_RESULT;
102
+ grpc_mdelem md) GRPC_MUST_USE_RESULT;
103
103
  /* Find a key/value pair in the table... returns the index in the table of the
104
104
  most similar entry, or 0 if the value was not found */
105
105
  typedef struct {
@@ -107,6 +107,6 @@ typedef struct {
107
107
  int has_value;
108
108
  } grpc_chttp2_hptbl_find_result;
109
109
  grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find(
110
- const grpc_chttp2_hptbl *tbl, grpc_mdelem *md);
110
+ const grpc_chttp2_hptbl *tbl, grpc_mdelem md);
111
111
 
112
112
  #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_TABLE_H */
@@ -57,7 +57,7 @@ void grpc_chttp2_incoming_metadata_buffer_destroy(
57
57
  }
58
58
 
59
59
  void grpc_chttp2_incoming_metadata_buffer_add(
60
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem) {
60
+ grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem elem) {
61
61
  GPR_ASSERT(!buffer->published);
62
62
  if (buffer->capacity == buffer->count) {
63
63
  buffer->capacity = GPR_MAX(8, 2 * buffer->capacity);
@@ -68,6 +68,19 @@ void grpc_chttp2_incoming_metadata_buffer_add(
68
68
  buffer->size += GRPC_MDELEM_LENGTH(elem);
69
69
  }
70
70
 
71
+ void grpc_chttp2_incoming_metadata_buffer_replace_or_add(
72
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer,
73
+ grpc_mdelem elem) {
74
+ for (size_t i = 0; i < buffer->count; i++) {
75
+ if (grpc_slice_eq(GRPC_MDKEY(buffer->elems[i].md), GRPC_MDKEY(elem))) {
76
+ GRPC_MDELEM_UNREF(exec_ctx, buffer->elems[i].md);
77
+ buffer->elems[i].md = elem;
78
+ return;
79
+ }
80
+ }
81
+ grpc_chttp2_incoming_metadata_buffer_add(buffer, elem);
82
+ }
83
+
71
84
  void grpc_chttp2_incoming_metadata_buffer_set_deadline(
72
85
  grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline) {
73
86
  GPR_ASSERT(!buffer->published);
@@ -75,21 +88,20 @@ void grpc_chttp2_incoming_metadata_buffer_set_deadline(
75
88
  }
76
89
 
77
90
  void grpc_chttp2_incoming_metadata_buffer_publish(
78
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch) {
91
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer,
92
+ grpc_metadata_batch *batch) {
79
93
  GPR_ASSERT(!buffer->published);
80
94
  buffer->published = 1;
81
95
  if (buffer->count > 0) {
82
96
  size_t i;
83
- for (i = 1; i < buffer->count; i++) {
84
- buffer->elems[i].prev = &buffer->elems[i - 1];
85
- }
86
- for (i = 0; i < buffer->count - 1; i++) {
87
- buffer->elems[i].next = &buffer->elems[i + 1];
97
+ for (i = 0; i < buffer->count; i++) {
98
+ /* TODO(ctiller): do something better here */
99
+ if (!GRPC_LOG_IF_ERROR("grpc_chttp2_incoming_metadata_buffer_publish",
100
+ grpc_metadata_batch_link_tail(
101
+ exec_ctx, batch, &buffer->elems[i]))) {
102
+ GRPC_MDELEM_UNREF(exec_ctx, buffer->elems[i].md);
103
+ }
88
104
  }
89
- buffer->elems[0].prev = NULL;
90
- buffer->elems[buffer->count - 1].next = NULL;
91
- batch->list.head = &buffer->elems[0];
92
- batch->list.tail = &buffer->elems[buffer->count - 1];
93
105
  } else {
94
106
  batch->list.head = batch->list.tail = NULL;
95
107
  }
@@ -51,10 +51,14 @@ void grpc_chttp2_incoming_metadata_buffer_init(
51
51
  void grpc_chttp2_incoming_metadata_buffer_destroy(
52
52
  grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer);
53
53
  void grpc_chttp2_incoming_metadata_buffer_publish(
54
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch);
54
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer,
55
+ grpc_metadata_batch *batch);
55
56
 
56
57
  void grpc_chttp2_incoming_metadata_buffer_add(
57
- grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem);
58
+ grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem elem);
59
+ void grpc_chttp2_incoming_metadata_buffer_replace_or_add(
60
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer,
61
+ grpc_mdelem elem);
58
62
  void grpc_chttp2_incoming_metadata_buffer_set_deadline(
59
63
  grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline);
60
64
 
@@ -50,7 +50,10 @@
50
50
  #include "src/core/ext/transport/chttp2/transport/stream_map.h"
51
51
  #include "src/core/lib/iomgr/combiner.h"
52
52
  #include "src/core/lib/iomgr/endpoint.h"
53
+ #include "src/core/lib/iomgr/timer.h"
54
+ #include "src/core/lib/transport/bdp_estimator.h"
53
55
  #include "src/core/lib/transport/connectivity_state.h"
56
+ #include "src/core/lib/transport/pid_controller.h"
54
57
  #include "src/core/lib/transport/transport_impl.h"
55
58
 
56
59
  /* streams are kept in various linked lists depending on what things need to
@@ -59,6 +62,7 @@ typedef enum {
59
62
  GRPC_CHTTP2_LIST_WRITABLE,
60
63
  GRPC_CHTTP2_LIST_WRITING,
61
64
  GRPC_CHTTP2_LIST_STALLED_BY_TRANSPORT,
65
+ GRPC_CHTTP2_LIST_STALLED_BY_STREAM,
62
66
  /** streams that are waiting to start because there are too many concurrent
63
67
  streams on the connection */
64
68
  GRPC_CHTTP2_LIST_WAITING_FOR_CONCURRENCY,
@@ -72,6 +76,34 @@ typedef enum {
72
76
  GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE_AND_COVERED_BY_POLLER,
73
77
  } grpc_chttp2_write_state;
74
78
 
79
+ typedef enum {
80
+ GRPC_CHTTP2_PING_ON_NEXT_WRITE = 0,
81
+ GRPC_CHTTP2_PING_BEFORE_TRANSPORT_WINDOW_UPDATE,
82
+ GRPC_CHTTP2_PING_TYPE_COUNT /* must be last */
83
+ } grpc_chttp2_ping_type;
84
+
85
+ typedef enum {
86
+ GRPC_CHTTP2_PCL_INITIATE = 0,
87
+ GRPC_CHTTP2_PCL_NEXT,
88
+ GRPC_CHTTP2_PCL_INFLIGHT,
89
+ GRPC_CHTTP2_PCL_COUNT /* must be last */
90
+ } grpc_chttp2_ping_closure_list;
91
+
92
+ typedef struct {
93
+ grpc_closure_list lists[GRPC_CHTTP2_PCL_COUNT];
94
+ uint64_t inflight_id;
95
+ } grpc_chttp2_ping_queue;
96
+
97
+ typedef struct {
98
+ gpr_timespec min_time_between_pings;
99
+ int max_pings_without_data;
100
+ } grpc_chttp2_repeated_ping_policy;
101
+
102
+ typedef struct {
103
+ gpr_timespec last_ping_sent_time;
104
+ int pings_before_data_required;
105
+ } grpc_chttp2_repeated_ping_state;
106
+
75
107
  /* deframer state for the overall http2 stream of bytes */
76
108
  typedef enum {
77
109
  /* prefix: one entry per http2 connection prefix byte */
@@ -144,14 +176,6 @@ typedef enum {
144
176
  GRPC_CHTTP2_GOAWAY_SENT,
145
177
  } grpc_chttp2_sent_goaway_state;
146
178
 
147
- /* Outstanding ping request data */
148
- typedef struct grpc_chttp2_outstanding_ping {
149
- uint8_t id[8];
150
- grpc_closure *on_recv;
151
- struct grpc_chttp2_outstanding_ping *next;
152
- struct grpc_chttp2_outstanding_ping *prev;
153
- } grpc_chttp2_outstanding_ping;
154
-
155
179
  typedef struct grpc_chttp2_write_cb {
156
180
  int64_t call_at_byte;
157
181
  grpc_closure *closure;
@@ -185,6 +209,12 @@ struct grpc_chttp2_incoming_byte_stream {
185
209
  grpc_closure finished_action;
186
210
  };
187
211
 
212
+ typedef enum {
213
+ GRPC_CHTTP2_KEEPALIVE_STATE_WAITING,
214
+ GRPC_CHTTP2_KEEPALIVE_STATE_PINGING,
215
+ GRPC_CHTTP2_KEEPALIVE_STATE_DYING,
216
+ } grpc_chttp2_keepalive_state;
217
+
188
218
  struct grpc_chttp2_transport {
189
219
  grpc_transport base; /* must be first */
190
220
  gpr_refcount refs;
@@ -204,6 +234,9 @@ struct grpc_chttp2_transport {
204
234
  /** is there a read request to the endpoint outstanding? */
205
235
  uint8_t endpoint_reading;
206
236
 
237
+ /** should we probe bdp? */
238
+ bool enable_bdp_probe;
239
+
207
240
  /** various lists of streams */
208
241
  grpc_chttp2_stream_list lists[STREAM_LIST_COUNT];
209
242
 
@@ -245,10 +278,6 @@ struct grpc_chttp2_transport {
245
278
  /** data to write next write */
246
279
  grpc_slice_buffer qbuf;
247
280
 
248
- /** window available to announce to peer */
249
- int64_t announce_incoming_window;
250
- /** how much window would we like to have for incoming_window */
251
- uint32_t connection_window_target;
252
281
  /** how much data are we willing to buffer when the WRITE_BUFFER_HINT is set?
253
282
  */
254
283
  uint32_t write_buffer_size;
@@ -271,16 +300,19 @@ struct grpc_chttp2_transport {
271
300
  copied to next_stream_id in parsing when parsing commences */
272
301
  uint32_t next_stream_id;
273
302
 
274
- /** how far to lookahead in a stream? */
275
- uint32_t stream_lookahead;
276
-
277
303
  /** last new stream id */
278
304
  uint32_t last_new_stream_id;
279
305
 
280
- /** pings awaiting responses */
281
- grpc_chttp2_outstanding_ping pings;
282
- /** next payload for an outgoing ping */
283
- uint64_t ping_counter;
306
+ /** ping queues for various ping insertion points */
307
+ grpc_chttp2_ping_queue ping_queues[GRPC_CHTTP2_PING_TYPE_COUNT];
308
+ grpc_chttp2_repeated_ping_policy ping_policy;
309
+ grpc_chttp2_repeated_ping_state ping_state;
310
+ uint64_t ping_ctr; /* unique id for pings */
311
+
312
+ /** ping acks */
313
+ size_t ping_ack_count;
314
+ size_t ping_ack_capacity;
315
+ uint64_t *ping_acks;
284
316
 
285
317
  /** parser for headers */
286
318
  grpc_chttp2_hpack_parser hpack_parser;
@@ -299,6 +331,16 @@ struct grpc_chttp2_transport {
299
331
 
300
332
  /** window available for peer to send to us */
301
333
  int64_t incoming_window;
334
+ /** calculating what we should give for incoming window:
335
+ we track the total amount of flow control over initial window size
336
+ across all streams: this is data that we want to receive right now (it
337
+ has an outstanding read)
338
+ and the total amount of flow control under initial window size across all
339
+ streams: this is data we've read early
340
+ we want to adjust incoming_window such that:
341
+ incoming_window = total_over - max(bdp - total_under, 0) */
342
+ int64_t stream_total_over_incoming_window;
343
+ int64_t stream_total_under_incoming_window;
302
344
 
303
345
  /* deframing */
304
346
  grpc_chttp2_deframe_transport_state deframe_state;
@@ -324,6 +366,13 @@ struct grpc_chttp2_transport {
324
366
 
325
367
  grpc_chttp2_write_cb *write_cb_pool;
326
368
 
369
+ /* bdp estimator */
370
+ grpc_bdp_estimator bdp_estimator;
371
+ grpc_pid_controller pid_controller;
372
+ grpc_closure start_bdp_ping_locked;
373
+ grpc_closure finish_bdp_ping_locked;
374
+ gpr_timespec last_pid_update;
375
+
327
376
  /* if non-NULL, close the transport with this error when writes are finished
328
377
  */
329
378
  grpc_error *close_transport_on_writes_finished;
@@ -340,6 +389,28 @@ struct grpc_chttp2_transport {
340
389
  grpc_closure benign_reclaimer_locked;
341
390
  /** destructive cleanup closure */
342
391
  grpc_closure destructive_reclaimer_locked;
392
+
393
+ /* keep-alive ping support */
394
+ /** Closure to initialize a keepalive ping */
395
+ grpc_closure init_keepalive_ping_locked;
396
+ /** Closure to run when the keepalive ping is sent */
397
+ grpc_closure start_keepalive_ping_locked;
398
+ /** Cousure to run when the keepalive ping ack is received */
399
+ grpc_closure finish_keepalive_ping_locked;
400
+ /** Closrue to run when the keepalive ping timeouts */
401
+ grpc_closure keepalive_watchdog_fired_locked;
402
+ /** timer to initiate ping events */
403
+ grpc_timer keepalive_ping_timer;
404
+ /** watchdog to kill the transport when waiting for the keepalive ping */
405
+ grpc_timer keepalive_watchdog_timer;
406
+ /** time duration in between pings */
407
+ gpr_timespec keepalive_time;
408
+ /** grace period for a ping to complete before watchdog kicks in */
409
+ gpr_timespec keepalive_timeout;
410
+ /** if keepalive pings are allowed when there's no outstanding streams */
411
+ bool keepalive_permit_without_calls;
412
+ /** keep-alive state machine state */
413
+ grpc_chttp2_keepalive_state keepalive_state;
343
414
  };
344
415
 
345
416
  typedef enum {
@@ -362,12 +433,10 @@ struct grpc_chttp2_stream {
362
433
  /** HTTP2 stream id for this stream, or zero if one has not been assigned */
363
434
  uint32_t id;
364
435
 
365
- /** window available for us to send to peer */
366
- int64_t outgoing_window;
367
- /** The number of bytes the upper layers have offered to receive.
368
- As the upper layer offers more bytes, this value increases.
369
- As bytes are read, this value decreases. */
370
- uint32_t max_recv_bytes;
436
+ /** window available for us to send to peer, over or under the initial window
437
+ * size of the transport... ie:
438
+ * outgoing_window = outgoing_window_delta + transport.initial_window_size */
439
+ int64_t outgoing_window_delta;
371
440
  /** things the upper layers would like to send */
372
441
  grpc_metadata_batch *send_initial_metadata;
373
442
  grpc_closure *send_initial_metadata_finished;
@@ -428,8 +497,10 @@ struct grpc_chttp2_stream {
428
497
  grpc_error *forced_close_error;
429
498
  /** how many header frames have we received? */
430
499
  uint8_t header_frames_received;
431
- /** window available for peer to send to us */
432
- int64_t incoming_window;
500
+ /** window available for peer to send to us (as a delta on
501
+ * transport.initial_window_size)
502
+ * incoming_window = incoming_window_delta + transport.initial_window_size */
503
+ int64_t incoming_window_delta;
433
504
  /** parsing state for data frames */
434
505
  grpc_chttp2_data_parser data_parser;
435
506
  /** number of bytes received - reset at end of parse thread execution */
@@ -478,36 +549,43 @@ bool grpc_chttp2_list_add_writable_stream(grpc_chttp2_transport *t,
478
549
  grpc_chttp2_stream *s);
479
550
  /** Get a writable stream
480
551
  returns non-zero if there was a stream available */
481
- int grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport *t,
482
- grpc_chttp2_stream **s);
552
+ bool grpc_chttp2_list_pop_writable_stream(grpc_chttp2_transport *t,
553
+ grpc_chttp2_stream **s);
483
554
  bool grpc_chttp2_list_remove_writable_stream(
484
555
  grpc_chttp2_transport *t, grpc_chttp2_stream *s) GRPC_MUST_USE_RESULT;
485
556
 
486
557
  bool grpc_chttp2_list_add_writing_stream(grpc_chttp2_transport *t,
487
558
  grpc_chttp2_stream *s);
488
- int grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport *t);
489
- int grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport *t,
490
- grpc_chttp2_stream **s);
559
+ bool grpc_chttp2_list_have_writing_streams(grpc_chttp2_transport *t);
560
+ bool grpc_chttp2_list_pop_writing_stream(grpc_chttp2_transport *t,
561
+ grpc_chttp2_stream **s);
491
562
 
492
563
  void grpc_chttp2_list_add_written_stream(grpc_chttp2_transport *t,
493
564
  grpc_chttp2_stream *s);
494
- int grpc_chttp2_list_pop_written_stream(grpc_chttp2_transport *t,
495
- grpc_chttp2_stream **s);
565
+ bool grpc_chttp2_list_pop_written_stream(grpc_chttp2_transport *t,
566
+ grpc_chttp2_stream **s);
496
567
 
497
568
  void grpc_chttp2_list_add_waiting_for_concurrency(grpc_chttp2_transport *t,
498
569
  grpc_chttp2_stream *s);
499
- int grpc_chttp2_list_pop_waiting_for_concurrency(grpc_chttp2_transport *t,
500
- grpc_chttp2_stream **s);
570
+ bool grpc_chttp2_list_pop_waiting_for_concurrency(grpc_chttp2_transport *t,
571
+ grpc_chttp2_stream **s);
501
572
  void grpc_chttp2_list_remove_waiting_for_concurrency(grpc_chttp2_transport *t,
502
573
  grpc_chttp2_stream *s);
503
574
 
504
575
  void grpc_chttp2_list_add_stalled_by_transport(grpc_chttp2_transport *t,
505
576
  grpc_chttp2_stream *s);
506
- int grpc_chttp2_list_pop_stalled_by_transport(grpc_chttp2_transport *t,
507
- grpc_chttp2_stream **s);
577
+ bool grpc_chttp2_list_pop_stalled_by_transport(grpc_chttp2_transport *t,
578
+ grpc_chttp2_stream **s);
508
579
  void grpc_chttp2_list_remove_stalled_by_transport(grpc_chttp2_transport *t,
509
580
  grpc_chttp2_stream *s);
510
581
 
582
+ void grpc_chttp2_list_add_stalled_by_stream(grpc_chttp2_transport *t,
583
+ grpc_chttp2_stream *s);
584
+ bool grpc_chttp2_list_pop_stalled_by_stream(grpc_chttp2_transport *t,
585
+ grpc_chttp2_stream **s);
586
+ bool grpc_chttp2_list_remove_stalled_by_stream(grpc_chttp2_transport *t,
587
+ grpc_chttp2_stream *s);
588
+
511
589
  grpc_chttp2_stream *grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport *t,
512
590
  uint32_t id);
513
591
  grpc_chttp2_stream *grpc_chttp2_parsing_accept_stream(grpc_exec_ctx *exec_ctx,
@@ -591,6 +669,44 @@ typedef enum {
591
669
  GRPC_CHTTP2_FLOW_CREDIT_COMMON(phase, dst_context, 0, dst_context, dst_var, \
592
670
  amount)
593
671
 
672
+ #define GRPC_CHTTP2_FLOW_STREAM_INCOMING_WINDOW_DELTA_PREUPDATE( \
673
+ phase, transport, dst_context) \
674
+ if (dst_context->incoming_window_delta < 0) { \
675
+ transport->stream_total_under_incoming_window += \
676
+ dst_context->incoming_window_delta; \
677
+ } else if (dst_context->incoming_window_delta > 0) { \
678
+ transport->stream_total_over_incoming_window -= \
679
+ dst_context->incoming_window_delta; \
680
+ }
681
+
682
+ #define GRPC_CHTTP2_FLOW_STREAM_INCOMING_WINDOW_DELTA_POSTUPDATE( \
683
+ phase, transport, dst_context) \
684
+ if (dst_context->incoming_window_delta < 0) { \
685
+ transport->stream_total_under_incoming_window -= \
686
+ dst_context->incoming_window_delta; \
687
+ } else if (dst_context->incoming_window_delta > 0) { \
688
+ transport->stream_total_over_incoming_window += \
689
+ dst_context->incoming_window_delta; \
690
+ }
691
+
692
+ #define GRPC_CHTTP2_FLOW_DEBIT_STREAM_INCOMING_WINDOW_DELTA( \
693
+ phase, transport, dst_context, amount) \
694
+ GRPC_CHTTP2_FLOW_STREAM_INCOMING_WINDOW_DELTA_PREUPDATE(phase, transport, \
695
+ dst_context); \
696
+ GRPC_CHTTP2_FLOW_DEBIT_STREAM(phase, transport, dst_context, \
697
+ incoming_window_delta, amount); \
698
+ GRPC_CHTTP2_FLOW_STREAM_INCOMING_WINDOW_DELTA_POSTUPDATE(phase, transport, \
699
+ dst_context);
700
+
701
+ #define GRPC_CHTTP2_FLOW_CREDIT_STREAM_INCOMING_WINDOW_DELTA( \
702
+ phase, transport, dst_context, amount) \
703
+ GRPC_CHTTP2_FLOW_STREAM_INCOMING_WINDOW_DELTA_PREUPDATE(phase, transport, \
704
+ dst_context); \
705
+ GRPC_CHTTP2_FLOW_CREDIT_STREAM(phase, transport, dst_context, \
706
+ incoming_window_delta, amount); \
707
+ GRPC_CHTTP2_FLOW_STREAM_INCOMING_WINDOW_DELTA_POSTUPDATE(phase, transport, \
708
+ dst_context);
709
+
594
710
  #define GRPC_CHTTP2_FLOW_DEBIT_COMMON(phase, transport, id, dst_context, \
595
711
  dst_var, amount) \
596
712
  do { \
@@ -618,8 +734,7 @@ void grpc_chttp2_flowctl_trace(const char *file, int line, const char *phase,
618
734
  uint32_t stream_id, int64_t val1, int64_t val2);
619
735
 
620
736
  void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
621
- grpc_chttp2_stream *stream,
622
- grpc_status_code status, grpc_slice *details);
737
+ grpc_chttp2_stream *stream, grpc_error *error);
623
738
  void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx,
624
739
  grpc_chttp2_transport *t,
625
740
  grpc_chttp2_stream *s, int close_reads,
@@ -673,13 +788,23 @@ void grpc_chttp2_incoming_byte_stream_finished(
673
788
  grpc_error *error);
674
789
 
675
790
  void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
676
- const uint8_t *opaque_8bytes);
791
+ uint64_t id);
792
+
793
+ typedef enum {
794
+ /* don't initiate a transport write, but piggyback on the next one */
795
+ GRPC_CHTTP2_STREAM_WRITE_PIGGYBACK,
796
+ /* initiate a covered write */
797
+ GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED,
798
+ /* initiate an uncovered write */
799
+ GRPC_CHTTP2_STREAM_WRITE_INITIATE_UNCOVERED
800
+ } grpc_chttp2_stream_write_type;
677
801
 
678
802
  /** add a ref to the stream and add it to the writable list;
679
803
  ref will be dropped in writing.c */
680
804
  void grpc_chttp2_become_writable(grpc_exec_ctx *exec_ctx,
681
805
  grpc_chttp2_transport *t,
682
- grpc_chttp2_stream *s, bool covered_by_poller,
806
+ grpc_chttp2_stream *s,
807
+ grpc_chttp2_stream_write_type type,
683
808
  const char *reason);
684
809
 
685
810
  void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx,
@@ -700,4 +825,6 @@ void grpc_chttp2_fail_pending_writes(grpc_exec_ctx *exec_ctx,
700
825
  grpc_chttp2_transport *t,
701
826
  grpc_chttp2_stream *s, grpc_error *error);
702
827
 
828
+ uint32_t grpc_chttp2_target_incoming_window(grpc_chttp2_transport *t);
829
+
703
830
  #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_INTERNAL_H */