grpc 1.2.5 → 1.3.4

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 (327) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1434 -399
  3. data/etc/roots.pem +34 -150
  4. data/include/grpc/grpc.h +71 -0
  5. data/include/grpc/impl/codegen/atm.h +5 -0
  6. data/include/grpc/impl/codegen/atm_gcc_atomic.h +6 -0
  7. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  8. data/include/grpc/impl/codegen/atm_windows.h +11 -0
  9. data/include/grpc/impl/codegen/grpc_types.h +54 -13
  10. data/include/grpc/impl/codegen/port_platform.h +15 -1
  11. data/include/grpc/support/alloc.h +2 -1
  12. data/include/grpc/support/sync.h +4 -0
  13. data/include/grpc/support/tls.h +1 -1
  14. data/src/core/ext/census/gen/trace_context.pb.h +1 -1
  15. data/src/core/ext/census/grpc_filter.c +14 -10
  16. data/src/core/ext/census/grpc_plugin.c +3 -1
  17. data/src/core/ext/census/trace_label.h +1 -1
  18. data/src/core/ext/census/trace_propagation.h +1 -1
  19. data/src/core/ext/census/trace_status.h +1 -1
  20. data/src/core/ext/census/trace_string.h +1 -1
  21. data/src/core/ext/census/tracing.h +1 -1
  22. data/src/core/ext/{client_channel → filters/client_channel}/channel_connectivity.c +56 -27
  23. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.c +407 -202
  24. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.h +10 -6
  25. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.c +1 -1
  26. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.h +4 -4
  27. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_plugin.c +12 -7
  28. data/src/core/ext/{client_channel → filters/client_channel}/connector.c +1 -1
  29. data/src/core/ext/{client_channel → filters/client_channel}/connector.h +3 -5
  30. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.c +6 -6
  31. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.h +3 -3
  32. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.c +4 -4
  33. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.h +3 -3
  34. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.c +1 -1
  35. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.h +4 -4
  36. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.c +22 -20
  37. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.h +4 -4
  38. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel.h +5 -4
  39. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel_secure.c +2 -2
  40. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.c +1 -1
  41. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.h +6 -5
  42. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +1 -1
  43. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -0
  44. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/pick_first/pick_first.c +20 -15
  45. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/round_robin/round_robin.c +21 -16
  46. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.c +1 -1
  47. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.h +5 -5
  48. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.c +1 -1
  49. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.h +4 -4
  50. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.c +1 -1
  51. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.h +4 -4
  52. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.c +1 -1
  53. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.h +3 -3
  54. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.c +10 -4
  55. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.h +4 -4
  56. data/src/core/ext/{client_channel → filters/client_channel}/resolver.c +1 -1
  57. data/src/core/ext/{client_channel → filters/client_channel}/resolver.h +4 -4
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
  63. data/src/core/ext/{resolver → filters/client_channel/resolver}/dns/native/dns_resolver.c +21 -5
  64. data/src/core/ext/{resolver → filters/client_channel/resolver}/sockaddr/sockaddr_resolver.c +3 -3
  65. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.c +1 -1
  66. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.h +6 -6
  67. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.c +1 -2
  68. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.h +4 -4
  69. data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
  70. data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
  71. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.c +49 -43
  72. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.h +21 -7
  73. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.c +1 -1
  74. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.h +5 -5
  75. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.c +1 -1
  76. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.h +3 -3
  77. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.c +4 -2
  78. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.h +3 -3
  79. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.c +17 -14
  80. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.h +4 -4
  81. data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
  82. data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
  83. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +6 -41
  84. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  85. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +2 -2
  86. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +3 -3
  87. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  88. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +2 -5
  89. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +2 -2
  90. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +449 -204
  91. data/src/core/ext/transport/chttp2/transport/frame_data.c +10 -7
  92. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +3 -2
  93. data/src/core/ext/transport/chttp2/transport/frame_ping.c +37 -7
  94. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -0
  95. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +4 -3
  96. data/src/core/ext/transport/chttp2/transport/frame_settings.c +18 -38
  97. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -29
  98. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +2 -2
  99. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +64 -37
  100. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +11 -4
  101. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +60 -39
  102. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  103. data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
  104. data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
  105. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +22 -43
  106. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +8 -10
  107. data/src/core/ext/transport/chttp2/transport/internal.h +24 -2
  108. data/src/core/ext/transport/chttp2/transport/parsing.c +33 -15
  109. data/src/core/ext/transport/chttp2/transport/writing.c +56 -10
  110. data/src/core/lib/channel/channel_args.c +7 -0
  111. data/src/core/lib/channel/channel_args.h +2 -0
  112. data/src/core/lib/channel/channel_stack.c +20 -27
  113. data/src/core/lib/channel/channel_stack.h +18 -16
  114. data/src/core/lib/channel/compress_filter.c +20 -18
  115. data/src/core/lib/channel/connected_channel.c +9 -8
  116. data/src/core/lib/channel/deadline_filter.c +28 -24
  117. data/src/core/lib/channel/deadline_filter.h +3 -3
  118. data/src/core/lib/channel/handshaker.c +3 -2
  119. data/src/core/lib/channel/http_client_filter.c +119 -61
  120. data/src/core/lib/channel/http_server_filter.c +124 -69
  121. data/src/core/lib/channel/message_size_filter.c +23 -19
  122. data/src/core/lib/http/httpcli.c +8 -6
  123. data/src/core/lib/http/httpcli_security_connector.c +5 -5
  124. data/src/core/lib/http/parser.c +57 -31
  125. data/src/core/lib/iomgr/closure.c +15 -0
  126. data/src/core/lib/iomgr/closure.h +4 -0
  127. data/src/core/lib/iomgr/combiner.c +8 -0
  128. data/src/core/lib/iomgr/endpoint_pair.h +2 -3
  129. data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -7
  130. data/src/core/lib/iomgr/endpoint_pair_uv.c +2 -3
  131. data/src/core/lib/iomgr/endpoint_pair_windows.c +9 -6
  132. data/src/core/lib/iomgr/error.c +360 -177
  133. data/src/core/lib/iomgr/error.h +31 -33
  134. data/src/core/lib/iomgr/error_internal.h +30 -9
  135. data/src/core/lib/iomgr/ev_epoll_linux.c +25 -239
  136. data/src/core/lib/iomgr/ev_poll_posix.c +11 -7
  137. data/src/core/lib/iomgr/ev_posix.c +6 -0
  138. data/src/core/lib/iomgr/ev_posix.h +3 -0
  139. data/src/core/lib/iomgr/exec_ctx.c +6 -0
  140. data/src/core/lib/iomgr/executor.c +8 -2
  141. data/src/core/lib/iomgr/load_file.c +6 -3
  142. data/src/core/lib/iomgr/lockfree_event.c +238 -0
  143. data/src/core/{ext/client_channel/initial_connect_string.h → lib/iomgr/lockfree_event.h} +17 -13
  144. data/src/core/lib/iomgr/pollset.h +4 -0
  145. data/src/core/lib/iomgr/pollset_windows.c +2 -2
  146. data/src/core/lib/iomgr/port.h +9 -0
  147. data/src/core/lib/iomgr/resolve_address_posix.c +15 -9
  148. data/src/core/lib/iomgr/resolve_address_uv.c +8 -6
  149. data/src/core/lib/iomgr/resolve_address_windows.c +2 -2
  150. data/src/core/lib/iomgr/resource_quota.c +19 -4
  151. data/src/core/lib/iomgr/resource_quota.h +2 -0
  152. data/src/core/lib/iomgr/sockaddr_utils.c +3 -1
  153. data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
  154. data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
  155. data/src/core/lib/iomgr/socket_utils_common_posix.c +25 -9
  156. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  157. data/src/core/lib/iomgr/tcp_client.h +0 -4
  158. data/src/core/lib/iomgr/tcp_client_posix.c +15 -31
  159. data/src/core/lib/iomgr/tcp_client_uv.c +10 -6
  160. data/src/core/lib/iomgr/tcp_client_windows.c +9 -19
  161. data/src/core/lib/iomgr/tcp_posix.c +111 -22
  162. data/src/core/lib/iomgr/tcp_posix.h +3 -4
  163. data/src/core/lib/iomgr/tcp_server_posix.c +39 -417
  164. data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
  165. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
  166. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
  167. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
  168. data/src/core/lib/iomgr/tcp_server_uv.c +43 -16
  169. data/src/core/lib/iomgr/tcp_server_windows.c +10 -22
  170. data/src/core/lib/iomgr/tcp_uv.c +16 -13
  171. data/src/core/lib/iomgr/tcp_windows.c +24 -12
  172. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  173. data/src/core/lib/iomgr/timer.h +3 -0
  174. data/src/core/lib/iomgr/timer_generic.c +257 -72
  175. data/src/core/lib/iomgr/timer_generic.h +1 -1
  176. data/src/core/lib/iomgr/timer_heap.c +8 -8
  177. data/src/core/lib/iomgr/udp_server.c +54 -24
  178. data/src/core/lib/iomgr/udp_server.h +7 -7
  179. data/src/core/lib/iomgr/unix_sockets_posix.c +1 -1
  180. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +2 -1
  181. data/src/core/lib/iomgr/wakeup_fd_posix.h +1 -1
  182. data/src/core/lib/profiling/basic_timers.c +1 -1
  183. data/src/core/lib/security/credentials/credentials.h +1 -1
  184. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +10 -9
  185. data/src/core/lib/security/credentials/jwt/json_token.c +1 -1
  186. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +2 -2
  187. data/src/core/lib/security/transport/client_auth_filter.c +33 -26
  188. data/src/core/lib/security/transport/secure_endpoint.c +8 -5
  189. data/src/core/lib/security/transport/security_connector.c +37 -37
  190. data/src/core/lib/security/transport/security_connector.h +1 -1
  191. data/src/core/lib/security/transport/security_handshaker.c +15 -12
  192. data/src/core/lib/security/transport/server_auth_filter.c +20 -18
  193. data/src/core/lib/security/transport/tsi_error.c +5 -3
  194. data/src/core/lib/security/transport/tsi_error.h +1 -1
  195. data/src/core/lib/{security/util → slice}/b64.c +21 -6
  196. data/src/core/lib/{security/util → slice}/b64.h +16 -4
  197. data/src/core/lib/slice/slice.c +4 -2
  198. data/src/core/lib/slice/slice_buffer.c +16 -14
  199. data/src/core/lib/support/arena.c +98 -0
  200. data/src/core/{ext/client_channel/initial_connect_string.c → lib/support/arena.h} +17 -15
  201. data/src/core/{ext/client_channel/default_initial_connect_string.c → lib/support/atm.c} +14 -5
  202. data/src/core/lib/support/cpu_linux.c +5 -0
  203. data/src/core/lib/support/sync.c +4 -0
  204. data/src/core/lib/support/time.c +4 -10
  205. data/src/core/lib/support/wrap_memcpy.c +3 -1
  206. data/src/core/lib/surface/call.c +252 -221
  207. data/src/core/lib/surface/channel.c +72 -21
  208. data/src/core/lib/surface/channel.h +8 -0
  209. data/src/core/lib/surface/completion_queue.c +2 -3
  210. data/src/core/lib/surface/completion_queue_factory.c +77 -0
  211. data/src/core/lib/surface/completion_queue_factory.h +51 -0
  212. data/src/core/lib/surface/init_secure.c +3 -1
  213. data/src/core/lib/surface/lame_client.c +18 -14
  214. data/src/core/lib/surface/server.c +43 -41
  215. data/src/core/lib/surface/validate_metadata.c +8 -4
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.h +1 -1
  218. data/src/core/lib/transport/connectivity_state.c +2 -1
  219. data/src/core/lib/transport/error_utils.c +17 -17
  220. data/src/core/lib/transport/error_utils.h +1 -1
  221. data/src/core/lib/transport/metadata_batch.c +6 -7
  222. data/src/core/lib/transport/pid_controller.c +1 -0
  223. data/src/core/lib/transport/service_config.c +12 -0
  224. data/src/core/lib/transport/service_config.h +6 -0
  225. data/src/core/lib/transport/transport.c +29 -17
  226. data/src/core/lib/transport/transport.h +85 -42
  227. data/src/core/lib/transport/transport_impl.h +5 -3
  228. data/src/core/lib/transport/transport_op_string.c +20 -14
  229. data/src/core/plugin_registry/grpc_plugin_registry.c +8 -0
  230. data/src/core/{lib/tsi → tsi}/fake_transport_security.c +2 -2
  231. data/src/core/{lib/tsi → tsi}/fake_transport_security.h +4 -4
  232. data/src/core/{lib/tsi → tsi}/ssl_transport_security.c +40 -79
  233. data/src/core/{lib/tsi → tsi}/ssl_transport_security.h +44 -21
  234. data/src/core/{lib/tsi → tsi}/ssl_types.h +3 -3
  235. data/src/core/{lib/tsi → tsi}/transport_security.c +2 -2
  236. data/src/core/{lib/tsi → tsi}/transport_security.h +4 -4
  237. data/src/core/{lib/tsi → tsi}/transport_security_interface.h +3 -3
  238. data/src/ruby/ext/grpc/extconf.rb +1 -0
  239. data/src/ruby/ext/grpc/rb_call_credentials.c +2 -2
  240. data/src/ruby/ext/grpc/rb_channel.c +520 -93
  241. data/src/ruby/ext/grpc/rb_channel.h +2 -0
  242. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -0
  243. data/src/ruby/ext/grpc/rb_compression_options.c +5 -2
  244. data/src/ruby/ext/grpc/rb_event_thread.c +6 -6
  245. data/src/ruby/ext/grpc/rb_grpc.c +29 -7
  246. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  247. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
  249. data/src/ruby/ext/grpc/rb_server.c +5 -3
  250. data/src/ruby/lib/grpc/version.rb +1 -1
  251. data/src/ruby/spec/channel_connection_spec.rb +173 -0
  252. data/src/ruby/spec/channel_spec.rb +29 -0
  253. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +27 -17
  254. data/third_party/cares/ares_build.h +264 -0
  255. data/third_party/cares/cares/ares.h +636 -0
  256. data/third_party/cares/cares/ares__close_sockets.c +61 -0
  257. data/third_party/cares/cares/ares__get_hostent.c +261 -0
  258. data/third_party/cares/cares/ares__read_line.c +73 -0
  259. data/third_party/cares/cares/ares__timeval.c +111 -0
  260. data/third_party/cares/cares/ares_cancel.c +63 -0
  261. data/third_party/cares/cares/ares_create_query.c +202 -0
  262. data/third_party/cares/cares/ares_data.c +221 -0
  263. data/third_party/cares/cares/ares_data.h +72 -0
  264. data/third_party/cares/cares/ares_destroy.c +108 -0
  265. data/third_party/cares/cares/ares_dns.h +103 -0
  266. data/third_party/cares/cares/ares_expand_name.c +205 -0
  267. data/third_party/cares/cares/ares_expand_string.c +70 -0
  268. data/third_party/cares/cares/ares_fds.c +59 -0
  269. data/third_party/cares/cares/ares_free_hostent.c +41 -0
  270. data/third_party/cares/cares/ares_free_string.c +25 -0
  271. data/third_party/cares/cares/ares_getenv.c +30 -0
  272. data/third_party/cares/cares/ares_getenv.h +26 -0
  273. data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
  274. data/third_party/cares/cares/ares_gethostbyname.c +518 -0
  275. data/third_party/cares/cares/ares_getnameinfo.c +422 -0
  276. data/third_party/cares/cares/ares_getopt.c +122 -0
  277. data/third_party/cares/cares/ares_getopt.h +53 -0
  278. data/third_party/cares/cares/ares_getsock.c +66 -0
  279. data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
  280. data/third_party/cares/cares/ares_init.c +2146 -0
  281. data/third_party/cares/cares/ares_iphlpapi.h +221 -0
  282. data/third_party/cares/cares/ares_ipv6.h +78 -0
  283. data/third_party/cares/cares/ares_library_init.c +167 -0
  284. data/third_party/cares/cares/ares_library_init.h +42 -0
  285. data/third_party/cares/cares/ares_llist.c +63 -0
  286. data/third_party/cares/cares/ares_llist.h +39 -0
  287. data/third_party/cares/cares/ares_mkquery.c +24 -0
  288. data/third_party/cares/cares/ares_nowarn.c +260 -0
  289. data/third_party/cares/cares/ares_nowarn.h +61 -0
  290. data/third_party/cares/cares/ares_options.c +402 -0
  291. data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
  292. data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
  293. data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
  294. data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
  295. data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
  296. data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
  297. data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
  298. data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
  299. data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
  300. data/third_party/cares/cares/ares_platform.c +11035 -0
  301. data/third_party/cares/cares/ares_platform.h +43 -0
  302. data/third_party/cares/cares/ares_private.h +363 -0
  303. data/third_party/cares/cares/ares_process.c +1359 -0
  304. data/third_party/cares/cares/ares_query.c +186 -0
  305. data/third_party/cares/cares/ares_rules.h +125 -0
  306. data/third_party/cares/cares/ares_search.c +316 -0
  307. data/third_party/cares/cares/ares_send.c +131 -0
  308. data/third_party/cares/cares/ares_setup.h +217 -0
  309. data/third_party/cares/cares/ares_strcasecmp.c +66 -0
  310. data/third_party/cares/cares/ares_strcasecmp.h +30 -0
  311. data/third_party/cares/cares/ares_strdup.c +49 -0
  312. data/third_party/cares/cares/ares_strdup.h +24 -0
  313. data/third_party/cares/cares/ares_strerror.c +56 -0
  314. data/third_party/cares/cares/ares_timeout.c +88 -0
  315. data/third_party/cares/cares/ares_version.c +11 -0
  316. data/third_party/cares/cares/ares_version.h +24 -0
  317. data/third_party/cares/cares/ares_writev.c +79 -0
  318. data/third_party/cares/cares/bitncmp.c +59 -0
  319. data/third_party/cares/cares/bitncmp.h +26 -0
  320. data/third_party/cares/cares/config-win32.h +377 -0
  321. data/third_party/cares/cares/inet_net_pton.c +450 -0
  322. data/third_party/cares/cares/inet_ntop.c +208 -0
  323. data/third_party/cares/cares/setup_once.h +554 -0
  324. data/third_party/cares/cares/windows_port.c +22 -0
  325. data/third_party/cares/config_darwin/ares_config.h +523 -0
  326. data/third_party/cares/config_linux/ares_config.h +524 -0
  327. metadata +164 -68
