grpc 0.14.1 → 0.15.0

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 (277) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1398 -817
  3. data/include/grpc/compression.h +2 -1
  4. data/include/grpc/grpc.h +10 -1
  5. data/include/grpc/grpc_cronet.h +51 -0
  6. data/include/grpc/grpc_posix.h +70 -0
  7. data/include/grpc/impl/codegen/atm.h +2 -2
  8. data/include/grpc/impl/codegen/{atm_win32.h → atm_windows.h} +3 -3
  9. data/include/grpc/impl/codegen/compression_types.h +39 -5
  10. data/include/grpc/impl/codegen/connectivity_state.h +1 -1
  11. data/include/grpc/impl/codegen/grpc_types.h +10 -0
  12. data/include/grpc/impl/codegen/log.h +2 -1
  13. data/include/grpc/impl/codegen/port_platform.h +30 -12
  14. data/include/grpc/impl/codegen/slice_buffer.h +2 -3
  15. data/include/grpc/impl/codegen/sync.h +2 -2
  16. data/include/grpc/impl/codegen/{sync_win32.h → sync_windows.h} +3 -3
  17. data/include/grpc/support/{sync_win32.h → atm_windows.h} +4 -4
  18. data/include/grpc/support/avl.h +5 -0
  19. data/include/grpc/support/{log_win32.h → log_windows.h} +3 -3
  20. data/include/grpc/support/string_util.h +2 -1
  21. data/include/grpc/support/{atm_win32.h → sync_windows.h} +4 -4
  22. data/src/core/ext/census/gen/census.pb.c +179 -0
  23. data/src/core/ext/census/gen/census.pb.h +294 -0
  24. data/src/core/ext/census/grpc_filter.c +11 -7
  25. data/src/core/ext/client_config/channel_connectivity.c +28 -14
  26. data/src/core/ext/client_config/client_channel.c +77 -53
  27. data/src/core/ext/client_config/connector.h +1 -1
  28. data/src/core/ext/client_config/lb_policy.c +9 -6
  29. data/src/core/ext/client_config/lb_policy.h +9 -5
  30. data/src/core/ext/client_config/subchannel.c +58 -39
  31. data/src/core/ext/client_config/subchannel.h +3 -2
  32. data/src/core/ext/client_config/subchannel_call_holder.c +34 -19
  33. data/src/core/ext/client_config/subchannel_call_holder.h +2 -1
  34. data/src/core/ext/client_config/subchannel_index.c +20 -9
  35. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +7 -7
  36. data/src/core/ext/lb_policy/grpclb/load_balancer_api.h +5 -5
  37. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/{v0 → v1}/load_balancer.pb.c +29 -30
  38. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +178 -0
  39. data/src/core/ext/lb_policy/pick_first/pick_first.c +65 -45
  40. data/src/core/ext/lb_policy/round_robin/round_robin.c +84 -43
  41. data/src/core/ext/load_reporting/load_reporting.c +133 -0
  42. data/src/core/ext/load_reporting/load_reporting.h +75 -0
  43. data/src/core/ext/load_reporting/load_reporting_filter.c +151 -0
  44. data/src/core/ext/load_reporting/load_reporting_filter.h +41 -0
  45. data/src/core/ext/resolver/dns/native/dns_resolver.c +22 -8
  46. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +2 -2
  47. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +4 -4
  48. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
  49. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +14 -18
  50. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +49 -24
  51. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +82 -0
  52. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +104 -60
  53. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +232 -0
  54. data/src/{ruby/ext/grpc/rb_signal.c → core/ext/transport/chttp2/transport/bin_decoder.h} +27 -31
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +481 -260
  56. data/src/core/ext/transport/chttp2/transport/frame.h +1 -7
  57. data/src/core/ext/transport/chttp2/transport/frame_data.c +44 -27
  58. data/src/core/ext/transport/chttp2/transport/frame_data.h +6 -5
  59. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +23 -17
  60. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +2 -2
  61. data/src/core/ext/transport/chttp2/transport/frame_ping.c +12 -7
  62. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -3
  63. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +25 -12
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +2 -2
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +23 -21
  66. data/src/core/ext/transport/chttp2/transport/frame_settings.h +2 -2
  67. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +17 -9
  68. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +2 -2
  69. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +365 -287
  70. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +8 -6
  71. data/src/core/ext/transport/chttp2/transport/hpack_table.c +24 -20
  72. data/src/core/ext/transport/chttp2/transport/hpack_table.h +5 -4
  73. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +1 -0
  74. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +1 -0
  75. data/src/core/ext/transport/chttp2/transport/internal.h +34 -32
  76. data/src/core/ext/transport/chttp2/transport/parsing.c +296 -212
  77. data/src/core/ext/transport/chttp2/transport/writing.c +12 -9
  78. data/src/core/lib/channel/channel_args.c +26 -12
  79. data/src/core/lib/channel/channel_args.h +1 -1
  80. data/src/core/lib/channel/channel_stack.c +12 -8
  81. data/src/core/lib/channel/channel_stack.h +27 -11
  82. data/src/core/lib/channel/channel_stack_builder.c +2 -2
  83. data/src/core/lib/channel/compress_filter.c +26 -31
  84. data/src/core/lib/channel/compress_filter.h +4 -4
  85. data/src/core/lib/channel/connected_channel.c +7 -5
  86. data/src/core/lib/channel/http_client_filter.c +34 -8
  87. data/src/core/lib/channel/http_client_filter.h +1 -1
  88. data/src/core/lib/channel/http_server_filter.c +21 -12
  89. data/src/core/lib/compression/{compression_algorithm.c → compression.c} +22 -21
  90. data/src/core/lib/http/httpcli.c +81 -59
  91. data/src/core/lib/http/httpcli.h +11 -15
  92. data/src/core/lib/http/httpcli_security_connector.c +5 -3
  93. data/src/core/lib/http/parser.c +127 -118
  94. data/src/core/lib/http/parser.h +11 -6
  95. data/src/core/lib/iomgr/closure.c +20 -16
  96. data/src/core/lib/iomgr/closure.h +19 -15
  97. data/src/core/lib/iomgr/endpoint.h +1 -1
  98. data/src/core/lib/iomgr/endpoint_pair_posix.c +2 -2
  99. data/src/core/lib/iomgr/error.c +535 -0
  100. data/src/core/lib/iomgr/error.h +192 -0
  101. data/src/core/lib/iomgr/ev_poll_and_epoll_posix.c +190 -83
  102. data/src/core/lib/iomgr/ev_poll_posix.c +1267 -0
  103. data/src/{ruby/ext/grpc/rb_signal.h → core/lib/iomgr/ev_poll_posix.h} +7 -5
  104. data/src/core/lib/iomgr/ev_posix.c +104 -14
  105. data/src/core/lib/iomgr/ev_posix.h +17 -7
  106. data/src/core/lib/iomgr/exec_ctx.c +25 -7
  107. data/src/core/lib/iomgr/exec_ctx.h +27 -8
  108. data/src/core/lib/iomgr/executor.c +2 -2
  109. data/src/core/lib/iomgr/executor.h +1 -1
  110. data/src/core/lib/iomgr/iocp_windows.c +2 -41
  111. data/src/core/lib/iomgr/iocp_windows.h +0 -8
  112. data/src/core/lib/iomgr/iomgr.c +5 -4
  113. data/src/core/lib/iomgr/iomgr_posix.c +5 -1
  114. data/src/core/lib/iomgr/iomgr_windows.c +1 -1
  115. data/src/core/lib/{support → iomgr}/load_file.c +15 -17
  116. data/src/core/lib/{support → iomgr}/load_file.h +8 -7
  117. data/src/core/lib/iomgr/polling_entity.c +104 -0
  118. data/src/core/lib/iomgr/polling_entity.h +81 -0
  119. data/src/core/lib/iomgr/pollset.h +6 -5
  120. data/src/core/lib/iomgr/pollset_set_windows.c +4 -1
  121. data/src/core/lib/iomgr/pollset_windows.c +10 -6
  122. data/src/core/lib/iomgr/resolve_address.h +5 -9
  123. data/src/core/lib/iomgr/resolve_address_posix.c +55 -38
  124. data/src/core/lib/iomgr/resolve_address_windows.c +51 -37
  125. data/src/core/lib/iomgr/sockaddr.h +2 -2
  126. data/src/core/lib/iomgr/{sockaddr_win32.h → sockaddr_windows.h} +3 -3
  127. data/src/core/lib/iomgr/socket_utils_common_posix.c +92 -45
  128. data/src/core/lib/iomgr/socket_utils_posix.h +19 -12
  129. data/src/core/lib/iomgr/socket_windows.c +61 -2
  130. data/src/core/lib/iomgr/socket_windows.h +13 -0
  131. data/src/core/lib/iomgr/tcp_client_posix.c +54 -39
  132. data/src/core/lib/iomgr/tcp_client_windows.c +34 -34
  133. data/src/core/lib/iomgr/tcp_posix.c +43 -39
  134. data/src/core/lib/iomgr/tcp_server.h +5 -3
  135. data/src/core/lib/iomgr/tcp_server_posix.c +103 -64
  136. data/src/core/lib/iomgr/tcp_server_windows.c +114 -101
  137. data/src/core/lib/iomgr/tcp_windows.c +45 -50
  138. data/src/core/lib/iomgr/tcp_windows.h +1 -1
  139. data/src/core/lib/iomgr/timer.c +26 -13
  140. data/src/core/lib/iomgr/udp_server.c +28 -4
  141. data/src/core/lib/iomgr/udp_server.h +5 -1
  142. data/src/core/lib/iomgr/unix_sockets_posix.c +8 -7
  143. data/src/core/lib/iomgr/unix_sockets_posix.h +2 -1
  144. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +4 -2
  145. data/src/core/lib/iomgr/wakeup_fd_eventfd.c +15 -5
  146. data/src/core/lib/iomgr/wakeup_fd_pipe.c +13 -9
  147. data/src/core/lib/iomgr/wakeup_fd_posix.c +6 -6
  148. data/src/core/lib/iomgr/wakeup_fd_posix.h +9 -6
  149. data/src/core/lib/iomgr/workqueue.h +5 -4
  150. data/src/core/lib/iomgr/workqueue_posix.c +40 -26
  151. data/src/core/lib/iomgr/workqueue_windows.c +2 -2
  152. data/src/core/lib/profiling/basic_timers.c +2 -2
  153. data/src/core/lib/security/{security_context.c → context/security_context.c} +1 -1
  154. data/src/core/lib/security/{security_context.h → context/security_context.h} +4 -4
  155. data/src/core/lib/security/credentials/composite/composite_credentials.c +263 -0
  156. data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
  157. data/src/core/lib/security/credentials/credentials.c +233 -0
  158. data/src/core/lib/security/{credentials.h → credentials/credentials.h} +19 -157
  159. data/src/core/lib/security/{credentials_metadata.c → credentials/credentials_metadata.c} +1 -1
  160. data/src/core/lib/security/credentials/fake/fake_credentials.c +139 -0
  161. data/src/core/lib/security/credentials/fake/fake_credentials.h +56 -0
  162. data/src/core/lib/security/{credentials_posix.c → credentials/google_default/credentials_posix.c} +1 -1
  163. data/src/core/lib/security/{credentials_win32.c → credentials/google_default/credentials_windows.c} +3 -3
  164. data/src/core/lib/security/{google_default_credentials.c → credentials/google_default/google_default_credentials.c} +93 -35
  165. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +46 -0
  166. data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
  167. data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
  168. data/src/core/lib/security/{json_token.c → credentials/jwt/json_token.c} +10 -101
  169. data/src/core/lib/security/{json_token.h → credentials/jwt/json_token.h} +3 -33
  170. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +160 -0
  171. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +62 -0
  172. data/src/core/lib/security/{jwt_verifier.c → credentials/jwt/jwt_verifier.c} +35 -15
  173. data/src/core/lib/security/{jwt_verifier.h → credentials/jwt/jwt_verifier.h} +3 -3
  174. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +433 -0
  175. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
  176. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +129 -0
  177. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
  178. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +240 -0
  179. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
  180. data/src/core/lib/security/{auth_filters.h → transport/auth_filters.h} +3 -3
  181. data/src/core/lib/security/{client_auth_filter.c → transport/client_auth_filter.c} +27 -20
  182. data/src/core/lib/security/{handshake.c → transport/handshake.c} +77 -45
  183. data/src/core/lib/security/{handshake.h → transport/handshake.h} +9 -11
  184. data/src/core/lib/security/{secure_endpoint.c → transport/secure_endpoint.c} +19 -12
  185. data/src/core/lib/security/{secure_endpoint.h → transport/secure_endpoint.h} +3 -3
  186. data/src/core/lib/security/{security_connector.c → transport/security_connector.c} +26 -17
  187. data/src/core/lib/security/{security_connector.h → transport/security_connector.h} +8 -8
  188. data/src/core/lib/security/{server_auth_filter.c → transport/server_auth_filter.c} +24 -16
  189. data/src/core/lib/security/transport/tsi_error.c +40 -0
  190. data/src/core/lib/security/transport/tsi_error.h +42 -0
  191. data/src/core/lib/security/{b64.c → util/b64.c} +1 -1
  192. data/src/core/lib/security/{b64.h → util/b64.h} +3 -3
  193. data/src/core/lib/security/util/json_util.c +61 -0
  194. data/src/core/lib/security/util/json_util.h +55 -0
  195. data/src/core/lib/support/avl.c +11 -0
  196. data/src/core/lib/support/cpu_windows.c +2 -2
  197. data/src/core/lib/support/{env_win32.c → env_windows.c} +3 -3
  198. data/src/core/lib/support/log.c +3 -1
  199. data/src/core/lib/support/log_linux.c +2 -2
  200. data/src/core/lib/support/{log_win32.c → log_windows.c} +4 -4
  201. data/src/core/lib/support/murmur_hash.c +3 -5
  202. data/src/core/lib/support/string.c +10 -0
  203. data/src/core/lib/support/string.h +4 -0
  204. data/src/core/lib/support/{string_util_win32.c → string_util_windows.c} +3 -3
  205. data/src/core/lib/support/{string_win32.c → string_windows.c} +2 -2
  206. data/src/core/lib/support/{string_win32.h → string_windows.h} +5 -5
  207. data/src/core/lib/support/subprocess_windows.c +1 -1
  208. data/src/core/lib/support/{sync_win32.c → sync_windows.c} +2 -2
  209. data/src/core/lib/support/{thd_win32.c → thd_windows.c} +2 -2
  210. data/src/core/lib/support/{time_win32.c → time_windows.c} +2 -2
  211. data/src/core/lib/support/tmpfile_msys.c +1 -1
  212. data/src/core/lib/support/{tmpfile_win32.c → tmpfile_windows.c} +3 -3
  213. data/src/core/lib/surface/alarm.c +2 -2
  214. data/src/core/lib/surface/byte_buffer_reader.c +13 -6
  215. data/src/core/lib/surface/call.c +323 -123
  216. data/src/core/lib/surface/call.h +2 -0
  217. data/src/core/lib/surface/call_log_batch.c +1 -1
  218. data/src/core/lib/surface/channel.c +64 -15
  219. data/src/core/lib/surface/channel.h +9 -0
  220. data/src/core/lib/surface/channel_ping.c +3 -3
  221. data/src/core/lib/surface/completion_queue.c +75 -19
  222. data/src/core/lib/surface/completion_queue.h +7 -2
  223. data/src/core/lib/surface/init.c +2 -1
  224. data/src/core/lib/surface/init_secure.c +4 -4
  225. data/src/core/lib/surface/lame_client.c +12 -8
  226. data/src/core/lib/surface/server.c +213 -120
  227. data/src/core/lib/surface/server.h +1 -0
  228. data/src/core/lib/surface/version.c +1 -1
  229. data/src/core/lib/transport/connectivity_state.c +40 -18
  230. data/src/core/lib/transport/connectivity_state.h +4 -1
  231. data/src/core/lib/transport/metadata.c +23 -23
  232. data/src/core/lib/transport/metadata.h +4 -0
  233. data/src/core/lib/transport/metadata_batch.c +9 -0
  234. data/src/core/lib/transport/metadata_batch.h +3 -0
  235. data/src/core/lib/transport/static_metadata.c +6 -5
  236. data/src/core/lib/transport/static_metadata.h +64 -60
  237. data/src/core/lib/transport/transport.c +24 -12
  238. data/src/core/lib/transport/transport.h +6 -5
  239. data/src/core/lib/transport/transport_impl.h +4 -0
  240. data/src/core/lib/transport/transport_op_string.c +2 -2
  241. data/src/core/plugin_registry/grpc_plugin_registry.c +4 -0
  242. data/src/ruby/bin/math_services.rb +41 -2
  243. data/src/ruby/ext/grpc/rb_call.c +42 -40
  244. data/src/ruby/ext/grpc/rb_channel.c +1 -1
  245. data/src/ruby/ext/grpc/rb_completion_queue.c +59 -6
  246. data/src/ruby/ext/grpc/rb_completion_queue.h +1 -1
  247. data/src/ruby/ext/grpc/rb_grpc.c +1 -3
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -2
  249. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +21 -5
  250. data/src/ruby/ext/grpc/rb_loader.c +1 -1
  251. data/src/ruby/ext/grpc/rb_server.c +5 -3
  252. data/src/ruby/lib/grpc.rb +0 -3
  253. data/src/ruby/lib/grpc/errors.rb +3 -2
  254. data/src/ruby/lib/grpc/generic/active_call.rb +32 -42
  255. data/src/ruby/lib/grpc/generic/bidi_call.rb +20 -0
  256. data/src/ruby/lib/grpc/generic/client_stub.rb +31 -54
  257. data/src/ruby/lib/grpc/generic/rpc_desc.rb +4 -4
  258. data/src/ruby/lib/grpc/generic/rpc_server.rb +12 -23
  259. data/src/ruby/lib/grpc/generic/service.rb +8 -8
  260. data/src/ruby/lib/grpc/version.rb +1 -1
  261. data/src/ruby/pb/grpc/health/v1/health_services.rb +30 -2
  262. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb +34 -4
  263. data/src/ruby/pb/grpc/testing/metrics_services.rb +39 -2
  264. data/src/ruby/pb/src/proto/grpc/testing/empty.rb +15 -0
  265. data/src/ruby/pb/src/proto/grpc/testing/messages.rb +84 -0
  266. data/src/ruby/pb/src/proto/grpc/testing/test.rb +14 -0
  267. data/src/ruby/pb/src/proto/grpc/testing/test_services.rb +110 -0
  268. data/src/ruby/pb/test/client.rb +5 -2
  269. data/src/ruby/spec/generic/active_call_spec.rb +3 -2
  270. data/src/ruby/spec/generic/client_stub_spec.rb +27 -24
  271. data/src/ruby/spec/generic/rpc_desc_spec.rb +11 -11
  272. data/src/ruby/spec/generic/rpc_server_spec.rb +42 -61
  273. data/src/ruby/spec/pb/health/checker_spec.rb +3 -5
  274. metadata +86 -48
  275. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0/load_balancer.pb.h +0 -182
  276. data/src/core/lib/security/credentials.c +0 -1296
  277. data/src/ruby/lib/grpc/signals.rb +0 -69
