Skip to content

Commit

Permalink
Merge github.com:grpc/grpc into plucking-hell
Browse files Browse the repository at this point in the history
Conflicts:
	Makefile
  • Loading branch information
ctiller committed Aug 1, 2015
2 parents 85c2a08 + 7716c53 commit 42ce225
Show file tree
Hide file tree
Showing 231 changed files with 1,885 additions and 362 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ coverage

# Makefile's cache
cache.mk

# Temporary test reports
report.xml
12 changes: 12 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ cc_library(
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
"src/core/client_config/subchannel_factory_decorators/add_channel_arg.h",
"src/core/client_config/subchannel_factory_decorators/merge_channel_args.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/message_compress.h",
"src/core/debug/trace.h",
Expand Down Expand Up @@ -289,6 +291,8 @@ cc_library(
"src/core/client_config/resolvers/sockaddr_resolver.c",
"src/core/client_config/subchannel.c",
"src/core/client_config/subchannel_factory.c",
"src/core/client_config/subchannel_factory_decorators/add_channel_arg.c",
"src/core/client_config/subchannel_factory_decorators/merge_channel_args.c",
"src/core/client_config/uri_parser.c",
"src/core/compression/algorithm.c",
"src/core/compression/message_compress.c",
Expand Down Expand Up @@ -426,6 +430,8 @@ cc_library(
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
"src/core/client_config/subchannel_factory_decorators/add_channel_arg.h",
"src/core/client_config/subchannel_factory_decorators/merge_channel_args.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/message_compress.h",
"src/core/debug/trace.h",
Expand Down Expand Up @@ -522,6 +528,8 @@ cc_library(
"src/core/client_config/resolvers/sockaddr_resolver.c",
"src/core/client_config/subchannel.c",
"src/core/client_config/subchannel_factory.c",
"src/core/client_config/subchannel_factory_decorators/add_channel_arg.c",
"src/core/client_config/subchannel_factory_decorators/merge_channel_args.c",
"src/core/client_config/uri_parser.c",
"src/core/compression/algorithm.c",
"src/core/compression/message_compress.c",
Expand Down Expand Up @@ -1005,6 +1013,8 @@ objc_library(
"src/core/client_config/resolvers/sockaddr_resolver.c",
"src/core/client_config/subchannel.c",
"src/core/client_config/subchannel_factory.c",
"src/core/client_config/subchannel_factory_decorators/add_channel_arg.c",
"src/core/client_config/subchannel_factory_decorators/merge_channel_args.c",
"src/core/client_config/uri_parser.c",
"src/core/compression/algorithm.c",
"src/core/compression/message_compress.c",
Expand Down Expand Up @@ -1144,6 +1154,8 @@ objc_library(
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
"src/core/client_config/subchannel_factory_decorators/add_channel_arg.h",
"src/core/client_config/subchannel_factory_decorators/merge_channel_args.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/message_compress.h",
"src/core/debug/trace.h",
Expand Down
243 changes: 225 additions & 18 deletions Makefile

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
"src/core/client_config/resolvers/sockaddr_resolver.h",
"src/core/client_config/subchannel.h",
"src/core/client_config/subchannel_factory.h",
"src/core/client_config/subchannel_factory_decorators/add_channel_arg.h",
"src/core/client_config/subchannel_factory_decorators/merge_channel_args.h",
"src/core/client_config/uri_parser.h",
"src/core/compression/message_compress.h",
"src/core/debug/trace.h",
Expand Down Expand Up @@ -230,6 +232,8 @@
"src/core/client_config/resolvers/sockaddr_resolver.c",
"src/core/client_config/subchannel.c",
"src/core/client_config/subchannel_factory.c",
"src/core/client_config/subchannel_factory_decorators/add_channel_arg.c",
"src/core/client_config/subchannel_factory_decorators/merge_channel_args.c",
"src/core/client_config/uri_parser.c",
"src/core/compression/algorithm.c",
"src/core/compression/message_compress.c",
Expand Down
6 changes: 6 additions & 0 deletions gRPC.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ Pod::Spec.new do |s|
'src/core/client_config/resolvers/sockaddr_resolver.h',
'src/core/client_config/subchannel.h',
'src/core/client_config/subchannel_factory.h',
'src/core/client_config/subchannel_factory_decorators/add_channel_arg.h',
'src/core/client_config/subchannel_factory_decorators/merge_channel_args.h',
'src/core/client_config/uri_parser.h',
'src/core/compression/message_compress.h',
'src/core/debug/trace.h',
Expand Down Expand Up @@ -298,6 +300,8 @@ Pod::Spec.new do |s|
'src/core/client_config/resolvers/sockaddr_resolver.c',
'src/core/client_config/subchannel.c',
'src/core/client_config/subchannel_factory.c',
'src/core/client_config/subchannel_factory_decorators/add_channel_arg.c',
'src/core/client_config/subchannel_factory_decorators/merge_channel_args.c',
'src/core/client_config/uri_parser.c',
'src/core/compression/algorithm.c',
'src/core/compression/message_compress.c',
Expand Down Expand Up @@ -436,6 +440,8 @@ Pod::Spec.new do |s|
'src/core/client_config/resolvers/sockaddr_resolver.h',
'src/core/client_config/subchannel.h',
'src/core/client_config/subchannel_factory.h',
'src/core/client_config/subchannel_factory_decorators/add_channel_arg.h',
'src/core/client_config/subchannel_factory_decorators/merge_channel_args.h',
'src/core/client_config/uri_parser.h',
'src/core/compression/message_compress.h',
'src/core/debug/trace.h',
Expand Down
2 changes: 2 additions & 0 deletions include/grpc/grpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ typedef struct {
/** Initial sequence number for http2 transports */
#define GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER \
"grpc.http2.initial_sequence_number"
/** Default authority to pass if none specified on call construction */
#define GRPC_ARG_DEFAULT_AUTHORITY "grpc.default_authority"
/** Primary user agent: goes at the start of the user-agent metadata
sent on each request */
#define GRPC_ARG_PRIMARY_USER_AGENT_STRING "grpc.primary_user_agent"
Expand Down
2 changes: 2 additions & 0 deletions include/grpc/support/atm_gcc_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ typedef gpr_intptr gpr_atm;
#define gpr_atm_no_barrier_load(p) (__atomic_load_n((p), __ATOMIC_RELAXED))
#define gpr_atm_rel_store(p, value) \
(__atomic_store_n((p), (gpr_intptr)(value), __ATOMIC_RELEASE))
#define gpr_atm_no_barrier_store(p, value) \
(__atomic_store_n((p), (gpr_intptr)(value), __ATOMIC_RELAXED))

#define gpr_atm_no_barrier_fetch_add(p, delta) \
(__atomic_fetch_add((p), (gpr_intptr)(delta), __ATOMIC_RELAXED))
Expand Down
5 changes: 5 additions & 0 deletions include/grpc/support/atm_gcc_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
*p = value;
}

static __inline void gpr_atm_no_barrier_store(gpr_atm *p, gpr_atm value) {
GPR_ATM_COMPILE_BARRIER_();
*p = value;
}

#undef GPR_ATM_LS_BARRIER_
#undef GPR_ATM_COMPILE_BARRIER_

Expand Down
5 changes: 5 additions & 0 deletions include/grpc/support/atm_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ static __inline void gpr_atm_rel_store(gpr_atm *p, gpr_atm value) {
*p = value;
}

static __inline void gpr_atm_no_barrier_store(gpr_atm *p, gpr_atm value) {
/* TODO(ctiller): Can we implement something better here? */
gpr_atm_rel_store(p, value);
}

static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
/* InterlockedCompareExchangePointerNoFence() not available on vista or
windows7 */
Expand Down
44 changes: 39 additions & 5 deletions src/core/channel/http_client_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
typedef struct call_data {
grpc_linked_mdelem method;
grpc_linked_mdelem scheme;
grpc_linked_mdelem authority;
grpc_linked_mdelem te_trailers;
grpc_linked_mdelem content_type;
grpc_linked_mdelem user_agent;
int sent_initial_metadata;
int sent_authority;

int got_initial_metadata;
grpc_stream_op_buffer *recv_ops;
Expand All @@ -62,6 +64,7 @@ typedef struct channel_data {
grpc_mdelem *scheme;
grpc_mdelem *content_type;
grpc_mdelem *status;
grpc_mdelem *default_authority;
/** complete user agent mdelem */
grpc_mdelem *user_agent;
} channel_data;
Expand Down Expand Up @@ -100,13 +103,18 @@ static void hc_on_recv(void *user_data, int success) {

static grpc_mdelem *client_strip_filter(void *user_data, grpc_mdelem *md) {
grpc_call_element *elem = user_data;
call_data *calld = elem->call_data;
channel_data *channeld = elem->channel_data;
/* eat the things we'd like to set ourselves */
if (md->key == channeld->method->key) return NULL;
if (md->key == channeld->scheme->key) return NULL;
if (md->key == channeld->te_trailers->key) return NULL;
if (md->key == channeld->content_type->key) return NULL;
if (md->key == channeld->user_agent->key) return NULL;
if (channeld->default_authority &&
channeld->default_authority->key == md->key) {
calld->sent_authority = 1;
}
return md;
}

Expand All @@ -130,6 +138,11 @@ static void hc_mutate_op(grpc_call_element *elem,
GRPC_MDELEM_REF(channeld->method));
grpc_metadata_batch_add_head(&op->data.metadata, &calld->scheme,
GRPC_MDELEM_REF(channeld->scheme));
if (channeld->default_authority && !calld->sent_authority) {
grpc_metadata_batch_add_head(
&op->data.metadata, &calld->authority,
GRPC_MDELEM_REF(channeld->default_authority));
}
grpc_metadata_batch_add_tail(&op->data.metadata, &calld->te_trailers,
GRPC_MDELEM_REF(channeld->te_trailers));
grpc_metadata_batch_add_tail(&op->data.metadata, &calld->content_type,
Expand Down Expand Up @@ -162,6 +175,7 @@ static void init_call_elem(grpc_call_element *elem,
call_data *calld = elem->call_data;
calld->sent_initial_metadata = 0;
calld->got_initial_metadata = 0;
calld->sent_authority = 0;
calld->on_done_recv = NULL;
grpc_iomgr_closure_init(&calld->hc_on_recv, hc_on_recv, elem);
if (initial_op) hc_mutate_op(elem, initial_op);
Expand Down Expand Up @@ -241,8 +255,10 @@ static grpc_mdstr *user_agent_from_args(grpc_mdctx *mdctx,

/* Constructor for channel_data */
static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
const grpc_channel_args *args, grpc_mdctx *mdctx,
int is_first, int is_last) {
const grpc_channel_args *channel_args,
grpc_mdctx *mdctx, int is_first, int is_last) {
size_t i;

/* grab pointers to our data from the channel element */
channel_data *channeld = elem->channel_data;

Expand All @@ -251,17 +267,32 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
path */
GPR_ASSERT(!is_last);

channeld->default_authority = NULL;
if (channel_args) {
for (i = 0; i < channel_args->num_args; i++) {
if (0 == strcmp(channel_args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) {
if (channel_args->args[i].type != GRPC_ARG_STRING) {
gpr_log(GPR_ERROR, "%s: must be an string",
GRPC_ARG_DEFAULT_AUTHORITY);
} else {
channeld->default_authority = grpc_mdelem_from_strings(
mdctx, ":authority", channel_args->args[i].value.string);
}
}
}
}

/* initialize members */
channeld->te_trailers = grpc_mdelem_from_strings(mdctx, "te", "trailers");
channeld->method = grpc_mdelem_from_strings(mdctx, ":method", "POST");
channeld->scheme =
grpc_mdelem_from_strings(mdctx, ":scheme", scheme_from_args(args));
channeld->scheme = grpc_mdelem_from_strings(mdctx, ":scheme",
scheme_from_args(channel_args));
channeld->content_type =
grpc_mdelem_from_strings(mdctx, "content-type", "application/grpc");
channeld->status = grpc_mdelem_from_strings(mdctx, ":status", "200");
channeld->user_agent = grpc_mdelem_from_metadata_strings(
mdctx, grpc_mdstr_from_string(mdctx, "user-agent", 0),
user_agent_from_args(mdctx, args));
user_agent_from_args(mdctx, channel_args));
}

/* Destructor for channel data */
Expand All @@ -275,6 +306,9 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
GRPC_MDELEM_UNREF(channeld->content_type);
GRPC_MDELEM_UNREF(channeld->status);
GRPC_MDELEM_UNREF(channeld->user_agent);
if (channeld->default_authority) {
GRPC_MDELEM_UNREF(channeld->default_authority);
}
}

const grpc_channel_filter grpc_http_client_filter = {
Expand Down
10 changes: 9 additions & 1 deletion src/core/channel/http_server_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct call_data {
gpr_uint8 sent_status;
gpr_uint8 seen_scheme;
gpr_uint8 seen_te_trailers;
gpr_uint8 seen_authority;
grpc_linked_mdelem status;

grpc_stream_op_buffer *recv_ops;
Expand Down Expand Up @@ -125,13 +126,17 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) {
}
calld->seen_path = 1;
return md;
} else if (md->key == channeld->authority_key) {
calld->seen_authority = 1;
return md;
} else if (md->key == channeld->host_key) {
/* translate host to :authority since :authority may be
omitted */
grpc_mdelem *authority = grpc_mdelem_from_metadata_strings(
channeld->mdctx, GRPC_MDSTR_REF(channeld->authority_key),
GRPC_MDSTR_REF(md->value));
GRPC_MDELEM_UNREF(md);
calld->seen_authority = 1;
return authority;
} else {
return md;
Expand All @@ -154,12 +159,15 @@ static void hs_on_recv(void *user_data, int success) {
(:method, :scheme, content-type, with :path and :authority covered
at the channel level right now) */
if (calld->seen_post && calld->seen_scheme && calld->seen_te_trailers &&
calld->seen_path) {
calld->seen_path && calld->seen_authority) {
/* do nothing */
} else {
if (!calld->seen_path) {
gpr_log(GPR_ERROR, "Missing :path header");
}
if (!calld->seen_authority) {
gpr_log(GPR_ERROR, "Missing :authority header");
}
if (!calld->seen_post) {
gpr_log(GPR_ERROR, "Missing :method header");
}
Expand Down
16 changes: 15 additions & 1 deletion src/core/client_config/resolvers/dns_resolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
#include <string.h>

#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/string_util.h>

#include "src/core/client_config/lb_policies/pick_first.h"
#include "src/core/client_config/subchannel_factory_decorators/add_channel_arg.h"
#include "src/core/iomgr/resolve_address.h"
#include "src/core/support/string.h"

Expand Down Expand Up @@ -201,6 +203,9 @@ static grpc_resolver *dns_create(
grpc_subchannel_factory *subchannel_factory) {
dns_resolver *r;
const char *path = uri->path;
grpc_arg default_host_arg;
char *host;
char *port;

if (0 != strcmp(uri->authority, "")) {
gpr_log(GPR_ERROR, "authority based uri's not supported");
Expand All @@ -209,6 +214,16 @@ static grpc_resolver *dns_create(

if (path[0] == '/') ++path;

gpr_split_host_port(path, &host, &port);

default_host_arg.type = GRPC_ARG_STRING;
default_host_arg.key = GRPC_ARG_DEFAULT_AUTHORITY;
default_host_arg.value.string = host;
subchannel_factory = grpc_subchannel_factory_add_channel_arg(subchannel_factory, &default_host_arg);

gpr_free(host);
gpr_free(port);

r = gpr_malloc(sizeof(dns_resolver));
memset(r, 0, sizeof(*r));
gpr_ref_init(&r->refs, 1);
Expand All @@ -218,7 +233,6 @@ static grpc_resolver *dns_create(
r->default_port = gpr_strdup(default_port);
r->subchannel_factory = subchannel_factory;
r->lb_policy_factory = lb_policy_factory;
grpc_subchannel_factory_ref(subchannel_factory);
return &r->base;
}

Expand Down
Loading

0 comments on commit 42ce225

Please sign in to comment.