Skip to content

Commit

Permalink
Merge pull request grpc#9383 from markdroth/http_connect_channel_arg
Browse files Browse the repository at this point in the history
Trigger HTTP CONNECT handshaker via channel args.
  • Loading branch information
markdroth authored Jan 25, 2017
2 parents 6e0697c + 1cae131 commit 674fe85
Show file tree
Hide file tree
Showing 22 changed files with 243 additions and 88 deletions.
2 changes: 2 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ grpc_cc_library(
"src/core/ext/client_channel/connector.c",
"src/core/ext/client_channel/default_initial_connect_string.c",
"src/core/ext/client_channel/http_connect_handshaker.c",
"src/core/ext/client_channel/http_proxy.c",
"src/core/ext/client_channel/initial_connect_string.c",
"src/core/ext/client_channel/lb_policy.c",
"src/core/ext/client_channel/lb_policy_factory.c",
Expand All @@ -681,6 +682,7 @@ grpc_cc_library(
"src/core/ext/client_channel/client_channel_factory.h",
"src/core/ext/client_channel/connector.h",
"src/core/ext/client_channel/http_connect_handshaker.h",
"src/core/ext/client_channel/http_proxy.h",
"src/core/ext/client_channel/initial_connect_string.h",
"src/core/ext/client_channel/lb_policy.h",
"src/core/ext/client_channel/lb_policy_factory.h",
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ add_library(grpc
src/core/ext/client_channel/connector.c
src/core/ext/client_channel/default_initial_connect_string.c
src/core/ext/client_channel/http_connect_handshaker.c
src/core/ext/client_channel/http_proxy.c
src/core/ext/client_channel/initial_connect_string.c
src/core/ext/client_channel/lb_policy.c
src/core/ext/client_channel/lb_policy_factory.c
Expand Down Expand Up @@ -832,6 +833,7 @@ add_library(grpc_cronet
src/core/ext/client_channel/connector.c
src/core/ext/client_channel/default_initial_connect_string.c
src/core/ext/client_channel/http_connect_handshaker.c
src/core/ext/client_channel/http_proxy.c
src/core/ext/client_channel/initial_connect_string.c
src/core/ext/client_channel/lb_policy.c
src/core/ext/client_channel/lb_policy_factory.c
Expand Down Expand Up @@ -1326,6 +1328,7 @@ add_library(grpc_unsecure
src/core/ext/client_channel/connector.c
src/core/ext/client_channel/default_initial_connect_string.c
src/core/ext/client_channel/http_connect_handshaker.c
src/core/ext/client_channel/http_proxy.c
src/core/ext/client_channel/initial_connect_string.c
src/core/ext/client_channel/lb_policy.c
src/core/ext/client_channel/lb_policy_factory.c
Expand Down Expand Up @@ -1829,6 +1832,7 @@ add_library(grpc++_cronet
src/core/ext/client_channel/connector.c
src/core/ext/client_channel/default_initial_connect_string.c
src/core/ext/client_channel/http_connect_handshaker.c
src/core/ext/client_channel/http_proxy.c
src/core/ext/client_channel/initial_connect_string.c
src/core/ext/client_channel/lb_policy.c
src/core/ext/client_channel/lb_policy_factory.c
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2831,6 +2831,7 @@ LIBGRPC_SRC = \
src/core/ext/client_channel/connector.c \
src/core/ext/client_channel/default_initial_connect_string.c \
src/core/ext/client_channel/http_connect_handshaker.c \
src/core/ext/client_channel/http_proxy.c \
src/core/ext/client_channel/initial_connect_string.c \
src/core/ext/client_channel/lb_policy.c \
src/core/ext/client_channel/lb_policy_factory.c \
Expand Down Expand Up @@ -3108,6 +3109,7 @@ LIBGRPC_CRONET_SRC = \
src/core/ext/client_channel/connector.c \
src/core/ext/client_channel/default_initial_connect_string.c \
src/core/ext/client_channel/http_connect_handshaker.c \
src/core/ext/client_channel/http_proxy.c \
src/core/ext/client_channel/initial_connect_string.c \
src/core/ext/client_channel/lb_policy.c \
src/core/ext/client_channel/lb_policy_factory.c \
Expand Down Expand Up @@ -3624,6 +3626,7 @@ LIBGRPC_UNSECURE_SRC = \
src/core/ext/client_channel/connector.c \
src/core/ext/client_channel/default_initial_connect_string.c \
src/core/ext/client_channel/http_connect_handshaker.c \
src/core/ext/client_channel/http_proxy.c \
src/core/ext/client_channel/initial_connect_string.c \
src/core/ext/client_channel/lb_policy.c \
src/core/ext/client_channel/lb_policy_factory.c \
Expand Down Expand Up @@ -4182,6 +4185,7 @@ LIBGRPC++_CRONET_SRC = \
src/core/ext/client_channel/connector.c \
src/core/ext/client_channel/default_initial_connect_string.c \
src/core/ext/client_channel/http_connect_handshaker.c \
src/core/ext/client_channel/http_proxy.c \
src/core/ext/client_channel/initial_connect_string.c \
src/core/ext/client_channel/lb_policy.c \
src/core/ext/client_channel/lb_policy_factory.c \
Expand Down
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@
'src/core/ext/client_channel/connector.c',
'src/core/ext/client_channel/default_initial_connect_string.c',
'src/core/ext/client_channel/http_connect_handshaker.c',
'src/core/ext/client_channel/http_proxy.c',
'src/core/ext/client_channel/initial_connect_string.c',
'src/core/ext/client_channel/lb_policy.c',
'src/core/ext/client_channel/lb_policy_factory.c',
Expand Down
2 changes: 2 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ filegroups:
- src/core/ext/client_channel/client_channel_factory.h
- src/core/ext/client_channel/connector.h
- src/core/ext/client_channel/http_connect_handshaker.h
- src/core/ext/client_channel/http_proxy.h
- src/core/ext/client_channel/initial_connect_string.h
- src/core/ext/client_channel/lb_policy.h
- src/core/ext/client_channel/lb_policy_factory.h
Expand All @@ -408,6 +409,7 @@ filegroups:
- src/core/ext/client_channel/connector.c
- src/core/ext/client_channel/default_initial_connect_string.c
- src/core/ext/client_channel/http_connect_handshaker.c
- src/core/ext/client_channel/http_proxy.c
- src/core/ext/client_channel/initial_connect_string.c
- src/core/ext/client_channel/lb_policy.c
- src/core/ext/client_channel/lb_policy_factory.c
Expand Down
1 change: 1 addition & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/ext/client_channel/connector.c \
src/core/ext/client_channel/default_initial_connect_string.c \
src/core/ext/client_channel/http_connect_handshaker.c \
src/core/ext/client_channel/http_proxy.c \
src/core/ext/client_channel/initial_connect_string.c \
src/core/ext/client_channel/lb_policy.c \
src/core/ext/client_channel/lb_policy_factory.c \
Expand Down
3 changes: 3 additions & 0 deletions gRPC-Core.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ Pod::Spec.new do |s|
'src/core/ext/client_channel/client_channel_factory.h',
'src/core/ext/client_channel/connector.h',
'src/core/ext/client_channel/http_connect_handshaker.h',
'src/core/ext/client_channel/http_proxy.h',
'src/core/ext/client_channel/initial_connect_string.h',
'src/core/ext/client_channel/lb_policy.h',
'src/core/ext/client_channel/lb_policy_factory.h',
Expand Down Expand Up @@ -606,6 +607,7 @@ Pod::Spec.new do |s|
'src/core/ext/client_channel/connector.c',
'src/core/ext/client_channel/default_initial_connect_string.c',
'src/core/ext/client_channel/http_connect_handshaker.c',
'src/core/ext/client_channel/http_proxy.c',
'src/core/ext/client_channel/initial_connect_string.c',
'src/core/ext/client_channel/lb_policy.c',
'src/core/ext/client_channel/lb_policy_factory.c',
Expand Down Expand Up @@ -812,6 +814,7 @@ Pod::Spec.new do |s|
'src/core/ext/client_channel/client_channel_factory.h',
'src/core/ext/client_channel/connector.h',
'src/core/ext/client_channel/http_connect_handshaker.h',
'src/core/ext/client_channel/http_proxy.h',
'src/core/ext/client_channel/initial_connect_string.h',
'src/core/ext/client_channel/lb_policy.h',
'src/core/ext/client_channel/lb_policy_factory.h',
Expand Down
2 changes: 2 additions & 0 deletions grpc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/ext/client_channel/client_channel_factory.h )
s.files += %w( src/core/ext/client_channel/connector.h )
s.files += %w( src/core/ext/client_channel/http_connect_handshaker.h )
s.files += %w( src/core/ext/client_channel/http_proxy.h )
s.files += %w( src/core/ext/client_channel/initial_connect_string.h )
s.files += %w( src/core/ext/client_channel/lb_policy.h )
s.files += %w( src/core/ext/client_channel/lb_policy_factory.h )
Expand Down Expand Up @@ -523,6 +524,7 @@ Gem::Specification.new do |s|
s.files += %w( src/core/ext/client_channel/connector.c )
s.files += %w( src/core/ext/client_channel/default_initial_connect_string.c )
s.files += %w( src/core/ext/client_channel/http_connect_handshaker.c )
s.files += %w( src/core/ext/client_channel/http_proxy.c )
s.files += %w( src/core/ext/client_channel/initial_connect_string.c )
s.files += %w( src/core/ext/client_channel/lb_policy.c )
s.files += %w( src/core/ext/client_channel/lb_policy_factory.c )
Expand Down
2 changes: 2 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
<file baseinstalldir="/" name="src/core/ext/client_channel/client_channel_factory.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/connector.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/http_connect_handshaker.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/http_proxy.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/initial_connect_string.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/lb_policy.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/lb_policy_factory.h" role="src" />
Expand Down Expand Up @@ -532,6 +533,7 @@
<file baseinstalldir="/" name="src/core/ext/client_channel/connector.c" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/default_initial_connect_string.c" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/http_connect_handshaker.c" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/http_proxy.c" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/initial_connect_string.c" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/lb_policy.c" role="src" />
<file baseinstalldir="/" name="src/core/ext/client_channel/lb_policy_factory.c" role="src" />
Expand Down
29 changes: 25 additions & 4 deletions src/core/ext/client_channel/client_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include <grpc/support/sync.h>
#include <grpc/support/useful.h>

#include "src/core/ext/client_channel/http_connect_handshaker.h"
#include "src/core/ext/client_channel/http_proxy.h"
#include "src/core/ext/client_channel/lb_policy_registry.h"
#include "src/core/ext/client_channel/resolver_registry.h"
#include "src/core/ext/client_channel/subchannel.h"
Expand Down Expand Up @@ -150,6 +152,10 @@ static void *method_parameters_create_from_json(const grpc_json *json) {
*/

typedef struct client_channel_channel_data {
/** server name */
char *server_name;
/** HTTP CONNECT proxy to use, if any */
char *proxy_name;
/** resolver for this channel */
grpc_resolver *resolver;
/** have we started resolving this channel */
Expand Down Expand Up @@ -310,6 +316,17 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg,
// Use pick_first if nothing was specified and we didn't select grpclb
// above.
if (lb_policy_name == NULL) lb_policy_name = "pick_first";
// If using a proxy, add channel arg for server in HTTP CONNECT request.
if (chand->proxy_name != NULL) {
grpc_arg new_arg;
new_arg.key = GRPC_ARG_HTTP_CONNECT_SERVER;
new_arg.type = GRPC_ARG_STRING;
new_arg.value.string = chand->server_name;
grpc_channel_args *tmp_args = chand->resolver_result;
chand->resolver_result =
grpc_channel_args_copy_and_add(chand->resolver_result, &new_arg, 1);
grpc_channel_args_destroy(exec_ctx, tmp_args);
}
// Instantiate LB policy.
grpc_lb_policy_args lb_policy_args;
lb_policy_args.args = chand->resolver_result;
Expand Down Expand Up @@ -528,9 +545,12 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx,
arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI);
GPR_ASSERT(arg != NULL);
GPR_ASSERT(arg->type == GRPC_ARG_STRING);
chand->resolver =
grpc_resolver_create(exec_ctx, arg->value.string, args->channel_args,
chand->interested_parties);
chand->server_name = gpr_strdup(arg->value.string);
chand->proxy_name = grpc_get_http_proxy_server();
char *name_to_resolve =
chand->proxy_name == NULL ? chand->server_name : chand->proxy_name;
chand->resolver = grpc_resolver_create(
exec_ctx, name_to_resolve, args->channel_args, chand->interested_parties);
if (chand->resolver == NULL) {
return GRPC_ERROR_CREATE("resolver creation failed");
}
Expand All @@ -541,7 +561,8 @@ static grpc_error *cc_init_channel_elem(grpc_exec_ctx *exec_ctx,
static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx,
grpc_channel_element *elem) {
channel_data *chand = elem->channel_data;

gpr_free(chand->server_name);
gpr_free(chand->proxy_name);
if (chand->resolver != NULL) {
grpc_resolver_shutdown(exec_ctx, chand->resolver);
GRPC_RESOLVER_UNREF(exec_ctx, chand->resolver, "channel");
Expand Down
Loading

0 comments on commit 674fe85

Please sign in to comment.