@@ -44,9 +44,8 @@
44
44
 
45
45
  typedef struct grpc_chttp2_hpack_parser grpc_chttp2_hpack_parser;
46
46
 
47
- typedef int (*grpc_chttp2_hpack_parser_state)(grpc_chttp2_hpack_parser *p,
48
- const uint8_t *beg,
49
- const uint8_t *end);
47
+ typedef grpc_error *(*grpc_chttp2_hpack_parser_state)(
48
+ grpc_chttp2_hpack_parser *p, const uint8_t *beg, const uint8_t *end);
50
49
 
51
50
  typedef struct {
52
51
  char *str;
@@ -59,6 +58,8 @@ struct grpc_chttp2_hpack_parser {
59
58
  void (*on_header)(void *user_data, grpc_mdelem *md);
60
59
  void *on_header_user_data;
61
60
 
61
+ grpc_error *last_error;
62
+
62
63
  /* current parse state - or a function that implements it */
63
64
  grpc_chttp2_hpack_parser_state state;
64
65
  /* future states dependent on the opening op code */
@@ -103,12 +104,13 @@ void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser *p);
103
104
  void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p);
104
105
 
105
106
  /* returns 1 on success, 0 on error */
106
- int grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p,
107
- const uint8_t *beg, const uint8_t *end);
107
+ grpc_error *grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser *p,
108
+ const uint8_t *beg,
109
+ const uint8_t *end);
108
110
 
