Merge pull request #6804 from ctiller/plugin_advertisement

Advertise transport selected in user-agent string
pull/6265/merge
Jan Tattermusch 9 years ago committed by GitHub
commit 216e1a18a9
  1. 2
      src/core/lib/channel/channel_stack.c
  2. 3
      src/core/lib/channel/channel_stack.h
  3. 4
      src/core/lib/channel/channel_stack_builder.c
  4. 13
      src/core/lib/channel/http_client_filter.c
  5. 2
      src/core/lib/channel/http_client_filter.h
  6. 2
      test/core/channel/channel_stack_test.c

@ -106,6 +106,7 @@ void grpc_channel_stack_init(grpc_exec_ctx *exec_ctx, int initial_refs,
const grpc_channel_filter **filters, const grpc_channel_filter **filters,
size_t filter_count, size_t filter_count,
const grpc_channel_args *channel_args, const grpc_channel_args *channel_args,
grpc_transport *optional_transport,
const char *name, grpc_channel_stack *stack) { const char *name, grpc_channel_stack *stack) {
size_t call_size = size_t call_size =
ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call_stack)) + ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(grpc_call_stack)) +
@ -127,6 +128,7 @@ void grpc_channel_stack_init(grpc_exec_ctx *exec_ctx, int initial_refs,
for (i = 0; i < filter_count; i++) { for (i = 0; i < filter_count; i++) {
args.channel_stack = stack; args.channel_stack = stack;
args.channel_args = channel_args; args.channel_args = channel_args;
args.optional_transport = optional_transport;
args.is_first = i == 0; args.is_first = i == 0;
args.is_last = i == (filter_count - 1); args.is_last = i == (filter_count - 1);
elems[i].filter = filters[i]; elems[i].filter = filters[i];

@ -60,6 +60,8 @@ typedef struct grpc_call_stack grpc_call_stack;
typedef struct { typedef struct {
grpc_channel_stack *channel_stack; grpc_channel_stack *channel_stack;
const grpc_channel_args *channel_args; const grpc_channel_args *channel_args;
/** Transport, iff it is known */
grpc_transport *optional_transport;
int is_first; int is_first;
int is_last; int is_last;
} grpc_channel_element_args; } grpc_channel_element_args;
@ -198,6 +200,7 @@ void grpc_channel_stack_init(grpc_exec_ctx *exec_ctx, int initial_refs,
grpc_iomgr_cb_func destroy, void *destroy_arg, grpc_iomgr_cb_func destroy, void *destroy_arg,
const grpc_channel_filter **filters, const grpc_channel_filter **filters,
size_t filter_count, const grpc_channel_args *args, size_t filter_count, const grpc_channel_args *args,
grpc_transport *optional_transport,
const char *name, grpc_channel_stack *stack); const char *name, grpc_channel_stack *stack);
/* Destroy a channel stack */ /* Destroy a channel stack */
void grpc_channel_stack_destroy(grpc_exec_ctx *exec_ctx, void grpc_channel_stack_destroy(grpc_exec_ctx *exec_ctx,

@ -257,8 +257,8 @@ void *grpc_channel_stack_builder_finish(grpc_exec_ctx *exec_ctx,
// and initialize it // and initialize it
grpc_channel_stack_init(exec_ctx, initial_refs, destroy, grpc_channel_stack_init(exec_ctx, initial_refs, destroy,
destroy_arg == NULL ? result : destroy_arg, filters, destroy_arg == NULL ? result : destroy_arg, filters,
num_filters, builder->args, builder->name, num_filters, builder->args, builder->transport,
channel_stack); builder->name, channel_stack);
// run post-initialization functions // run post-initialization functions
i = 0; i = 0;

@ -38,6 +38,7 @@
#include "src/core/lib/profiling/timers.h" #include "src/core/lib/profiling/timers.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
#include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/static_metadata.h"
#include "src/core/lib/transport/transport_impl.h"
#define EXPECTED_CONTENT_TYPE "application/grpc" #define EXPECTED_CONTENT_TYPE "application/grpc"
#define EXPECTED_CONTENT_TYPE_LENGTH sizeof(EXPECTED_CONTENT_TYPE) - 1 #define EXPECTED_CONTENT_TYPE_LENGTH sizeof(EXPECTED_CONTENT_TYPE) - 1
@ -199,7 +200,8 @@ static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) {
return GRPC_MDELEM_SCHEME_HTTP; return GRPC_MDELEM_SCHEME_HTTP;
} }
static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args) { static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args,
const char *transport_name) {
gpr_strvec v; gpr_strvec v;
size_t i; size_t i;
int is_first = 1; int is_first = 1;
@ -221,8 +223,8 @@ static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args) {
} }
} }
gpr_asprintf(&tmp, "%sgrpc-c/%s (%s)", is_first ? "" : " ", gpr_asprintf(&tmp, "%sgrpc-c/%s (%s; %s)", is_first ? "" : " ",
grpc_version_string(), GPR_PLATFORM_STRING); grpc_version_string(), GPR_PLATFORM_STRING, transport_name);
is_first = 0; is_first = 0;
gpr_strvec_add(&v, tmp); gpr_strvec_add(&v, tmp);
@ -253,9 +255,12 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx,
grpc_channel_element_args *args) { grpc_channel_element_args *args) {
channel_data *chand = elem->channel_data; channel_data *chand = elem->channel_data;
GPR_ASSERT(!args->is_last); GPR_ASSERT(!args->is_last);
GPR_ASSERT(args->optional_transport != NULL);
chand->static_scheme = scheme_from_args(args->channel_args); chand->static_scheme = scheme_from_args(args->channel_args);
chand->user_agent = grpc_mdelem_from_metadata_strings( chand->user_agent = grpc_mdelem_from_metadata_strings(
GRPC_MDSTR_USER_AGENT, user_agent_from_args(args->channel_args)); GRPC_MDSTR_USER_AGENT,
user_agent_from_args(args->channel_args,
args->optional_transport->vtable->name));
} }
/* Destructor for channel data */ /* Destructor for channel data */

@ -1,5 +1,4 @@
/* /*
*
* Copyright 2015, Google Inc. * Copyright 2015, Google Inc.
* All rights reserved. * All rights reserved.
* *
@ -39,6 +38,7 @@
/* Processes metadata on the client side for HTTP2 transports */ /* Processes metadata on the client side for HTTP2 transports */
extern const grpc_channel_filter grpc_http_client_filter; extern const grpc_channel_filter grpc_http_client_filter;
/* Channel arg to override the http2 :scheme header */
#define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme" #define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme"
#endif /* GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H */ #endif /* GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H */

@ -124,7 +124,7 @@ static void test_create_channel_stack(void) {
channel_stack = gpr_malloc(grpc_channel_stack_size(&filters, 1)); channel_stack = gpr_malloc(grpc_channel_stack_size(&filters, 1));
grpc_channel_stack_init(&exec_ctx, 1, free_channel, channel_stack, &filters, grpc_channel_stack_init(&exec_ctx, 1, free_channel, channel_stack, &filters,
1, &chan_args, "test", channel_stack); 1, &chan_args, NULL, "test", channel_stack);
GPR_ASSERT(channel_stack->count == 1); GPR_ASSERT(channel_stack->count == 1);
channel_elem = grpc_channel_stack_element(channel_stack, 0); channel_elem = grpc_channel_stack_element(channel_stack, 0);
channel_data = (int *)channel_elem->channel_data; channel_data = (int *)channel_elem->channel_data;

Loading…
Cancel
Save