grpc 1.1.2 → 1.2.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (255) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1257 -404
  3. data/etc/roots.pem +189 -102
  4. data/include/grpc/census.h +7 -7
  5. data/include/grpc/compression.h +4 -4
  6. data/include/grpc/grpc.h +13 -7
  7. data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
  8. data/include/grpc/impl/codegen/grpc_types.h +39 -30
  9. data/include/grpc/impl/codegen/slice.h +24 -6
  10. data/include/grpc/impl/codegen/sync.h +8 -0
  11. data/include/grpc/load_reporting.h +63 -0
  12. data/include/grpc/slice.h +37 -1
  13. data/include/grpc/slice_buffer.h +7 -0
  14. data/include/grpc/support/alloc.h +3 -0
  15. data/include/grpc/support/useful.h +3 -0
  16. data/src/core/ext/census/gen/census.pb.h +1 -1
  17. data/src/core/ext/census/gen/trace_context.pb.c +9 -36
  18. data/src/core/ext/census/gen/trace_context.pb.h +20 -26
  19. data/src/core/ext/census/grpc_filter.c +3 -5
  20. data/src/core/ext/census/trace_context.c +1 -1
  21. data/src/core/ext/census/trace_context.h +3 -0
  22. data/src/core/ext/census/trace_label.h +61 -0
  23. data/src/core/ext/census/trace_propagation.h +63 -0
  24. data/src/core/ext/census/trace_status.h +45 -0
  25. data/src/core/ext/census/trace_string.h +50 -0
  26. data/src/core/ext/census/tracing.c +31 -11
  27. data/src/core/ext/census/tracing.h +124 -0
  28. data/src/core/ext/client_channel/client_channel.c +456 -368
  29. data/src/core/ext/client_channel/client_channel.h +4 -0
  30. data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
  31. data/src/core/ext/client_channel/connector.c +3 -3
  32. data/src/core/ext/client_channel/connector.h +4 -3
  33. data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
  34. data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
  35. data/src/core/ext/client_channel/http_proxy.c +125 -0
  36. data/src/core/ext/client_channel/http_proxy.h +39 -0
  37. data/src/core/ext/client_channel/lb_policy.c +56 -35
  38. data/src/core/ext/client_channel/lb_policy.h +46 -39
  39. data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
  40. data/src/core/ext/client_channel/parse_address.c +32 -6
  41. data/src/core/ext/client_channel/proxy_mapper.c +63 -0
  42. data/src/core/ext/client_channel/proxy_mapper.h +89 -0
  43. data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
  44. data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
  45. data/src/core/ext/client_channel/resolver.c +16 -9
  46. data/src/core/ext/client_channel/resolver.h +23 -12
  47. data/src/core/ext/client_channel/resolver_factory.h +1 -0
  48. data/src/core/ext/client_channel/resolver_registry.c +15 -11
  49. data/src/core/ext/client_channel/resolver_registry.h +5 -3
  50. data/src/core/ext/client_channel/subchannel.c +44 -27
  51. data/src/core/ext/client_channel/subchannel.h +6 -2
  52. data/src/core/ext/client_channel/uri_parser.c +26 -14
  53. data/src/core/ext/client_channel/uri_parser.h +3 -1
  54. data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
  55. data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
  56. data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
  57. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
  58. data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
  59. data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
  60. data/src/core/ext/load_reporting/load_reporting.c +20 -0
  61. data/src/core/ext/load_reporting/load_reporting.h +1 -16
  62. data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
  63. data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
  64. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
  65. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
  67. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
  68. data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
  69. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
  70. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
  71. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
  72. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
  73. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
  74. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
  75. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
  76. data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
  77. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
  78. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
  79. data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
  80. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
  81. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
  84. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
  86. data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
  87. data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
  88. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
  89. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
  90. data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
  91. data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
  92. data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
  93. data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
  94. data/src/core/lib/channel/channel_stack.c +14 -44
  95. data/src/core/lib/channel/channel_stack.h +10 -17
  96. data/src/core/lib/channel/channel_stack_builder.c +2 -3
  97. data/src/core/lib/channel/compress_filter.c +54 -46
  98. data/src/core/lib/channel/connected_channel.c +4 -4
  99. data/src/core/lib/channel/connected_channel.h +5 -0
  100. data/src/core/lib/channel/context.h +3 -0
  101. data/src/core/lib/channel/deadline_filter.c +61 -61
  102. data/src/core/lib/channel/deadline_filter.h +8 -5
  103. data/src/core/lib/channel/handshaker.c +47 -7
  104. data/src/core/lib/channel/handshaker.h +21 -3
  105. data/src/core/lib/channel/http_client_filter.c +149 -99
  106. data/src/core/lib/channel/http_server_filter.c +163 -147
  107. data/src/core/lib/channel/message_size_filter.c +15 -10
  108. data/src/core/lib/compression/algorithm_metadata.h +4 -4
  109. data/src/core/lib/compression/compression.c +17 -23
  110. data/src/core/lib/http/httpcli.c +3 -2
  111. data/src/core/lib/http/httpcli.h +2 -1
  112. data/src/core/lib/http/httpcli_security_connector.c +2 -3
  113. data/src/core/lib/http/parser.c +2 -2
  114. data/src/core/lib/iomgr/closure.c +6 -3
  115. data/src/core/lib/iomgr/closure.h +4 -2
  116. data/src/core/lib/iomgr/combiner.c +35 -5
  117. data/src/core/lib/iomgr/combiner.h +21 -2
  118. data/src/core/lib/iomgr/endpoint.c +3 -2
  119. data/src/core/lib/iomgr/endpoint.h +3 -2
  120. data/src/core/lib/iomgr/error.c +60 -94
  121. data/src/core/lib/iomgr/error.h +7 -10
  122. data/src/core/lib/iomgr/error_internal.h +54 -0
  123. data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
  124. data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
  125. data/src/core/lib/iomgr/ev_posix.c +7 -8
  126. data/src/core/lib/iomgr/ev_posix.h +4 -4
  127. data/src/core/lib/iomgr/exec_ctx.c +11 -6
  128. data/src/core/lib/iomgr/exec_ctx.h +11 -14
  129. data/src/core/lib/iomgr/executor.c +2 -2
  130. data/src/core/lib/iomgr/load_file.c +1 -1
  131. data/src/core/lib/iomgr/network_status_tracker.c +5 -81
  132. data/src/core/lib/iomgr/pollset.h +1 -3
  133. data/src/core/lib/iomgr/pollset_set.h +2 -1
  134. data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
  135. data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
  136. data/src/core/lib/iomgr/pollset_uv.c +25 -11
  137. data/src/core/lib/iomgr/pollset_windows.c +0 -11
  138. data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
  139. data/src/core/lib/iomgr/resource_quota.c +41 -11
  140. data/src/core/lib/iomgr/resource_quota.h +6 -0
  141. data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
  142. data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
  143. data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
  144. data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
  145. data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
  146. data/src/core/lib/iomgr/tcp_posix.c +4 -5
  147. data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
  148. data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
  149. data/src/core/lib/iomgr/tcp_uv.c +11 -5
  150. data/src/core/lib/iomgr/tcp_windows.c +20 -7
  151. data/src/core/lib/iomgr/timer_generic.c +15 -22
  152. data/src/core/lib/iomgr/timer_generic.h +1 -1
  153. data/src/core/lib/iomgr/timer_uv.c +10 -6
  154. data/src/core/lib/iomgr/timer_uv.h +1 -1
  155. data/src/core/lib/iomgr/udp_server.c +45 -6
  156. data/src/core/lib/iomgr/udp_server.h +7 -1
  157. data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
  158. data/src/core/lib/json/json.c +1 -2
  159. data/src/core/lib/profiling/basic_timers.c +17 -3
  160. data/src/core/lib/security/context/security_context.c +3 -10
  161. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
  162. data/src/core/lib/security/credentials/credentials.c +48 -2
  163. data/src/core/lib/security/credentials/credentials.h +13 -0
  164. data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
  165. data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
  166. data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
  167. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
  168. data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
  169. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
  170. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
  171. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  172. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
  173. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
  174. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
  175. data/src/core/lib/security/transport/client_auth_filter.c +72 -47
  176. data/src/core/lib/security/transport/lb_targets_info.c +70 -0
  177. data/src/core/lib/security/transport/lb_targets_info.h +47 -0
  178. data/src/core/lib/security/transport/secure_endpoint.c +3 -3
  179. data/src/core/lib/security/transport/security_connector.c +125 -28
  180. data/src/core/lib/security/transport/security_connector.h +4 -3
  181. data/src/core/lib/security/transport/security_handshaker.c +13 -9
  182. data/src/core/lib/security/transport/server_auth_filter.c +31 -40
  183. data/src/core/lib/security/util/b64.c +1 -1
  184. data/src/core/lib/slice/slice.c +110 -20
  185. data/src/core/lib/slice/slice_buffer.c +92 -39
  186. data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
  187. data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
  188. data/src/core/lib/slice/slice_intern.c +346 -0
  189. data/src/core/lib/slice/slice_internal.h +15 -0
  190. data/src/core/lib/slice/slice_string_helpers.c +5 -0
  191. data/src/core/lib/slice/slice_string_helpers.h +5 -0
  192. data/src/core/lib/support/alloc.c +26 -1
  193. data/src/core/lib/support/cmdline.c +2 -4
  194. data/src/core/lib/support/cpu_posix.c +2 -7
  195. data/src/core/lib/support/histogram.c +1 -2
  196. data/src/core/lib/support/log_posix.c +8 -4
  197. data/src/core/lib/support/spinlock.h +52 -0
  198. data/src/core/lib/support/subprocess_posix.c +1 -2
  199. data/src/core/lib/support/sync.c +7 -1
  200. data/src/core/lib/support/sync_posix.c +9 -0
  201. data/src/core/lib/support/time_windows.c +7 -1
  202. data/src/core/lib/surface/call.c +647 -629
  203. data/src/core/lib/surface/call.h +4 -1
  204. data/src/core/lib/surface/call_details.c +8 -2
  205. data/src/core/lib/surface/call_log_batch.c +17 -6
  206. data/src/core/lib/surface/channel.c +49 -59
  207. data/src/core/lib/surface/channel.h +5 -6
  208. data/src/core/lib/surface/completion_queue.c +16 -45
  209. data/src/core/lib/surface/completion_queue.h +0 -3
  210. data/src/core/lib/surface/init.c +6 -2
  211. data/src/core/lib/surface/init_secure.c +1 -1
  212. data/src/core/lib/surface/lame_client.c +14 -4
  213. data/src/core/lib/surface/server.c +79 -82
  214. data/src/core/lib/surface/validate_metadata.c +46 -15
  215. data/src/core/lib/surface/validate_metadata.h +43 -0
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.c +104 -0
  218. data/src/core/lib/transport/bdp_estimator.h +76 -0
  219. data/src/core/lib/transport/connectivity_state.c +33 -13
  220. data/src/core/lib/transport/connectivity_state.h +15 -5
  221. data/src/core/lib/transport/error_utils.c +124 -0
  222. data/src/core/lib/transport/error_utils.h +56 -0
  223. data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
  224. data/src/core/lib/transport/metadata.c +259 -503
  225. data/src/core/lib/transport/metadata.h +69 -68
  226. data/src/core/lib/transport/metadata_batch.c +183 -63
  227. data/src/core/lib/transport/metadata_batch.h +50 -26
  228. data/src/core/lib/transport/pid_controller.c +28 -8
  229. data/src/core/lib/transport/pid_controller.h +15 -2
  230. data/src/core/lib/transport/service_config.c +21 -18
  231. data/src/core/lib/transport/service_config.h +5 -5
  232. data/src/core/lib/transport/static_metadata.c +753 -112
  233. data/src/core/lib/transport/static_metadata.h +403 -264
  234. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
  235. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
  236. data/src/core/lib/transport/timeout_encoding.c +11 -9
  237. data/src/core/lib/transport/timeout_encoding.h +3 -1
  238. data/src/core/lib/transport/transport.c +47 -87
  239. data/src/core/lib/transport/transport.h +20 -25
  240. data/src/core/lib/transport/transport_op_string.c +7 -19
  241. data/src/core/lib/tsi/fake_transport_security.c +2 -4
  242. data/src/core/lib/tsi/ssl_transport_security.c +7 -16
  243. data/src/core/lib/tsi/transport_security.c +2 -4
  244. data/src/ruby/ext/grpc/extconf.rb +4 -1
  245. data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
  246. data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
  247. data/src/ruby/ext/grpc/rb_call.c +47 -46
  248. data/src/ruby/ext/grpc/rb_channel.c +21 -6
  249. data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
  250. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
  251. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
  252. data/src/ruby/ext/grpc/rb_server.c +6 -4
  253. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  254. data/src/ruby/lib/grpc/version.rb +1 -1
  255. metadata +33 -9