109
111
  /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for
110
112
  the transport */
111
- grpc_chttp2_parse_error grpc_chttp2_header_parser_parse(
113
+ grpc_error *grpc_chttp2_header_parser_parse(
112
114
  grpc_exec_ctx *exec_ctx, void *hpack_parser,
113
115
  grpc_chttp2_transport_parsing *transport_parsing,
114
116
  grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last);
@@ -38,6 +38,7 @@
38
38
 
39
39
  #include <grpc/support/alloc.h>
40
40
  #include <grpc/support/log.h>
41
+ #include <grpc/support/string_util.h>
41
42
 
42
43
  #include "src/core/lib/support/murmur_hash.h"
43
44
 
@@ -262,18 +263,19 @@ void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl,
262
263
  tbl->max_bytes = max_bytes;
263
264
  }
264
265
 
265
- int grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
266
- uint32_t bytes) {
266
+ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
267
+ uint32_t bytes) {
267
268
  if (tbl->current_table_bytes == bytes) {
268
- return 1;
269
+ return GRPC_ERROR_NONE;
269
270
  }
270
271
  if (bytes > tbl->max_bytes) {
271
- if (grpc_http_trace) {
272
- gpr_log(GPR_ERROR,
273
- "Attempt to make hpack table %d bytes when max is %d bytes",
274
- bytes, tbl->max_bytes);
275
- }
276
- return 0;
272
+ char *msg;
273
+ gpr_asprintf(&msg,
274
+ "Attempt to make hpack table %d bytes when max is %d bytes",
275
+ bytes, tbl->max_bytes);
276
+ grpc_error *err = GRPC_ERROR_CREATE(msg);
277
+ gpr_free(msg);
278
+ return err;
277
279
  }
278
280
  if (grpc_http_trace) {
279
281
  gpr_log(GPR_DEBUG, "Update hpack parser table size to %d", bytes);
@@ -291,23 +293,25 @@ int grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
291
293
  rebuild_ents(tbl, new_cap);
292
294
  }
293
295
  }
294
- return 1;
296
+ return GRPC_ERROR_NONE;
295
297
  }
296
298
 
297
- int grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
299
+ grpc_error *grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
298
300
  /* determine how many bytes of buffer this entry represents */
299
301
  size_t elem_bytes = GPR_SLICE_LENGTH(md->key->slice) +
300
302
  GPR_SLICE_LENGTH(md->value->slice) +
301
303
  GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD;
302
304
 
303
305
  if (tbl->current_table_bytes > tbl->max_bytes) {
304
- if (grpc_http_trace) {
305
- gpr_log(GPR_ERROR,
306
- "HPACK max table size reduced to %d but not reflected by hpack "
307
- "stream (still at %d)",
308
- tbl->max_bytes, tbl->current_table_bytes);
309
- }
310
- return 0;
306
+ char *msg;
307
+ gpr_asprintf(
308
+ &msg,
309
+ "HPACK max table size reduced to %d but not reflected by hpack "
310
+ "stream (still at %d)",
311
+ tbl->max_bytes, tbl->current_table_bytes);
312
+ grpc_error *err = GRPC_ERROR_CREATE(msg);
313
+ gpr_free(msg);
314
+ return err;
311
315
  }
312
316
 
313
317
  /* we can't add elements bigger than the max table size */
@@ -324,7 +328,7 @@ int grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
324
328
  while (tbl->num_ents) {
325
329
  evict1(tbl);
326
330
  }
327
- return 1;
331
+ return GRPC_ERROR_NONE;
328
332
  }
329
333
 
330
334
  /* evict entries to ensure no overflow */
@@ -339,7 +343,7 @@ int grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl, grpc_mdelem *md) {
339
343
  /* update accounting values */
340
344
  tbl->num_ents++;
341
345
  tbl->mem_used += (uint32_t)elem_bytes;
342
- return 1;
346
+ return GRPC_ERROR_NONE;
343
347
  }
344
348
 
345
349
  grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find(
@@ -36,6 +36,7 @@
36
36
 
37
37
  #include <grpc/support/port_platform.h>
38
38
  #include <grpc/support/slice.h>
39
+ #include "src/core/lib/iomgr/error.h"
39
40
  #include "src/core/lib/transport/metadata.h"
40
41
 
41
42
  /* HPACK header table */
@@ -87,15 +88,15 @@ void grpc_chttp2_hptbl_init(grpc_chttp2_hptbl *tbl);
87
88
  void grpc_chttp2_hptbl_destroy(grpc_chttp2_hptbl *tbl);
88
89
  void grpc_chttp2_hptbl_set_max_bytes(grpc_chttp2_hptbl *tbl,
89
90
  uint32_t max_bytes);
90
- int grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
91
- uint32_t bytes);
91
+ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_chttp2_hptbl *tbl,
92
+ uint32_t bytes);
92
93
 
93
94
  /* lookup a table entry based on its hpack index */
94
95
  grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl,
95
96
  uint32_t index);
96
97
  /* add a table entry to the index */
97
- int grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl,
98
- grpc_mdelem *md) GRPC_MUST_USE_RESULT;
98
+ grpc_error *grpc_chttp2_hptbl_add(grpc_chttp2_hptbl *tbl,
99
+ grpc_mdelem *md) GRPC_MUST_USE_RESULT;
99
100
  /* Find a key/value pair in the table... returns the index in the table of the
100
101
  most similar entry, or 0 if the value was not found */
101
102
  typedef struct {
@@ -65,6 +65,7 @@ void grpc_chttp2_incoming_metadata_buffer_add(
65
65
  gpr_realloc(buffer->elems, sizeof(*buffer->elems) * buffer->capacity);
66
66
  }
67
67
  buffer->elems[buffer->count++].md = elem;
68
+ buffer->size += GRPC_MDELEM_LENGTH(elem);
68
69
  }
69
70
 
