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
@@ -35,6 +35,7 @@
35
35
 
36
36
  #include <grpc/support/alloc.h>
37
37
  #include <grpc/support/log.h>
38
+ #include <grpc/support/string_util.h>
38
39
  #include <grpc/support/useful.h>
39
40
  #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
40
41
  #include "src/core/lib/channel/http_server_filter.h"
@@ -43,14 +44,8 @@
43
44
  #include "src/core/lib/surface/api_trace.h"
44
45
  #include "src/core/lib/surface/server.h"
45
46
 
46
- static void setup_transport(grpc_exec_ctx *exec_ctx, void *server,
47
- grpc_transport *transport) {
48
- grpc_server_setup_transport(exec_ctx, server, transport,
49
- grpc_server_get_channel_args(server));
50
- }
51
-
52
47
  static void new_transport(grpc_exec_ctx *exec_ctx, void *server,
53
- grpc_endpoint *tcp,
48
+ grpc_endpoint *tcp, grpc_pollset *accepting_pollset,
54
49
  grpc_tcp_server_acceptor *acceptor) {
55
50
  /*
56
51
  * Beware that the call to grpc_create_chttp2_transport() has to happen before
@@ -61,7 +56,8 @@ static void new_transport(grpc_exec_ctx *exec_ctx, void *server,
61
56
  */
62
57
  grpc_transport *transport = grpc_create_chttp2_transport(
63
58
  exec_ctx, grpc_server_get_channel_args(server), tcp, 0);
64
- setup_transport(exec_ctx, server, transport);
59
+ grpc_server_setup_transport(exec_ctx, server, transport, accepting_pollset,
60
+ grpc_server_get_channel_args(server));
65
61
  grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL, 0);
66
62
  }
67
63
 
@@ -79,34 +75,40 @@ static void destroy(grpc_exec_ctx *exec_ctx, grpc_server *server, void *tcpp,
79
75
  grpc_closure *destroy_done) {
80
76
  grpc_tcp_server *tcp = tcpp;
81
77
  grpc_tcp_server_unref(exec_ctx, tcp);
82
- grpc_exec_ctx_enqueue(exec_ctx, destroy_done, true, NULL);
78
+ grpc_exec_ctx_sched(exec_ctx, destroy_done, GRPC_ERROR_NONE, NULL);
83
79
  }
84
80
 