@@ -0,0 +1,439 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include "src/core/ext/filters/max_age/max_age_filter.h"
35
+
36
+ #include <limits.h>
37
+ #include <string.h>
38
+
39
+ #include "src/core/lib/channel/channel_args.h"
40
+ #include "src/core/lib/channel/channel_stack_builder.h"
41
+ #include "src/core/lib/iomgr/timer.h"
42
+ #include "src/core/lib/surface/channel_init.h"
43
+ #include "src/core/lib/transport/http2_errors.h"
44
+
45
+ #define DEFAULT_MAX_CONNECTION_AGE_MS INT_MAX
46
+ #define DEFAULT_MAX_CONNECTION_AGE_GRACE_MS INT_MAX
47
+ #define DEFAULT_MAX_CONNECTION_IDLE_MS INT_MAX
48
+ #define MAX_CONNECTION_AGE_JITTER 0.1
49
+
50
+ typedef struct channel_data {
51
+ /* We take a reference to the channel stack for the timer callback */
52
+ grpc_channel_stack* channel_stack;
53
+ /* Guards access to max_age_timer, max_age_timer_pending, max_age_grace_timer
54
+ and max_age_grace_timer_pending */
55
+ gpr_mu max_age_timer_mu;
56
+ /* True if the max_age timer callback is currently pending */
57
+ bool max_age_timer_pending;
58
+ /* True if the max_age_grace timer callback is currently pending */
59
+ bool max_age_grace_timer_pending;
60
+ /* The timer for checking if the channel has reached its max age */
61
+ grpc_timer max_age_timer;
62
+ /* The timer for checking if the max-aged channel has uesed up the grace
63
+ period */
64
+ grpc_timer max_age_grace_timer;
65
+ /* The timer for checking if the channel's idle duration reaches
66
+ max_connection_idle */
67
+ grpc_timer max_idle_timer;
68
+ /* Allowed max time a channel may have no outstanding rpcs */
69
+ gpr_timespec max_connection_idle;
70
+ /* Allowed max time a channel may exist */
71
+ gpr_timespec max_connection_age;
72
+ /* Allowed grace period after the channel reaches its max age */
73
+ gpr_timespec max_connection_age_grace;
74
+ /* Closure to run when the channel's idle duration reaches max_connection_idle
75
+ and should be closed gracefully */
76
+ grpc_closure close_max_idle_channel;
77
+ /* Closure to run when the channel reaches its max age and should be closed
78
+ gracefully */
79
+ grpc_closure close_max_age_channel;
80
+ /* Closure to run the channel uses up its max age grace time and should be
81
+ closed forcibly */
82
+ grpc_closure force_close_max_age_channel;
83
+ /* Closure to run when the init fo channel stack is done and the max_idle
84
+ timer should be started */
85
+ grpc_closure start_max_idle_timer_after_init;
86
+ /* Closure to run when the init fo channel stack is done and the max_age timer
87
+ should be started */
88
+ grpc_closure start_max_age_timer_after_init;
89
+ /* Closure to run when the goaway op is finished and the max_age_timer */
90
+ grpc_closure start_max_age_grace_timer_after_goaway_op;
91
+ /* Closure to run when the channel connectivity state changes */
92
+ grpc_closure channel_connectivity_changed;
93
+ /* Records the current connectivity state */
94
+ grpc_connectivity_state connectivity_state;
95
+ /* Number of active calls */
96
+ gpr_atm call_count;
97
+ } channel_data;
98
+
99
+ /* Increase the nubmer of active calls. Before the increasement, if there are no
100
+ calls, the max_idle_timer should be cancelled. */
101
+ static void increase_call_count(grpc_exec_ctx* exec_ctx, channel_data* chand) {
102
+ if (gpr_atm_full_fetch_add(&chand->call_count, 1) == 0) {
103
+ grpc_timer_cancel(exec_ctx, &chand->max_idle_timer);
104
+ }
105
+ }
106
+
107
+ /* Decrease the nubmer of active calls. After the decrement, if there are no
108
+ calls, the max_idle_timer should be started. */
109
+ static void decrease_call_count(grpc_exec_ctx* exec_ctx, channel_data* chand) {
110
+ if (gpr_atm_full_fetch_add(&chand->call_count, -1) == 1) {
111
+ GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_idle_timer");
112
+ grpc_timer_init(
113
+ exec_ctx, &chand->max_idle_timer,
114
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), chand->max_connection_idle),
115
+ &chand->close_max_idle_channel, gpr_now(GPR_CLOCK_MONOTONIC));
116
+ }
117
+ }
118
+
119
+ static void start_max_idle_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg,
120
+ grpc_error* error) {
121
+ channel_data* chand = arg;
122
+ /* Decrease call_count. If there are no active calls at this time,
123
+ max_idle_timer will start here. If the number of active calls is not 0,
124
+ max_idle_timer will start after all the active calls end. */
125
+ decrease_call_count(exec_ctx, chand);
126
+ GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack,
127
+ "max_age start_max_idle_timer_after_init");
128
+ }
129
+
130
+ static void start_max_age_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg,
131
+ grpc_error* error) {
132
+ channel_data* chand = arg;
133
+ gpr_mu_lock(&chand->max_age_timer_mu);
134
+ chand->max_age_timer_pending = true;
135
+ GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_timer");
136
+ grpc_timer_init(
137
+ exec_ctx, &chand->max_age_timer,
138
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), chand->max_connection_age),
139
+ &chand->close_max_age_channel, gpr_now(GPR_CLOCK_MONOTONIC));
140
+ gpr_mu_unlock(&chand->max_age_timer_mu);
141
+ grpc_transport_op* op = grpc_make_transport_op(NULL);
142
+ op->on_connectivity_state_change = &chand->channel_connectivity_changed,
143
+ op->connectivity_state = &chand->connectivity_state;
144
+ grpc_channel_next_op(exec_ctx,
145
+ grpc_channel_stack_element(chand->channel_stack, 0), op);
146
+ GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack,
147
+ "max_age start_max_age_timer_after_init");
148
+ }
149
+
150
+ static void start_max_age_grace_timer_after_goaway_op(grpc_exec_ctx* exec_ctx,
151
+ void* arg,
152
+ grpc_error* error) {
153
+ channel_data* chand = arg;
154
+ gpr_mu_lock(&chand->max_age_timer_mu);
155
+ chand->max_age_grace_timer_pending = true;
156
+ GRPC_CHANNEL_STACK_REF(chand->channel_stack, "max_age max_age_grace_timer");
157
+ grpc_timer_init(exec_ctx, &chand->max_age_grace_timer,
158
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
159
+ chand->max_connection_age_grace),
160
+ &chand->force_close_max_age_channel,
161
+ gpr_now(GPR_CLOCK_MONOTONIC));
162
+ gpr_mu_unlock(&chand->max_age_timer_mu);
163
+ GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack,
164
+ "max_age start_max_age_grace_timer_after_goaway_op");
165
+ }
166
+
167
+ static void close_max_idle_channel(grpc_exec_ctx* exec_ctx, void* arg,
168
+ grpc_error* error) {
169
+ channel_data* chand = arg;
170
+ if (error == GRPC_ERROR_NONE) {
171
+ /* Prevent the max idle timer from being set again */
172
+ gpr_atm_no_barrier_fetch_add(&chand->call_count, 1);
173
+ grpc_transport_op* op = grpc_make_transport_op(NULL);
174
+ op->goaway_error =
175
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("max_idle"),
176
+ GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_NO_ERROR);
177
+ grpc_channel_element* elem =
178
+ grpc_channel_stack_element(chand->channel_stack, 0);
179
+ elem->filter->start_transport_op(exec_ctx, elem, op);
180
+ } else if (error != GRPC_ERROR_CANCELLED) {
181
+ GRPC_LOG_IF_ERROR("close_max_idle_channel", error);
182
+ }
183
+ GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack,
184
+ "max_age max_idle_timer");
185
+ }
186
+
187
+ static void close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg,
188
+ grpc_error* error) {
189
+ channel_data* chand = arg;
190
+ gpr_mu_lock(&chand->max_age_timer_mu);
191
+ chand->max_age_timer_pending = false;
192
+ gpr_mu_unlock(&chand->max_age_timer_mu);
193
+ if (error == GRPC_ERROR_NONE) {
194
+ GRPC_CHANNEL_STACK_REF(chand->channel_stack,
195
+ "max_age start_max_age_grace_timer_after_goaway_op");
196
+ grpc_transport_op* op = grpc_make_transport_op(
197
+ &chand->start_max_age_grace_timer_after_goaway_op);
198
+ op->goaway_error =
199
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("max_age"),
200
+ GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_NO_ERROR);
201
+ grpc_channel_element* elem =
202
+ grpc_channel_stack_element(chand->channel_stack, 0);
203
+ elem->filter->start_transport_op(exec_ctx, elem, op);
204
+ } else if (error != GRPC_ERROR_CANCELLED) {
205
+ GRPC_LOG_IF_ERROR("close_max_age_channel", error);
206
+ }
207
+ GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack,
208
+ "max_age max_age_timer");
209
+ }
210
+
211
+ static void force_close_max_age_channel(grpc_exec_ctx* exec_ctx, void* arg,
212
+ grpc_error* error) {
213
+ channel_data* chand = arg;
214
+ gpr_mu_lock(&chand->max_age_timer_mu);
215
+ chand->max_age_grace_timer_pending = false;
216
+ gpr_mu_unlock(&chand->max_age_timer_mu);
217
+ if (error == GRPC_ERROR_NONE) {
218
+ grpc_transport_op* op = grpc_make_transport_op(NULL);
219
+ op->disconnect_with_error =
220
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Channel reaches max age");
221
+ grpc_channel_element* elem =
222
+ grpc_channel_stack_element(chand->channel_stack, 0);
223
+ elem->filter->start_transport_op(exec_ctx, elem, op);
224
+ } else if (error != GRPC_ERROR_CANCELLED) {
225
+ GRPC_LOG_IF_ERROR("force_close_max_age_channel", error);
226
+ }
227
+ GRPC_CHANNEL_STACK_UNREF(exec_ctx, chand->channel_stack,
228
+ "max_age max_age_grace_timer");
229
+ }
230
+
231
+ static void channel_connectivity_changed(grpc_exec_ctx* exec_ctx, void* arg,
232
+ grpc_error* error) {
233
+ channel_data* chand = arg;
234
+ if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) {
235
+ grpc_transport_op* op = grpc_make_transport_op(NULL);
236
+ op->on_connectivity_state_change = &chand->channel_connectivity_changed,
237
+ op->connectivity_state = &chand->connectivity_state;
238
+ grpc_channel_next_op(
239
+ exec_ctx, grpc_channel_stack_element(chand->channel_stack, 0), op);
240
+ } else {
241
+ gpr_mu_lock(&chand->max_age_timer_mu);
242
+ if (chand->max_age_timer_pending) {
243
+ grpc_timer_cancel(exec_ctx, &chand->max_age_timer);
244
+ chand->max_age_timer_pending = false;
245
+ }
246
+ if (chand->max_age_grace_timer_pending) {
247
+ grpc_timer_cancel(exec_ctx, &chand->max_age_grace_timer);
248
+ chand->max_age_grace_timer_pending = false;
249
+ }
250
+ gpr_mu_unlock(&chand->max_age_timer_mu);
251
+ /* If there are no active calls, this increasement will cancel
252
+ max_idle_timer, and prevent max_idle_timer from being started in the
253
+ future. */
254
+ increase_call_count(exec_ctx, chand);
255
+ }
256
+ }
257
+
258
+ /* A random jitter of +/-10% will be added to MAX_CONNECTION_AGE to spread out
259
+ connection storms. Note that the MAX_CONNECTION_AGE option without jitter
260
+ would not create connection storms by itself, but if there happened to be a
261
+ connection storm it could cause it to repeat at a fixed period. */
262
+ static int add_random_max_connection_age_jitter(int value) {
263
+ /* generate a random number between 1 - MAX_CONNECTION_AGE_JITTER and
264
+ 1 + MAX_CONNECTION_AGE_JITTER */
265
+ double multiplier = rand() * MAX_CONNECTION_AGE_JITTER * 2.0 / RAND_MAX +
266
+ 1.0 - MAX_CONNECTION_AGE_JITTER;
267
+ double result = multiplier * value;
268
+ /* INT_MAX - 0.5 converts the value to float, so that result will not be
269
+ cast to int implicitly before the comparison. */
270
+ return result > INT_MAX - 0.5 ? INT_MAX : (int)result;
271
+ }
272
+
273
+ /* Constructor for call_data. */
274
+ static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx,
275
+ grpc_call_element* elem,
276
+ const grpc_call_element_args* args) {
277
+ channel_data* chand = elem->channel_data;
278
+ increase_call_count(exec_ctx, chand);
279
+ return GRPC_ERROR_NONE;
280
+ }
281
+
282
+ /* Destructor for call_data. */
283
+ static void destroy_call_elem(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
284
+ const grpc_call_final_info* final_info,
285
+ grpc_closure* ignored) {
286
+ channel_data* chand = elem->channel_data;
287
+ decrease_call_count(exec_ctx, chand);
288
+ }
289
+
290
+ /* Constructor for channel_data. */
291
+ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx,
292
+ grpc_channel_element* elem,
293
+ grpc_channel_element_args* args) {
294
+ channel_data* chand = elem->channel_data;
295
+ gpr_mu_init(&chand->max_age_timer_mu);
296
+ chand->max_age_timer_pending = false;
297
+ chand->max_age_grace_timer_pending = false;
298
+ chand->channel_stack = args->channel_stack;
299
+ chand->max_connection_age =
300
+ DEFAULT_MAX_CONNECTION_AGE_MS == INT_MAX
301
+ ? gpr_inf_future(GPR_TIMESPAN)
302
+ : gpr_time_from_millis(add_random_max_connection_age_jitter(
303
+ DEFAULT_MAX_CONNECTION_AGE_MS),
304
+ GPR_TIMESPAN);
305
+ chand->max_connection_age_grace =
306
+ DEFAULT_MAX_CONNECTION_AGE_GRACE_MS == INT_MAX
307
+ ? gpr_inf_future(GPR_TIMESPAN)
308
+ : gpr_time_from_millis(DEFAULT_MAX_CONNECTION_AGE_GRACE_MS,
309
+ GPR_TIMESPAN);
310
+ chand->max_connection_idle =
311
+ DEFAULT_MAX_CONNECTION_IDLE_MS == INT_MAX
312
+ ? gpr_inf_future(GPR_TIMESPAN)
313
+ : gpr_time_from_millis(DEFAULT_MAX_CONNECTION_IDLE_MS, GPR_TIMESPAN);
314
+ for (size_t i = 0; i < args->channel_args->num_args; ++i) {
315
+ if (0 == strcmp(args->channel_args->args[i].key,
316
+ GRPC_ARG_MAX_CONNECTION_AGE_MS)) {
317
+ const int value = grpc_channel_arg_get_integer(
318
+ &args->channel_args->args[i],
319
+ (grpc_integer_options){DEFAULT_MAX_CONNECTION_AGE_MS, 1, INT_MAX});
320
+ chand->max_connection_age =
321
+ value == INT_MAX
322
+ ? gpr_inf_future(GPR_TIMESPAN)
323
+ : gpr_time_from_millis(
324
+ add_random_max_connection_age_jitter(value), GPR_TIMESPAN);
325
+ } else if (0 == strcmp(args->channel_args->args[i].key,
326
+ GRPC_ARG_MAX_CONNECTION_AGE_GRACE_MS)) {
327
+ const int value = grpc_channel_arg_get_integer(
328
+ &args->channel_args->args[i],
329
+ (grpc_integer_options){DEFAULT_MAX_CONNECTION_AGE_GRACE_MS, 0,
330
+ INT_MAX});
331
+ chand->max_connection_age_grace =
332
+ value == INT_MAX ? gpr_inf_future(GPR_TIMESPAN)
333
+ : gpr_time_from_millis(value, GPR_TIMESPAN);
334
+ } else if (0 == strcmp(args->channel_args->args[i].key,
335
+ GRPC_ARG_MAX_CONNECTION_IDLE_MS)) {
336
+ const int value = grpc_channel_arg_get_integer(
337
+ &args->channel_args->args[i],
338
+ (grpc_integer_options){DEFAULT_MAX_CONNECTION_IDLE_MS, 1, INT_MAX});
339
+ chand->max_connection_idle =
340
+ value == INT_MAX ? gpr_inf_future(GPR_TIMESPAN)
341
+ : gpr_time_from_millis(value, GPR_TIMESPAN);
342
+ }
343
+ }
344
+ grpc_closure_init(&chand->close_max_idle_channel, close_max_idle_channel,
345
+ chand, grpc_schedule_on_exec_ctx);
346
+ grpc_closure_init(&chand->close_max_age_channel, close_max_age_channel, chand,
347
+ grpc_schedule_on_exec_ctx);
348
+ grpc_closure_init(&chand->force_close_max_age_channel,
349
+ force_close_max_age_channel, chand,
350
+ grpc_schedule_on_exec_ctx);
351
+ grpc_closure_init(&chand->start_max_idle_timer_after_init,
352
+ start_max_idle_timer_after_init, chand,
353
+ grpc_schedule_on_exec_ctx);
354
+ grpc_closure_init(&chand->start_max_age_timer_after_init,
355
+ start_max_age_timer_after_init, chand,
356
+ grpc_schedule_on_exec_ctx);
357
+ grpc_closure_init(&chand->start_max_age_grace_timer_after_goaway_op,
358
+ start_max_age_grace_timer_after_goaway_op, chand,
359
+ grpc_schedule_on_exec_ctx);
360
+ grpc_closure_init(&chand->channel_connectivity_changed,
361
+ channel_connectivity_changed, chand,
362
+ grpc_schedule_on_exec_ctx);
363
+
364
+ if (gpr_time_cmp(chand->max_connection_age, gpr_inf_future(GPR_TIMESPAN)) !=
365
+ 0) {
366
+ /* When the channel reaches its max age, we send down an op with
367
+ goaway_error set. However, we can't send down any ops until after the
368
+ channel stack is fully initialized. If we start the timer here, we have
369
+ no guarantee that the timer won't pop before channel stack initialization
370
+ is finished. To avoid that problem, we create a closure to start the
371
+ timer, and we schedule that closure to be run after call stack
372
+ initialization is done. */
373
+ GRPC_CHANNEL_STACK_REF(chand->channel_stack,
374
+ "max_age start_max_age_timer_after_init");
375
+ grpc_closure_sched(exec_ctx, &chand->start_max_age_timer_after_init,
376
+ GRPC_ERROR_NONE);
377
+ }
378
+
379
+ /* Initialize the number of calls as 1, so that the max_idle_timer will not
380
+ start until start_max_idle_timer_after_init is invoked. */
381
+ gpr_atm_rel_store(&chand->call_count, 1);
382
+ if (gpr_time_cmp(chand->max_connection_idle, gpr_inf_future(GPR_TIMESPAN)) !=
383
+ 0) {
384
+ GRPC_CHANNEL_STACK_REF(chand->channel_stack,
385
+ "max_age start_max_idle_timer_after_init");
386
+ grpc_closure_sched(exec_ctx, &chand->start_max_idle_timer_after_init,
387
+ GRPC_ERROR_NONE);
388
+ }
389
+ return GRPC_ERROR_NONE;
390
+ }
391
+
392
+ /* Destructor for channel_data. */
393
+ static void destroy_channel_elem(grpc_exec_ctx* exec_ctx,
394
+ grpc_channel_element* elem) {}
395
+
396
+ const grpc_channel_filter grpc_max_age_filter = {
397
+ grpc_call_next_op,
398
+ grpc_channel_next_op,
399
+ 0, /* sizeof_call_data */
400
+ init_call_elem,
401
+ grpc_call_stack_ignore_set_pollset_or_pollset_set,
402
+ destroy_call_elem,
403
+ sizeof(channel_data),
404
+ init_channel_elem,
405
+ destroy_channel_elem,
406
+ grpc_call_next_get_peer,
407
+ grpc_channel_next_get_info,
408
+ "max_age"};
409
+
410
+ static bool maybe_add_max_age_filter(grpc_exec_ctx* exec_ctx,
411
+ grpc_channel_stack_builder* builder,
412
+ void* arg) {
413
+ const grpc_channel_args* channel_args =
414
+ grpc_channel_stack_builder_get_channel_arguments(builder);
415
+ const grpc_arg* a =
416
+ grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_AGE_MS);
417
+ bool enable = false;
418
+ if (a != NULL && a->type == GRPC_ARG_INTEGER && a->value.integer != INT_MAX) {
419
+ enable = true;
420
+ }
421
+ a = grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_IDLE_MS);
422
+ if (a != NULL && a->type == GRPC_ARG_INTEGER && a->value.integer != INT_MAX) {
423
+ enable = true;
424
+ }
425
+ if (enable) {
426
+ return grpc_channel_stack_builder_prepend_filter(
427
+ builder, &grpc_max_age_filter, NULL, NULL);
428
+ } else {
429
+ return true;
430
+ }
431
+ }
432
+
433
+ void grpc_max_age_filter_init(void) {
434
+ grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
435
+ GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
436
+ maybe_add_max_age_filter, NULL);
437
+ }
438
+
439
+ void grpc_max_age_filter_shutdown(void) {}
@@ -0,0 +1,39 @@
1
+ //
2
+ // Copyright 2017, Google Inc.
3
+ // All rights reserved.
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without
6
+ // modification, are permitted provided that the following conditions are
7
+ // met:
8
+ //
9
+ // * Redistributions of source code must retain the above copyright
10
+ // notice, this list of conditions and the following disclaimer.
11
+ // * Redistributions in binary form must reproduce the above
12
+ // copyright notice, this list of conditions and the following disclaimer
13
+ // in the documentation and/or other materials provided with the
14
+ // distribution.
15
+ // * Neither the name of Google Inc. nor the names of its
16
+ // contributors may be used to endorse or promote products derived from
17
+ // this software without specific prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+ //
31
+
32
+ #ifndef GRPC_CORE_EXT_FILTERS_MAX_AGE_MAX_AGE_FILTER_H
33
+ #define GRPC_CORE_EXT_FILTERS_MAX_AGE_MAX_AGE_FILTER_H
34
+
35
+ #include "src/core/lib/channel/channel_stack.h"
36
+
37
+ extern const grpc_channel_filter grpc_max_age_filter;
38
+
39
+ #endif /* GRPC_CORE_EXT_FILTERS_MAX_AGE_MAX_AGE_FILTER_H */