70
71
  void grpc_chttp2_incoming_metadata_buffer_set_deadline(
@@ -42,6 +42,7 @@ typedef struct {
42
42
  size_t capacity;
43
43
  gpr_timespec deadline;
44
44
  int published;
45
+ size_t size; // total size of metadata
45
46
  } grpc_chttp2_incoming_metadata_buffer;
46
47
 
47
48
  /** assumes everything initially zeroed */
@@ -156,7 +156,7 @@ struct grpc_chttp2_incoming_byte_stream {
156
156
  grpc_byte_stream base;
157
157
  gpr_refcount refs;
158
158
  struct grpc_chttp2_incoming_byte_stream *next_message;
159
- int failed;
159
+ grpc_error *error;
160
160
 
161
161
  grpc_chttp2_transport *transport;
162
162
  grpc_chttp2_stream *stream;
@@ -265,6 +265,7 @@ struct grpc_chttp2_transport_parsing {
265
265
  uint8_t incoming_frame_type;
266
266
  uint8_t incoming_frame_flags;
267
267
  uint8_t header_eof;
268
+ bool is_first_frame;
268
269
  uint32_t expect_continuation_stream_id;
269
270
  uint32_t incoming_frame_size;
270
271
  uint32_t incoming_stream_id;
@@ -275,10 +276,10 @@ struct grpc_chttp2_transport_parsing {
275
276
  /* active parser */
276
277
  void *parser_data;
277
278
  grpc_chttp2_stream_parsing *incoming_stream;
278
- grpc_chttp2_parse_error (*parser)(
279
- grpc_exec_ctx *exec_ctx, void *parser_user_data,
280
- grpc_chttp2_transport_parsing *transport_parsing,
281
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last);
279
+ grpc_error *(*parser)(grpc_exec_ctx *exec_ctx, void *parser_user_data,
280
+ grpc_chttp2_transport_parsing *transport_parsing,
281
+ grpc_chttp2_stream_parsing *stream_parsing,
282
+ gpr_slice slice, int is_last);
282
283
 
283
284
  /* received settings */
284
285
  uint32_t settings[GRPC_CHTTP2_NUM_SETTINGS];
@@ -383,6 +384,9 @@ struct grpc_chttp2_transport {
383
384
 
384
385
  /** Transport op to be applied post-parsing */
385
386
  grpc_transport_op *post_parsing_op;
387
+
388
+ /** Message explaining the reason of dropping connection */
389
+ gpr_slice optional_drop_message;
386
390
  };
387
391
 
388
392
  typedef struct {
@@ -422,23 +426,22 @@ typedef struct {
422
426
  /** number of streams that are currently being read */
423
427
  gpr_refcount active_streams;
424
428
 
425
- /** when the application requests writes be closed, the write_closed is
426
- 'queued'; when the close is flow controlled into the send path, we are
427
- 'sending' it; when the write has been performed it is 'sent' */
429
+ /** Is this stream closed for writing. */
428
430
  bool write_closed;
429
- /** is this stream reading half-closed (boolean) */
431
+ /** Is this stream reading half-closed. */
430
432
  bool read_closed;
431
- /** are all published incoming byte streams closed */
433
+ /** Are all published incoming byte streams closed. */
432
434
  bool all_incoming_byte_streams_finished;
433
- /** is this stream in the stream map? (boolean) */
435
+ /** Is this stream in the stream map. */
434
436
  bool in_stream_map;
435
- /** has this stream seen an error? if 1, then pending incoming frames
436
- can be thrown away */
437
+ /** Has this stream seen an error.
438
+ If true, then pending incoming frames can be thrown away. */
437
439
  bool seen_error;
440
+ bool exceeded_metadata_size;
438
441
 
439
442
  bool published_initial_metadata;
440
443
  bool published_trailing_metadata;
441
- bool faked_trailing_metadata;
444
+ bool final_metadata_requested;
442
445
 
443
446
  grpc_chttp2_incoming_metadata_buffer received_initial_metadata;
444
447
  grpc_chttp2_incoming_metadata_buffer received_trailing_metadata;
@@ -470,24 +473,23 @@ typedef struct {
470
473
  } grpc_chttp2_stream_writing;
471
474
 
472
475
  struct grpc_chttp2_stream_parsing {
476
+ /** saw some stream level error */
477
+ grpc_error *forced_close_error;
473
478
  /** HTTP2 stream id for this stream, or zero if one has not been assigned */
474
479
  uint32_t id;
475
480
  /** has this stream received a close */
476
481
  uint8_t received_close;
477
- /** saw a rst_stream */
478
- uint8_t saw_rst_stream;
479
482
  /** how many header frames have we received? */
480
483
  uint8_t header_frames_received;
481
484
  /** which metadata did we get (on this parse) */
482
485
  uint8_t got_metadata_on_parse[2];
483
486
  /** should we raise the seen_error flag in transport_global */
484
- uint8_t seen_error;
487
+ bool seen_error;
488
+ bool exceeded_metadata_size;
485
489
  /** window available for peer to send to us */
486
490
  int64_t incoming_window;
487
491
  /** parsing state for data frames */
488
492
  grpc_chttp2_data_parser data_parser;
489
- /** reason give to rst_stream */
490
- uint32_t rst_stream_reason;
491
493
  /** amount of window given */
492
494
  int64_t outgoing_window;
493
495
  /** number of bytes received - reset at end of parse thread execution */
@@ -524,13 +526,12 @@ struct grpc_chttp2_stream {
524
526
  are required, and schedule them if so */
525
527
  int grpc_chttp2_unlocking_check_writes(grpc_exec_ctx *exec_ctx,
526
528
  grpc_chttp2_transport_global *global,
527
- grpc_chttp2_transport_writing *writing,
528
- int is_parsing);
529
+ grpc_chttp2_transport_writing *writing);
529
530
  void grpc_chttp2_perform_writes(
530
531
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_writing *transport_writing,
531
532
  grpc_endpoint *endpoint);
532
533
  void grpc_chttp2_terminate_writing(grpc_exec_ctx *exec_ctx,
533
- void *transport_writing, bool success);
534
+ void *transport_writing, grpc_error *error);
534
535
  void grpc_chttp2_cleanup_writing(grpc_exec_ctx *exec_ctx,
535
536
  grpc_chttp2_transport_global *global,
536
537
  grpc_chttp2_transport_writing *writing);
@@ -539,9 +540,9 @@ void grpc_chttp2_prepare_to_read(grpc_chttp2_transport_global *global,
539
540
  grpc_chttp2_transport_parsing *parsing);
540
541
  /** Process one slice of incoming data; return 1 if the connection is still
541
542
  viable after reading, or 0 if the connection should be torn down */
542
- int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
543
- grpc_chttp2_transport_parsing *transport_parsing,
544
- gpr_slice slice);
543
+ grpc_error *grpc_chttp2_perform_read(
544
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
545
+ gpr_slice slice);
545
546
  void grpc_chttp2_publish_reads(grpc_exec_ctx *exec_ctx,
546
547
  grpc_chttp2_transport_global *global,
547
548
  grpc_chttp2_transport_parsing *parsing);
@@ -671,9 +672,10 @@ void grpc_chttp2_for_all_streams(
671
672
  void grpc_chttp2_parsing_become_skip_parser(
672
673
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing);
673
674
 
674
- void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx,
675
- grpc_chttp2_stream_global *stream_global,
676
- grpc_closure **pclosure, int success);
675
+ void grpc_chttp2_complete_closure_step(
676
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global,
677
+ grpc_chttp2_stream_global *stream_global, grpc_closure **pclosure,
678
+ grpc_error *error);
677
679
 
678
680
  void grpc_chttp2_run_with_global_lock(grpc_exec_ctx *exec_ctx,
679
681
  grpc_chttp2_transport *transport,
@@ -776,8 +778,8 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx,
776
778
  grpc_status_code status, gpr_slice *details);
777
779
  void grpc_chttp2_mark_stream_closed(
778
780
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_global *transport_global,
779
- grpc_chttp2_stream_global *stream_global, int close_reads,
780
- int close_writes);
781
+ grpc_chttp2_stream_global *stream_global, int close_reads, int close_writes,
782
+ grpc_error *error);
781
783
  void grpc_chttp2_start_writing(grpc_exec_ctx *exec_ctx,
782
784
  grpc_chttp2_transport_global *transport_global);
783
785
 
@@ -809,8 +811,8 @@ void grpc_chttp2_incoming_byte_stream_push(grpc_exec_ctx *exec_ctx,
809
811
  grpc_chttp2_incoming_byte_stream *bs,
810
812
  gpr_slice slice);
811
813
  void grpc_chttp2_incoming_byte_stream_finished(
812
- grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs, int success,
813
- int from_parsing_thread);
814
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs,
815
+ grpc_error *error, int from_parsing_thread);
814
816
 
815
817
  void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx,
816
818
  grpc_chttp2_transport_parsing *parsing,
@@ -45,30 +45,34 @@
45
45
  #include "src/core/lib/profiling/timers.h"
46
46
  #include "src/core/lib/transport/static_metadata.h"
47
47
 
48
- static int init_frame_parser(grpc_exec_ctx *exec_ctx,
49
- grpc_chttp2_transport_parsing *transport_parsing);
50
- static int init_header_frame_parser(
48
+ #define TRANSPORT_FROM_PARSING(tp) \
49
+ ((grpc_chttp2_transport *)((char *)(tp)-offsetof(grpc_chttp2_transport, \
50
+ parsing)))
51
+
52
+ static grpc_error *init_frame_parser(
53
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing);
54
+ static grpc_error *init_header_frame_parser(
51
55
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
52
56
  int is_continuation);
53
- static int init_data_frame_parser(
57
+ static grpc_error *init_data_frame_parser(
58
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing);
59
+ static grpc_error *init_rst_stream_parser(
54
60
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing);
55
- static int init_rst_stream_parser(
61
+ static grpc_error *init_settings_frame_parser(
56
62
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing);
57
- static int init_settings_frame_parser(
63
+ static grpc_error *init_window_update_frame_parser(
58
64
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing);
59
- static int init_window_update_frame_parser(
65
+ static grpc_error *init_ping_parser(
60
66
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing);
61
- static int init_ping_parser(grpc_exec_ctx *exec_ctx,
62
- grpc_chttp2_transport_parsing *transport_parsing);
63
- static int init_goaway_parser(grpc_exec_ctx *exec_ctx,
64
- grpc_chttp2_transport_parsing *transport_parsing);
65
- static int init_skip_frame_parser(
67
+ static grpc_error *init_goaway_parser(
68
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing);
69
+ static grpc_error *init_skip_frame_parser(
66
70
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
67
71
  int is_header);
68
72
 
69
- static int parse_frame_slice(grpc_exec_ctx *exec_ctx,
70
- grpc_chttp2_transport_parsing *transport_parsing,
71
- gpr_slice slice, int is_last);
73
+ static grpc_error *parse_frame_slice(
74
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
75
+ gpr_slice slice, int is_last);
72
76
 
73
77
  void grpc_chttp2_prepare_to_read(
74
78
  grpc_chttp2_transport_global *transport_global,
@@ -170,7 +174,9 @@ void grpc_chttp2_publish_reads(
170
174
  while (grpc_chttp2_list_pop_parsing_seen_stream(
171
175
  transport_global, transport_parsing, &stream_global, &stream_parsing)) {
172
176
  if (stream_parsing->seen_error) {
173
- stream_global->seen_error = 1;
177
+ stream_global->seen_error = true;
178
+ stream_global->exceeded_metadata_size =
179
+ stream_parsing->exceeded_metadata_size;
174
180
  grpc_chttp2_list_add_check_read_ops(transport_global, stream_global);
175
181
  }
176
182
 
@@ -224,38 +230,42 @@ void grpc_chttp2_publish_reads(
224
230
  grpc_chttp2_list_add_check_read_ops(transport_global, stream_global);
225
231
  }
226
232
 
227
- if (stream_parsing->saw_rst_stream) {
228
- if (stream_parsing->rst_stream_reason != GRPC_CHTTP2_NO_ERROR) {
229
- grpc_status_code status_code = grpc_chttp2_http2_error_to_grpc_status(
230
- (grpc_chttp2_error_code)stream_parsing->rst_stream_reason);
231
- char *status_details;
232
- gpr_slice slice_details;
233
- gpr_asprintf(&status_details, "Received RST_STREAM err=%d",
234
- stream_parsing->rst_stream_reason);
235
- slice_details = gpr_slice_from_copied_string(status_details);
236
- gpr_free(status_details);
233
+ if (stream_parsing->forced_close_error != GRPC_ERROR_NONE) {
234
+ intptr_t reason;
235
+ bool has_reason = grpc_error_get_int(stream_parsing->forced_close_error,
236
+ GRPC_ERROR_INT_HTTP2_ERROR, &reason);
237
+ if (has_reason && reason != GRPC_CHTTP2_NO_ERROR) {
238
+ grpc_status_code status_code =
239
+ has_reason ? grpc_chttp2_http2_error_to_grpc_status(
240
+ (grpc_chttp2_error_code)reason)
241
+ : GRPC_STATUS_INTERNAL;
242
+ const char *status_details =
243
+ grpc_error_string(stream_parsing->forced_close_error);
244
+ gpr_slice slice_details = gpr_slice_from_copied_string(status_details);
245
+ grpc_error_free_string(status_details);
237
246
  grpc_chttp2_fake_status(exec_ctx, transport_global, stream_global,
238
247
  status_code, &slice_details);
239
248
  }
240
249
  grpc_chttp2_mark_stream_closed(exec_ctx, transport_global, stream_global,
241
- 1, 1);
250
+ 1, 1, stream_parsing->forced_close_error);
242
251
  }
243
252
 
244
253
  if (stream_parsing->received_close) {
245
254
  grpc_chttp2_mark_stream_closed(exec_ctx, transport_global, stream_global,
246
- 1, 0);
255
+ 1, 0, GRPC_ERROR_NONE);
247
256
  }
248
257
  }
249
258
  }
250
259
 
251
- int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
252
- grpc_chttp2_transport_parsing *transport_parsing,
253
- gpr_slice slice) {
260
+ grpc_error *grpc_chttp2_perform_read(
261
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
262
+ gpr_slice slice) {
254
263
  uint8_t *beg = GPR_SLICE_START_PTR(slice);
255
264
  uint8_t *end = GPR_SLICE_END_PTR(slice);
256
265
  uint8_t *cur = beg;
266
+ grpc_error *err;
257
267
 
258
- if (cur == end) return 1;
268
+ if (cur == end) return GRPC_ERROR_NONE;
259
269
 
260
270
  switch (transport_parsing->deframe_state) {
261
271
  case GRPC_DTS_CLIENT_PREFIX_0:
@@ -285,21 +295,25 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
285
295
  while (cur != end && transport_parsing->deframe_state != GRPC_DTS_FH_0) {
286
296
  if (*cur != GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing
287
297
  ->deframe_state]) {
288
- gpr_log(GPR_INFO,
289
- "Connect string mismatch: expected '%c' (%d) got '%c' (%d) "
290
- "at byte %d",
291
- GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing
292
- ->deframe_state],
293
- (int)(uint8_t)GRPC_CHTTP2_CLIENT_CONNECT_STRING
294
- [transport_parsing->deframe_state],
295
- *cur, (int)*cur, transport_parsing->deframe_state);
296
- return 0;
298
+ char *msg;
299
+ gpr_asprintf(
300
+ &msg,
301
+ "Connect string mismatch: expected '%c' (%d) got '%c' (%d) "
302
+ "at byte %d",
303
+ GRPC_CHTTP2_CLIENT_CONNECT_STRING[transport_parsing
304
+ ->deframe_state],
305
+ (int)(uint8_t)GRPC_CHTTP2_CLIENT_CONNECT_STRING
306
+ [transport_parsing->deframe_state],
307
+ *cur, (int)*cur, transport_parsing->deframe_state);
308
+ err = GRPC_ERROR_CREATE(msg);
309
+ gpr_free(msg);
310
+ return err;
297
311
  }
298
312
  ++cur;
299
313
  ++transport_parsing->deframe_state;
300
314
  }
301
315
  if (cur == end) {
302
- return 1;
316
+ return GRPC_ERROR_NONE;
303
317
  }
304
318
  /* fallthrough */
305
319
  dts_fh_0:
@@ -308,7 +322,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
308
322
  transport_parsing->incoming_frame_size = ((uint32_t)*cur) << 16;
309
323
  if (++cur == end) {
310
324
  transport_parsing->deframe_state = GRPC_DTS_FH_1;
311
- return 1;
325
+ return GRPC_ERROR_NONE;
312
326
  }
313
327
  /* fallthrough */
314
328
  case GRPC_DTS_FH_1:
@@ -316,7 +330,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
316
330
  transport_parsing->incoming_frame_size |= ((uint32_t)*cur) << 8;
317
331
  if (++cur == end) {
318
332
  transport_parsing->deframe_state = GRPC_DTS_FH_2;
319
- return 1;
333
+ return GRPC_ERROR_NONE;
320
334
  }
321
335
  /* fallthrough */
322
336
  case GRPC_DTS_FH_2:
@@ -324,7 +338,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
324
338
  transport_parsing->incoming_frame_size |= *cur;
325
339
  if (++cur == end) {
326
340
  transport_parsing->deframe_state = GRPC_DTS_FH_3;
327
- return 1;
341
+ return GRPC_ERROR_NONE;
328
342
  }
329
343
  /* fallthrough */
330
344
  case GRPC_DTS_FH_3:
@@ -332,7 +346,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
332
346
  transport_parsing->incoming_frame_type = *cur;
333
347
  if (++cur == end) {
334
348
  transport_parsing->deframe_state = GRPC_DTS_FH_4;
335
- return 1;
349
+ return GRPC_ERROR_NONE;
336
350
  }
337
351
  /* fallthrough */
338
352
  case GRPC_DTS_FH_4:
@@ -340,7 +354,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
340
354
  transport_parsing->incoming_frame_flags = *cur;
341
355
  if (++cur == end) {
342
356
  transport_parsing->deframe_state = GRPC_DTS_FH_5;
343
- return 1;
357
+ return GRPC_ERROR_NONE;
344
358
  }
345
359
  /* fallthrough */
346
360
  case GRPC_DTS_FH_5:
@@ -348,7 +362,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
348
362
  transport_parsing->incoming_stream_id = (((uint32_t)*cur) & 0x7f) << 24;
349
363
  if (++cur == end) {
350
364
  transport_parsing->deframe_state = GRPC_DTS_FH_6;
351
- return 1;
365
+ return GRPC_ERROR_NONE;
352
366
  }
353
367
  /* fallthrough */
354
368
  case GRPC_DTS_FH_6:
@@ -356,7 +370,7 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
356
370
  transport_parsing->incoming_stream_id |= ((uint32_t)*cur) << 16;
357
371
  if (++cur == end) {
358
372
  transport_parsing->deframe_state = GRPC_DTS_FH_7;
359
- return 1;
373
+ return GRPC_ERROR_NONE;
360
374
  }
361
375
  /* fallthrough */
362
376
  case GRPC_DTS_FH_7:
@@ -364,15 +378,16 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
364
378
  transport_parsing->incoming_stream_id |= ((uint32_t)*cur) << 8;
365
379
  if (++cur == end) {
366
380
  transport_parsing->deframe_state = GRPC_DTS_FH_8;
367
- return 1;
381
+ return GRPC_ERROR_NONE;
368
382
  }
369
383
  /* fallthrough */
370
384
  case GRPC_DTS_FH_8:
371
385
  GPR_ASSERT(cur < end);
372
386
  transport_parsing->incoming_stream_id |= ((uint32_t)*cur);
373
387
  transport_parsing->deframe_state = GRPC_DTS_FRAME;
374
- if (!init_frame_parser(exec_ctx, transport_parsing)) {
375
- return 0;
388
+ err = init_frame_parser(exec_ctx, transport_parsing);
389
+ if (err != GRPC_ERROR_NONE) {
390
+ return err;
376
391
  }
377
392
  if (transport_parsing->incoming_stream_id != 0 &&
378
393
  transport_parsing->incoming_stream_id >
@@ -381,62 +396,69 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
381
396
  transport_parsing->incoming_stream_id;
382
397
  }
383
398
  if (transport_parsing->incoming_frame_size == 0) {
384
- if (!parse_frame_slice(exec_ctx, transport_parsing, gpr_empty_slice(),
385
- 1)) {
386
- return 0;
399
+ err = parse_frame_slice(exec_ctx, transport_parsing, gpr_empty_slice(),
400
+ 1);
401
+ if (err != GRPC_ERROR_NONE) {
402
+ return err;
387
403
  }
388
404
  transport_parsing->incoming_stream = NULL;
389
405
  if (++cur == end) {
390
406
  transport_parsing->deframe_state = GRPC_DTS_FH_0;
391
- return 1;
407
+ return GRPC_ERROR_NONE;
392
408
  }
393
409
  goto dts_fh_0; /* loop */
394
410
  } else if (transport_parsing->incoming_frame_size >
395
411
  transport_parsing->max_frame_size) {
396
- gpr_log(GPR_DEBUG, "Frame size %d is larger than max frame size %d",
397
- transport_parsing->incoming_frame_size,
398
- transport_parsing->max_frame_size);
399
- return 0;
412
+ char *msg;
413
+ gpr_asprintf(&msg, "Frame size %d is larger than max frame size %d",
414
+ transport_parsing->incoming_frame_size,
415
+ transport_parsing->max_frame_size);
416
+ err = GRPC_ERROR_CREATE(msg);
417
+ gpr_free(msg);
418
+ return err;
400
419
  }
401
420
  if (++cur == end) {
402
- return 1;
421
+ return GRPC_ERROR_NONE;
403
422
  }
404
423
  /* fallthrough */
405
424
  case GRPC_DTS_FRAME:
406
425
  GPR_ASSERT(cur < end);
407
426
  if ((uint32_t)(end - cur) == transport_parsing->incoming_frame_size) {
408
- if (!parse_frame_slice(exec_ctx, transport_parsing,
409
- gpr_slice_sub_no_ref(slice, (size_t)(cur - beg),
410
- (size_t)(end - beg)),
411
- 1)) {
412
- return 0;
427
+ err = parse_frame_slice(exec_ctx, transport_parsing,
428
+ gpr_slice_sub_no_ref(slice, (size_t)(cur - beg),
429
+ (size_t)(end - beg)),
430
+ 1);
431
+ if (err != GRPC_ERROR_NONE) {
432
+ return err;
413
433
  }
414
434
  transport_parsing->deframe_state = GRPC_DTS_FH_0;
415
435
  transport_parsing->incoming_stream = NULL;
416
- return 1;
436
+ return GRPC_ERROR_NONE;
417
437
  } else if ((uint32_t)(end - cur) >
418
438
  transport_parsing->incoming_frame_size) {
419
439
  size_t cur_offset = (size_t)(cur - beg);
420
- if (!parse_frame_slice(
421
- exec_ctx, transport_parsing,
422
- gpr_slice_sub_no_ref(
423
- slice, cur_offset,
424
- cur_offset + transport_parsing->incoming_frame_size),
425
- 1)) {
426
- return 0;
440
+ err = parse_frame_slice(
441
+ exec_ctx, transport_parsing,
442
+ gpr_slice_sub_no_ref(
443
+ slice, cur_offset,
444
+ cur_offset + transport_parsing->incoming_frame_size),
445
+ 1);
446
+ if (err != GRPC_ERROR_NONE) {
447
+ return err;
427
448
  }
428
449
  cur += transport_parsing->incoming_frame_size;
429
450
  transport_parsing->incoming_stream = NULL;
430
451
  goto dts_fh_0; /* loop */
431
452
  } else {
432
- if (!parse_frame_slice(exec_ctx, transport_parsing,
433
- gpr_slice_sub_no_ref(slice, (size_t)(cur - beg),
434
- (size_t)(end - beg)),
435
- 0)) {
436
- return 0;
453
+ err = parse_frame_slice(exec_ctx, transport_parsing,
454
+ gpr_slice_sub_no_ref(slice, (size_t)(cur - beg),
455
+ (size_t)(end - beg)),
456
+ 0);
457
+ if (err != GRPC_ERROR_NONE) {
458
+ return err;
437
459
  }
438
460
  transport_parsing->incoming_frame_size -= (uint32_t)(end - cur);
439
- return 1;
461
+ return GRPC_ERROR_NONE;
440
462
  }
441
463
  GPR_UNREACHABLE_CODE(return 0);
442
464
  }
@@ -444,23 +466,41 @@ int grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx,
444
466
  GPR_UNREACHABLE_CODE(return 0);
445
467
  }
446
468
 
447
- static int init_frame_parser(grpc_exec_ctx *exec_ctx,
448
- grpc_chttp2_transport_parsing *transport_parsing) {
469
+ static grpc_error *init_frame_parser(
470
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) {
471
+ if (transport_parsing->is_first_frame &&
472
+ transport_parsing->incoming_frame_type != GRPC_CHTTP2_FRAME_SETTINGS) {
473
+ char *msg;
474
+ gpr_asprintf(
475
+ &msg, "Expected SETTINGS frame as the first frame, got frame type %d",
476
+ transport_parsing->incoming_frame_type);
477
+ grpc_error *err = GRPC_ERROR_CREATE(msg);
478
+ gpr_free(msg);
479
+ return err;
480
+ }
481
+ transport_parsing->is_first_frame = false;
449
482
  if (transport_parsing->expect_continuation_stream_id != 0) {
450
483
  if (transport_parsing->incoming_frame_type !=
451
484
  GRPC_CHTTP2_FRAME_CONTINUATION) {
452
- gpr_log(GPR_ERROR, "Expected CONTINUATION frame, got frame type %02x",
453
- transport_parsing->incoming_frame_type);
454
- return 0;
485
+ char *msg;
486
+ gpr_asprintf(&msg, "Expected CONTINUATION frame, got frame type %02x",
487
+ transport_parsing->incoming_frame_type);
488
+ grpc_error *err = GRPC_ERROR_CREATE(msg);
489
+ gpr_free(msg);
490
+ return err;
455
491
  }
456
492
  if (transport_parsing->expect_continuation_stream_id !=
457
493
  transport_parsing->incoming_stream_id) {
458
- gpr_log(GPR_ERROR,
459
- "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got "
460
- "grpc_chttp2_stream %08x",
461
- transport_parsing->expect_continuation_stream_id,
462
- transport_parsing->incoming_stream_id);
463
- return 0;
494
+ char *msg;
495
+ gpr_asprintf(
496
+ &msg,
497
+ "Expected CONTINUATION frame for grpc_chttp2_stream %08x, got "
498
+ "grpc_chttp2_stream %08x",
499
+ transport_parsing->expect_continuation_stream_id,
500
+ transport_parsing->incoming_stream_id);
501
+ grpc_error *err = GRPC_ERROR_CREATE(msg);
502
+ gpr_free(msg);
503
+ return err;
464
504
  }
465
505
  return init_header_frame_parser(exec_ctx, transport_parsing, 1);
466
506
  }
@@ -470,8 +510,7 @@ static int init_frame_parser(grpc_exec_ctx *exec_ctx,
470
510
  case GRPC_CHTTP2_FRAME_HEADER:
471
511
  return init_header_frame_parser(exec_ctx, transport_parsing, 0);
472
512
  case GRPC_CHTTP2_FRAME_CONTINUATION:
473
- gpr_log(GPR_ERROR, "Unexpected CONTINUATION frame");
474
- return 0;
513
+ return GRPC_ERROR_CREATE("Unexpected CONTINUATION frame");
475
514
  case GRPC_CHTTP2_FRAME_RST_STREAM:
476
515
  return init_rst_stream_parser(exec_ctx, transport_parsing);
477
516
  case GRPC_CHTTP2_FRAME_SETTINGS:
@@ -483,22 +522,24 @@ static int init_frame_parser(grpc_exec_ctx *exec_ctx,
483
522
  case GRPC_CHTTP2_FRAME_GOAWAY:
484
523
  return init_goaway_parser(exec_ctx, transport_parsing);
485
524
  default:
486
- gpr_log(GPR_ERROR, "Unknown frame type %02x",
487
- transport_parsing->incoming_frame_type);
525
+ if (grpc_http_trace) {
526
+ gpr_log(GPR_ERROR, "Unknown frame type %02x",
527
+ transport_parsing->incoming_frame_type);
528
+ }
488
529
  return init_skip_frame_parser(exec_ctx, transport_parsing, 0);
489
530
  }
490
531
  }
491
532
 
492
- static grpc_chttp2_parse_error skip_parser(
493
- grpc_exec_ctx *exec_ctx, void *parser,
494
- grpc_chttp2_transport_parsing *transport_parsing,
495
- grpc_chttp2_stream_parsing *stream_parsing, gpr_slice slice, int is_last) {
496
- return GRPC_CHTTP2_PARSE_OK;
533
+ static grpc_error *skip_parser(grpc_exec_ctx *exec_ctx, void *parser,
534
+ grpc_chttp2_transport_parsing *transport_parsing,
535
+ grpc_chttp2_stream_parsing *stream_parsing,
536
+ gpr_slice slice, int is_last) {
537
+ return GRPC_ERROR_NONE;
497
538
  }
498
539
 
499
540
  static void skip_header(void *tp, grpc_mdelem *md) { GRPC_MDELEM_UNREF(md); }
500
541
 
501
- static int init_skip_frame_parser(
542
+ static grpc_error *init_skip_frame_parser(
502
543
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
503
544
  int is_header) {
504
545
  if (is_header) {
@@ -513,7 +554,7 @@ static int init_skip_frame_parser(
513
554
  } else {
514
555
  transport_parsing->parser = skip_parser;
515
556
  }
516
- return 1;
557
+ return GRPC_ERROR_NONE;
517
558
  }
518
559
 
519
560
  void grpc_chttp2_parsing_become_skip_parser(
@@ -523,22 +564,28 @@ void grpc_chttp2_parsing_become_skip_parser(
523
564
  transport_parsing->parser == grpc_chttp2_header_parser_parse);
524
565
  }
525
566
 
526
- static grpc_chttp2_parse_error update_incoming_window(
567
+ static grpc_error *update_incoming_window(
527
568
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
528
569
  grpc_chttp2_stream_parsing *stream_parsing) {
529
570
  uint32_t incoming_frame_size = transport_parsing->incoming_frame_size;
530
571
  if (incoming_frame_size > transport_parsing->incoming_window) {
531
- gpr_log(GPR_ERROR, "frame of size %d overflows incoming window of %d",
532
- transport_parsing->incoming_frame_size,
533
- transport_parsing->incoming_window);
534
- return GRPC_CHTTP2_CONNECTION_ERROR;
572
+ char *msg;
573
+ gpr_asprintf(&msg, "frame of size %d overflows incoming window of %" PRId64,
574
+ transport_parsing->incoming_frame_size,
575
+ transport_parsing->incoming_window);
576
+ grpc_error *err = GRPC_ERROR_CREATE(msg);
577
+ gpr_free(msg);
578
+ return err;
535
579
  }
536
580
 
537
581
  if (incoming_frame_size > stream_parsing->incoming_window) {
538
- gpr_log(GPR_ERROR, "frame of size %d overflows incoming window of %d",
539
- transport_parsing->incoming_frame_size,
540
- stream_parsing->incoming_window);
541
- return GRPC_CHTTP2_CONNECTION_ERROR;
582
+ char *msg;
583
+ gpr_asprintf(&msg, "frame of size %d overflows incoming window of %" PRId64,
584
+ transport_parsing->incoming_frame_size,
585
+ stream_parsing->incoming_window);
586
+ grpc_error *err = GRPC_ERROR_CREATE(msg);
587
+ gpr_free(msg);
588
+ return err;
542
589
  }
543
590
 
544
591
  GRPC_CHTTP2_FLOW_DEBIT_TRANSPORT("parse", transport_parsing, incoming_window,
@@ -549,15 +596,15 @@ static grpc_chttp2_parse_error update_incoming_window(
549
596
 
550
597
  grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, stream_parsing);
551
598
 
552
- return GRPC_CHTTP2_PARSE_OK;
599
+ return GRPC_ERROR_NONE;
553
600
  }
554
601
 
555
- static int init_data_frame_parser(
602
+ static grpc_error *init_data_frame_parser(
556
603
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) {
557
604
  grpc_chttp2_stream_parsing *stream_parsing =
558
605
  grpc_chttp2_parsing_lookup_stream(transport_parsing,
559
606
  transport_parsing->incoming_stream_id);
560
- grpc_chttp2_parse_error err = GRPC_CHTTP2_PARSE_OK;
607
+ grpc_error *err = GRPC_ERROR_NONE;
561
608
  if (stream_parsing == NULL) {
562
609
  return init_skip_frame_parser(exec_ctx, transport_parsing, 0);
563
610
  }
@@ -565,33 +612,32 @@ static int init_data_frame_parser(
565
612
  if (stream_parsing->received_close) {
566
613
  return init_skip_frame_parser(exec_ctx, transport_parsing, 0);
567
614
  }
568
- if (err == GRPC_CHTTP2_PARSE_OK) {
615
+ if (err == GRPC_ERROR_NONE) {
569
616
  err = update_incoming_window(exec_ctx, transport_parsing, stream_parsing);
570
617
  }
571
- if (err == GRPC_CHTTP2_PARSE_OK) {
618
+ if (err == GRPC_ERROR_NONE) {
572
619
  err = grpc_chttp2_data_parser_begin_frame(
573
- &stream_parsing->data_parser, transport_parsing->incoming_frame_flags);
574
- }
575
- switch (err) {
576
- case GRPC_CHTTP2_PARSE_OK:
577
- transport_parsing->incoming_stream = stream_parsing;
578
- transport_parsing->parser = grpc_chttp2_data_parser_parse;
579
- transport_parsing->parser_data = &stream_parsing->data_parser;
580
- return 1;
581
- case GRPC_CHTTP2_STREAM_ERROR:
582
- stream_parsing->received_close = 1;
583
- stream_parsing->saw_rst_stream = 1;
584
- stream_parsing->rst_stream_reason = GRPC_CHTTP2_PROTOCOL_ERROR;
585
- gpr_slice_buffer_add(
586
- &transport_parsing->qbuf,
587
- grpc_chttp2_rst_stream_create(transport_parsing->incoming_stream_id,
588
- GRPC_CHTTP2_PROTOCOL_ERROR,
589
- &stream_parsing->stats.outgoing));
590
- return init_skip_frame_parser(exec_ctx, transport_parsing, 0);
591
- case GRPC_CHTTP2_CONNECTION_ERROR:
592
- return 0;
620
+ &stream_parsing->data_parser, transport_parsing->incoming_frame_flags,
621
+ stream_parsing->id);
622
+ }
623
+ if (err == GRPC_ERROR_NONE) {
624
+ transport_parsing->incoming_stream = stream_parsing;
625
+ transport_parsing->parser = grpc_chttp2_data_parser_parse;
626
+ transport_parsing->parser_data = &stream_parsing->data_parser;
627
+ return GRPC_ERROR_NONE;
628
+ } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, NULL)) {
629
+ /* handle stream errors by closing the stream */
630
+ stream_parsing->received_close = 1;
631
+ stream_parsing->forced_close_error = err;
632
+ gpr_slice_buffer_add(
633
+ &transport_parsing->qbuf,
634
+ grpc_chttp2_rst_stream_create(transport_parsing->incoming_stream_id,
635
+ GRPC_CHTTP2_PROTOCOL_ERROR,
636
+ &stream_parsing->stats.outgoing));
637
+ return init_skip_frame_parser(exec_ctx, transport_parsing, 0);
638
+ } else {
639
+ return err;
593
640
  }
594
- GPR_UNREACHABLE_CODE(return 0);
595
641
  }
596
642
 
597
643
  static void free_timeout(void *p) { gpr_free(p); }
@@ -612,7 +658,7 @@ static void on_initial_header(void *tp, grpc_mdelem *md) {
612
658
 
613
659
  if (md->key == GRPC_MDSTR_GRPC_STATUS && md != GRPC_MDELEM_GRPC_STATUS_0) {
614
660
  /* TODO(ctiller): check for a status like " 0" */
615
- stream_parsing->seen_error = 1;
661
+ stream_parsing->seen_error = true;
616
662
  }
617
663
 
618
664
  if (md->key == GRPC_MDSTR_GRPC_TIMEOUT) {
@@ -633,8 +679,27 @@ static void on_initial_header(void *tp, grpc_mdelem *md) {
633
679
  gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), *cached_timeout));
634
680
  GRPC_MDELEM_UNREF(md);
635
681
  } else {
636
- grpc_chttp2_incoming_metadata_buffer_add(
637
- &stream_parsing->metadata_buffer[0], md);
682
+ const size_t new_size =
683
+ stream_parsing->metadata_buffer[0].size + GRPC_MDELEM_LENGTH(md);
684
+ grpc_chttp2_transport_global *transport_global =
685
+ &TRANSPORT_FROM_PARSING(transport_parsing)->global;
686
+ const size_t metadata_size_limit =
687
+ transport_global->settings[GRPC_LOCAL_SETTINGS]
688
+ [GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE];
689
+ if (new_size > metadata_size_limit) {
690
+ if (!stream_parsing->exceeded_metadata_size) {
691
+ gpr_log(GPR_DEBUG,
692
+ "received initial metadata size exceeds limit (%" PRIuPTR
693
+ " vs. %" PRIuPTR ")",
694
+ new_size, metadata_size_limit);
695
+ stream_parsing->seen_error = true;
696
+ stream_parsing->exceeded_metadata_size = true;
697
+ }
698
+ GRPC_MDELEM_UNREF(md);
699
+ } else {
700
+ grpc_chttp2_incoming_metadata_buffer_add(
701
+ &stream_parsing->metadata_buffer[0], md);
702
+ }
638
703
  }
639
704
 
640
705
  grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, stream_parsing);
@@ -658,18 +723,37 @@ static void on_trailing_header(void *tp, grpc_mdelem *md) {
658
723
 
659
724
  if (md->key == GRPC_MDSTR_GRPC_STATUS && md != GRPC_MDELEM_GRPC_STATUS_0) {
660
725
  /* TODO(ctiller): check for a status like " 0" */
661
- stream_parsing->seen_error = 1;
726
+ stream_parsing->seen_error = true;
727
+ }
728
+
729
+ const size_t new_size =
730
+ stream_parsing->metadata_buffer[1].size + GRPC_MDELEM_LENGTH(md);
731
+ grpc_chttp2_transport_global *transport_global =
732
+ &TRANSPORT_FROM_PARSING(transport_parsing)->global;
733
+ const size_t metadata_size_limit =
734
+ transport_global->settings[GRPC_LOCAL_SETTINGS]
735
+ [GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE];
736
+ if (new_size > metadata_size_limit) {
737
+ if (!stream_parsing->exceeded_metadata_size) {
738
+ gpr_log(GPR_DEBUG,
739
+ "received trailing metadata size exceeds limit (%" PRIuPTR
740
+ " vs. %" PRIuPTR ")",
741
+ new_size, metadata_size_limit);
742
+ stream_parsing->seen_error = true;
743
+ stream_parsing->exceeded_metadata_size = true;
744
+ }
745
+ GRPC_MDELEM_UNREF(md);
746
+ } else {
747
+ grpc_chttp2_incoming_metadata_buffer_add(
748
+ &stream_parsing->metadata_buffer[1], md);
662
749
  }
663
750
 
664
- grpc_chttp2_incoming_metadata_buffer_add(&stream_parsing->metadata_buffer[1],
665
- md);
666
-
667
751
  grpc_chttp2_list_add_parsing_seen_stream(transport_parsing, stream_parsing);
668
752
 
669
753
  GPR_TIMER_END("on_trailing_header", 0);
670
754
  }
671
755
 
672
- static int init_header_frame_parser(
756
+ static grpc_error *init_header_frame_parser(
673
757
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
674
758
  int is_continuation) {
675
759
  uint8_t is_eoh = (transport_parsing->incoming_frame_flags &
@@ -764,15 +848,16 @@ static int init_header_frame_parser(
764
848
  GRPC_CHTTP2_FLAG_HAS_PRIORITY)) {
765
849
  grpc_chttp2_hpack_parser_set_has_priority(&transport_parsing->hpack_parser);
766
850
  }
767
- return 1;
851
+ return GRPC_ERROR_NONE;
768
852
  }
769
853
 
770
- static int init_window_update_frame_parser(
854
+ static grpc_error *init_window_update_frame_parser(
771
855
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) {
772
- int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_window_update_parser_begin_frame(
773
- &transport_parsing->simple.window_update,
774
- transport_parsing->incoming_frame_size,
775
- transport_parsing->incoming_frame_flags);
856
+ grpc_error *err = grpc_chttp2_window_update_parser_begin_frame(
857
+ &transport_parsing->simple.window_update,
858
+ transport_parsing->incoming_frame_size,
859
+ transport_parsing->incoming_frame_flags);
860
+ if (err != GRPC_ERROR_NONE) return err;
776
861
  if (transport_parsing->incoming_stream_id != 0) {
777
862
  grpc_chttp2_stream_parsing *stream_parsing =
778
863
  transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream(
@@ -784,26 +869,27 @@ static int init_window_update_frame_parser(
784
869
  }
785
870
  transport_parsing->parser = grpc_chttp2_window_update_parser_parse;
786
871
  transport_parsing->parser_data = &transport_parsing->simple.window_update;
787
- return ok;
872
+ return GRPC_ERROR_NONE;
788
873
  }
789
874
 
790
- static int init_ping_parser(grpc_exec_ctx *exec_ctx,
791
- grpc_chttp2_transport_parsing *transport_parsing) {
792
- int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_ping_parser_begin_frame(
793
- &transport_parsing->simple.ping,
794
- transport_parsing->incoming_frame_size,
795
- transport_parsing->incoming_frame_flags);
875
+ static grpc_error *init_ping_parser(
876
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) {
877
+ grpc_error *err = grpc_chttp2_ping_parser_begin_frame(
878
+ &transport_parsing->simple.ping, transport_parsing->incoming_frame_size,
879
+ transport_parsing->incoming_frame_flags);
880
+ if (err != GRPC_ERROR_NONE) return err;
796
881
  transport_parsing->parser = grpc_chttp2_ping_parser_parse;
797
882
  transport_parsing->parser_data = &transport_parsing->simple.ping;
798
- return ok;
883
+ return GRPC_ERROR_NONE;
799
884
  }
800
885
 
801
- static int init_rst_stream_parser(
886
+ static grpc_error *init_rst_stream_parser(
802
887
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) {
803
- int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_rst_stream_parser_begin_frame(
804
- &transport_parsing->simple.rst_stream,
805
- transport_parsing->incoming_frame_size,
806
- transport_parsing->incoming_frame_flags);
888
+ grpc_error *err = grpc_chttp2_rst_stream_parser_begin_frame(
889
+ &transport_parsing->simple.rst_stream,
890
+ transport_parsing->incoming_frame_size,
891
+ transport_parsing->incoming_frame_flags);
892
+ if (err != GRPC_ERROR_NONE) return err;
807
893
  grpc_chttp2_stream_parsing *stream_parsing =
808
894
  transport_parsing->incoming_stream = grpc_chttp2_parsing_lookup_stream(
809
895
  transport_parsing, transport_parsing->incoming_stream_id);
@@ -813,37 +899,32 @@ static int init_rst_stream_parser(
813
899
  stream_parsing->stats.incoming.framing_bytes += 9;
814
900
  transport_parsing->parser = grpc_chttp2_rst_stream_parser_parse;
815
901
  transport_parsing->parser_data = &transport_parsing->simple.rst_stream;
816
- return ok;
902
+ return GRPC_ERROR_NONE;
817
903
  }
818
904
 
819
- static int init_goaway_parser(
905
+ static grpc_error *init_goaway_parser(
820
906
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) {
821
- int ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_goaway_parser_begin_frame(
822
- &transport_parsing->goaway_parser,
823
- transport_parsing->incoming_frame_size,
824
- transport_parsing->incoming_frame_flags);
907
+ grpc_error *err = grpc_chttp2_goaway_parser_begin_frame(
908
+ &transport_parsing->goaway_parser, transport_parsing->incoming_frame_size,
909
+ transport_parsing->incoming_frame_flags);
910
+ if (err != GRPC_ERROR_NONE) return err;
825
911
  transport_parsing->parser = grpc_chttp2_goaway_parser_parse;
826
912
  transport_parsing->parser_data = &transport_parsing->goaway_parser;
827
- return ok;
913
+ return GRPC_ERROR_NONE;
828
914
  }
829
915
 
830
- static int init_settings_frame_parser(
916
+ static grpc_error *init_settings_frame_parser(
831
917
  grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing) {
832
- int ok;
833
-
834
918
  if (transport_parsing->incoming_stream_id != 0) {
835
- gpr_log(GPR_ERROR, "settings frame received for grpc_chttp2_stream %d",
836
- transport_parsing->incoming_stream_id);
837
- return 0;
919
+ return GRPC_ERROR_CREATE("Settings frame received for grpc_chttp2_stream");
838
920
  }
839
921
 
840
- ok = GRPC_CHTTP2_PARSE_OK == grpc_chttp2_settings_parser_begin_frame(
841
- &transport_parsing->simple.settings,
842
- transport_parsing->incoming_frame_size,
843
- transport_parsing->incoming_frame_flags,
844
- transport_parsing->settings);
845
- if (!ok) {
846
- return 0;
922
+ grpc_error *err = grpc_chttp2_settings_parser_begin_frame(
923
+ &transport_parsing->simple.settings,
924
+ transport_parsing->incoming_frame_size,
925
+ transport_parsing->incoming_frame_flags, transport_parsing->settings);
926
+ if (err != GRPC_ERROR_NONE) {
927
+ return err;
847
928
  }
848
929
  if (transport_parsing->incoming_frame_flags & GRPC_CHTTP2_FLAG_ACK) {
849
930
  transport_parsing->settings_ack_received = 1;
@@ -857,7 +938,7 @@ static int init_settings_frame_parser(
857
938
  }
858
939
  transport_parsing->parser = grpc_chttp2_settings_parser_parse;
859
940
  transport_parsing->parser_data = &transport_parsing->simple.settings;
860
- return ok;
941
+ return GRPC_ERROR_NONE;
861
942
  }
862
943
 
863
944
  /*
@@ -866,34 +947,37 @@ static int is_window_update_legal(int64_t window_update, int64_t window) {
866
947
  }
867
948
  */
868
949
 
869
- static int parse_frame_slice(grpc_exec_ctx *exec_ctx,
870
- grpc_chttp2_transport_parsing *transport_parsing,
871
- gpr_slice slice, int is_last) {
950
+ static grpc_error *parse_frame_slice(
951
+ grpc_exec_ctx *exec_ctx, grpc_chttp2_transport_parsing *transport_parsing,
952
+ gpr_slice slice, int is_last) {
872
953
  grpc_chttp2_stream_parsing *stream_parsing =
873
954
  transport_parsing->incoming_stream;
874
- switch (transport_parsing->parser(exec_ctx, transport_parsing->parser_data,
875
- transport_parsing, stream_parsing, slice,
876
- is_last)) {
877
- case GRPC_CHTTP2_PARSE_OK:
878
- if (stream_parsing) {
879
- grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
880
- stream_parsing);
881
- }
882
- return 1;
883
- case GRPC_CHTTP2_STREAM_ERROR:
884
- grpc_chttp2_parsing_become_skip_parser(exec_ctx, transport_parsing);
885
- if (stream_parsing) {
886
- stream_parsing->saw_rst_stream = 1;
887
- stream_parsing->rst_stream_reason = GRPC_CHTTP2_PROTOCOL_ERROR;
888
- gpr_slice_buffer_add(
889
- &transport_parsing->qbuf,
890
- grpc_chttp2_rst_stream_create(transport_parsing->incoming_stream_id,
891
- GRPC_CHTTP2_PROTOCOL_ERROR,
892
- &stream_parsing->stats.outgoing));
893
- }
894
- return 1;
895
- case GRPC_CHTTP2_CONNECTION_ERROR:
896
- return 0;
955
+ grpc_error *err = transport_parsing->parser(
956
+ exec_ctx, transport_parsing->parser_data, transport_parsing,
957
+ stream_parsing, slice, is_last);
958
+ if (err == GRPC_ERROR_NONE) {
959
+ if (stream_parsing) {
960
+ grpc_chttp2_list_add_parsing_seen_stream(transport_parsing,
961
+ stream_parsing);
962
+ }
963
+ return GRPC_ERROR_NONE;
964
+ } else if (grpc_error_get_int(err, GRPC_ERROR_INT_STREAM_ID, NULL)) {
965
+ if (grpc_http_trace) {
966
+ const char *msg = grpc_error_string(err);
967
+ gpr_log(GPR_ERROR, "%s", msg);
968
+ grpc_error_free_string(msg);
969
+ }
970
+ grpc_chttp2_parsing_become_skip_parser(exec_ctx, transport_parsing);
971
+ if (stream_parsing) {
972
+ stream_parsing->forced_close_error = err;
973
+ gpr_slice_buffer_add(
974
+ &transport_parsing->qbuf,
975
+ grpc_chttp2_rst_stream_create(transport_parsing->incoming_stream_id,
976
+ GRPC_CHTTP2_PROTOCOL_ERROR,
977
+ &stream_parsing->stats.outgoing));
978
+ } else {
979
+ GRPC_ERROR_UNREF(err);
980
+ }
897
981
  }
898
- GPR_UNREACHABLE_CODE(return 0);
982
+ return err;
899
983
  }