aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2015-08-26 10:16:31 -0700
committerGravatar yang-g <yangg@google.com>2015-08-26 10:16:31 -0700
commit5e700f3d1fe24e7eed6d1b0414f5c083734df21d (patch)
treed8ff7c7db5cafe9501b9e48744d6801473ee6f15 /src
parentd090fe1379932d7d785fa805339110e70b96bd87 (diff)
parent60e0e743bed05b248c485949c6cd9e05fa02b607 (diff)
Merge remote-tracking branch 'upstream/master' into string_ref_auth
Diffstat (limited to 'src')
-rw-r--r--src/core/channel/compress_filter.h2
-rw-r--r--src/core/channel/http_client_filter.c33
-rw-r--r--src/core/client_config/resolver_factory.c8
-rw-r--r--src/core/client_config/resolver_factory.h12
-rw-r--r--src/core/client_config/resolver_registry.c91
-rw-r--r--src/core/client_config/resolver_registry.h15
-rw-r--r--src/core/client_config/resolvers/dns_resolver.c25
-rw-r--r--src/core/client_config/resolvers/sockaddr_resolver.c49
-rw-r--r--src/core/client_config/resolvers/zookeeper_resolver.c11
-rw-r--r--src/core/profiling/basic_timers.c10
-rw-r--r--src/core/support/time_posix.c14
-rw-r--r--src/core/support/time_precise.h (renamed from src/core/profiling/timers_preciseclock.h)56
-rw-r--r--src/core/support/time_win32.c4
-rw-r--r--src/core/surface/call.c5
-rw-r--r--src/core/surface/channel.c44
-rw-r--r--src/core/surface/init.c8
-rw-r--r--src/core/transport/metadata.c24
-rw-r--r--src/core/transport/metadata.h1
-rw-r--r--src/cpp/util/string_ref.cc4
-rw-r--r--src/python/grpcio_test/grpc_test/_adapter/_links_test.py4
-rw-r--r--src/python/grpcio_test/grpc_test/_cython/adapter_low_test.py2
-rw-r--r--src/python/grpcio_test/grpc_test/_links/_transmission_test.py18
-rw-r--r--src/python/grpcio_test/setup.py1
23 files changed, 269 insertions, 172 deletions
diff --git a/src/core/channel/compress_filter.h b/src/core/channel/compress_filter.h
index 0917e81ca4..415459bca6 100644
--- a/src/core/channel/compress_filter.h
+++ b/src/core/channel/compress_filter.h
@@ -36,7 +36,7 @@
#include "src/core/channel/channel_stack.h"
-#define GRPC_COMPRESS_REQUEST_ALGORITHM_KEY "internal:grpc-encoding-request"
+#define GRPC_COMPRESS_REQUEST_ALGORITHM_KEY "grpc-internal-encoding-request"
/** Compression filter for outgoing data.
*
diff --git a/src/core/channel/http_client_filter.c b/src/core/channel/http_client_filter.c
index 48c623d359..2b61d33c29 100644
--- a/src/core/channel/http_client_filter.c
+++ b/src/core/channel/http_client_filter.c
@@ -45,7 +45,6 @@ typedef struct call_data {
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;
@@ -64,7 +63,6 @@ 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;
@@ -103,7 +101,6 @@ 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;
@@ -111,10 +108,6 @@ static grpc_mdelem *client_strip_filter(void *user_data, grpc_mdelem *md) {
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;
}
@@ -138,11 +131,6 @@ 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,
@@ -175,7 +163,6 @@ 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);
@@ -257,8 +244,6 @@ static grpc_mdstr *user_agent_from_args(grpc_mdctx *mdctx,
static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
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;
@@ -267,21 +252,6 @@ 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");
@@ -306,9 +276,6 @@ 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 = {
diff --git a/src/core/client_config/resolver_factory.c b/src/core/client_config/resolver_factory.c
index 6721977e21..5b859a8d10 100644
--- a/src/core/client_config/resolver_factory.c
+++ b/src/core/client_config/resolver_factory.c
@@ -45,6 +45,12 @@ void grpc_resolver_factory_unref(grpc_resolver_factory *factory) {
grpc_resolver *grpc_resolver_factory_create_resolver(
grpc_resolver_factory *factory, grpc_uri *uri,
grpc_subchannel_factory *subchannel_factory) {
- if (!factory) return NULL;
+ if (factory == NULL) return NULL;
return factory->vtable->create_resolver(factory, uri, subchannel_factory);
}
+
+char *grpc_resolver_factory_get_default_authority(
+ grpc_resolver_factory *factory, grpc_uri *uri) {
+ if (factory == NULL) return NULL;
+ return factory->vtable->get_default_authority(factory, uri);
+}
diff --git a/src/core/client_config/resolver_factory.h b/src/core/client_config/resolver_factory.h
index c5d85499c6..e243b23988 100644
--- a/src/core/client_config/resolver_factory.h
+++ b/src/core/client_config/resolver_factory.h
@@ -51,9 +51,16 @@ struct grpc_resolver_factory_vtable {
void (*ref)(grpc_resolver_factory *factory);
void (*unref)(grpc_resolver_factory *factory);
+ /** Implementation of grpc_resolver_factory_create_resolver */
grpc_resolver *(*create_resolver)(
grpc_resolver_factory *factory, grpc_uri *uri,
grpc_subchannel_factory *subchannel_factory);
+
+ /** Implementation of grpc_resolver_factory_get_default_authority */
+ char *(*get_default_authority)(grpc_resolver_factory *factory, grpc_uri *uri);
+
+ /** URI scheme that this factory implements */
+ const char *scheme;
};
void grpc_resolver_factory_ref(grpc_resolver_factory *resolver);
@@ -64,4 +71,9 @@ grpc_resolver *grpc_resolver_factory_create_resolver(
grpc_resolver_factory *factory, grpc_uri *uri,
grpc_subchannel_factory *subchannel_factory);
+/** Return a (freshly allocated with gpr_malloc) string representing
+ the default authority to use for this scheme. */
+char *grpc_resolver_factory_get_default_authority(
+ grpc_resolver_factory *factory, grpc_uri *uri);
+
#endif /* GRPC_INTERNAL_CORE_CONFIG_RESOLVER_FACTORY_H */
diff --git a/src/core/client_config/resolver_registry.c b/src/core/client_config/resolver_registry.c
index 16be2da994..37979b3b86 100644
--- a/src/core/client_config/resolver_registry.c
+++ b/src/core/client_config/resolver_registry.c
@@ -41,41 +41,33 @@
#define MAX_RESOLVERS 10
-typedef struct {
- char *scheme;
- grpc_resolver_factory *factory;
-} registered_resolver;
-
-static registered_resolver g_all_of_the_resolvers[MAX_RESOLVERS];
+static grpc_resolver_factory *g_all_of_the_resolvers[MAX_RESOLVERS];
static int g_number_of_resolvers = 0;
-static char *g_default_resolver_scheme;
+static char *g_default_resolver_prefix;
-void grpc_resolver_registry_init(const char *default_resolver_scheme) {
+void grpc_resolver_registry_init(const char *default_resolver_prefix) {
g_number_of_resolvers = 0;
- g_default_resolver_scheme = gpr_strdup(default_resolver_scheme);
+ g_default_resolver_prefix = gpr_strdup(default_resolver_prefix);
}
void grpc_resolver_registry_shutdown(void) {
int i;
for (i = 0; i < g_number_of_resolvers; i++) {
- gpr_free(g_all_of_the_resolvers[i].scheme);
- grpc_resolver_factory_unref(g_all_of_the_resolvers[i].factory);
+ grpc_resolver_factory_unref(g_all_of_the_resolvers[i]);
}
- gpr_free(g_default_resolver_scheme);
+ gpr_free(g_default_resolver_prefix);
}
-void grpc_register_resolver_type(const char *scheme,
- grpc_resolver_factory *factory) {
+void grpc_register_resolver_type(grpc_resolver_factory *factory) {
int i;
for (i = 0; i < g_number_of_resolvers; i++) {
- GPR_ASSERT(0 != strcmp(scheme, g_all_of_the_resolvers[i].scheme));
+ GPR_ASSERT(0 != strcmp(factory->vtable->scheme,
+ g_all_of_the_resolvers[i]->vtable->scheme));
}
GPR_ASSERT(g_number_of_resolvers != MAX_RESOLVERS);
- g_all_of_the_resolvers[g_number_of_resolvers].scheme = gpr_strdup(scheme);
grpc_resolver_factory_ref(factory);
- g_all_of_the_resolvers[g_number_of_resolvers].factory = factory;
- g_number_of_resolvers++;
+ g_all_of_the_resolvers[g_number_of_resolvers++] = factory;
}
static grpc_resolver_factory *lookup_factory(grpc_uri *uri) {
@@ -85,40 +77,57 @@ static grpc_resolver_factory *lookup_factory(grpc_uri *uri) {
if (!uri) return NULL;
for (i = 0; i < g_number_of_resolvers; i++) {
- if (0 == strcmp(uri->scheme, g_all_of_the_resolvers[i].scheme)) {
- return g_all_of_the_resolvers[i].factory;
+ if (0 == strcmp(uri->scheme, g_all_of_the_resolvers[i]->vtable->scheme)) {
+ return g_all_of_the_resolvers[i];
}
}
return NULL;
}
-grpc_resolver *grpc_resolver_create(
- const char *name, grpc_subchannel_factory *subchannel_factory) {
- grpc_uri *uri;
+static grpc_resolver_factory *resolve_factory(const char *target,
+ grpc_uri **uri) {
char *tmp;
grpc_resolver_factory *factory = NULL;
- grpc_resolver *resolver;
-
- uri = grpc_uri_parse(name, 1);
- factory = lookup_factory(uri);
- if (factory == NULL && g_default_resolver_scheme != NULL) {
- grpc_uri_destroy(uri);
- gpr_asprintf(&tmp, "%s%s", g_default_resolver_scheme, name);
- uri = grpc_uri_parse(tmp, 1);
- factory = lookup_factory(uri);
- if (factory == NULL) {
- grpc_uri_destroy(grpc_uri_parse(name, 0));
- grpc_uri_destroy(grpc_uri_parse(tmp, 0));
- gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", name, tmp);
+
+ GPR_ASSERT(uri != NULL);
+ *uri = grpc_uri_parse(target, 1);
+ factory = lookup_factory(*uri);
+ if (factory == NULL) {
+ if (g_default_resolver_prefix != NULL) {
+ grpc_uri_destroy(*uri);
+ gpr_asprintf(&tmp, "%s%s", g_default_resolver_prefix, target);
+ *uri = grpc_uri_parse(tmp, 1);
+ factory = lookup_factory(*uri);
+ if (factory == NULL) {
+ grpc_uri_destroy(grpc_uri_parse(target, 0));
+ grpc_uri_destroy(grpc_uri_parse(tmp, 0));
+ gpr_log(GPR_ERROR, "don't know how to resolve '%s' or '%s'", target,
+ tmp);
+ }
+ gpr_free(tmp);
+ } else {
+ grpc_uri_destroy(grpc_uri_parse(target, 0));
+ gpr_log(GPR_ERROR, "don't know how to resolve '%s'", target);
}
- gpr_free(tmp);
- } else if (factory == NULL) {
- grpc_uri_destroy(grpc_uri_parse(name, 0));
- gpr_log(GPR_ERROR, "don't know how to resolve '%s'", name);
}
- resolver =
+ return factory;
+}
+
+grpc_resolver *grpc_resolver_create(
+ const char *target, grpc_subchannel_factory *subchannel_factory) {
+ grpc_uri *uri = NULL;
+ grpc_resolver_factory *factory = resolve_factory(target, &uri);
+ grpc_resolver *resolver =
grpc_resolver_factory_create_resolver(factory, uri, subchannel_factory);
grpc_uri_destroy(uri);
return resolver;
}
+
+char *grpc_get_default_authority(const char *target) {
+ grpc_uri *uri = NULL;
+ grpc_resolver_factory *factory = resolve_factory(target, &uri);
+ char *authority = grpc_resolver_factory_get_default_authority(factory, uri);
+ grpc_uri_destroy(uri);
+ return authority;
+}
diff --git a/src/core/client_config/resolver_registry.h b/src/core/client_config/resolver_registry.h
index 31aa47620a..5a7193b7ae 100644
--- a/src/core/client_config/resolver_registry.h
+++ b/src/core/client_config/resolver_registry.h
@@ -44,19 +44,22 @@ void grpc_resolver_registry_shutdown(void);
If \a priority is greater than zero, then the resolver will be eligible
to resolve names that are passed in with no scheme. Higher priority
resolvers will be tried before lower priority schemes. */
-void grpc_register_resolver_type(const char *scheme,
- grpc_resolver_factory *factory);
+void grpc_register_resolver_type(grpc_resolver_factory *factory);
-/** Create a resolver given \a name.
- First tries to parse \a name as a URI. If this succeeds, tries
+/** Create a resolver given \a target.
+ First tries to parse \a target as a URI. If this succeeds, tries
to locate a registered resolver factory based on the URI scheme.
If parsing or location fails, prefixes default_prefix from
- grpc_resolver_registry_init to name, and tries again (if default_prefix
+ grpc_resolver_registry_init to target, and tries again (if default_prefix
was not NULL).
If a resolver factory was found, use it to instantiate a resolver and
return it.
If a resolver factory was not found, return NULL. */
grpc_resolver *grpc_resolver_create(
- const char *name, grpc_subchannel_factory *subchannel_factory);
+ const char *target, grpc_subchannel_factory *subchannel_factory);
+
+/** Given a target, return a (freshly allocated with gpr_malloc) string
+ representing the default authority to pass from a client. */
+char *grpc_get_default_authority(const char *target);
#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_RESOLVER_REGISTRY_H */
diff --git a/src/core/client_config/resolvers/dns_resolver.c b/src/core/client_config/resolvers/dns_resolver.c
index 7b35b7902f..84643c464a 100644
--- a/src/core/client_config/resolvers/dns_resolver.c
+++ b/src/core/client_config/resolvers/dns_resolver.c
@@ -203,9 +203,6 @@ 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");
@@ -214,17 +211,6 @@ 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);
@@ -233,6 +219,7 @@ static grpc_resolver *dns_create(
r->name = gpr_strdup(path);
r->default_port = gpr_strdup(default_port);
r->subchannel_factory = subchannel_factory;
+ grpc_subchannel_factory_ref(subchannel_factory);
r->lb_policy_factory = lb_policy_factory;
return &r->base;
}
@@ -252,8 +239,16 @@ static grpc_resolver *dns_factory_create_resolver(
subchannel_factory);
}
+char *dns_factory_get_default_host_name(grpc_resolver_factory *factory,
+ grpc_uri *uri) {
+ const char *path = uri->path;
+ if (path[0] == '/') ++path;
+ return gpr_strdup(path);
+}
+
static const grpc_resolver_factory_vtable dns_factory_vtable = {
- dns_factory_ref, dns_factory_unref, dns_factory_create_resolver};
+ dns_factory_ref, dns_factory_unref, dns_factory_create_resolver,
+ dns_factory_get_default_host_name, "dns"};
static grpc_resolver_factory dns_resolver_factory = {&dns_factory_vtable};
grpc_resolver_factory *grpc_dns_resolver_factory_create() {
diff --git a/src/core/client_config/resolvers/sockaddr_resolver.c b/src/core/client_config/resolvers/sockaddr_resolver.c
index 8419873908..0d8540a566 100644
--- a/src/core/client_config/resolvers/sockaddr_resolver.c
+++ b/src/core/client_config/resolvers/sockaddr_resolver.c
@@ -166,8 +166,29 @@ static int parse_unix(grpc_uri *uri, struct sockaddr_storage *addr, int *len) {
return 1;
}
+
+static char *unix_get_default_authority(grpc_resolver_factory *factory,
+ grpc_uri *uri) {
+ return gpr_strdup("localhost");
+}
#endif
+static char *ip_get_default_authority(grpc_uri *uri) {
+ const char *path = uri->path;
+ if (path[0] == '/') ++path;
+ return gpr_strdup(path);
+}
+
+static char *ipv4_get_default_authority(grpc_resolver_factory *factory,
+ grpc_uri *uri) {
+ return ip_get_default_authority(uri);
+}
+
+static char *ipv6_get_default_authority(grpc_resolver_factory *factory,
+ grpc_uri *uri) {
+ return ip_get_default_authority(uri);
+}
+
static int parse_ipv4(grpc_uri *uri, struct sockaddr_storage *addr, int *len) {
const char *host_port = uri->path;
char *host;
@@ -313,20 +334,20 @@ static void sockaddr_factory_ref(grpc_resolver_factory *factory) {}
static void sockaddr_factory_unref(grpc_resolver_factory *factory) {}
-#define DECL_FACTORY(name) \
- static grpc_resolver *name##_factory_create_resolver( \
- grpc_resolver_factory *factory, grpc_uri *uri, \
- grpc_subchannel_factory *subchannel_factory) { \
- return sockaddr_create(uri, grpc_create_pick_first_lb_policy, \
- subchannel_factory, parse_##name); \
- } \
- static const grpc_resolver_factory_vtable name##_factory_vtable = { \
- sockaddr_factory_ref, sockaddr_factory_unref, \
- name##_factory_create_resolver}; \
- static grpc_resolver_factory name##_resolver_factory = { \
- &name##_factory_vtable}; \
- grpc_resolver_factory *grpc_##name##_resolver_factory_create() { \
- return &name##_resolver_factory; \
+#define DECL_FACTORY(name) \
+ static grpc_resolver *name##_factory_create_resolver( \
+ grpc_resolver_factory *factory, grpc_uri *uri, \
+ grpc_subchannel_factory *subchannel_factory) { \
+ return sockaddr_create(uri, grpc_create_pick_first_lb_policy, \
+ subchannel_factory, parse_##name); \
+ } \
+ static const grpc_resolver_factory_vtable name##_factory_vtable = { \
+ sockaddr_factory_ref, sockaddr_factory_unref, \
+ name##_factory_create_resolver, name##_get_default_authority, #name}; \
+ static grpc_resolver_factory name##_resolver_factory = { \
+ &name##_factory_vtable}; \
+ grpc_resolver_factory *grpc_##name##_resolver_factory_create() { \
+ return &name##_resolver_factory; \
}
#ifdef GPR_POSIX_SOCKET
diff --git a/src/core/client_config/resolvers/zookeeper_resolver.c b/src/core/client_config/resolvers/zookeeper_resolver.c
index acb2ba136e..da399f9954 100644
--- a/src/core/client_config/resolvers/zookeeper_resolver.c
+++ b/src/core/client_config/resolvers/zookeeper_resolver.c
@@ -467,8 +467,7 @@ static grpc_resolver *zookeeper_create(
}
static void zookeeper_plugin_init() {
- grpc_register_resolver_type("zookeeper",
- grpc_zookeeper_resolver_factory_create());
+ grpc_register_resolver_type(grpc_zookeeper_resolver_factory_create());
}
void grpc_zookeeper_register() {
@@ -483,6 +482,11 @@ static void zookeeper_factory_ref(grpc_resolver_factory *factory) {}
static void zookeeper_factory_unref(grpc_resolver_factory *factory) {}
+static char *zookeeper_factory_get_default_hostname(
+ grpc_resolver_factory *factory, grpc_uri *uri) {
+ return NULL;
+}
+
static grpc_resolver *zookeeper_factory_create_resolver(
grpc_resolver_factory *factory, grpc_uri *uri,
grpc_subchannel_factory *subchannel_factory) {
@@ -492,7 +496,8 @@ static grpc_resolver *zookeeper_factory_create_resolver(
static const grpc_resolver_factory_vtable zookeeper_factory_vtable = {
zookeeper_factory_ref, zookeeper_factory_unref,
- zookeeper_factory_create_resolver};
+ zookeeper_factory_create_resolver, zookeeper_factory_get_default_hostname,
+ "zookeeper"};
static grpc_resolver_factory zookeeper_resolver_factory = {
&zookeeper_factory_vtable};
diff --git a/src/core/profiling/basic_timers.c b/src/core/profiling/basic_timers.c
index ae37f584eb..4b6a0d2f56 100644
--- a/src/core/profiling/basic_timers.c
+++ b/src/core/profiling/basic_timers.c
@@ -36,7 +36,6 @@
#ifdef GRPC_BASIC_PROFILER
#include "src/core/profiling/timers.h"
-#include "src/core/profiling/timers_preciseclock.h"
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
@@ -53,7 +52,7 @@ typedef enum {
} marker_type;
typedef struct grpc_timer_entry {
- grpc_precise_clock tm;
+ gpr_timespec tm;
int tag;
const char* tagstr;
marker_type type;
@@ -71,9 +70,8 @@ static void log_report() {
int i;
for (i = 0; i < count; i++) {
grpc_timer_entry* entry = &(log[i]);
- printf("GRPC_LAT_PROF " GRPC_PRECISE_CLOCK_FORMAT
- " %p %c %d(%s) %p %s %d\n",
- GRPC_PRECISE_CLOCK_PRINTF_ARGS(&entry->tm),
+ printf("GRPC_LAT_PROF %ld.%09d %p %c %d(%s) %p %s %d\n",
+ entry->tm.tv_sec, entry->tm.tv_nsec,
(void*)(gpr_intptr)gpr_thd_currentid(), entry->type, entry->tag,
entry->tagstr, entry->id, entry->file, entry->line);
}
@@ -93,7 +91,7 @@ static void grpc_timers_log_add(int tag, const char* tagstr, marker_type type,
entry = &log[count++];
- grpc_precise_clock_now(&entry->tm);
+ entry->tm = gpr_now(GPR_CLOCK_PRECISE);
entry->tag = tag;
entry->tagstr = tagstr;
entry->type = type;
diff --git a/src/core/support/time_posix.c b/src/core/support/time_posix.c
index 841485c4b4..a274400243 100644
--- a/src/core/support/time_posix.c
+++ b/src/core/support/time_posix.c
@@ -32,6 +32,7 @@
*/
#include <grpc/support/port_platform.h>
+#include <src/core/support/time_precise.h>
#ifdef GPR_POSIX_TIME
@@ -66,8 +67,14 @@ void gpr_time_init(void) {}
gpr_timespec gpr_now(gpr_clock_type clock) {
struct timespec now;
GPR_ASSERT(clock != GPR_TIMESPAN);
- clock_gettime(clockid_for_gpr_clock[clock], &now);
- return gpr_from_timespec(now, clock);
+ if (clock == GPR_CLOCK_PRECISE) {
+ gpr_timespec ret;
+ gpr_precise_clock_now(&ret);
+ return ret;
+ } else {
+ clock_gettime(clockid_for_gpr_clock[clock], &now);
+ return gpr_from_timespec(now, clock);
+ }
}
#else
/* For some reason Apple's OSes haven't implemented clock_gettime. */
@@ -104,6 +111,9 @@ gpr_timespec gpr_now(gpr_clock_type clock) {
now.tv_sec = now_dbl * 1e-9;
now.tv_nsec = now_dbl - now.tv_sec * 1e9;
break;
+ case GPR_CLOCK_PRECISE:
+ gpr_precise_clock_now(&now);
+ break;
case GPR_TIMESPAN:
abort();
}
diff --git a/src/core/profiling/timers_preciseclock.h b/src/core/support/time_precise.h
index 5c251b47e6..574ebb8448 100644
--- a/src/core/profiling/timers_preciseclock.h
+++ b/src/core/support/time_precise.h
@@ -31,65 +31,63 @@
*
*/
-#ifndef GRPC_CORE_PROFILING_TIMERS_PRECISECLOCK_H
-#define GRPC_CORE_PROFILING_TIMERS_PRECISECLOCK_H
+#ifndef GRPC_CORE_SUPPORT_TIME_PRECISE_H_
+#define GRPC_CORE_SUPPORT_TIME_PRECISE_H_
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
#include <stdio.h>
#ifdef GRPC_TIMERS_RDTSC
-typedef long long int grpc_precise_clock;
#if defined(__i386__)
-static void grpc_precise_clock_now(grpc_precise_clock *clk) {
- grpc_precise_clock ret;
+static void gpr_get_cycle_counter(long long int *clk) {
+ long long int ret;
__asm__ volatile("rdtsc" : "=A"(ret));
*clk = ret;
}
// ----------------------------------------------------------------
#elif defined(__x86_64__) || defined(__amd64__)
-static void grpc_precise_clock_now(grpc_precise_clock *clk) {
+static void gpr_get_cycle_counter(long long int *clk) {
unsigned long long low, high;
__asm__ volatile("rdtsc" : "=a"(low), "=d"(high));
*clk = (high << 32) | low;
}
#endif
+
static gpr_once precise_clock_init = GPR_ONCE_INIT;
-static double cycles_per_second = 0.0;
-static void grpc_precise_clock_init() {
+static long long cycles_per_second = 0;
+static void gpr_precise_clock_init() {
time_t start = time(NULL);
- grpc_precise_clock start_time;
- grpc_precise_clock end_time;
+ gpr_precise_clock start_cycle;
+ gpr_precise_clock end_cycle;
while (time(NULL) == start)
;
- grpc_precise_clock_now(&start_time);
+ gpr_get_cycle_counter(&start_cycle);
while (time(NULL) == start + 1)
;
- grpc_precise_clock_now(&end_time);
- cycles_per_second = end_time - start_time;
+ gpr_get_cycle_counter(&end_cycle);
+ cycles_per_second = end_cycle - start_cycle;
}
+
static double grpc_precise_clock_scaling_factor() {
gpr_once_init(&precise_clock_init, grpc_precise_clock_init);
return 1e6 / cycles_per_second;
}
-#define GRPC_PRECISE_CLOCK_FORMAT "%f"
-#define GRPC_PRECISE_CLOCK_PRINTF_ARGS(clk) \
- (*(clk)*grpc_precise_clock_scaling_factor())
-#else
-typedef struct grpc_precise_clock grpc_precise_clock;
-struct grpc_precise_clock {
- gpr_timespec clock;
-};
-static void grpc_precise_clock_now(grpc_precise_clock* clk) {
- clk->clock = gpr_now(GPR_CLOCK_REALTIME);
+
+static void gpr_precise_clock_now(gpr_timespec *clk) {
+ long long int counter;
+ gpr_get_cycle_counter(&counter);
+ clk->clock = GPR_CLOCK_REALTIME;
+ clk->tv_sec = counter / cycles_per_second;
+ clk->tv_nsec = counter % cycles_per_second;
}
-#define GRPC_PRECISE_CLOCK_FORMAT "%ld.%09d"
-#define GRPC_PRECISE_CLOCK_PRINTF_ARGS(clk) \
- (clk)->clock.tv_sec, (clk)->clock.tv_nsec
-static void grpc_precise_clock_print(const grpc_precise_clock* clk, FILE* fp) {
- fprintf(fp, "%ld.%09d", clk->clock.tv_sec, clk->clock.tv_nsec);
+
+#else /* GRPC_TIMERS_RDTSC */
+static void gpr_precise_clock_now(gpr_timespec *clk) {
+ *clk = gpr_now(GPR_CLOCK_REALTIME);
+ clk->clock_type = GPR_CLOCK_PRECISE;
}
#endif /* GRPC_TIMERS_RDTSC */
-#endif /* GRPC_CORE_PROFILING_TIMERS_PRECISECLOCK_H */
+#endif /* GRPC_CORE_SUPPORT_TIME_PRECISE_ */
diff --git a/src/core/support/time_win32.c b/src/core/support/time_win32.c
index 7f64c80e27..f794855429 100644
--- a/src/core/support/time_win32.c
+++ b/src/core/support/time_win32.c
@@ -38,6 +38,7 @@
#ifdef GPR_WIN32
#include <grpc/support/time.h>
+#include <src/core/support/time_precise.h>
#include <sys/timeb.h>
static LARGE_INTEGER g_start_time;
@@ -68,6 +69,9 @@ gpr_timespec gpr_now(gpr_clock_type clock) {
now_tv.tv_sec = (time_t)now_dbl;
now_tv.tv_nsec = (int)((now_dbl - (double)now_tv.tv_sec) * 1e9);
break;
+ case GPR_CLOCK_PRECISE:
+ gpr_precise_clock_now(&now_tv);
+ break;
}
return now_tv;
}
diff --git a/src/core/surface/call.c b/src/core/surface/call.c
index 33f277da46..4426bbbce9 100644
--- a/src/core/surface/call.c
+++ b/src/core/surface/call.c
@@ -1046,10 +1046,11 @@ static int prepare_application_metadata(grpc_call *call, size_t count,
(const gpr_uint8 *)md->value,
md->value_length, 1);
if (!grpc_mdstr_is_legal_header(l->md->key)) {
- gpr_log(GPR_ERROR, "attempt to send invalid metadata key");
+ gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s",
+ grpc_mdstr_as_c_string(l->md->key));
return 0;
} else if (!grpc_mdstr_is_bin_suffixed(l->md->key) &&
- !grpc_mdstr_is_legal_header(l->md->value)) {
+ !grpc_mdstr_is_legal_nonbin_header(l->md->value)) {
gpr_log(GPR_ERROR, "attempt to send invalid metadata value");
return 0;
}
diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c
index e50251566d..586402e21c 100644
--- a/src/core/surface/channel.c
+++ b/src/core/surface/channel.c
@@ -40,6 +40,7 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
+#include "src/core/client_config/resolver_registry.h"
#include "src/core/iomgr/iomgr.h"
#include "src/core/support/string.h"
#include "src/core/surface/call.h"
@@ -70,6 +71,7 @@ struct grpc_channel {
grpc_mdstr *grpc_message_string;
grpc_mdstr *path_string;
grpc_mdstr *authority_string;
+ grpc_mdelem *default_authority;
/** mdelem for grpc-status: 0 thru grpc-status: 2 */
grpc_mdelem *grpc_status_elem[NUM_CACHED_STATUS_ELEMS];
@@ -134,10 +136,47 @@ grpc_channel *grpc_channel_create_from_filters(
} else {
channel->max_message_length = args->args[i].value.integer;
}
+ } else if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) {
+ if (args->args[i].type != GRPC_ARG_STRING) {
+ gpr_log(GPR_ERROR, "%s: must be an string",
+ GRPC_ARG_DEFAULT_AUTHORITY);
+ } else {
+ if (channel->default_authority) {
+ /* setting this takes precedence over anything else */
+ GRPC_MDELEM_UNREF(channel->default_authority);
+ }
+ channel->default_authority = grpc_mdelem_from_strings(
+ mdctx, ":authority", args->args[i].value.string);
+ }
+ } else if (0 ==
+ strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) {
+ if (args->args[i].type != GRPC_ARG_STRING) {
+ gpr_log(GPR_ERROR, "%s: must be an string",
+ GRPC_SSL_TARGET_NAME_OVERRIDE_ARG);
+ } else {
+ if (channel->default_authority) {
+ /* other ways of setting this (notably ssl) take precedence */
+ gpr_log(GPR_ERROR, "%s: default host already set some other way",
+ GRPC_ARG_DEFAULT_AUTHORITY);
+ } else {
+ channel->default_authority = grpc_mdelem_from_strings(
+ mdctx, ":authority", args->args[i].value.string);
+ }
+ }
}
}
}
+ if (channel->is_client && channel->default_authority == NULL &&
+ target != NULL) {
+ char *default_authority = grpc_get_default_authority(target);
+ if (default_authority) {
+ channel->default_authority = grpc_mdelem_from_strings(
+ channel->metadata_context, ":authority", default_authority);
+ }
+ gpr_free(default_authority);
+ }
+
grpc_channel_stack_init(filters, num_filters, channel, args,
channel->metadata_context,
CHANNEL_STACK_FROM_CHANNEL(channel));
@@ -161,6 +200,8 @@ static grpc_call *grpc_channel_create_call_internal(
send_metadata[num_metadata++] = path_mdelem;
if (authority_mdelem != NULL) {
send_metadata[num_metadata++] = authority_mdelem;
+ } else if (channel->default_authority != NULL) {
+ send_metadata[num_metadata++] = GRPC_MDELEM_REF(channel->default_authority);
}
return grpc_call_create(channel, parent_call, propagation_mask, cq, NULL,
@@ -251,6 +292,9 @@ static void destroy_channel(void *p, int ok) {
}
gpr_free(rc);
}
+ if (channel->default_authority != NULL) {
+ GRPC_MDELEM_UNREF(channel->default_authority);
+ }
grpc_mdctx_unref(channel->metadata_context);
gpr_mu_destroy(&channel->registered_call_mu);
gpr_free(channel->target);
diff --git a/src/core/surface/init.c b/src/core/surface/init.c
index d9044549f2..0d48cd42d7 100644
--- a/src/core/surface/init.c
+++ b/src/core/surface/init.c
@@ -86,11 +86,11 @@ void grpc_init(void) {
if (++g_initializations == 1) {
gpr_time_init();
grpc_resolver_registry_init("dns:///");
- grpc_register_resolver_type("dns", grpc_dns_resolver_factory_create());
- grpc_register_resolver_type("ipv4", grpc_ipv4_resolver_factory_create());
- grpc_register_resolver_type("ipv6", grpc_ipv6_resolver_factory_create());
+ grpc_register_resolver_type(grpc_dns_resolver_factory_create());
+ grpc_register_resolver_type(grpc_ipv4_resolver_factory_create());
+ grpc_register_resolver_type(grpc_ipv6_resolver_factory_create());
#ifdef GPR_POSIX_SOCKET
- grpc_register_resolver_type("unix", grpc_unix_resolver_factory_create());
+ grpc_register_resolver_type(grpc_unix_resolver_factory_create());
#endif
grpc_register_tracer("channel", &grpc_trace_channel);
grpc_register_tracer("surface", &grpc_surface_trace);
diff --git a/src/core/transport/metadata.c b/src/core/transport/metadata.c
index f92e87e9dd..3fd21a2f5d 100644
--- a/src/core/transport/metadata.c
+++ b/src/core/transport/metadata.c
@@ -681,16 +681,34 @@ void grpc_mdctx_locked_mdelem_unref(grpc_mdctx *ctx,
void grpc_mdctx_unlock(grpc_mdctx *ctx) { unlock(ctx); }
-int grpc_mdstr_is_legal_header(grpc_mdstr *s) {
- /* TODO(ctiller): consider caching this, or computing it on construction */
+static int conforms_to(grpc_mdstr *s, const gpr_uint8 *legal_bits) {
const gpr_uint8 *p = GPR_SLICE_START_PTR(s->slice);
const gpr_uint8 *e = GPR_SLICE_END_PTR(s->slice);
for (; p != e; p++) {
- if (*p < 32 || *p > 126) return 0;
+ int idx = *p;
+ int byte = idx / 8;
+ int bit = idx % 8;
+ if ((legal_bits[byte] & (1 << bit)) == 0) return 0;
}
return 1;
}
+int grpc_mdstr_is_legal_header(grpc_mdstr *s) {
+ static const gpr_uint8 legal_header_bits[256 / 8] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xff, 0x03, 0x00, 0x00, 0x00,
+ 0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ return conforms_to(s, legal_header_bits);
+}
+
+int grpc_mdstr_is_legal_nonbin_header(grpc_mdstr *s) {
+ static const gpr_uint8 legal_header_bits[256 / 8] = {
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+ return conforms_to(s, legal_header_bits);
+}
+
int grpc_mdstr_is_bin_suffixed(grpc_mdstr *s) {
/* TODO(ctiller): consider caching this */
return grpc_is_binary_header((const char *)GPR_SLICE_START_PTR(s->slice),
diff --git a/src/core/transport/metadata.h b/src/core/transport/metadata.h
index a7af49ba55..eb17747be7 100644
--- a/src/core/transport/metadata.h
+++ b/src/core/transport/metadata.h
@@ -154,6 +154,7 @@ void grpc_mdelem_unref(grpc_mdelem *md);
const char *grpc_mdstr_as_c_string(grpc_mdstr *s);
int grpc_mdstr_is_legal_header(grpc_mdstr *s);
+int grpc_mdstr_is_legal_nonbin_header(grpc_mdstr *s);
int grpc_mdstr_is_bin_suffixed(grpc_mdstr *s);
/* Batch mode metadata functions.
diff --git a/src/cpp/util/string_ref.cc b/src/cpp/util/string_ref.cc
index d9c9019da8..eb54f65e3a 100644
--- a/src/cpp/util/string_ref.cc
+++ b/src/cpp/util/string_ref.cc
@@ -108,4 +108,8 @@ bool operator>=(string_ref x, string_ref y) {
return x.compare(y) >= 0;
}
+std::ostream& operator<<(std::ostream& out, const string_ref& string) {
+ return out << grpc::string(string.begin(), string.end());
+}
+
} // namespace grpc
diff --git a/src/python/grpcio_test/grpc_test/_adapter/_links_test.py b/src/python/grpcio_test/grpc_test/_adapter/_links_test.py
index c4686b327a..4077b8e350 100644
--- a/src/python/grpcio_test/grpc_test/_adapter/_links_test.py
+++ b/src/python/grpcio_test/grpc_test/_adapter/_links_test.py
@@ -46,8 +46,8 @@ _TIMEOUT = 32
# TODO(nathaniel): End-to-end metadata testing.
def _transform_metadata(unused_metadata):
return (
- ('one unused key', 'one unused value'),
- ('another unused key', 'another unused value'),
+ ('one_unused_key', 'one unused value'),
+ ('another_unused_key', 'another unused value'),
)
diff --git a/src/python/grpcio_test/grpc_test/_cython/adapter_low_test.py b/src/python/grpcio_test/grpc_test/_cython/adapter_low_test.py
index 9bab930e56..f1bec238cf 100644
--- a/src/python/grpcio_test/grpc_test/_cython/adapter_low_test.py
+++ b/src/python/grpcio_test/grpc_test/_cython/adapter_low_test.py
@@ -76,7 +76,7 @@ class InsecureServerInsecureClient(unittest.TestCase):
CLIENT_METADATA_BIN_VALUE = b'\0'*1000
SERVER_INITIAL_METADATA_KEY = 'init_me_me_me'
SERVER_INITIAL_METADATA_VALUE = 'whodawha?'
- SERVER_TRAILING_METADATA_KEY = 'California_is_in_a_drought'
+ SERVER_TRAILING_METADATA_KEY = 'california_is_in_a_drought'
SERVER_TRAILING_METADATA_VALUE = 'zomg it is'
SERVER_STATUS_CODE = _types.StatusCode.OK
SERVER_STATUS_DETAILS = 'our work is never over'
diff --git a/src/python/grpcio_test/grpc_test/_links/_transmission_test.py b/src/python/grpcio_test/grpc_test/_links/_transmission_test.py
index 02ddd512c2..db011bca66 100644
--- a/src/python/grpcio_test/grpc_test/_links/_transmission_test.py
+++ b/src/python/grpcio_test/grpc_test/_links/_transmission_test.py
@@ -66,9 +66,9 @@ class TransmissionTest(test_cases.TransmissionTest, unittest.TestCase):
def create_invocation_initial_metadata(self):
return (
- ('first invocation initial metadata key', 'just a string value'),
- ('second invocation initial metadata key', '0123456789'),
- ('third invocation initial metadata key-bin', '\x00\x57' * 100),
+ ('first_invocation_initial_metadata_key', 'just a string value'),
+ ('second_invocation_initial_metadata_key', '0123456789'),
+ ('third_invocation_initial_metadata_key-bin', '\x00\x57' * 100),
)
def create_invocation_terminal_metadata(self):
@@ -76,16 +76,16 @@ class TransmissionTest(test_cases.TransmissionTest, unittest.TestCase):
def create_service_initial_metadata(self):
return (
- ('first service initial metadata key', 'just another string value'),
- ('second service initial metadata key', '9876543210'),
- ('third service initial metadata key-bin', '\x00\x59\x02' * 100),
+ ('first_service_initial_metadata_key', 'just another string value'),
+ ('second_service_initial_metadata_key', '9876543210'),
+ ('third_service_initial_metadata_key-bin', '\x00\x59\x02' * 100),
)
def create_service_terminal_metadata(self):
return (
- ('first service terminal metadata key', 'yet another string value'),
- ('second service terminal metadata key', 'abcdefghij'),
- ('third service terminal metadata key-bin', '\x00\x37' * 100),
+ ('first_service_terminal_metadata_key', 'yet another string value'),
+ ('second_service_terminal_metadata_key', 'abcdefghij'),
+ ('third_service_terminal_metadata_key-bin', '\x00\x37' * 100),
)
def create_invocation_completion(self):
diff --git a/src/python/grpcio_test/setup.py b/src/python/grpcio_test/setup.py
index a6203cae2d..898ea204ac 100644
--- a/src/python/grpcio_test/setup.py
+++ b/src/python/grpcio_test/setup.py
@@ -61,6 +61,7 @@ _SETUP_REQUIRES = (
'pytest>=2.6',
'pytest-cov>=2.0',
'pytest-xdist>=1.11',
+ 'pytest-timeout>=0.5',
)
_INSTALL_REQUIRES = (