@@ -0,0 +1,43 @@
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
+ #ifndef GRPC_CORE_LIB_SURFACE_VALIDATE_METADATA_H
35
+ #define GRPC_CORE_LIB_SURFACE_VALIDATE_METADATA_H
36
+
37
+ #include <grpc/slice.h>
38
+ #include "src/core/lib/iomgr/error.h"
39
+
40
+ grpc_error *grpc_validate_header_key_is_legal(grpc_slice slice);
41
+ grpc_error *grpc_validate_header_nonbin_value_is_legal(grpc_slice slice);
42
+
43
+ #endif /* GRPC_CORE_LIB_SURFACE_VALIDATE_METADATA_H */
@@ -36,6 +36,6 @@
36
36
 
37
37
  #include <grpc/grpc.h>
38
38
 
39
- const char *grpc_version_string(void) { return "2.0.0"; }
39
+ const char *grpc_version_string(void) { return "3.0.0-dev"; }
40
40
 
41
- const char *grpc_g_stands_for(void) { return "good"; }
41
+ const char *grpc_g_stands_for(void) { return "green"; }
@@ -0,0 +1,104 @@
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 "src/core/lib/transport/bdp_estimator.h"
35
+
36
+ #include <stdlib.h>
37
+
38
+ #include <grpc/support/log.h>
39
+ #include <grpc/support/useful.h>
40
+
41
+ int grpc_bdp_estimator_trace = 0;
42
+
43
+ void grpc_bdp_estimator_init(grpc_bdp_estimator *estimator, const char *name) {
44
+ estimator->estimate = 65536;
45
+ estimator->ping_state = GRPC_BDP_PING_UNSCHEDULED;
46
+ estimator->name = name;
47
+ }
48
+
49
+ bool grpc_bdp_estimator_get_estimate(grpc_bdp_estimator *estimator,
50
+ int64_t *estimate) {
51
+ *estimate = estimator->estimate;
52
+ return true;
53
+ }
54
+
55
+ bool grpc_bdp_estimator_add_incoming_bytes(grpc_bdp_estimator *estimator,
56
+ int64_t num_bytes) {
57
+ estimator->accumulator += num_bytes;
58
+ switch (estimator->ping_state) {
59
+ case GRPC_BDP_PING_UNSCHEDULED:
60
+ return true;
61
+ case GRPC_BDP_PING_SCHEDULED:
62
+ return false;
63
+ case GRPC_BDP_PING_STARTED:
64
+ return false;
65
+ }
66
+ GPR_UNREACHABLE_CODE(return false);
67
+ }
68
+
69
+ void grpc_bdp_estimator_schedule_ping(grpc_bdp_estimator *estimator) {
70
+ if (grpc_bdp_estimator_trace) {
71
+ gpr_log(GPR_DEBUG, "bdp[%s]:sched acc=%" PRId64 " est=%" PRId64,
72
+ estimator->name, estimator->accumulator, estimator->estimate);
73
+ }
74
+ GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_UNSCHEDULED);
75
+ estimator->ping_state = GRPC_BDP_PING_SCHEDULED;
76
+ estimator->accumulator = 0;
77
+ }
78
+
79
+ void grpc_bdp_estimator_start_ping(grpc_bdp_estimator *estimator) {
80
+ if (grpc_bdp_estimator_trace) {
81
+ gpr_log(GPR_DEBUG, "bdp[%s]:start acc=%" PRId64 " est=%" PRId64,
82
+ estimator->name, estimator->accumulator, estimator->estimate);
83
+ }
84
+ GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_SCHEDULED);
85
+ estimator->ping_state = GRPC_BDP_PING_STARTED;
86
+ estimator->accumulator = 0;
87
+ }
88
+
89
+ void grpc_bdp_estimator_complete_ping(grpc_bdp_estimator *estimator) {
90
+ if (grpc_bdp_estimator_trace) {
91
+ gpr_log(GPR_DEBUG, "bdp[%s]:complete acc=%" PRId64 " est=%" PRId64,
92
+ estimator->name, estimator->accumulator, estimator->estimate);
93
+ }
94
+ GPR_ASSERT(estimator->ping_state == GRPC_BDP_PING_STARTED);
95
+ if (estimator->accumulator > 2 * estimator->estimate / 3) {
96
+ estimator->estimate *= 2;
97
+ if (grpc_bdp_estimator_trace) {
98
+ gpr_log(GPR_DEBUG, "bdp[%s]: estimate increased to %" PRId64,
99
+ estimator->name, estimator->estimate);
100
+ }
101
+ }
102
+ estimator->ping_state = GRPC_BDP_PING_UNSCHEDULED;
103
+ estimator->accumulator = 0;
104
+ }
@@ -0,0 +1,76 @@
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
+ #ifndef GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H
35
+ #define GRPC_CORE_LIB_TRANSPORT_BDP_ESTIMATOR_H
36
+
37
+ #include <stdbool.h>
38
+ #include <stdint.h>
39
+
40
+ #define GRPC_BDP_SAMPLES 16
41
+ #define GRPC_BDP_MIN_SAMPLES_FOR_ESTIMATE 3
42
+
43
+ extern int grpc_bdp_estimator_trace;
44
+
45
+ typedef enum {
46
+ GRPC_BDP_PING_UNSCHEDULED,
47
+ GRPC_BDP_PING_SCHEDULED,
48
+ GRPC_BDP_PING_STARTED
49
+ } grpc_bdp_estimator_ping_state;
50
+
51
+ typedef struct grpc_bdp_estimator {
52
+ grpc_bdp_estimator_ping_state ping_state;
53
+ int64_t accumulator;
54
+ int64_t estimate;
55
+ const char *name;
56
+ } grpc_bdp_estimator;
57
+
58
+ void grpc_bdp_estimator_init(grpc_bdp_estimator *estimator, const char *name);
59
+
60
+ // Returns true if a reasonable estimate could be obtained
61
+ bool grpc_bdp_estimator_get_estimate(grpc_bdp_estimator *estimator,
62
+ int64_t *estimate);
63
+ // Returns true if the user should schedule a ping
64
+ bool grpc_bdp_estimator_add_incoming_bytes(grpc_bdp_estimator *estimator,
65
+ int64_t num_bytes);
66
+ // Schedule a ping: call in response to receiving a true from
67
+ // grpc_bdp_estimator_add_incoming_bytes once a ping has been scheduled by a
68
+ // transport (but not necessarily started)
69
+ void grpc_bdp_estimator_schedule_ping(grpc_bdp_estimator *estimator);
70
+ // Start a ping: call after calling grpc_bdp_estimator_schedule_ping and once
71
+ // the ping is on the wire
72
+ void grpc_bdp_estimator_start_ping(grpc_bdp_estimator *estimator);
73
+ // Completes a previously started ping
74
+ void grpc_bdp_estimator_complete_ping(grpc_bdp_estimator *estimator);
75
+
76
+ #endif
@@ -62,7 +62,7 @@ const char *grpc_connectivity_state_name(grpc_connectivity_state state) {
62
62
  void grpc_connectivity_state_init(grpc_connectivity_state_tracker *tracker,
63
63
  grpc_connectivity_state init_state,
64
64
  const char *name) {
65
- tracker->current_state = init_state;
65
+ gpr_atm_no_barrier_store(&tracker->current_state_atm, init_state);
66
66
  tracker->current_error = GRPC_ERROR_NONE;
67
67
  tracker->watchers = NULL;
68
68
  tracker->name = gpr_strdup(name);
@@ -89,15 +89,30 @@ void grpc_connectivity_state_destroy(grpc_exec_ctx *exec_ctx,
89
89
  }
90
90
 
91
91
  grpc_connectivity_state grpc_connectivity_state_check(
92
+ grpc_connectivity_state_tracker *tracker) {
93
+ grpc_connectivity_state cur =
94
+ (grpc_connectivity_state)gpr_atm_no_barrier_load(
95
+ &tracker->current_state_atm);
96
+ if (grpc_connectivity_state_trace) {
97
+ gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name,
98
+ grpc_connectivity_state_name(cur));
99
+ }
100
+ return cur;
101
+ }
102
+
103
+ grpc_connectivity_state grpc_connectivity_state_get(
92
104
  grpc_connectivity_state_tracker *tracker, grpc_error **error) {
105
+ grpc_connectivity_state cur =
106
+ (grpc_connectivity_state)gpr_atm_no_barrier_load(
107
+ &tracker->current_state_atm);
93
108
  if (grpc_connectivity_state_trace) {
94
109
  gpr_log(GPR_DEBUG, "CONWATCH: %p %s: get %s", tracker, tracker->name,
95
- grpc_connectivity_state_name(tracker->current_state));
110
+ grpc_connectivity_state_name(cur));
96
111
  }
97
112
  if (error != NULL) {
98
113
  *error = GRPC_ERROR_REF(tracker->current_error);
99
114
  }
100
- return tracker->current_state;
115
+ return cur;
101
116
  }
