wearefair-grpc 1.3.1.pre.c → 1.4.0.fair

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +418 -126
  3. data/include/grpc/grpc.h +15 -69
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/compression_types.h +3 -4
  6. data/include/grpc/impl/codegen/gpr_types.h +0 -1
  7. data/include/grpc/impl/codegen/grpc_types.h +69 -3
  8. data/include/grpc/impl/codegen/port_platform.h +6 -0
  9. data/include/grpc/impl/codegen/slice.h +2 -1
  10. data/include/grpc/load_reporting.h +6 -6
  11. data/include/grpc/slice.h +25 -3
  12. data/include/grpc/slice_buffer.h +4 -0
  13. data/src/core/ext/census/context.c +1 -1
  14. data/src/core/ext/census/resource.c +3 -1
  15. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  16. data/src/core/ext/filters/client_channel/client_channel.c +158 -100
  17. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  18. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  19. data/src/core/ext/filters/client_channel/lb_policy.h +5 -6
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +344 -88
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +47 -5
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +6 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  29. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  30. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +13 -12
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  32. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  33. data/src/core/ext/filters/client_channel/parse_address.c +37 -7
  34. data/src/core/ext/filters/client_channel/parse_address.h +11 -8
  35. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  36. data/src/core/ext/filters/client_channel/subchannel.c +19 -16
  37. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  38. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  39. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  40. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  41. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  42. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  43. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  44. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  45. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  46. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  47. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  48. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  49. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  50. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  51. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  52. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  53. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  54. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  55. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  56. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  57. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  58. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +296 -172
  59. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  60. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  61. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  62. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  63. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  66. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  67. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  68. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  69. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  70. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  71. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  72. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  73. data/src/core/lib/channel/channel_args.c +28 -9
  74. data/src/core/lib/channel/channel_args.h +5 -1
  75. data/src/core/lib/channel/channel_stack.c +1 -1
  76. data/src/core/lib/channel/channel_stack.h +2 -2
  77. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  78. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  79. data/src/core/lib/channel/connected_channel.c +3 -1
  80. data/src/core/lib/channel/context.h +2 -2
  81. data/src/core/lib/compression/message_compress.c +2 -2
  82. data/src/core/lib/debug/trace.c +13 -6
  83. data/src/core/lib/debug/trace.h +27 -1
  84. data/src/core/lib/http/httpcli.c +1 -1
  85. data/src/core/lib/http/httpcli_security_connector.c +6 -10
  86. data/src/core/lib/http/parser.c +2 -2
  87. data/src/core/lib/http/parser.h +2 -1
  88. data/src/core/lib/iomgr/combiner.c +6 -6
  89. data/src/core/lib/iomgr/combiner.h +2 -1
  90. data/src/core/lib/iomgr/error.c +12 -5
  91. data/src/core/lib/iomgr/error.h +13 -13
  92. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  93. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  94. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  95. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  96. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  97. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  98. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  99. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  100. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +24 -31
  101. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  102. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  103. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  104. data/src/core/lib/iomgr/ev_posix.c +22 -8
  105. data/src/core/lib/iomgr/ev_posix.h +4 -3
  106. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  107. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  108. data/src/core/lib/iomgr/iomgr.c +4 -0
  109. data/src/core/lib/iomgr/iomgr.h +3 -0
  110. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  111. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  112. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  113. data/src/core/lib/iomgr/pollset.h +2 -5
  114. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  115. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  116. data/src/core/lib/iomgr/resource_quota.c +9 -8
  117. data/src/core/lib/iomgr/resource_quota.h +2 -1
  118. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  119. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  120. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  121. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  122. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  123. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  124. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  125. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  126. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  127. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  128. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  129. data/src/core/lib/iomgr/timer_generic.c +24 -25
  130. data/src/core/lib/iomgr/timer_manager.c +276 -0
  131. data/src/core/lib/iomgr/timer_manager.h +52 -0
  132. data/src/core/lib/iomgr/timer_uv.c +6 -0
  133. data/src/core/lib/iomgr/udp_server.c +42 -9
  134. data/src/core/lib/iomgr/udp_server.h +3 -1
  135. data/src/core/lib/security/credentials/credentials.c +0 -1
  136. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  137. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  138. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  139. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  140. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  141. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  142. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  143. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  144. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  145. data/src/core/lib/security/transport/security_connector.c +32 -51
  146. data/src/core/lib/security/transport/security_connector.h +10 -14
  147. data/src/core/lib/slice/b64.c +1 -1
  148. data/src/core/lib/slice/percent_encoding.c +3 -3
  149. data/src/core/lib/slice/slice.c +66 -33
  150. data/src/core/lib/slice/slice_buffer.c +25 -6
  151. data/src/core/lib/slice/slice_hash_table.c +33 -35
  152. data/src/core/lib/slice/slice_hash_table.h +7 -12
  153. data/src/core/lib/support/atomic.h +45 -0
  154. data/src/core/lib/support/atomic_with_atm.h +70 -0
  155. data/src/core/lib/support/atomic_with_std.h +48 -0
  156. data/src/core/lib/support/avl.c +14 -14
  157. data/src/core/lib/support/memory.h +74 -0
  158. data/src/core/lib/support/mpscq.c +12 -1
  159. data/src/core/lib/support/mpscq.h +4 -0
  160. data/src/core/lib/support/stack_lockfree.c +3 -36
  161. data/src/core/lib/support/time_posix.c +8 -0
  162. data/src/core/lib/support/tmpfile_posix.c +10 -10
  163. data/src/core/lib/surface/alarm.c +3 -1
  164. data/src/core/lib/surface/api_trace.c +2 -1
  165. data/src/core/lib/surface/api_trace.h +2 -2
  166. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  167. data/src/core/lib/surface/call.c +65 -22
  168. data/src/core/lib/surface/call.h +4 -2
  169. data/src/core/lib/surface/channel_init.c +2 -19
  170. data/src/core/lib/surface/channel_stack_type.c +18 -0
  171. data/src/core/lib/surface/channel_stack_type.h +2 -0
  172. data/src/core/lib/surface/completion_queue.c +249 -83
  173. data/src/core/lib/surface/completion_queue.h +18 -13
  174. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  175. data/src/core/lib/surface/init.c +1 -52
  176. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  177. data/src/core/lib/surface/server.c +50 -27
  178. data/src/core/lib/surface/server.h +2 -1
  179. data/src/core/lib/surface/version.c +2 -2
  180. data/src/core/lib/transport/bdp_estimator.c +20 -9
  181. data/src/core/lib/transport/bdp_estimator.h +5 -1
  182. data/src/core/lib/transport/byte_stream.c +23 -9
  183. data/src/core/lib/transport/byte_stream.h +15 -6
  184. data/src/core/lib/transport/connectivity_state.c +6 -6
  185. data/src/core/lib/transport/connectivity_state.h +2 -1
  186. data/src/core/lib/transport/service_config.c +6 -13
  187. data/src/core/lib/transport/service_config.h +2 -2
  188. data/src/core/lib/transport/static_metadata.c +403 -389
  189. data/src/core/lib/transport/static_metadata.h +127 -114
  190. data/src/core/plugin_registry/grpc_plugin_registry.c +12 -0
  191. data/src/core/tsi/fake_transport_security.c +5 -4
  192. data/src/core/tsi/ssl_transport_security.c +71 -82
  193. data/src/core/tsi/ssl_transport_security.h +39 -61
  194. data/src/core/tsi/transport_security.c +83 -2
  195. data/src/core/tsi/transport_security.h +27 -2
  196. data/src/core/tsi/transport_security_adapter.c +236 -0
  197. data/src/core/tsi/transport_security_adapter.h +62 -0
  198. data/src/core/tsi/transport_security_interface.h +179 -66
  199. data/src/ruby/ext/grpc/extconf.rb +2 -1
  200. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  201. data/src/ruby/ext/grpc/rb_call.c +56 -48
  202. data/src/ruby/ext/grpc/rb_call.h +3 -4
  203. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  204. data/src/ruby/ext/grpc/rb_channel.c +45 -29
  205. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  206. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  207. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  208. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  209. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  210. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  211. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  212. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  213. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +14 -6
  214. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +22 -10
  215. data/src/ruby/ext/grpc/rb_server.c +26 -28
  216. data/src/ruby/lib/grpc/version.rb +1 -1
  217. metadata +40 -18
  218. data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
  219. data/src/ruby/lib/grpc/grpc_c.so +0 -0