85
81
  int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) {
86
82
  grpc_resolved_addresses *resolved = NULL;
87
83
  grpc_tcp_server *tcp = NULL;
88
84
  size_t i;
89
- unsigned count = 0;
85
+ size_t count = 0;
90
86
  int port_num = -1;
91
87
  int port_temp;
92
88
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
89
+ grpc_error *err = GRPC_ERROR_NONE;
93
90
 
94
91
  GRPC_API_TRACE("grpc_server_add_insecure_http2_port(server=%p, addr=%s)", 2,
95
92
  (server, addr));
96
93
 
97
- resolved = grpc_blocking_resolve_address(addr, "http");
98
- if (!resolved) {
94
+ grpc_error **errors = NULL;
95
+ err = grpc_blocking_resolve_address(addr, "https", &resolved);
96
+ if (err != GRPC_ERROR_NONE) {
99
97
  goto error;
100
98
  }
101
99
 
102
- tcp = grpc_tcp_server_create(NULL);
103
- GPR_ASSERT(tcp);
100
+ err = grpc_tcp_server_create(NULL, &tcp);
101
+ if (err != GRPC_ERROR_NONE) {
102
+ goto error;
103
+ }
104
104
 
105
- for (i = 0; i < resolved->naddrs; i++) {
106
- port_temp = grpc_tcp_server_add_port(
105
+ const size_t naddrs = resolved->naddrs;
106
+ errors = gpr_malloc(sizeof(*errors) * naddrs);
107
+ for (i = 0; i < naddrs; i++) {
108
+ errors[i] = grpc_tcp_server_add_port(
107
109
  tcp, (struct sockaddr *)&resolved->addrs[i].addr,
108
- resolved->addrs[i].len);
109
- if (port_temp > 0) {
110
+ resolved->addrs[i].len, &port_temp);
111
+ if (errors[i] == GRPC_ERROR_NONE) {
110
112
  if (port_num == -1) {
111
113
  port_num = port_temp;
112
114
  } else {
@@ -116,13 +118,24 @@ int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) {
116
118
  }
117
119
  }
118
120
  if (count == 0) {
119
- gpr_log(GPR_ERROR, "No address added out of total %d resolved",
120
- resolved->naddrs);
121
+ char *msg;
122
+ gpr_asprintf(&msg, "No address added out of total %" PRIuPTR " resolved",
123
+ naddrs);
124
+ err = GRPC_ERROR_CREATE_REFERENCING(msg, errors, naddrs);
125
+ gpr_free(msg);
121
126
  goto error;
122
- }
123
- if (count != resolved->naddrs) {
124
- gpr_log(GPR_ERROR, "Only %d addresses added out of total %d resolved",
125
- count, resolved->naddrs);
127
+ } else if (count != naddrs) {
128
+ char *msg;
129
+ gpr_asprintf(&msg, "Only %" PRIuPTR
130
+ " addresses added out of total %" PRIuPTR " resolved",
131
+ count, naddrs);
132
+ err = GRPC_ERROR_CREATE_REFERENCING(msg, errors, naddrs);
133
+ gpr_free(msg);
134
+
135
+ const char *warning_message = grpc_error_string(err);
136
+ gpr_log(GPR_INFO, "WARNING: %s", warning_message);
137
+ grpc_error_free_string(warning_message);
138
+ /* we managed to bind some addresses: continue */
126
139
  }
127
140
  grpc_resolved_addresses_destroy(resolved);
128
141
 
@@ -132,6 +145,7 @@ int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) {
132
145
 
133
146
  /* Error path: cleanup and return */
134
147
  error:
148
+ GPR_ASSERT(err != GRPC_ERROR_NONE);
135
149
  if (resolved) {
136
150
  grpc_resolved_addresses_destroy(resolved);
137
151
  }
@@ -140,7 +154,18 @@ error:
140
154
  }
141
155
  port_num = 0;
142
156
 
157
+ const char *msg = grpc_error_string(err);
158
+ gpr_log(GPR_ERROR, "%s", msg);
159
+ grpc_error_free_string(msg);
160
+ GRPC_ERROR_UNREF(err);
161
+
143
162
  done:
144
163
  grpc_exec_ctx_finish(&exec_ctx);
164
+ if (errors != NULL) {
165
+ for (i = 0; i < naddrs; i++) {
166
+ GRPC_ERROR_UNREF(errors[i]);
167
+ }
168
+ }
169
+ gpr_free(errors);
145
170
  return port_num;
146
171
  }
@@ -0,0 +1,82 @@
1
+ /*
2
+ *
3
+ * Copyright 2016, 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 <grpc/grpc.h>
35
+ #include <grpc/grpc_posix.h>
36
+ #include <grpc/support/log.h>
37
+ #include <grpc/support/port_platform.h>
38
+
39
+ #ifdef GPR_SUPPORT_CHANNELS_FROM_FD
40
+
41
+ #include <grpc/support/alloc.h>
42
+ #include <grpc/support/string_util.h>
43
+
44
+ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
45
+ #include "src/core/lib/channel/channel_args.h"
46
+ #include "src/core/lib/iomgr/endpoint.h"
47
+ #include "src/core/lib/iomgr/exec_ctx.h"
48
+ #include "src/core/lib/iomgr/tcp_posix.h"
49
+ #include "src/core/lib/surface/completion_queue.h"
50
+ #include "src/core/lib/surface/server.h"
51
+
52
+ void grpc_server_add_insecure_channel_from_fd(grpc_server *server,
53
+ grpc_completion_queue *cq,
54
+ int fd) {
55
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
56
+
57
+ char *name;
58
+ gpr_asprintf(&name, "fd:%d", fd);
59
+
60
+ grpc_endpoint *server_endpoint = grpc_tcp_create(
61
+ grpc_fd_create(fd, name), GRPC_TCP_DEFAULT_READ_SLICE_SIZE, name);
62
+
63
+ gpr_free(name);
64
+
65
+ const grpc_channel_args *server_args = grpc_server_get_channel_args(server);
66
+ grpc_transport *transport = grpc_create_chttp2_transport(
67
+ &exec_ctx, server_args, server_endpoint, 0 /* is_client */);
68
+ grpc_endpoint_add_to_pollset(&exec_ctx, server_endpoint, grpc_cq_pollset(cq));
69
+ grpc_server_setup_transport(&exec_ctx, server, transport, NULL, server_args);
70
+ grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
71
+ grpc_exec_ctx_finish(&exec_ctx);
72
+ }
73
+
74
+ #else // !GPR_SUPPORT_CHANNELS_FROM_FD
75
+
76
+ void grpc_server_add_insecure_channel_from_fd(grpc_server *server,
77
+ grpc_completion_queue *cq,
78
+ int fd) {
79
+ GPR_ASSERT(0);
80
+ }
81
+
82
+ #endif // GPR_SUPPORT_CHANNELS_FROM_FD
@@ -37,6 +37,7 @@
37
37
 
38
38
  #include <grpc/support/alloc.h>
39
39
  #include <grpc/support/log.h>
40
+ #include <grpc/support/string_util.h>
40
41
  #include <grpc/support/sync.h>
41
42
  #include <grpc/support/useful.h>
42
43
  #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
@@ -45,14 +46,14 @@
45
46
  #include "src/core/lib/iomgr/endpoint.h"
46
47
  #include "src/core/lib/iomgr/resolve_address.h"
47
48
  #include "src/core/lib/iomgr/tcp_server.h"
48
- #include "src/core/lib/security/auth_filters.h"
49
- #include "src/core/lib/security/credentials.h"
50
- #include "src/core/lib/security/security_connector.h"
51
- #include "src/core/lib/security/security_context.h"
49
+ #include "src/core/lib/security/context/security_context.h"
50
+ #include "src/core/lib/security/credentials/credentials.h"
51
+ #include "src/core/lib/security/transport/auth_filters.h"
52
+ #include "src/core/lib/security/transport/security_connector.h"
52
53
  #include "src/core/lib/surface/api_trace.h"
53
54
  #include "src/core/lib/surface/server.h"
54
55
 
55
- typedef struct grpc_server_secure_state {
56
+ typedef struct server_secure_state {
56
57
  grpc_server *server;
57
58
  grpc_tcp_server *tcp;
58
59
  grpc_server_security_connector *sc;
@@ -62,13 +63,16 @@ typedef struct grpc_server_secure_state {
62
63
  gpr_refcount refcount;
63
64
  grpc_closure destroy_closure;
64
65
  grpc_closure *destroy_callback;
65
- } grpc_server_secure_state;
66
+ } server_secure_state;
66
67
 
67
- static void state_ref(grpc_server_secure_state *state) {
68
- gpr_ref(&state->refcount);
69
- }
68
+ typedef struct server_secure_connect {
69
+ server_secure_state *state;
70
+ grpc_pollset *accepting_pollset;
71
+ } server_secure_connect;
72
+
73
+ static void state_ref(server_secure_state *state) { gpr_ref(&state->refcount); }
70
74
 
71
- static void state_unref(grpc_server_secure_state *state) {
75
+ static void state_unref(server_secure_state *state) {
72
76
  if (gpr_unref(&state->refcount)) {
73
77
  /* ensure all threads have unlocked */
74
78
  gpr_mu_lock(&state->mu);
@@ -80,70 +84,72 @@ static void state_unref(grpc_server_secure_state *state) {
80
84
  }
81
85
  }
82
86
 
83
- static void setup_transport(grpc_exec_ctx *exec_ctx, void *statep,
84
- grpc_transport *transport,
85
- grpc_auth_context *auth_context) {
86
- grpc_server_secure_state *state = statep;
87
- grpc_channel_args *args_copy;
88
- grpc_arg args_to_add[2];
89
- args_to_add[0] = grpc_server_credentials_to_arg(state->creds);
90
- args_to_add[1] = grpc_auth_context_to_arg(auth_context);
91
- args_copy = grpc_channel_args_copy_and_add(
92
- grpc_server_get_channel_args(state->server), args_to_add,
93
- GPR_ARRAY_SIZE(args_to_add));
94
- grpc_server_setup_transport(exec_ctx, state->server, transport, args_copy);
95
- grpc_channel_args_destroy(args_copy);
96
- }
97
-
98
87
  static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *statep,
99
88
  grpc_security_status status,
100
89
  grpc_endpoint *secure_endpoint,
101
90
  grpc_auth_context *auth_context) {
102
- grpc_server_secure_state *state = statep;
91
+ server_secure_connect *state = statep;
103
92
  grpc_transport *transport;
104
93
  if (status == GRPC_SECURITY_OK) {
105
94
  if (secure_endpoint) {
106
- gpr_mu_lock(&state->mu);
107
- if (!state->is_shutdown) {
95
+ gpr_mu_lock(&state->state->mu);
96
+ if (!state->state->is_shutdown) {
108
97
  transport = grpc_create_chttp2_transport(
109
- exec_ctx, grpc_server_get_channel_args(state->server),
98
+ exec_ctx, grpc_server_get_channel_args(state->state->server),
110
99
  secure_endpoint, 0);
111
- setup_transport(exec_ctx, state, transport, auth_context);
100
+ grpc_channel_args *args_copy;
101
+ grpc_arg args_to_add[2];
102
+ args_to_add[0] = grpc_server_credentials_to_arg(state->state->creds);
103
+ args_to_add[1] = grpc_auth_context_to_arg(auth_context);
104
+ args_copy = grpc_channel_args_copy_and_add(
105
+ grpc_server_get_channel_args(state->state->server), args_to_add,
106
+ GPR_ARRAY_SIZE(args_to_add));
107
+ grpc_server_setup_transport(exec_ctx, state->state->server, transport,
108
+ state->accepting_pollset, args_copy);
109
+ grpc_channel_args_destroy(args_copy);
112
110
  grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL, 0);
113
111
  } else {
114
112
  /* We need to consume this here, because the server may already have
115
113
  * gone away. */
116
114
  grpc_endpoint_destroy(exec_ctx, secure_endpoint);
117
115
  }
118
- gpr_mu_unlock(&state->mu);
116
+ gpr_mu_unlock(&state->state->mu);
119
117
  }
120
118
  } else {
121
119
  gpr_log(GPR_ERROR, "Secure transport failed with error %d", status);
122
120
  }
123
- state_unref(state);
121
+ state_unref(state->state);
122
+ gpr_free(state);
124
123
  }
125
124
 
126
125
  static void on_accept(grpc_exec_ctx *exec_ctx, void *statep, grpc_endpoint *tcp,
126
+ grpc_pollset *accepting_pollset,
127
127
  grpc_tcp_server_acceptor *acceptor) {
128
- grpc_server_secure_state *state = statep;
129
- state_ref(state);
128
+ server_secure_connect *state = gpr_malloc(sizeof(*state));
129
+ state->state = statep;
130
+ state_ref(state->state);
131
+ state->accepting_pollset = accepting_pollset;
130
132
  grpc_server_security_connector_do_handshake(
131
- exec_ctx, state->sc, acceptor, tcp, on_secure_handshake_done, state);
133
+ exec_ctx, state->state->sc, acceptor, tcp,
134
+ gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
135
+ gpr_time_from_seconds(120, GPR_TIMESPAN)),
136
+ on_secure_handshake_done, state);
132
137
  }
133
138
 
134
139
  /* Server callback: start listening on our ports */
135
140
  static void start(grpc_exec_ctx *exec_ctx, grpc_server *server, void *statep,
136
141
  grpc_pollset **pollsets, size_t pollset_count) {
137
- grpc_server_secure_state *state = statep;
142
+ server_secure_state *state = statep;
138
143
  grpc_tcp_server_start(exec_ctx, state->tcp, pollsets, pollset_count,
139
144
  on_accept, state);
140
145
  }
141
146
 
142
- static void destroy_done(grpc_exec_ctx *exec_ctx, void *statep, bool success) {
143
- grpc_server_secure_state *state = statep;
147
+ static void destroy_done(grpc_exec_ctx *exec_ctx, void *statep,
148
+ grpc_error *error) {
149
+ server_secure_state *state = statep;
144
150
  if (state->destroy_callback != NULL) {
145
151
  state->destroy_callback->cb(exec_ctx, state->destroy_callback->cb_arg,
146
- success);
152
+ GRPC_ERROR_REF(error));
147
153
  }
148
154
  grpc_server_security_connector_shutdown(exec_ctx, state->sc);
149
155
  state_unref(state);
@@ -153,7 +159,7 @@ static void destroy_done(grpc_exec_ctx *exec_ctx, void *statep, bool success) {
153
159
  callbacks) */
154
160
  static void destroy(grpc_exec_ctx *exec_ctx, grpc_server *server, void *statep,
155
161
  grpc_closure *callback) {
156
- grpc_server_secure_state *state = statep;
162
+ server_secure_state *state = statep;
157
163
  grpc_tcp_server *tcp;
158
164
  gpr_mu_lock(&state->mu);
159
165
  state->is_shutdown = 1;
@@ -167,14 +173,16 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
167
173
  grpc_server_credentials *creds) {
168
174
  grpc_resolved_addresses *resolved = NULL;
169
175
  grpc_tcp_server *tcp = NULL;
170
- grpc_server_secure_state *state = NULL;
176
+ server_secure_state *state = NULL;
171
177
  size_t i;
172
- unsigned count = 0;
178
+ size_t count = 0;
173
179
  int port_num = -1;
174
180
  int port_temp;
175
181
  grpc_security_status status = GRPC_SECURITY_ERROR;
176
182
  grpc_server_security_connector *sc = NULL;
177
183
  grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
184
+ grpc_error *err = GRPC_ERROR_NONE;
185
+ grpc_error **errors = NULL;
178
186
 
179
187
  GRPC_API_TRACE(
180
188
  "grpc_server_add_secure_http2_port("
@@ -182,26 +190,34 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
182
190
  3, (server, addr, creds));
183
191
 
184
192
  /* create security context */
185
- if (creds == NULL) goto error;
193
+ if (creds == NULL) {
194
+ err = GRPC_ERROR_CREATE(
195
+ "No credentials specified for secure server port (creds==NULL)");
196
+ goto error;
197
+ }
186
198
  status = grpc_server_credentials_create_security_connector(creds, &sc);
187
199
  if (status != GRPC_SECURITY_OK) {
188
- gpr_log(GPR_ERROR,
189
- "Unable to create secure server with credentials of type %s.",
190
- creds->type);
200
+ char *msg;
201
+ gpr_asprintf(&msg,
202
+ "Unable to create secure server with credentials of type %s.",
203
+ creds->type);
204
+ err = grpc_error_set_int(GRPC_ERROR_CREATE(msg),
205
+ GRPC_ERROR_INT_SECURITY_STATUS, status);
206
+ gpr_free(msg);
191
207
  goto error;
192
208
  }
193
209
  sc->channel_args = grpc_server_get_channel_args(server);
194
210
 
195
211
  /* resolve address */
196
- resolved = grpc_blocking_resolve_address(addr, "https");
197
- if (!resolved) {
212
+ err = grpc_blocking_resolve_address(addr, "https", &resolved);
213
+ if (err != GRPC_ERROR_NONE) {
198
214
  goto error;
199
215
  }
200
216
  state = gpr_malloc(sizeof(*state));
201
217
  memset(state, 0, sizeof(*state));
202
218
  grpc_closure_init(&state->destroy_closure, destroy_done, state);
203
- tcp = grpc_tcp_server_create(&state->destroy_closure);
204
- if (!tcp) {
219
+ err = grpc_tcp_server_create(&state->destroy_closure, &tcp);
220
+ if (err != GRPC_ERROR_NONE) {
205
221
  goto error;
206
222
  }
207
223
 
@@ -213,11 +229,12 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
213
229
  gpr_mu_init(&state->mu);
214
230
  gpr_ref_init(&state->refcount, 1);
215
231
 
232
+ errors = gpr_malloc(sizeof(*errors) * resolved->naddrs);
216
233
  for (i = 0; i < resolved->naddrs; i++) {
217
- port_temp = grpc_tcp_server_add_port(
234
+ errors[i] = grpc_tcp_server_add_port(
218
235
  tcp, (struct sockaddr *)&resolved->addrs[i].addr,
219
- resolved->addrs[i].len);
220
- if (port_temp > 0) {
236
+ resolved->addrs[i].len, &port_temp);
237
+ if (errors[i] == GRPC_ERROR_NONE) {
221
238
  if (port_num == -1) {
222
239
  port_num = port_temp;
223
240
  } else {
@@ -227,15 +244,31 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
227
244
  }
228
245
  }
229
246
  if (count == 0) {
230
- gpr_log(GPR_ERROR, "No address added out of total %d resolved",
231
- resolved->naddrs);
247
+ char *msg;
248
+ gpr_asprintf(&msg, "No address added out of total %" PRIuPTR " resolved",
249
+ resolved->naddrs);
250
+ err = GRPC_ERROR_CREATE_REFERENCING(msg, errors, resolved->naddrs);
251
+ gpr_free(msg);
232
252
  goto error;
253
+ } else if (count != resolved->naddrs) {
254
+ char *msg;
255
+ gpr_asprintf(&msg, "Only %" PRIuPTR
256
+ " addresses added out of total %" PRIuPTR " resolved",
257
+ count, resolved->naddrs);
258
+ err = GRPC_ERROR_CREATE_REFERENCING(msg, errors, resolved->naddrs);
259
+ gpr_free(msg);
260
+
261
+ const char *warning_message = grpc_error_string(err);
262
+ gpr_log(GPR_INFO, "WARNING: %s", warning_message);
263
+ grpc_error_free_string(warning_message);
264
+ /* we managed to bind some addresses: continue */
265
+ } else {
266
+ for (i = 0; i < resolved->naddrs; i++) {
267
+ GRPC_ERROR_UNREF(errors[i]);
268
+ }
233
269
  }
234
- if (count != resolved->naddrs) {
235
- gpr_log(GPR_ERROR, "Only %d addresses added out of total %d resolved",
236
- count, resolved->naddrs);
237
- /* if it's an error, don't we want to goto error; here ? */
238
- }
270
+ gpr_free(errors);
271
+ errors = NULL;
239
272
  grpc_resolved_addresses_destroy(resolved);
240
273
 
241
274
  /* Register with the server only upon success */
@@ -246,6 +279,13 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
246
279
 
247
280
  /* Error path: cleanup and return */
248
281
  error:
282
+ GPR_ASSERT(err != GRPC_ERROR_NONE);
283
+ if (errors != NULL) {
284
+ for (i = 0; i < resolved->naddrs; i++) {
285
+ GRPC_ERROR_UNREF(errors[i]);
286
+ }
287
+ gpr_free(errors);
288
+ }
249
289
  if (resolved) {
250
290
  grpc_resolved_addresses_destroy(resolved);
251
291
  }
@@ -260,5 +300,9 @@ error:
260
300
  }
261
301
  }
262
302
  grpc_exec_ctx_finish(&exec_ctx);
303
+ const char *msg = grpc_error_string(err);
304
+ GRPC_ERROR_UNREF(err);
305
+ gpr_log(GPR_ERROR, "%s", msg);
306
+ grpc_error_free_string(msg);
263
307
  return 0;
264
308
  }