102
117
 
103
118
  bool grpc_connectivity_state_has_watchers(
@@ -108,6 +123,9 @@ bool grpc_connectivity_state_has_watchers(
108
123
  bool grpc_connectivity_state_notify_on_state_change(
109
124
  grpc_exec_ctx *exec_ctx, grpc_connectivity_state_tracker *tracker,
110
125
  grpc_connectivity_state *current, grpc_closure *notify) {
126
+ grpc_connectivity_state cur =
127
+ (grpc_connectivity_state)gpr_atm_no_barrier_load(
128
+ &tracker->current_state_atm);
111
129
  if (grpc_connectivity_state_trace) {
112
130
  if (current == NULL) {
113
131
  gpr_log(GPR_DEBUG, "CONWATCH: %p %s: unsubscribe notify=%p", tracker,
@@ -115,7 +133,7 @@ bool grpc_connectivity_state_notify_on_state_change(
115
133
  } else {
116
134
  gpr_log(GPR_DEBUG, "CONWATCH: %p %s: from %s [cur=%s] notify=%p", tracker,
117
135
  tracker->name, grpc_connectivity_state_name(*current),
118
- grpc_connectivity_state_name(tracker->current_state), notify);
136
+ grpc_connectivity_state_name(cur), notify);
119
137
  }
120
138
  }
121
139
  if (current == NULL) {
@@ -138,8 +156,8 @@ bool grpc_connectivity_state_notify_on_state_change(
138
156
  }
139
157
  return false;
140
158
  } else {
141
- if (tracker->current_state != *current) {
142
- *current = tracker->current_state;
159
+ if (cur != *current) {
160
+ *current = cur;
143
161
  grpc_closure_sched(exec_ctx, notify,
144
162
  GRPC_ERROR_REF(tracker->current_error));
145
163
  } else {
@@ -149,7 +167,7 @@ bool grpc_connectivity_state_notify_on_state_change(
149
167
  w->next = tracker->watchers;
150
168
  tracker->watchers = w;
151
169
  }
152
- return tracker->current_state == GRPC_CHANNEL_IDLE;
170
+ return cur == GRPC_CHANNEL_IDLE;
153
171
  }
154
172
  }
155
173
 
@@ -157,13 +175,15 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx,
157
175
  grpc_connectivity_state_tracker *tracker,
158
176
  grpc_connectivity_state state,
159
177
  grpc_error *error, const char *reason) {
178
+ grpc_connectivity_state cur =
179
+ (grpc_connectivity_state)gpr_atm_no_barrier_load(
180
+ &tracker->current_state_atm);
160
181
  grpc_connectivity_state_watcher *w;
161
182
  if (grpc_connectivity_state_trace) {
162
183
  const char *error_string = grpc_error_string(error);
163
184
  gpr_log(GPR_DEBUG, "SET: %p %s: %s --> %s [%s] error=%p %s", tracker,
164
- tracker->name, grpc_connectivity_state_name(tracker->current_state),
185
+ tracker->name, grpc_connectivity_state_name(cur),
165
186
  grpc_connectivity_state_name(state), reason, error, error_string);
166
- grpc_error_free_string(error_string);
167
187
  }
168
188
  switch (state) {
169
189
  case GRPC_CHANNEL_INIT:
@@ -179,13 +199,13 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx,
179
199
  }
180
200
  GRPC_ERROR_UNREF(tracker->current_error);
181
201
  tracker->current_error = error;
182
- if (tracker->current_state == state) {
202
+ if (cur == state) {
183
203
  return;
184
204
  }
185
- GPR_ASSERT(tracker->current_state != GRPC_CHANNEL_SHUTDOWN);
186
- tracker->current_state = state;
205
+ GPR_ASSERT(cur != GRPC_CHANNEL_SHUTDOWN);
206
+ gpr_atm_no_barrier_store(&tracker->current_state_atm, state);
187
207
  while ((w = tracker->watchers) != NULL) {
188
- *w->current = tracker->current_state;
208
+ *w->current = state;
189
209
  tracker->watchers = w->next;
190
210
  if (grpc_connectivity_state_trace) {
191
211
  gpr_log(GPR_DEBUG, "NOTIFY: %p %s: %p", tracker, tracker->name,
@@ -47,8 +47,8 @@ typedef struct grpc_connectivity_state_watcher {
47
47
  } grpc_connectivity_state_watcher;
48
48
 
49
49
  typedef struct {
50
- /** current connectivity state */
51
- grpc_connectivity_state current_state;
50
+ /** current grpc_connectivity_state */
51
+ gpr_atm current_state_atm;
52
52
  /** error associated with state */
53
53
  grpc_error *current_error;
54
54
  /** all our watchers */
@@ -59,6 +59,7 @@ typedef struct {
59
59
 
60
60
  extern int grpc_connectivity_state_trace;
61
61
 
62
+ /** enum --> string conversion */
62
63
  const char *grpc_connectivity_state_name(grpc_connectivity_state state);
63
64
 
64
65
  void grpc_connectivity_state_init(grpc_connectivity_state_tracker *tracker,
@@ -68,22 +69,31 @@ void grpc_connectivity_state_destroy(grpc_exec_ctx *exec_ctx,
68
69
  grpc_connectivity_state_tracker *tracker);
69
70
 
70
71
  /** Set connectivity state; not thread safe; access must be serialized with an
71
- * external lock */
72
+ * external lock */
72
73
  void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx,
73
74
  grpc_connectivity_state_tracker *tracker,
74
75
  grpc_connectivity_state state,
75
76
  grpc_error *associated_error,
76
77
  const char *reason);
77
78
 
79
+ /** Return true if this connectivity state has watchers.
80
+ Access must be serialized with an external lock. */
78
81
  bool grpc_connectivity_state_has_watchers(
79
82
  grpc_connectivity_state_tracker *tracker);
80
83
 
84
+ /** Return the last seen connectivity state. No need to synchronize access. */
81
85
  grpc_connectivity_state grpc_connectivity_state_check(
82
- grpc_connectivity_state_tracker *tracker, grpc_error **current_error);
86
+ grpc_connectivity_state_tracker *tracker);
87
+
88
+ /** Return the last seen connectivity state, and the associated error.
89
+ Access must be serialized with an external lock. */
90
+ grpc_connectivity_state grpc_connectivity_state_get(
91
+ grpc_connectivity_state_tracker *tracker, grpc_error **error);
83
92
 
84
93
  /** Return 1 if the channel should start connecting, 0 otherwise.
85
94
  If current==NULL cancel notify if it is already queued (success==0 in that
86
- case) */
95
+ case).
96
+ Access must be serialized with an external lock. */
87
97
  bool grpc_connectivity_state_notify_on_state_change(
88
98
  grpc_exec_ctx *exec_ctx, grpc_connectivity_state_tracker *tracker,
89
99
  grpc_connectivity_state *current, grpc_closure *notify);
@@ -0,0 +1,124 @@
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 "src/core/lib/transport/error_utils.h"
35
+
36
+ #include "src/core/lib/iomgr/error_internal.h"
37
+ #include "src/core/lib/transport/status_conversion.h"
38
+
39
+ static grpc_error *recursively_find_error_with_field(grpc_error *error,
40
+ grpc_error_ints which) {
41
+ // If the error itself has a status code, return it.
42
+ if (grpc_error_get_int(error, which, NULL)) {
43
+ return error;
44
+ }
45
+ if (grpc_error_is_special(error)) return NULL;
46
+ // Otherwise, search through its children.
47
+ intptr_t key = 0;
48
+ while (true) {
49
+ grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++);
50
+ if (child_error == NULL) break;
51
+ grpc_error *result = recursively_find_error_with_field(child_error, which);
52
+ if (result != NULL) return result;
53
+ }
54
+ return NULL;
55
+ }
56
+
57
+ void grpc_error_get_status(grpc_error *error, gpr_timespec deadline,
58
+ grpc_status_code *code, const char **msg,
59
+ grpc_http2_error_code *http_error) {
60
+ // Start with the parent error and recurse through the tree of children
61
+ // until we find the first one that has a status code.
62
+ grpc_error *found_error =
63
+ recursively_find_error_with_field(error, GRPC_ERROR_INT_GRPC_STATUS);
64
+ if (found_error == NULL) {
65
+ /// If no grpc-status exists, retry through the tree to find a http2 error
66
+ /// code
67
+ found_error =
68
+ recursively_find_error_with_field(error, GRPC_ERROR_INT_HTTP2_ERROR);
69
+ }
70
+
71
+ // If we found an error with a status code above, use that; otherwise,
72
+ // fall back to using the parent error.
73
+ if (found_error == NULL) found_error = error;
74
+
75
+ grpc_status_code status = GRPC_STATUS_UNKNOWN;
76
+ intptr_t integer;
77
+ if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, &integer)) {
78
+ status = (grpc_status_code)integer;
79
+ } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR,
80
+ &integer)) {
81
+ status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer,
82
+ deadline);
83
+ }
84
+ if (code != NULL) *code = status;
85
+
86
+ if (http_error != NULL) {
87
+ if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) {
88
+ *http_error = (grpc_http2_error_code)integer;
89
+ } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS,
90
+ &integer)) {
91
+ *http_error = grpc_status_to_http2_error((grpc_status_code)integer);
92
+ } else {
93
+ *http_error = found_error == GRPC_ERROR_NONE ? GRPC_HTTP2_NO_ERROR
94
+ : GRPC_HTTP2_INTERNAL_ERROR;
95
+ }
96
+ }
97
+
98
+ // If the error has a status message, use it. Otherwise, fall back to
99
+ // the error description.
100
+ if (msg != NULL) {
101
+ *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE);
102
+ if (*msg == NULL && error != GRPC_ERROR_NONE) {
103
+ *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION);
104
+ if (*msg == NULL) *msg = "unknown error"; // Just in case.
105
+ }
106
+ }
107
+
108
+ if (found_error == NULL) found_error = error;
109
+ }
110
+
111
+ bool grpc_error_has_clear_grpc_status(grpc_error *error) {
112
+ if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, NULL)) {
113
+ return true;
114
+ }
115
+ intptr_t key = 0;
116
+ while (true) {
117
+ grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++);
118
+ if (child_error == NULL) break;
119
+ if (grpc_error_has_clear_grpc_status(child_error)) {
120
+ return true;
121
+ }
122
+ }
123
+ return false;
124
+ }