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.
- checksums.yaml +4 -4
- data/Makefile +1257 -404
- data/etc/roots.pem +189 -102
- data/include/grpc/census.h +7 -7
- data/include/grpc/compression.h +4 -4
- data/include/grpc/grpc.h +13 -7
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
- data/include/grpc/impl/codegen/grpc_types.h +39 -30
- data/include/grpc/impl/codegen/slice.h +24 -6
- data/include/grpc/impl/codegen/sync.h +8 -0
- data/include/grpc/load_reporting.h +63 -0
- data/include/grpc/slice.h +37 -1
- data/include/grpc/slice_buffer.h +7 -0
- data/include/grpc/support/alloc.h +3 -0
- data/include/grpc/support/useful.h +3 -0
- data/src/core/ext/census/gen/census.pb.h +1 -1
- data/src/core/ext/census/gen/trace_context.pb.c +9 -36
- data/src/core/ext/census/gen/trace_context.pb.h +20 -26
- data/src/core/ext/census/grpc_filter.c +3 -5
- data/src/core/ext/census/trace_context.c +1 -1
- data/src/core/ext/census/trace_context.h +3 -0
- data/src/core/ext/census/trace_label.h +61 -0
- data/src/core/ext/census/trace_propagation.h +63 -0
- data/src/core/ext/census/trace_status.h +45 -0
- data/src/core/ext/census/trace_string.h +50 -0
- data/src/core/ext/census/tracing.c +31 -11
- data/src/core/ext/census/tracing.h +124 -0
- data/src/core/ext/client_channel/client_channel.c +456 -368
- data/src/core/ext/client_channel/client_channel.h +4 -0
- data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
- data/src/core/ext/client_channel/connector.c +3 -3
- data/src/core/ext/client_channel/connector.h +4 -3
- data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
- data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
- data/src/core/ext/client_channel/http_proxy.c +125 -0
- data/src/core/ext/client_channel/http_proxy.h +39 -0
- data/src/core/ext/client_channel/lb_policy.c +56 -35
- data/src/core/ext/client_channel/lb_policy.h +46 -39
- data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
- data/src/core/ext/client_channel/parse_address.c +32 -6
- data/src/core/ext/client_channel/proxy_mapper.c +63 -0
- data/src/core/ext/client_channel/proxy_mapper.h +89 -0
- data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
- data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
- data/src/core/ext/client_channel/resolver.c +16 -9
- data/src/core/ext/client_channel/resolver.h +23 -12
- data/src/core/ext/client_channel/resolver_factory.h +1 -0
- data/src/core/ext/client_channel/resolver_registry.c +15 -11
- data/src/core/ext/client_channel/resolver_registry.h +5 -3
- data/src/core/ext/client_channel/subchannel.c +44 -27
- data/src/core/ext/client_channel/subchannel.h +6 -2
- data/src/core/ext/client_channel/uri_parser.c +26 -14
- data/src/core/ext/client_channel/uri_parser.h +3 -1
- data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
- data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
- data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
- data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
- data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
- data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
- data/src/core/ext/load_reporting/load_reporting.c +20 -0
- data/src/core/ext/load_reporting/load_reporting.h +1 -16
- data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
- data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
- data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
- data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
- data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
- data/src/core/lib/channel/channel_stack.c +14 -44
- data/src/core/lib/channel/channel_stack.h +10 -17
- data/src/core/lib/channel/channel_stack_builder.c +2 -3
- data/src/core/lib/channel/compress_filter.c +54 -46
- data/src/core/lib/channel/connected_channel.c +4 -4
- data/src/core/lib/channel/connected_channel.h +5 -0
- data/src/core/lib/channel/context.h +3 -0
- data/src/core/lib/channel/deadline_filter.c +61 -61
- data/src/core/lib/channel/deadline_filter.h +8 -5
- data/src/core/lib/channel/handshaker.c +47 -7
- data/src/core/lib/channel/handshaker.h +21 -3
- data/src/core/lib/channel/http_client_filter.c +149 -99
- data/src/core/lib/channel/http_server_filter.c +163 -147
- data/src/core/lib/channel/message_size_filter.c +15 -10
- data/src/core/lib/compression/algorithm_metadata.h +4 -4
- data/src/core/lib/compression/compression.c +17 -23
- data/src/core/lib/http/httpcli.c +3 -2
- data/src/core/lib/http/httpcli.h +2 -1
- data/src/core/lib/http/httpcli_security_connector.c +2 -3
- data/src/core/lib/http/parser.c +2 -2
- data/src/core/lib/iomgr/closure.c +6 -3
- data/src/core/lib/iomgr/closure.h +4 -2
- data/src/core/lib/iomgr/combiner.c +35 -5
- data/src/core/lib/iomgr/combiner.h +21 -2
- data/src/core/lib/iomgr/endpoint.c +3 -2
- data/src/core/lib/iomgr/endpoint.h +3 -2
- data/src/core/lib/iomgr/error.c +60 -94
- data/src/core/lib/iomgr/error.h +7 -10
- data/src/core/lib/iomgr/error_internal.h +54 -0
- data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
- data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
- data/src/core/lib/iomgr/ev_posix.c +7 -8
- data/src/core/lib/iomgr/ev_posix.h +4 -4
- data/src/core/lib/iomgr/exec_ctx.c +11 -6
- data/src/core/lib/iomgr/exec_ctx.h +11 -14
- data/src/core/lib/iomgr/executor.c +2 -2
- data/src/core/lib/iomgr/load_file.c +1 -1
- data/src/core/lib/iomgr/network_status_tracker.c +5 -81
- data/src/core/lib/iomgr/pollset.h +1 -3
- data/src/core/lib/iomgr/pollset_set.h +2 -1
- data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
- data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
- data/src/core/lib/iomgr/pollset_uv.c +25 -11
- data/src/core/lib/iomgr/pollset_windows.c +0 -11
- data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
- data/src/core/lib/iomgr/resource_quota.c +41 -11
- data/src/core/lib/iomgr/resource_quota.h +6 -0
- data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
- data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
- data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
- data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
- data/src/core/lib/iomgr/tcp_posix.c +4 -5
- data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
- data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
- data/src/core/lib/iomgr/tcp_uv.c +11 -5
- data/src/core/lib/iomgr/tcp_windows.c +20 -7
- data/src/core/lib/iomgr/timer_generic.c +15 -22
- data/src/core/lib/iomgr/timer_generic.h +1 -1
- data/src/core/lib/iomgr/timer_uv.c +10 -6
- data/src/core/lib/iomgr/timer_uv.h +1 -1
- data/src/core/lib/iomgr/udp_server.c +45 -6
- data/src/core/lib/iomgr/udp_server.h +7 -1
- data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
- data/src/core/lib/json/json.c +1 -2
- data/src/core/lib/profiling/basic_timers.c +17 -3
- data/src/core/lib/security/context/security_context.c +3 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
- data/src/core/lib/security/credentials/credentials.c +48 -2
- data/src/core/lib/security/credentials/credentials.h +13 -0
- data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
- data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
- data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
- data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
- data/src/core/lib/security/transport/client_auth_filter.c +72 -47
- data/src/core/lib/security/transport/lb_targets_info.c +70 -0
- data/src/core/lib/security/transport/lb_targets_info.h +47 -0
- data/src/core/lib/security/transport/secure_endpoint.c +3 -3
- data/src/core/lib/security/transport/security_connector.c +125 -28
- data/src/core/lib/security/transport/security_connector.h +4 -3
- data/src/core/lib/security/transport/security_handshaker.c +13 -9
- data/src/core/lib/security/transport/server_auth_filter.c +31 -40
- data/src/core/lib/security/util/b64.c +1 -1
- data/src/core/lib/slice/slice.c +110 -20
- data/src/core/lib/slice/slice_buffer.c +92 -39
- data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
- data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
- data/src/core/lib/slice/slice_intern.c +346 -0
- data/src/core/lib/slice/slice_internal.h +15 -0
- data/src/core/lib/slice/slice_string_helpers.c +5 -0
- data/src/core/lib/slice/slice_string_helpers.h +5 -0
- data/src/core/lib/support/alloc.c +26 -1
- data/src/core/lib/support/cmdline.c +2 -4
- data/src/core/lib/support/cpu_posix.c +2 -7
- data/src/core/lib/support/histogram.c +1 -2
- data/src/core/lib/support/log_posix.c +8 -4
- data/src/core/lib/support/spinlock.h +52 -0
- data/src/core/lib/support/subprocess_posix.c +1 -2
- data/src/core/lib/support/sync.c +7 -1
- data/src/core/lib/support/sync_posix.c +9 -0
- data/src/core/lib/support/time_windows.c +7 -1
- data/src/core/lib/surface/call.c +647 -629
- data/src/core/lib/surface/call.h +4 -1
- data/src/core/lib/surface/call_details.c +8 -2
- data/src/core/lib/surface/call_log_batch.c +17 -6
- data/src/core/lib/surface/channel.c +49 -59
- data/src/core/lib/surface/channel.h +5 -6
- data/src/core/lib/surface/completion_queue.c +16 -45
- data/src/core/lib/surface/completion_queue.h +0 -3
- data/src/core/lib/surface/init.c +6 -2
- data/src/core/lib/surface/init_secure.c +1 -1
- data/src/core/lib/surface/lame_client.c +14 -4
- data/src/core/lib/surface/server.c +79 -82
- data/src/core/lib/surface/validate_metadata.c +46 -15
- data/src/core/lib/surface/validate_metadata.h +43 -0
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/bdp_estimator.c +104 -0
- data/src/core/lib/transport/bdp_estimator.h +76 -0
- data/src/core/lib/transport/connectivity_state.c +33 -13
- data/src/core/lib/transport/connectivity_state.h +15 -5
- data/src/core/lib/transport/error_utils.c +124 -0
- data/src/core/lib/transport/error_utils.h +56 -0
- data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
- data/src/core/lib/transport/metadata.c +259 -503
- data/src/core/lib/transport/metadata.h +69 -68
- data/src/core/lib/transport/metadata_batch.c +183 -63
- data/src/core/lib/transport/metadata_batch.h +50 -26
- data/src/core/lib/transport/pid_controller.c +28 -8
- data/src/core/lib/transport/pid_controller.h +15 -2
- data/src/core/lib/transport/service_config.c +21 -18
- data/src/core/lib/transport/service_config.h +5 -5
- data/src/core/lib/transport/static_metadata.c +753 -112
- data/src/core/lib/transport/static_metadata.h +403 -264
- data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
- data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
- data/src/core/lib/transport/timeout_encoding.c +11 -9
- data/src/core/lib/transport/timeout_encoding.h +3 -1
- data/src/core/lib/transport/transport.c +47 -87
- data/src/core/lib/transport/transport.h +20 -25
- data/src/core/lib/transport/transport_op_string.c +7 -19
- data/src/core/lib/tsi/fake_transport_security.c +2 -4
- data/src/core/lib/tsi/ssl_transport_security.c +7 -16
- data/src/core/lib/tsi/transport_security.c +2 -4
- data/src/ruby/ext/grpc/extconf.rb +4 -1
- data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
- data/src/ruby/ext/grpc/rb_call.c +47 -46
- data/src/ruby/ext/grpc/rb_channel.c +21 -6
- data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
- data/src/ruby/ext/grpc/rb_server.c +6 -4
- data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- metadata +33 -9
@@ -57,4 +57,8 @@ void grpc_client_channel_watch_connectivity_state(
|
|
57
57
|
grpc_exec_ctx *exec_ctx, grpc_channel_element *elem, grpc_pollset *pollset,
|
58
58
|
grpc_connectivity_state *state, grpc_closure *on_complete);
|
59
59
|
|
60
|
+
/* Debug helper: pull the subchannel call from a call stack element */
|
61
|
+
grpc_subchannel_call *grpc_client_channel_get_subchannel_call(
|
62
|
+
grpc_call_element *elem);
|
63
|
+
|
60
64
|
#endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_CLIENT_CHANNEL_H */
|
@@ -39,7 +39,9 @@
|
|
39
39
|
|
40
40
|
#include "src/core/ext/client_channel/client_channel.h"
|
41
41
|
#include "src/core/ext/client_channel/http_connect_handshaker.h"
|
42
|
+
#include "src/core/ext/client_channel/http_proxy.h"
|
42
43
|
#include "src/core/ext/client_channel/lb_policy_registry.h"
|
44
|
+
#include "src/core/ext/client_channel/proxy_mapper_registry.h"
|
43
45
|
#include "src/core/ext/client_channel/resolver_registry.h"
|
44
46
|
#include "src/core/ext/client_channel/subchannel_index.h"
|
45
47
|
#include "src/core/lib/surface/channel_init.h"
|
@@ -62,7 +64,7 @@ static bool set_default_host_if_unset(grpc_exec_ctx *exec_ctx,
|
|
62
64
|
}
|
63
65
|
}
|
64
66
|
char *default_authority = grpc_get_default_authority(
|
65
|
-
grpc_channel_stack_builder_get_target(builder));
|
67
|
+
exec_ctx, grpc_channel_stack_builder_get_target(builder));
|
66
68
|
if (default_authority != NULL) {
|
67
69
|
grpc_arg arg;
|
68
70
|
arg.type = GRPC_ARG_STRING;
|
@@ -80,6 +82,8 @@ static bool set_default_host_if_unset(grpc_exec_ctx *exec_ctx,
|
|
80
82
|
void grpc_client_channel_init(void) {
|
81
83
|
grpc_lb_policy_registry_init();
|
82
84
|
grpc_resolver_registry_init();
|
85
|
+
grpc_proxy_mapper_registry_init();
|
86
|
+
grpc_register_http_proxy_mapper();
|
83
87
|
grpc_subchannel_index_init();
|
84
88
|
grpc_channel_init_register_stage(GRPC_CLIENT_CHANNEL, INT_MIN,
|
85
89
|
set_default_host_if_unset, NULL);
|
@@ -91,6 +95,7 @@ void grpc_client_channel_init(void) {
|
|
91
95
|
void grpc_client_channel_shutdown(void) {
|
92
96
|
grpc_subchannel_index_shutdown();
|
93
97
|
grpc_channel_init_shutdown();
|
98
|
+
grpc_proxy_mapper_registry_shutdown();
|
94
99
|
grpc_resolver_registry_shutdown();
|
95
100
|
grpc_lb_policy_registry_shutdown();
|
96
101
|
}
|
@@ -49,7 +49,7 @@ void grpc_connector_connect(grpc_exec_ctx* exec_ctx, grpc_connector* connector,
|
|
49
49
|
connector->vtable->connect(exec_ctx, connector, in_args, out_args, notify);
|
50
50
|
}
|
51
51
|
|
52
|
-
void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx,
|
53
|
-
|
54
|
-
connector->vtable->shutdown(exec_ctx, connector);
|
52
|
+
void grpc_connector_shutdown(grpc_exec_ctx* exec_ctx, grpc_connector* connector,
|
53
|
+
grpc_error* why) {
|
54
|
+
connector->vtable->shutdown(exec_ctx, connector, why);
|
55
55
|
}
|
@@ -68,7 +68,8 @@ struct grpc_connector_vtable {
|
|
68
68
|
void (*ref)(grpc_connector *connector);
|
69
69
|
void (*unref)(grpc_exec_ctx *exec_ctx, grpc_connector *connector);
|
70
70
|
/** Implementation of grpc_connector_shutdown */
|
71
|
-
void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_connector *connector
|
71
|
+
void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_connector *connector,
|
72
|
+
grpc_error *why);
|
72
73
|
/** Implementation of grpc_connector_connect */
|
73
74
|
void (*connect)(grpc_exec_ctx *exec_ctx, grpc_connector *connector,
|
74
75
|
const grpc_connect_in_args *in_args,
|
@@ -83,7 +84,7 @@ void grpc_connector_connect(grpc_exec_ctx *exec_ctx, grpc_connector *connector,
|
|
83
84
|
grpc_connect_out_args *out_args,
|
84
85
|
grpc_closure *notify);
|
85
86
|
/** Cancel any pending connection */
|
86
|
-
void grpc_connector_shutdown(grpc_exec_ctx *exec_ctx,
|
87
|
-
|
87
|
+
void grpc_connector_shutdown(grpc_exec_ctx *exec_ctx, grpc_connector *connector,
|
88
|
+
grpc_error *why);
|
88
89
|
|
89
90
|
#endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_CONNECTOR_H */
|
@@ -49,15 +49,12 @@
|
|
49
49
|
#include "src/core/lib/http/parser.h"
|
50
50
|
#include "src/core/lib/slice/slice_internal.h"
|
51
51
|
#include "src/core/lib/support/env.h"
|
52
|
+
#include "src/core/lib/support/string.h"
|
52
53
|
|
53
54
|
typedef struct http_connect_handshaker {
|
54
55
|
// Base class. Must be first.
|
55
56
|
grpc_handshaker base;
|
56
57
|
|
57
|
-
char* proxy_server;
|
58
|
-
grpc_http_header* headers;
|
59
|
-
size_t num_headers;
|
60
|
-
|
61
58
|
gpr_refcount refcount;
|
62
59
|
gpr_mu mu;
|
63
60
|
|
@@ -91,12 +88,6 @@ static void http_connect_handshaker_unref(grpc_exec_ctx* exec_ctx,
|
|
91
88
|
handshaker->read_buffer_to_destroy);
|
92
89
|
gpr_free(handshaker->read_buffer_to_destroy);
|
93
90
|
}
|
94
|
-
gpr_free(handshaker->proxy_server);
|
95
|
-
for (size_t i = 0; i < handshaker->num_headers; ++i) {
|
96
|
-
gpr_free(handshaker->headers[i].key);
|
97
|
-
gpr_free(handshaker->headers[i].value);
|
98
|
-
}
|
99
|
-
gpr_free(handshaker->headers);
|
100
91
|
grpc_slice_buffer_destroy_internal(exec_ctx, &handshaker->write_buffer);
|
101
92
|
grpc_http_parser_destroy(&handshaker->http_parser);
|
102
93
|
grpc_http_response_destroy(&handshaker->http_response);
|
@@ -132,7 +123,8 @@ static void handshake_failed_locked(grpc_exec_ctx* exec_ctx,
|
|
132
123
|
// before destroying them, even if we know that there are no
|
133
124
|
// pending read/write callbacks. This should be fixed, at which
|
134
125
|
// point this can be removed.
|
135
|
-
grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint
|
126
|
+
grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint,
|
127
|
+
GRPC_ERROR_REF(error));
|
136
128
|
// Not shutting down, so the handshake failed. Clean up before
|
137
129
|
// invoking the callback.
|
138
130
|
cleanup_args_for_failure_locked(exec_ctx, handshaker);
|
@@ -260,15 +252,18 @@ static void http_connect_handshaker_destroy(grpc_exec_ctx* exec_ctx,
|
|
260
252
|
}
|
261
253
|
|
262
254
|
static void http_connect_handshaker_shutdown(grpc_exec_ctx* exec_ctx,
|
263
|
-
grpc_handshaker* handshaker_in
|
255
|
+
grpc_handshaker* handshaker_in,
|
256
|
+
grpc_error* why) {
|
264
257
|
http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in;
|
265
258
|
gpr_mu_lock(&handshaker->mu);
|
266
259
|
if (!handshaker->shutdown) {
|
267
260
|
handshaker->shutdown = true;
|
268
|
-
grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint
|
261
|
+
grpc_endpoint_shutdown(exec_ctx, handshaker->args->endpoint,
|
262
|
+
GRPC_ERROR_REF(why));
|
269
263
|
cleanup_args_for_failure_locked(exec_ctx, handshaker);
|
270
264
|
}
|
271
265
|
gpr_mu_unlock(&handshaker->mu);
|
266
|
+
GRPC_ERROR_UNREF(why);
|
272
267
|
}
|
273
268
|
|
274
269
|
static void http_connect_handshaker_do_handshake(
|
@@ -276,64 +271,88 @@ static void http_connect_handshaker_do_handshake(
|
|
276
271
|
grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done,
|
277
272
|
grpc_handshaker_args* args) {
|
278
273
|
http_connect_handshaker* handshaker = (http_connect_handshaker*)handshaker_in;
|
279
|
-
//
|
280
|
-
|
281
|
-
|
274
|
+
// Check for HTTP CONNECT channel arg.
|
275
|
+
// If not found, invoke on_handshake_done without doing anything.
|
276
|
+
const grpc_arg* arg =
|
277
|
+
grpc_channel_args_find(args->args, GRPC_ARG_HTTP_CONNECT_SERVER);
|
278
|
+
if (arg == NULL) {
|
279
|
+
// Set shutdown to true so that subsequent calls to
|
280
|
+
// http_connect_handshaker_shutdown() do nothing.
|
281
|
+
gpr_mu_lock(&handshaker->mu);
|
282
|
+
handshaker->shutdown = true;
|
283
|
+
gpr_mu_unlock(&handshaker->mu);
|
284
|
+
grpc_closure_sched(exec_ctx, on_handshake_done, GRPC_ERROR_NONE);
|
285
|
+
return;
|
286
|
+
}
|
282
287
|
GPR_ASSERT(arg->type == GRPC_ARG_STRING);
|
283
|
-
char*
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
+
char* server_name = arg->value.string;
|
289
|
+
// Get headers from channel args.
|
290
|
+
arg = grpc_channel_args_find(args->args, GRPC_ARG_HTTP_CONNECT_HEADERS);
|
291
|
+
grpc_http_header* headers = NULL;
|
292
|
+
size_t num_headers = 0;
|
293
|
+
char** header_strings = NULL;
|
294
|
+
size_t num_header_strings = 0;
|
295
|
+
if (arg != NULL) {
|
296
|
+
GPR_ASSERT(arg->type == GRPC_ARG_STRING);
|
297
|
+
gpr_string_split(arg->value.string, "\n", &header_strings,
|
298
|
+
&num_header_strings);
|
299
|
+
headers = gpr_malloc(sizeof(grpc_http_header) * num_header_strings);
|
300
|
+
for (size_t i = 0; i < num_header_strings; ++i) {
|
301
|
+
char* sep = strchr(header_strings[i], ':');
|
302
|
+
if (sep == NULL) {
|
303
|
+
gpr_log(GPR_ERROR, "skipping unparseable HTTP CONNECT header: %s",
|
304
|
+
header_strings[i]);
|
305
|
+
continue;
|
306
|
+
}
|
307
|
+
*sep = '\0';
|
308
|
+
headers[num_headers].key = header_strings[i];
|
309
|
+
headers[num_headers].value = sep + 1;
|
310
|
+
++num_headers;
|
311
|
+
}
|
312
|
+
}
|
288
313
|
// Save state in the handshaker object.
|
289
314
|
gpr_mu_lock(&handshaker->mu);
|
290
315
|
handshaker->args = args;
|
291
316
|
handshaker->on_handshake_done = on_handshake_done;
|
292
|
-
//
|
317
|
+
// Log connection via proxy.
|
318
|
+
char* proxy_name = grpc_endpoint_get_peer(args->endpoint);
|
293
319
|
gpr_log(GPR_INFO, "Connecting to server %s via HTTP proxy %s", server_name,
|
294
|
-
|
320
|
+
proxy_name);
|
321
|
+
gpr_free(proxy_name);
|
322
|
+
// Construct HTTP CONNECT request.
|
295
323
|
grpc_httpcli_request request;
|
296
324
|
memset(&request, 0, sizeof(request));
|
297
325
|
request.host = server_name;
|
298
326
|
request.http.method = "CONNECT";
|
299
327
|
request.http.path = server_name;
|
300
|
-
request.http.hdrs =
|
301
|
-
request.http.hdr_count =
|
328
|
+
request.http.hdrs = headers;
|
329
|
+
request.http.hdr_count = num_headers;
|
302
330
|
request.handshaker = &grpc_httpcli_plaintext;
|
303
331
|
grpc_slice request_slice = grpc_httpcli_format_connect_request(&request);
|
304
332
|
grpc_slice_buffer_add(&handshaker->write_buffer, request_slice);
|
333
|
+
// Clean up.
|
334
|
+
gpr_free(headers);
|
335
|
+
for (size_t i = 0; i < num_header_strings; ++i) {
|
336
|
+
gpr_free(header_strings[i]);
|
337
|
+
}
|
338
|
+
gpr_free(header_strings);
|
305
339
|
// Take a new ref to be held by the write callback.
|
306
340
|
gpr_ref(&handshaker->refcount);
|
307
341
|
grpc_endpoint_write(exec_ctx, args->endpoint, &handshaker->write_buffer,
|
308
342
|
&handshaker->request_done_closure);
|
309
343
|
gpr_mu_unlock(&handshaker->mu);
|
310
|
-
// Clean up.
|
311
|
-
gpr_free(canonical_uri);
|
312
|
-
grpc_uri_destroy(uri);
|
313
344
|
}
|
314
345
|
|
315
346
|
static const grpc_handshaker_vtable http_connect_handshaker_vtable = {
|
316
347
|
http_connect_handshaker_destroy, http_connect_handshaker_shutdown,
|
317
348
|
http_connect_handshaker_do_handshake};
|
318
349
|
|
319
|
-
grpc_handshaker* grpc_http_connect_handshaker_create(
|
320
|
-
grpc_http_header* headers,
|
321
|
-
size_t num_headers) {
|
322
|
-
GPR_ASSERT(proxy_server != NULL);
|
350
|
+
static grpc_handshaker* grpc_http_connect_handshaker_create() {
|
323
351
|
http_connect_handshaker* handshaker = gpr_malloc(sizeof(*handshaker));
|
324
352
|
memset(handshaker, 0, sizeof(*handshaker));
|
325
353
|
grpc_handshaker_init(&http_connect_handshaker_vtable, &handshaker->base);
|
326
354
|
gpr_mu_init(&handshaker->mu);
|
327
355
|
gpr_ref_init(&handshaker->refcount, 1);
|
328
|
-
handshaker->proxy_server = gpr_strdup(proxy_server);
|
329
|
-
if (num_headers > 0) {
|
330
|
-
handshaker->headers = gpr_malloc(sizeof(grpc_http_header) * num_headers);
|
331
|
-
for (size_t i = 0; i < num_headers; ++i) {
|
332
|
-
handshaker->headers[i].key = gpr_strdup(headers[i].key);
|
333
|
-
handshaker->headers[i].value = gpr_strdup(headers[i].value);
|
334
|
-
}
|
335
|
-
handshaker->num_headers = num_headers;
|
336
|
-
}
|
337
356
|
grpc_slice_buffer_init(&handshaker->write_buffer);
|
338
357
|
grpc_closure_init(&handshaker->request_done_closure, on_write_done,
|
339
358
|
handshaker, grpc_schedule_on_exec_ctx);
|
@@ -344,30 +363,6 @@ grpc_handshaker* grpc_http_connect_handshaker_create(const char* proxy_server,
|
|
344
363
|
return &handshaker->base;
|
345
364
|
}
|
346
365
|
|
347
|
-
char* grpc_get_http_proxy_server() {
|
348
|
-
char* uri_str = gpr_getenv("http_proxy");
|
349
|
-
if (uri_str == NULL) return NULL;
|
350
|
-
grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */);
|
351
|
-
char* proxy_name = NULL;
|
352
|
-
if (uri == NULL || uri->authority == NULL) {
|
353
|
-
gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var");
|
354
|
-
goto done;
|
355
|
-
}
|
356
|
-
if (strcmp(uri->scheme, "http") != 0) {
|
357
|
-
gpr_log(GPR_ERROR, "'%s' scheme not supported in proxy URI", uri->scheme);
|
358
|
-
goto done;
|
359
|
-
}
|
360
|
-
if (strchr(uri->authority, '@') != NULL) {
|
361
|
-
gpr_log(GPR_ERROR, "userinfo not supported in proxy URI");
|
362
|
-
goto done;
|
363
|
-
}
|
364
|
-
proxy_name = gpr_strdup(uri->authority);
|
365
|
-
done:
|
366
|
-
gpr_free(uri_str);
|
367
|
-
grpc_uri_destroy(uri);
|
368
|
-
return proxy_name;
|
369
|
-
}
|
370
|
-
|
371
366
|
//
|
372
367
|
// handshaker factory
|
373
368
|
//
|
@@ -375,13 +370,8 @@ done:
|
|
375
370
|
static void handshaker_factory_add_handshakers(
|
376
371
|
grpc_exec_ctx* exec_ctx, grpc_handshaker_factory* factory,
|
377
372
|
const grpc_channel_args* args, grpc_handshake_manager* handshake_mgr) {
|
378
|
-
|
379
|
-
|
380
|
-
grpc_handshake_manager_add(
|
381
|
-
handshake_mgr,
|
382
|
-
grpc_http_connect_handshaker_create(proxy_name, NULL, 0));
|
383
|
-
gpr_free(proxy_name);
|
384
|
-
}
|
373
|
+
grpc_handshake_manager_add(handshake_mgr,
|
374
|
+
grpc_http_connect_handshaker_create());
|
385
375
|
}
|
386
376
|
|
387
377
|
static void handshaker_factory_destroy(grpc_exec_ctx* exec_ctx,
|
@@ -34,17 +34,14 @@
|
|
34
34
|
#ifndef GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_CONNECT_HANDSHAKER_H
|
35
35
|
#define GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_CONNECT_HANDSHAKER_H
|
36
36
|
|
37
|
-
|
38
|
-
|
37
|
+
/// Channel arg indicating the server in HTTP CONNECT request (string).
|
38
|
+
/// The presence of this arg triggers the use of HTTP CONNECT.
|
39
|
+
#define GRPC_ARG_HTTP_CONNECT_SERVER "grpc.http_connect_server"
|
39
40
|
|
40
|
-
///
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
/// Returns the name of the proxy to use, or NULL if no proxy is configured.
|
46
|
-
/// Caller takes ownership of result.
|
47
|
-
char* grpc_get_http_proxy_server();
|
41
|
+
/// Channel arg indicating HTTP CONNECT headers (string).
|
42
|
+
/// Multiple headers are separated by newlines. Key/value pairs are
|
43
|
+
/// seperated by colons.
|
44
|
+
#define GRPC_ARG_HTTP_CONNECT_HEADERS "grpc.http_connect_headers"
|
48
45
|
|
49
46
|
/// Registers handshaker factory.
|
50
47
|
void grpc_http_connect_register_handshaker_factory();
|
@@ -0,0 +1,125 @@
|
|
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/ext/client_channel/http_proxy.h"
|
35
|
+
|
36
|
+
#include <stdbool.h>
|
37
|
+
#include <string.h>
|
38
|
+
|
39
|
+
#include <grpc/support/alloc.h>
|
40
|
+
#include <grpc/support/log.h>
|
41
|
+
#include <grpc/support/string_util.h>
|
42
|
+
|
43
|
+
#include "src/core/ext/client_channel/http_connect_handshaker.h"
|
44
|
+
#include "src/core/ext/client_channel/proxy_mapper_registry.h"
|
45
|
+
#include "src/core/ext/client_channel/uri_parser.h"
|
46
|
+
#include "src/core/lib/channel/channel_args.h"
|
47
|
+
#include "src/core/lib/support/env.h"
|
48
|
+
|
49
|
+
static char* grpc_get_http_proxy_server(grpc_exec_ctx* exec_ctx) {
|
50
|
+
char* uri_str = gpr_getenv("http_proxy");
|
51
|
+
if (uri_str == NULL) return NULL;
|
52
|
+
grpc_uri* uri =
|
53
|
+
grpc_uri_parse(exec_ctx, uri_str, false /* suppress_errors */);
|
54
|
+
char* proxy_name = NULL;
|
55
|
+
if (uri == NULL || uri->authority == NULL) {
|
56
|
+
gpr_log(GPR_ERROR, "cannot parse value of 'http_proxy' env var");
|
57
|
+
goto done;
|
58
|
+
}
|
59
|
+
if (strcmp(uri->scheme, "http") != 0) {
|
60
|
+
gpr_log(GPR_ERROR, "'%s' scheme not supported in proxy URI", uri->scheme);
|
61
|
+
goto done;
|
62
|
+
}
|
63
|
+
if (strchr(uri->authority, '@') != NULL) {
|
64
|
+
gpr_log(GPR_ERROR, "userinfo not supported in proxy URI");
|
65
|
+
goto done;
|
66
|
+
}
|
67
|
+
proxy_name = gpr_strdup(uri->authority);
|
68
|
+
done:
|
69
|
+
gpr_free(uri_str);
|
70
|
+
grpc_uri_destroy(uri);
|
71
|
+
return proxy_name;
|
72
|
+
}
|
73
|
+
|
74
|
+
static bool proxy_mapper_map_name(grpc_exec_ctx* exec_ctx,
|
75
|
+
grpc_proxy_mapper* mapper,
|
76
|
+
const char* server_uri,
|
77
|
+
const grpc_channel_args* args,
|
78
|
+
char** name_to_resolve,
|
79
|
+
grpc_channel_args** new_args) {
|
80
|
+
*name_to_resolve = grpc_get_http_proxy_server(exec_ctx);
|
81
|
+
if (*name_to_resolve == NULL) return false;
|
82
|
+
grpc_uri* uri =
|
83
|
+
grpc_uri_parse(exec_ctx, server_uri, false /* suppress_errors */);
|
84
|
+
if (uri == NULL || uri->path[0] == '\0') {
|
85
|
+
gpr_log(GPR_ERROR,
|
86
|
+
"'http_proxy' environment variable set, but cannot "
|
87
|
+
"parse server URI '%s' -- not using proxy",
|
88
|
+
server_uri);
|
89
|
+
if (uri != NULL) grpc_uri_destroy(uri);
|
90
|
+
return false;
|
91
|
+
}
|
92
|
+
if (strcmp(uri->scheme, "unix") == 0) {
|
93
|
+
gpr_log(GPR_INFO, "not using proxy for Unix domain socket '%s'",
|
94
|
+
server_uri);
|
95
|
+
grpc_uri_destroy(uri);
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
grpc_arg new_arg;
|
99
|
+
new_arg.key = GRPC_ARG_HTTP_CONNECT_SERVER;
|
100
|
+
new_arg.type = GRPC_ARG_STRING;
|
101
|
+
new_arg.value.string = uri->path[0] == '/' ? uri->path + 1 : uri->path;
|
102
|
+
*new_args = grpc_channel_args_copy_and_add(args, &new_arg, 1);
|
103
|
+
grpc_uri_destroy(uri);
|
104
|
+
return true;
|
105
|
+
}
|
106
|
+
|
107
|
+
static bool proxy_mapper_map_address(grpc_exec_ctx* exec_ctx,
|
108
|
+
grpc_proxy_mapper* mapper,
|
109
|
+
const grpc_resolved_address* address,
|
110
|
+
const grpc_channel_args* args,
|
111
|
+
grpc_resolved_address** new_address,
|
112
|
+
grpc_channel_args** new_args) {
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
|
116
|
+
static void proxy_mapper_destroy(grpc_proxy_mapper* mapper) {}
|
117
|
+
|
118
|
+
static const grpc_proxy_mapper_vtable proxy_mapper_vtable = {
|
119
|
+
proxy_mapper_map_name, proxy_mapper_map_address, proxy_mapper_destroy};
|
120
|
+
|
121
|
+
static grpc_proxy_mapper proxy_mapper = {&proxy_mapper_vtable};
|
122
|
+
|
123
|
+
void grpc_register_http_proxy_mapper() {
|
124
|
+
grpc_proxy_mapper_register(true /* at_start */, &proxy_mapper);
|
125
|
+
}
|