aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/transport
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2016-07-15 08:48:25 -0700
committerGravatar Mark D. Roth <roth@google.com>2016-07-15 08:48:25 -0700
commit45015dc8dac51979fe7bffdc20a92e895e57180e (patch)
treeabf74bd21726e11947f180ea5169c62fa65ab0ed /src/core/ext/transport
parentef31ba1e03ad55b0c46b5dd8b5ed38eec555412b (diff)
Plumb channel args through handshakers.
Diffstat (limited to 'src/core/ext/transport')
-rw-r--r--src/core/ext/transport/chttp2/client/insecure/channel_create.c12
-rw-r--r--src/core/ext/transport/chttp2/client/secure/secure_channel_create.c21
-rw-r--r--src/core/ext/transport/chttp2/server/insecure/server_chttp2.c10
-rw-r--r--src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c31
4 files changed, 43 insertions, 31 deletions
diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.c b/src/core/ext/transport/chttp2/client/insecure/channel_create.c
index 648a9d90a5..154c4493ff 100644
--- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c
+++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c
@@ -88,13 +88,13 @@ static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg,
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
- void *arg) {
- connector *c = arg;
+ grpc_channel_args* args, void *user_data) {
+ connector *c = user_data;
c->result->transport =
- grpc_create_chttp2_transport(exec_ctx, c->args.channel_args, endpoint, 1);
+ grpc_create_chttp2_transport(exec_ctx, args, endpoint, 1);
GPR_ASSERT(c->result->transport);
grpc_chttp2_transport_start_reading(exec_ctx, c->result->transport, NULL, 0);
- c->result->channel_args = grpc_channel_args_copy(c->args.channel_args);
+ c->result->channel_args = args;
grpc_closure *notify = c->notify;
c->notify = NULL;
grpc_exec_ctx_sched(exec_ctx, notify, GRPC_ERROR_NONE, NULL);
@@ -102,7 +102,6 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
connector *c = arg;
- grpc_closure *notify;
grpc_endpoint *tcp = c->tcp;
if (tcp != NULL) {
if (!GPR_SLICE_IS_EMPTY(c->args.initial_connect_string)) {
@@ -116,12 +115,13 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
&c->initial_string_sent);
} else {
grpc_handshake_manager_do_handshake(exec_ctx, c->handshake_mgr, tcp,
+ c->args.channel_args,
c->args.deadline, on_handshake_done,
c);
}
} else {
memset(c->result, 0, sizeof(*c->result));
- notify = c->notify;
+ grpc_closure *notify = c->notify;
c->notify = NULL;
grpc_exec_ctx_sched(exec_ctx, notify, GRPC_ERROR_REF(error), NULL);
}
diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
index 30477ded1a..f071e31cb3 100644
--- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
+++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
@@ -72,6 +72,9 @@ typedef struct {
grpc_closure connected_closure;
grpc_handshake_manager *handshake_mgr;
+
+ // TODO(roth): Remove once we eliminate on_secure_handshake_done().
+ grpc_channel_args* tmp_args;
} connector;
static void connector_ref(grpc_connector *con) {
@@ -83,6 +86,7 @@ static void connector_unref(grpc_exec_ctx *exec_ctx, grpc_connector *con) {
connector *c = (connector *)con;
if (gpr_unref(&c->refs)) {
/* c->initial_string_buffer does not need to be destroyed */
+ grpc_channel_args_destroy(c->tmp_args);
grpc_handshake_manager_destroy(exec_ctx, c->handshake_mgr);
gpr_free(c);
}
@@ -93,7 +97,6 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
grpc_endpoint *secure_endpoint,
grpc_auth_context *auth_context) {
connector *c = arg;
- grpc_closure *notify;
gpr_mu_lock(&c->mu);
if (c->connecting_endpoint == NULL) {
memset(c->result, 0, sizeof(*c->result));
@@ -113,19 +116,20 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
0);
auth_context_arg = grpc_auth_context_to_arg(auth_context);
c->result->channel_args = grpc_channel_args_copy_and_add(
- c->args.channel_args, &auth_context_arg, 1);
+ c->tmp_args, &auth_context_arg, 1);
}
- notify = c->notify;
+ grpc_closure *notify = c->notify;
c->notify = NULL;
grpc_exec_ctx_sched(exec_ctx, notify, GRPC_ERROR_NONE, NULL);
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
- void *arg) {
- connector *c = arg;
+ grpc_channel_args* args, void *user_data) {
+ connector *c = user_data;
// TODO(roth, jboeuf): Convert security connector handshaking to use new
// handshake API, and then move the code from on_secure_handshake_done()
// into this function.
+ c->tmp_args = args;
grpc_channel_security_connector_do_handshake(exec_ctx, c->security_connector,
endpoint, c->args.deadline,
on_secure_handshake_done, c);
@@ -135,13 +139,13 @@ static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) {
connector *c = arg;
grpc_handshake_manager_do_handshake(exec_ctx, c->handshake_mgr,
- c->connecting_endpoint, c->args.deadline,
+ c->connecting_endpoint,
+ c->args.channel_args, c->args.deadline,
on_handshake_done, c);
}
static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
connector *c = arg;
- grpc_closure *notify;
grpc_endpoint *tcp = c->newly_connecting_endpoint;
if (tcp != NULL) {
gpr_mu_lock(&c->mu);
@@ -158,12 +162,13 @@ static void connected(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
&c->initial_string_sent);
} else {
grpc_handshake_manager_do_handshake(exec_ctx, c->handshake_mgr, tcp,
+ c->args.channel_args,
c->args.deadline, on_handshake_done,
c);
}
} else {
memset(c->result, 0, sizeof(*c->result));
- notify = c->notify;
+ grpc_closure *notify = c->notify;
c->notify = NULL;
grpc_exec_ctx_sched(exec_ctx, notify, GRPC_ERROR_REF(error), NULL);
}
diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c
index d3748f576d..920875f694 100644
--- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c
+++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c
@@ -37,7 +37,9 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/useful.h>
+
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
+#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/channel/http_server_filter.h"
#include "src/core/lib/iomgr/resolve_address.h"
@@ -53,8 +55,8 @@ typedef struct server_connect_state {
} server_connect_state;
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
- void *arg) {
- server_connect_state *state = arg;
+ grpc_channel_args* args, void *user_data) {
+ server_connect_state *state = user_data;
/*
* Beware that the call to grpc_create_chttp2_transport() has to happen before
* grpc_tcp_server_destroy(). This is fine here, but similar code
@@ -63,12 +65,13 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
* case.
*/
grpc_transport *transport = grpc_create_chttp2_transport(
- exec_ctx, grpc_server_get_channel_args(state->server), endpoint, 0);
+ exec_ctx, args, endpoint, 0);
grpc_server_setup_transport(exec_ctx, state->server, transport,
state->accepting_pollset,
grpc_server_get_channel_args(state->server));
grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL, 0);
// Clean up.
+ grpc_channel_args_destroy(args);
grpc_handshake_manager_destroy(exec_ctx, state->handshake_mgr);
gpr_free(state);
}
@@ -86,6 +89,7 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *server, grpc_endpoint *tcp,
const gpr_timespec deadline = gpr_time_add(
gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(120, GPR_TIMESPAN));
grpc_handshake_manager_do_handshake(exec_ctx, state->handshake_mgr, tcp,
+ grpc_server_get_channel_args(server),
deadline, on_handshake_done, state);
}
diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c
index 57931bdb43..e3184bc1f9 100644
--- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c
+++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c
@@ -70,9 +70,11 @@ typedef struct server_secure_connect {
server_secure_state *state;
grpc_pollset *accepting_pollset;
grpc_tcp_server_acceptor *acceptor;
- gpr_timespec deadline; // FIXME: remove when we eliminate
- // grpc_server_security_connector_do_handshake()
grpc_handshake_manager *handshake_mgr;
+ // TODO(roth): Remove the following two fields when we eliminate
+ // grpc_server_security_connector_do_handshake().
+ gpr_timespec deadline;
+ grpc_channel_args* args;
} server_secure_connect;
static void state_ref(server_secure_state *state) { gpr_ref(&state->refcount); }
@@ -102,13 +104,11 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *statep,
transport = grpc_create_chttp2_transport(
exec_ctx, grpc_server_get_channel_args(state->state->server),
secure_endpoint, 0);
- grpc_channel_args *args_copy;
grpc_arg args_to_add[2];
args_to_add[0] = grpc_server_credentials_to_arg(state->state->creds);
args_to_add[1] = grpc_auth_context_to_arg(auth_context);
- args_copy = grpc_channel_args_copy_and_add(
- grpc_server_get_channel_args(state->state->server), args_to_add,
- GPR_ARRAY_SIZE(args_to_add));
+ grpc_channel_args *args_copy = grpc_channel_args_copy_and_add(
+ state->args, args_to_add, GPR_ARRAY_SIZE(args_to_add));
grpc_server_setup_transport(exec_ctx, state->state->server, transport,
state->accepting_pollset, args_copy);
grpc_channel_args_destroy(args_copy);
@@ -123,18 +123,20 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *statep,
} else {
gpr_log(GPR_ERROR, "Secure transport failed with error %d", status);
}
+ grpc_channel_args_destroy(state->args);
state_unref(state->state);
gpr_free(state);
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
- void *arg) {
- server_secure_connect *state = arg;
- grpc_handshake_manager_destroy(exec_ctx, state->handshake_mgr);
- state->handshake_mgr = NULL;
+ grpc_channel_args* args, void *user_data) {
+ server_secure_connect *state = user_data;
// TODO(roth, jboeuf): Convert security connector handshaking to use new
// handshake API, and then move the code from on_secure_handshake_done()
// into this function.
+ grpc_handshake_manager_destroy(exec_ctx, state->handshake_mgr);
+ state->handshake_mgr = NULL;
+ state->args = args;
grpc_server_security_connector_do_handshake(
exec_ctx, state->state->sc, state->acceptor, endpoint, state->deadline,
on_secure_handshake_done, state);
@@ -148,14 +150,15 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *statep, grpc_endpoint *tcp,
state_ref(state->state);
state->accepting_pollset = accepting_pollset;
state->acceptor = acceptor;
+ state->handshake_mgr = grpc_handshake_manager_create();
// TODO(roth): We should really get this timeout value from channel
// args instead of hard-coding it.
state->deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_seconds(120, GPR_TIMESPAN));
- state->handshake_mgr = grpc_handshake_manager_create();
- grpc_handshake_manager_do_handshake(exec_ctx, state->handshake_mgr, tcp,
- state->deadline, on_handshake_done,
- state);
+ grpc_handshake_manager_do_handshake(
+ exec_ctx, state->handshake_mgr, tcp,
+ grpc_server_get_channel_args(state->state->server), state->deadline,
+ on_handshake_done, state);
}
/* Server callback: start listening on our ports */