@@ -119,6 +119,7 @@ typedef struct {
119
119
  gpr_timespec start_time;
120
120
  gpr_timespec deadline;
121
121
  gpr_arena *arena;
122
+ grpc_call_context_element *context;
122
123
  } grpc_connected_subchannel_call_args;
123
124
 
124
125
  grpc_error *grpc_connected_subchannel_create_call(
@@ -50,7 +50,7 @@
50
50
  #define NOT_SET (~(size_t)0)
51
51
 
52
52
  static grpc_uri *bad_uri(const char *uri_text, size_t pos, const char *section,
53
- int suppress_errors) {
53
+ bool suppress_errors) {
54
54
  char *line_prefix;
55
55
  size_t pfx_len;
56
56
 
@@ -83,6 +83,11 @@ static char *decode_and_copy_component(grpc_exec_ctx *exec_ctx, const char *src,
83
83
  return out;
84
84
  }
85
85
 
86
+ static bool valid_hex(char c) {
87
+ return ((c >= 'a') && (c <= 'f')) || ((c >= 'A') && (c <= 'F')) ||
88
+ ((c >= '0') && (c <= '9'));
89
+ }
90
+
86
91
  /** Returns how many chars to advance if \a uri_text[i] begins a valid \a pchar
87
92
  * production. If \a uri_text[i] introduces an invalid \a pchar (such as percent
88
93
  * sign not followed by two hex digits), NOT_SET is returned. */
@@ -93,27 +98,36 @@ static size_t parse_pchar(const char *uri_text, size_t i) {
93
98
  * sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
94
99
  / "*" / "+" / "," / ";" / "=" */
95
100
  char c = uri_text[i];
96
- if (((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z')) ||
97
- ((c >= '0') && (c <= '9')) ||
98
- (c == '-' || c == '.' || c == '_' || c == '~') || /* unreserved */
99
- (c == '!' || c == '$' || c == '&' || c == '\'' || c == '$' || c == '&' ||
100
- c == '(' || c == ')' || c == '*' || c == '+' || c == ',' || c == ';' ||
101
- c == '=') /* sub-delims */) {
102
- return 1;
103
- }
104
- if (c == '%') { /* pct-encoded */
105
- size_t j;
106
- if (uri_text[i + 1] == 0 || uri_text[i + 2] == 0) {
107
- return NOT_SET;
108
- }
109
- for (j = i + 1; j < 2; j++) {
110
- c = uri_text[j];
111
- if (!(((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ||
112
- ((c >= 'A') && (c <= 'F')))) {
113
- return NOT_SET;
101
+ switch (c) {
102
+ default:
103
+ if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) ||
104
+ ((c >= '0') && (c <= '9'))) {
105
+ return 1;
114
106
  }
115
- }
116
- return 2;
107
+ break;
108
+ case ':':
109
+ case '@':
110
+ case '-':
111
+ case '.':
112
+ case '_':
113
+ case '~':
114
+ case '!':
115
+ case '$':
116
+ case '&':
117
+ case '\'':
118
+ case '(':
119
+ case ')':
120
+ case '*':
121
+ case '+':
122
+ case ',':
123
+ case ';':
124
+ case '=':
125
+ return 1;
126
+ case '%': /* pct-encoded */
127
+ if (valid_hex(uri_text[i + 1]) && valid_hex(uri_text[i + 2])) {
128
+ return 2;
129
+ }
130
+ return NOT_SET;
117
131
  }
118
132
  return 0;
119
133
  }
@@ -183,7 +197,7 @@ static void parse_query_parts(grpc_uri *uri) {
183
197
  }
184
198
 
185
199
  grpc_uri *grpc_uri_parse(grpc_exec_ctx *exec_ctx, const char *uri_text,
186
- int suppress_errors) {
200
+ bool suppress_errors) {
187
201
  grpc_uri *uri;
188
202
  size_t scheme_begin = 0;
189
203
  size_t scheme_end = NOT_SET;
@@ -53,7 +53,7 @@ typedef struct {
53
53
 
54
54
  /** parse a uri, return NULL on failure */
55
55
  grpc_uri *grpc_uri_parse(grpc_exec_ctx *exec_ctx, const char *uri_text,
56
- int suppress_errors);
56
+ bool suppress_errors);
57
57
 
58
58
  /** return the part of a query string after the '=' in "?key=xxx&...", or NULL
59
59
  * if key is not present */
@@ -29,7 +29,7 @@
29
29
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
30
  //
31
31
 
32
- #include "src/core/lib/channel/deadline_filter.h"
32
+ #include "src/core/ext/filters/deadline/deadline_filter.h"
33
33
 
34
34
  #include <stdbool.h>
35
35
  #include <string.h>
@@ -39,9 +39,11 @@
39
39
  #include <grpc/support/sync.h>
40
40
  #include <grpc/support/time.h>
41
41
 
42
+ #include "src/core/lib/channel/channel_stack_builder.h"
42
43
  #include "src/core/lib/iomgr/exec_ctx.h"
43
44
  #include "src/core/lib/iomgr/timer.h"
44
45
  #include "src/core/lib/slice/slice_internal.h"
46
+ #include "src/core/lib/surface/channel_init.h"
45
47
 
46
48
  //
47
49
  // grpc_deadline_state
@@ -141,18 +143,6 @@ static void inject_on_complete_cb(grpc_deadline_state* deadline_state,
141
143
  op->on_complete = &deadline_state->on_complete;
142
144
  }
143
145
 
144
- void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
145
- grpc_call_stack* call_stack) {
146
- grpc_deadline_state* deadline_state = elem->call_data;
147
- deadline_state->call_stack = call_stack;
148
- }
149
-
150
- void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx,
151
- grpc_call_element* elem) {
152
- grpc_deadline_state* deadline_state = elem->call_data;
153
- cancel_timer_if_needed(exec_ctx, deadline_state);
154
- }
155
-
156
146
  // Callback and associated state for starting the timer after call stack
157
147
  // initialization has been completed.
158
148
  struct start_timer_after_init_state {
@@ -167,8 +157,11 @@ static void start_timer_after_init(grpc_exec_ctx* exec_ctx, void* arg,
167
157
  gpr_free(state);
168
158
  }
169
159
 
170
- void grpc_deadline_state_start(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
171
- gpr_timespec deadline) {
160
+ void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
161
+ grpc_call_stack* call_stack,
162
+ gpr_timespec deadline) {
163
+ grpc_deadline_state* deadline_state = elem->call_data;
164
+ deadline_state->call_stack = call_stack;
172
165
  // Deadline will always be infinite on servers, so the timer will only be
173
166
  // set on clients with a finite deadline.
174
167
  deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC);
@@ -189,6 +182,12 @@ void grpc_deadline_state_start(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
189
182
  }
190
183
  }
191
184
 
185
+ void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx,
186
+ grpc_call_element* elem) {
187
+ grpc_deadline_state* deadline_state = elem->call_data;
188
+ cancel_timer_if_needed(exec_ctx, deadline_state);
189
+ }
190
+
192
191
  void grpc_deadline_state_reset(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
193
192
  gpr_timespec new_deadline) {
194
193
  grpc_deadline_state* deadline_state = elem->call_data;
@@ -248,8 +247,7 @@ typedef struct server_call_data {
248
247
  static grpc_error* init_call_elem(grpc_exec_ctx* exec_ctx,
249
248
  grpc_call_element* elem,
250
249
  const grpc_call_element_args* args) {
251
- grpc_deadline_state_init(exec_ctx, elem, args->call_stack);
252
- grpc_deadline_state_start(exec_ctx, elem, args->deadline);
250
+ grpc_deadline_state_init(exec_ctx, elem, args->call_stack, args->deadline);
253
251
  return GRPC_ERROR_NONE;
254
252
  }
255
253
 
@@ -346,3 +344,30 @@ const grpc_channel_filter grpc_server_deadline_filter = {
346
344
  grpc_channel_next_get_info,
347
345
  "deadline",
348
346
  };
347
+
348
+ bool grpc_deadline_checking_enabled(const grpc_channel_args* channel_args) {
349
+ return grpc_channel_arg_get_bool(
350
+ grpc_channel_args_find(channel_args, GRPC_ARG_ENABLE_DEADLINE_CHECKS),
351
+ !grpc_channel_args_want_minimal_stack(channel_args));
352
+ }
353
+
354
+ static bool maybe_add_deadline_filter(grpc_exec_ctx* exec_ctx,
355
+ grpc_channel_stack_builder* builder,
356
+ void* arg) {
357
+ return grpc_deadline_checking_enabled(
358
+ grpc_channel_stack_builder_get_channel_arguments(builder))
359
+ ? grpc_channel_stack_builder_prepend_filter(builder, arg, NULL,
360
+ NULL)
361
+ : true;
362
+ }
363
+
364
+ void grpc_deadline_filter_init(void) {
365
+ grpc_channel_init_register_stage(
366
+ GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
367
+ maybe_add_deadline_filter, (void*)&grpc_client_deadline_filter);
368
+ grpc_channel_init_register_stage(
369
+ GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
370
+ maybe_add_deadline_filter, (void*)&grpc_server_deadline_filter);
371
+ }
372
+
373
+ void grpc_deadline_filter_shutdown(void) {}
@@ -29,8 +29,8 @@
29
29
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
30
  //
31
31
 
32
- #ifndef GRPC_CORE_LIB_CHANNEL_DEADLINE_FILTER_H
33
- #define GRPC_CORE_LIB_CHANNEL_DEADLINE_FILTER_H
32
+ #ifndef GRPC_CORE_EXT_FILTERS_DEADLINE_DEADLINE_FILTER_H
33
+ #define GRPC_CORE_EXT_FILTERS_DEADLINE_DEADLINE_FILTER_H
34
34
 
35
35
  #include "src/core/lib/channel/channel_stack.h"
36
36
  #include "src/core/lib/iomgr/timer.h"
@@ -64,15 +64,11 @@ typedef struct grpc_deadline_state {
64
64
 
65
65
  // assumes elem->call_data is zero'd
66
66
  void grpc_deadline_state_init(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
67
- grpc_call_stack* call_stack);
67
+ grpc_call_stack* call_stack,
68
+ gpr_timespec deadline);
68
69
  void grpc_deadline_state_destroy(grpc_exec_ctx* exec_ctx,
69
70
  grpc_call_element* elem);
70
71
 
71
- // Starts the timer with the specified deadline.
72
- // Should be called from the filter's init_call_elem() method.
73
- void grpc_deadline_state_start(grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
74
- gpr_timespec deadline);
75
-
76
72
  // Cancels the existing timer and starts a new one with new_deadline.
77
73
  //
78
74
  // Note: It is generally safe to call this with an earlier deadline
@@ -93,10 +89,13 @@ void grpc_deadline_state_client_start_transport_stream_op_batch(
93
89
  grpc_exec_ctx* exec_ctx, grpc_call_element* elem,
94
90
  grpc_transport_stream_op_batch* op);
95
91
 
92
+ // Should deadline checking be performed (according to channel args)
93
+ bool grpc_deadline_checking_enabled(const grpc_channel_args* args);
94
+
96
95
  // Deadline filters for direct client channels and server channels.
97
96
  // Note: Deadlines for non-direct client channels are handled by the
98
97
  // client_channel filter.
99
98
  extern const grpc_channel_filter grpc_client_deadline_filter;
100
99
  extern const grpc_channel_filter grpc_server_deadline_filter;
101
100
 
102
- #endif /* GRPC_CORE_LIB_CHANNEL_DEADLINE_FILTER_H */
101
+ #endif /* GRPC_CORE_EXT_FILTERS_DEADLINE_DEADLINE_FILTER_H */
@@ -30,7 +30,7 @@
30
30
  *
31
31
  */
32
32
 
33
- #include "src/core/lib/channel/http_client_filter.h"
33
+ #include "src/core/ext/filters/http/client/http_client_filter.h"
34
34
  #include <grpc/support/alloc.h>
35
35
  #include <grpc/support/log.h>
36
36
  #include <grpc/support/string_util.h>
@@ -220,10 +220,15 @@ static void continue_send_message(grpc_exec_ctx *exec_ctx,
220
220
  call_data *calld = elem->call_data;
221
221
  uint8_t *wrptr = calld->payload_bytes;
222
222
  while (grpc_byte_stream_next(
223
- exec_ctx, calld->send_op->payload->send_message.send_message,
224
- &calld->incoming_slice, ~(size_t)0, &calld->got_slice)) {
225
- memcpy(wrptr, GRPC_SLICE_START_PTR(calld->incoming_slice),
226
- GRPC_SLICE_LENGTH(calld->incoming_slice));
223
+ exec_ctx, calld->send_op->payload->send_message.send_message, ~(size_t)0,
224
+ &calld->got_slice)) {
225
+ grpc_byte_stream_pull(exec_ctx,
226
+ calld->send_op->payload->send_message.send_message,
227
+ &calld->incoming_slice);
228
+ if (GRPC_SLICE_LENGTH(calld->incoming_slice) > 0) {
229
+ memcpy(wrptr, GRPC_SLICE_START_PTR(calld->incoming_slice),
230
+ GRPC_SLICE_LENGTH(calld->incoming_slice));
231
+ }
227
232
  wrptr += GRPC_SLICE_LENGTH(calld->incoming_slice);
228
233
  grpc_slice_buffer_add(&calld->slices, calld->incoming_slice);
229
234
  if (calld->send_length == calld->slices.length) {
@@ -237,6 +242,13 @@ static void got_slice(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) {
237
242
  grpc_call_element *elem = elemp;
238
243
  call_data *calld = elem->call_data;
239
244
  calld->send_message_blocked = false;
245
+ if (GRPC_ERROR_NONE !=
246
+ grpc_byte_stream_pull(exec_ctx,
247
+ calld->send_op->payload->send_message.send_message,
248
+ &calld->incoming_slice)) {
249
+ /* Should never reach here */
250
+ abort();
251
+ }
240
252
  grpc_slice_buffer_add(&calld->slices, calld->incoming_slice);
241
253
  if (calld->send_length == calld->slices.length) {
242
254
  /* Pass down the original send_message op that was blocked.*/
@@ -311,8 +323,7 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx,
311
323
  estimated_len += grpc_base64_estimate_encoded_size(
312
324
  op->payload->send_message.send_message->length, k_url_safe,
313
325
  k_multi_line);
314
- estimated_len += 1; /* for the trailing 0 */
315
- grpc_slice path_with_query_slice = grpc_slice_malloc(estimated_len);
326
+ grpc_slice path_with_query_slice = GRPC_SLICE_MALLOC(estimated_len);
316
327
 
317
328
  /* memcopy individual pieces into this slice */
318
329
  uint8_t *write_ptr =
@@ -332,10 +343,8 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx,
332
343
  */
333
344
  char *t = (char *)GRPC_SLICE_START_PTR(path_with_query_slice);
334
345
  /* safe to use strlen since base64_encode will always add '\0' */
335
- size_t path_length = strlen(t) + 1;
336
- *(t + path_length) = '\0';
337
346
  path_with_query_slice =
338
- grpc_slice_sub(path_with_query_slice, 0, path_length);
347
+ grpc_slice_sub_no_ref(path_with_query_slice, 0, strlen(t));
339
348
 
340
349
  /* substitute previous path with the new path+query */
341
350
  grpc_mdelem mdelem_path_and_query = grpc_mdelem_from_slices(
@@ -349,7 +358,6 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx,
349
358
  calld->on_complete = op->on_complete;
350
359
  op->on_complete = &calld->hc_on_complete;
351
360
  op->send_message = false;
352
- grpc_slice_unref_internal(exec_ctx, path_with_query_slice);
353
361
  } else {
354
362
  /* Not all data is available. Fall back to POST. */
355
363
  gpr_log(GPR_DEBUG,
@@ -30,18 +30,15 @@
30
30
  *
31
31
  */
32
32
 
33
- #ifndef GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H
34
- #define GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H
33
+ #ifndef GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_HTTP_CLIENT_FILTER_H
34
+ #define GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_HTTP_CLIENT_FILTER_H
35
35
 
36
36
  #include "src/core/lib/channel/channel_stack.h"
37
37
 
38
38
  /* Processes metadata on the client side for HTTP2 transports */
39
39
  extern const grpc_channel_filter grpc_http_client_filter;
40
40
 
41
- /* Channel arg to override the http2 :scheme header */
42
- #define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme"
43
-
44
41
  /* Channel arg to determine maximum size of payload eligable for GET request */
45
42
  #define GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET "grpc.max_payload_size_for_get"
46
43
 
47
- #endif /* GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H */
44
+ #endif /* GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_HTTP_CLIENT_FILTER_H */
@@ -0,0 +1,104 @@
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 <string.h>
35
+
36
+ #include "src/core/ext/filters/http/client/http_client_filter.h"
37
+ #include "src/core/ext/filters/http/message_compress/message_compress_filter.h"
38
+ #include "src/core/ext/filters/http/server/http_server_filter.h"
39
+ #include "src/core/lib/channel/channel_stack_builder.h"
40
+ #include "src/core/lib/surface/call.h"
41
+ #include "src/core/lib/surface/channel_init.h"
42
+ #include "src/core/lib/transport/transport_impl.h"
43
+
44
+ typedef struct {
45
+ const grpc_channel_filter *filter;
46
+ const char *control_channel_arg;
47
+ } optional_filter;
48
+
49
+ static optional_filter compress_filter = {
50
+ &grpc_message_compress_filter, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION};
51
+
52
+ static bool is_building_http_like_transport(
53
+ grpc_channel_stack_builder *builder) {
54
+ grpc_transport *t = grpc_channel_stack_builder_get_transport(builder);
55
+ return t != NULL && strstr(t->vtable->name, "http");
56
+ }
57
+
58
+ static bool maybe_add_optional_filter(grpc_exec_ctx *exec_ctx,
59
+ grpc_channel_stack_builder *builder,
60
+ void *arg) {
61
+ if (!is_building_http_like_transport(builder)) return true;
62
+ optional_filter *filtarg = arg;
63
+ const grpc_channel_args *channel_args =
64
+ grpc_channel_stack_builder_get_channel_arguments(builder);
65
+ bool enable = grpc_channel_arg_get_bool(
66
+ grpc_channel_args_find(channel_args, filtarg->control_channel_arg),
67
+ !grpc_channel_args_want_minimal_stack(channel_args));
68
+ return enable ? grpc_channel_stack_builder_prepend_filter(
69
+ builder, filtarg->filter, NULL, NULL)
70
+ : true;
71
+ }
72
+
73
+ static bool maybe_add_required_filter(grpc_exec_ctx *exec_ctx,
74
+ grpc_channel_stack_builder *builder,
75
+ void *arg) {
76
+ return is_building_http_like_transport(builder)
77
+ ? grpc_channel_stack_builder_prepend_filter(
78
+ builder, (const grpc_channel_filter *)arg, NULL, NULL)
79
+ : true;
80
+ }
81
+
82
+ void grpc_http_filters_init(void) {
83
+ grpc_register_tracer("compression", &grpc_compression_trace);
84
+ grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
85
+ GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
86
+ maybe_add_optional_filter, &compress_filter);
87
+ grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
88
+ GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
89
+ maybe_add_optional_filter, &compress_filter);
90
+ grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
91
+ GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
92
+ maybe_add_optional_filter, &compress_filter);
93
+ grpc_channel_init_register_stage(
94
+ GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
95
+ maybe_add_required_filter, (void *)&grpc_http_client_filter);
96
+ grpc_channel_init_register_stage(
97
+ GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
98
+ maybe_add_required_filter, (void *)&grpc_http_client_filter);
99
+ grpc_channel_init_register_stage(
100
+ GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
101
+ maybe_add_required_filter, (void *)&grpc_http_server_filter);
102
+ }
103
+
104
+ void grpc_http_filters_shutdown(void) {}