aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/transport/chttp2
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/ext/transport/chttp2')
-rw-r--r--src/core/ext/transport/chttp2/client/chttp2_connector.c20
-rw-r--r--src/core/ext/transport/chttp2/client/chttp2_connector.h12
-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.c60
-rw-r--r--src/core/ext/transport/chttp2/server/chttp2_server.c36
-rw-r--r--src/core/ext/transport/chttp2/server/chttp2_server.h39
-rw-r--r--src/core/ext/transport/chttp2/server/insecure/server_chttp2.c3
-rw-r--r--src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c49
8 files changed, 47 insertions, 184 deletions
diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.c b/src/core/ext/transport/chttp2/client/chttp2_connector.c
index 2385f91dbd..2c5dfaea60 100644
--- a/src/core/ext/transport/chttp2/client/chttp2_connector.c
+++ b/src/core/ext/transport/chttp2/client/chttp2_connector.c
@@ -46,6 +46,7 @@
#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/handshaker_registry.h"
#include "src/core/lib/iomgr/tcp_client.h"
#include "src/core/lib/slice/slice_internal.h"
@@ -58,9 +59,6 @@ typedef struct {
bool shutdown;
bool connecting;
- grpc_chttp2_add_handshakers_func add_handshakers;
- void *add_handshakers_user_data;
-
grpc_closure *notify;
grpc_connect_in_args args;
grpc_connect_out_args *result;
@@ -151,16 +149,8 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
static void start_handshake_locked(grpc_exec_ctx *exec_ctx,
chttp2_connector *c) {
c->handshake_mgr = grpc_handshake_manager_create();
- char *proxy_name = grpc_get_http_proxy_server();
- if (proxy_name != NULL) {
- grpc_handshake_manager_add(c->handshake_mgr,
- grpc_http_connect_handshaker_create(proxy_name));
- gpr_free(proxy_name);
- }
- if (c->add_handshakers != NULL) {
- c->add_handshakers(exec_ctx, c->add_handshakers_user_data,
+ grpc_handshakers_add(exec_ctx, HANDSHAKER_CLIENT, c->args.channel_args,
c->handshake_mgr);
- }
grpc_handshake_manager_do_handshake(
exec_ctx, c->handshake_mgr, c->endpoint, c->args.channel_args,
c->args.deadline, NULL /* acceptor */, on_handshake_done, c);
@@ -250,15 +240,11 @@ static const grpc_connector_vtable chttp2_connector_vtable = {
chttp2_connector_ref, chttp2_connector_unref, chttp2_connector_shutdown,
chttp2_connector_connect};
-grpc_connector *grpc_chttp2_connector_create(
- grpc_exec_ctx *exec_ctx, grpc_chttp2_add_handshakers_func add_handshakers,
- void *add_handshakers_user_data) {
+grpc_connector *grpc_chttp2_connector_create() {
chttp2_connector *c = gpr_malloc(sizeof(*c));
memset(c, 0, sizeof(*c));
c->base.vtable = &chttp2_connector_vtable;
gpr_mu_init(&c->mu);
gpr_ref_init(&c->refs, 1);
- c->add_handshakers = add_handshakers;
- c->add_handshakers_user_data = add_handshakers_user_data;
return &c->base;
}
diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.h b/src/core/ext/transport/chttp2/client/chttp2_connector.h
index 58eba22417..f5d1025432 100644
--- a/src/core/ext/transport/chttp2/client/chttp2_connector.h
+++ b/src/core/ext/transport/chttp2/client/chttp2_connector.h
@@ -35,17 +35,7 @@
#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_CHTTP2_CONNECTOR_H
#include "src/core/ext/client_channel/connector.h"
-#include "src/core/lib/channel/handshaker.h"
-#include "src/core/lib/iomgr/exec_ctx.h"
-typedef void (*grpc_chttp2_add_handshakers_func)(
- grpc_exec_ctx* exec_ctx, void* user_data,
- grpc_handshake_manager* handshake_mgr);
-
-/// If \a add_handshakers is non-NULL, it will be called with
-/// \a add_handshakers_user_data to add handshakers.
-grpc_connector* grpc_chttp2_connector_create(
- grpc_exec_ctx* exec_ctx, grpc_chttp2_add_handshakers_func add_handshakers,
- void* add_handshakers_user_data);
+grpc_connector* grpc_chttp2_connector_create();
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_CLIENT_CHTTP2_CONNECTOR_H */
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 1d3592ef06..c9f4021216 100644
--- a/src/core/ext/transport/chttp2/client/insecure/channel_create.c
+++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.c
@@ -53,8 +53,7 @@ static void client_channel_factory_unref(
static grpc_subchannel *client_channel_factory_create_subchannel(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
const grpc_subchannel_args *args) {
- grpc_connector *connector = grpc_chttp2_connector_create(
- exec_ctx, NULL /* add_handshakers */, NULL /* user_data */);
+ grpc_connector *connector = grpc_chttp2_connector_create();
grpc_subchannel *s = grpc_subchannel_create(exec_ctx, connector, args);
grpc_connector_unref(exec_ctx, connector);
return s;
@@ -96,17 +95,16 @@ grpc_channel *grpc_insecure_channel_create(const char *target,
"grpc_insecure_channel_create(target=%p, args=%p, reserved=%p)", 3,
(target, args, reserved));
GPR_ASSERT(reserved == NULL);
- grpc_client_channel_factory *factory =
- (grpc_client_channel_factory *)&client_channel_factory;
// Add channel arg containing the client channel factory.
- grpc_arg arg = grpc_client_channel_factory_create_channel_arg(factory);
+ grpc_arg arg =
+ grpc_client_channel_factory_create_channel_arg(&client_channel_factory);
grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
// Create channel.
grpc_channel *channel = client_channel_factory_create_channel(
- &exec_ctx, factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
+ &exec_ctx, &client_channel_factory, target,
+ GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
// Clean up.
grpc_channel_args_destroy(&exec_ctx, new_args);
- grpc_client_channel_factory_unref(&exec_ctx, factory);
grpc_exec_ctx_finish(&exec_ctx);
return channel != NULL ? channel : grpc_lame_client_channel_create(
target, GRPC_STATUS_INTERNAL,
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 54663ef6a4..f979d9bad5 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
@@ -46,40 +46,16 @@
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/channel.h"
-typedef struct {
- grpc_client_channel_factory base;
- gpr_refcount refs;
- grpc_channel_security_connector *security_connector;
-} client_channel_factory;
-
static void client_channel_factory_ref(
- grpc_client_channel_factory *cc_factory) {
- client_channel_factory *f = (client_channel_factory *)cc_factory;
- gpr_ref(&f->refs);
-}
+ grpc_client_channel_factory *cc_factory) {}
static void client_channel_factory_unref(
- grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) {
- client_channel_factory *f = (client_channel_factory *)cc_factory;
- if (gpr_unref(&f->refs)) {
- GRPC_SECURITY_CONNECTOR_UNREF(exec_ctx, &f->security_connector->base,
- "client_channel_factory");
- gpr_free(f);
- }
-}
-
-static void add_handshakers(grpc_exec_ctx *exec_ctx, void *security_connector,
- grpc_handshake_manager *handshake_mgr) {
- grpc_channel_security_connector_add_handshakers(exec_ctx, security_connector,
- handshake_mgr);
-}
+ grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory) {}
static grpc_subchannel *client_channel_factory_create_subchannel(
grpc_exec_ctx *exec_ctx, grpc_client_channel_factory *cc_factory,
const grpc_subchannel_args *args) {
- client_channel_factory *f = (client_channel_factory *)cc_factory;
- grpc_connector *connector = grpc_chttp2_connector_create(
- exec_ctx, add_handshakers, f->security_connector);
+ grpc_connector *connector = grpc_chttp2_connector_create();
grpc_subchannel *s = grpc_subchannel_create(exec_ctx, connector, args);
grpc_connector_unref(exec_ctx, connector);
return s;
@@ -106,6 +82,9 @@ static const grpc_client_channel_factory_vtable client_channel_factory_vtable =
client_channel_factory_create_subchannel,
client_channel_factory_create_channel};
+static grpc_client_channel_factory client_channel_factory = {
+ &client_channel_factory_vtable};
+
/* Create a secure client channel:
Asynchronously: - resolve target
- connect to it (trying alternatives as presented)
@@ -138,33 +117,26 @@ grpc_channel *grpc_secure_channel_create(grpc_channel_credentials *creds,
return grpc_lame_client_channel_create(
target, GRPC_STATUS_INTERNAL, "Failed to create security connector.");
}
- // Create client channel factory.
- client_channel_factory *f = gpr_malloc(sizeof(*f));
- memset(f, 0, sizeof(*f));
- f->base.vtable = &client_channel_factory_vtable;
- gpr_ref_init(&f->refs, 1);
- GRPC_SECURITY_CONNECTOR_REF(&security_connector->base,
- "grpc_secure_channel_create");
- f->security_connector = security_connector;
// Add channel args containing the client channel factory and security
// connector.
- grpc_arg new_args[2];
- new_args[0] = grpc_client_channel_factory_create_channel_arg(&f->base);
- new_args[1] = grpc_security_connector_to_arg(&security_connector->base);
- grpc_channel_args *args_copy = grpc_channel_args_copy_and_add(
+ grpc_arg args_to_add[2];
+ args_to_add[0] =
+ grpc_client_channel_factory_create_channel_arg(&client_channel_factory);
+ args_to_add[1] = grpc_security_connector_to_arg(&security_connector->base);
+ grpc_channel_args *new_args = grpc_channel_args_copy_and_add(
new_args_from_connector != NULL ? new_args_from_connector : args,
- new_args, GPR_ARRAY_SIZE(new_args));
+ args_to_add, GPR_ARRAY_SIZE(args_to_add));
if (new_args_from_connector != NULL) {
grpc_channel_args_destroy(&exec_ctx, new_args_from_connector);
}
// Create channel.
grpc_channel *channel = client_channel_factory_create_channel(
- &exec_ctx, &f->base, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR, args_copy);
+ &exec_ctx, &client_channel_factory, target,
+ GRPC_CLIENT_CHANNEL_TYPE_REGULAR, new_args);
// Clean up.
- GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &f->security_connector->base,
+ GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &security_connector->base,
"secure_client_channel_factory_create_channel");
- grpc_channel_args_destroy(&exec_ctx, args_copy);
- grpc_client_channel_factory_unref(&exec_ctx, &f->base);
+ grpc_channel_args_destroy(&exec_ctx, new_args);
grpc_exec_ctx_finish(&exec_ctx);
return channel; /* may be NULL */
}
diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.c b/src/core/ext/transport/chttp2/server/chttp2_server.c
index 86fe8d1ccd..56a1a0de9b 100644
--- a/src/core/ext/transport/chttp2/server/chttp2_server.c
+++ b/src/core/ext/transport/chttp2/server/chttp2_server.c
@@ -46,6 +46,7 @@
#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/handshaker_registry.h"
#include "src/core/lib/channel/http_server_filter.h"
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/iomgr/resolve_address.h"
@@ -54,24 +55,6 @@
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/server.h"
-void grpc_chttp2_server_handshaker_factory_add_handshakers(
- grpc_exec_ctx *exec_ctx,
- grpc_chttp2_server_handshaker_factory *handshaker_factory,
- grpc_handshake_manager *handshake_mgr) {
- if (handshaker_factory != NULL) {
- handshaker_factory->vtable->add_handshakers(exec_ctx, handshaker_factory,
- handshake_mgr);
- }
-}
-
-void grpc_chttp2_server_handshaker_factory_destroy(
- grpc_exec_ctx *exec_ctx,
- grpc_chttp2_server_handshaker_factory *handshaker_factory) {
- if (handshaker_factory != NULL) {
- handshaker_factory->vtable->destroy(exec_ctx, handshaker_factory);
- }
-}
-
typedef struct pending_handshake_manager_node {
grpc_handshake_manager *handshake_mgr;
struct pending_handshake_manager_node *next;
@@ -81,7 +64,6 @@ typedef struct {
grpc_server *server;
grpc_tcp_server *tcp_server;
grpc_channel_args *args;
- grpc_chttp2_server_handshaker_factory *handshaker_factory;
gpr_mu mu;
bool shutdown;
grpc_closure tcp_server_shutdown_complete;
@@ -198,8 +180,8 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
connection_state->accepting_pollset = accepting_pollset;
connection_state->acceptor = acceptor;
connection_state->handshake_mgr = handshake_mgr;
- grpc_chttp2_server_handshaker_factory_add_handshakers(
- exec_ctx, state->handshaker_factory, connection_state->handshake_mgr);
+ grpc_handshakers_add(exec_ctx, HANDSHAKER_SERVER, state->args,
+ connection_state->handshake_mgr);
// TODO(roth): We should really get this timeout value from channel
// args instead of hard-coding it.
const gpr_timespec deadline = gpr_time_add(
@@ -233,8 +215,6 @@ static void tcp_server_shutdown_complete(grpc_exec_ctx *exec_ctx, void *arg,
// Flush queued work before destroying handshaker factory, since that
// may do a synchronous unref.
grpc_exec_ctx_flush(exec_ctx);
- grpc_chttp2_server_handshaker_factory_destroy(exec_ctx,
- state->handshaker_factory);
if (destroy_done != NULL) {
destroy_done->cb(exec_ctx, destroy_done->cb_arg, GRPC_ERROR_REF(error));
grpc_exec_ctx_flush(exec_ctx);
@@ -259,10 +239,10 @@ static void server_destroy_listener(grpc_exec_ctx *exec_ctx,
grpc_tcp_server_unref(exec_ctx, tcp_server);
}
-grpc_error *grpc_chttp2_server_add_port(
- grpc_exec_ctx *exec_ctx, grpc_server *server, const char *addr,
- grpc_channel_args *args,
- grpc_chttp2_server_handshaker_factory *handshaker_factory, int *port_num) {
+grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx,
+ grpc_server *server, const char *addr,
+ grpc_channel_args *args,
+ int *port_num) {
grpc_resolved_addresses *resolved = NULL;
grpc_tcp_server *tcp_server = NULL;
size_t i;
@@ -293,7 +273,6 @@ grpc_error *grpc_chttp2_server_add_port(
state->server = server;
state->tcp_server = tcp_server;
state->args = args;
- state->handshaker_factory = handshaker_factory;
state->shutdown = true;
gpr_mu_init(&state->mu);
@@ -348,7 +327,6 @@ error:
grpc_tcp_server_unref(exec_ctx, tcp_server);
} else {
grpc_channel_args_destroy(exec_ctx, args);
- grpc_chttp2_server_handshaker_factory_destroy(exec_ctx, handshaker_factory);
gpr_free(state);
}
*port_num = 0;
diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.h b/src/core/ext/transport/chttp2/server/chttp2_server.h
index aa364b565d..2581ebaae9 100644
--- a/src/core/ext/transport/chttp2/server/chttp2_server.h
+++ b/src/core/ext/transport/chttp2/server/chttp2_server.h
@@ -36,43 +36,12 @@
#include <grpc/impl/codegen/grpc_types.h>
-#include "src/core/lib/channel/handshaker.h"
#include "src/core/lib/iomgr/exec_ctx.h"
-/// A server handshaker factory is used to create handshakers for server
-/// connections.
-typedef struct grpc_chttp2_server_handshaker_factory
- grpc_chttp2_server_handshaker_factory;
-
-typedef struct {
- void (*add_handshakers)(
- grpc_exec_ctx *exec_ctx,
- grpc_chttp2_server_handshaker_factory *handshaker_factory,
- grpc_handshake_manager *handshake_mgr);
- void (*destroy)(grpc_exec_ctx *exec_ctx,
- grpc_chttp2_server_handshaker_factory *handshaker_factory);
-} grpc_chttp2_server_handshaker_factory_vtable;
-
-struct grpc_chttp2_server_handshaker_factory {
- const grpc_chttp2_server_handshaker_factory_vtable *vtable;
-};
-
-void grpc_chttp2_server_handshaker_factory_add_handshakers(
- grpc_exec_ctx *exec_ctx,
- grpc_chttp2_server_handshaker_factory *handshaker_factory,
- grpc_handshake_manager *handshake_mgr);
-
-void grpc_chttp2_server_handshaker_factory_destroy(
- grpc_exec_ctx *exec_ctx,
- grpc_chttp2_server_handshaker_factory *handshaker_factory);
-
/// Adds a port to \a server. Sets \a port_num to the port number.
-/// If \a handshaker_factory is not NULL, it will be used to create
-/// handshakers for the port.
-/// Takes ownership of \a args and \a handshaker_factory.
-grpc_error *grpc_chttp2_server_add_port(
- grpc_exec_ctx *exec_ctx, grpc_server *server, const char *addr,
- grpc_channel_args *args,
- grpc_chttp2_server_handshaker_factory *handshaker_factory, int *port_num);
+/// Takes ownership of \a args.
+grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx,
+ grpc_server *server, const char *addr,
+ grpc_channel_args *args, int *port_num);
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_SERVER_CHTTP2_SERVER_H */
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 77ed26a54a..c219a7d85f 100644
--- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c
+++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c
@@ -47,8 +47,7 @@ int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) {
(server, addr));
grpc_error *err = grpc_chttp2_server_add_port(
&exec_ctx, server, addr,
- grpc_channel_args_copy(grpc_server_get_channel_args(server)),
- NULL /* handshaker_factory */, &port_num);
+ grpc_channel_args_copy(grpc_server_get_channel_args(server)), &port_num);
if (err != GRPC_ERROR_NONE) {
const char *msg = grpc_error_string(err);
gpr_log(GPR_ERROR, "%s", msg);
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 f909a760d0..cb2b3f5502 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
@@ -49,34 +49,6 @@
#include "src/core/lib/surface/api_trace.h"
#include "src/core/lib/surface/server.h"
-typedef struct {
- grpc_chttp2_server_handshaker_factory base;
- grpc_server_security_connector *security_connector;
-} server_security_handshaker_factory;
-
-static void server_security_handshaker_factory_add_handshakers(
- grpc_exec_ctx *exec_ctx, grpc_chttp2_server_handshaker_factory *hf,
- grpc_handshake_manager *handshake_mgr) {
- server_security_handshaker_factory *handshaker_factory =
- (server_security_handshaker_factory *)hf;
- grpc_server_security_connector_add_handshakers(
- exec_ctx, handshaker_factory->security_connector, handshake_mgr);
-}
-
-static void server_security_handshaker_factory_destroy(
- grpc_exec_ctx *exec_ctx, grpc_chttp2_server_handshaker_factory *hf) {
- server_security_handshaker_factory *handshaker_factory =
- (server_security_handshaker_factory *)hf;
- GRPC_SECURITY_CONNECTOR_UNREF(
- exec_ctx, &handshaker_factory->security_connector->base, "server");
- gpr_free(hf);
-}
-
-static const grpc_chttp2_server_handshaker_factory_vtable
- server_security_handshaker_factory_vtable = {
- server_security_handshaker_factory_add_handshakers,
- server_security_handshaker_factory_destroy};
-
int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
grpc_server_credentials *creds) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
@@ -105,20 +77,19 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
gpr_free(msg);
goto done;
}
- // Create handshaker factory.
- server_security_handshaker_factory *handshaker_factory =
- gpr_malloc(sizeof(*handshaker_factory));
- memset(handshaker_factory, 0, sizeof(*handshaker_factory));
- handshaker_factory->base.vtable = &server_security_handshaker_factory_vtable;
- handshaker_factory->security_connector = sc;
// Create channel args.
- grpc_arg channel_arg = grpc_server_credentials_to_arg(creds);
- grpc_channel_args *args = grpc_channel_args_copy_and_add(
- grpc_server_get_channel_args(server), &channel_arg, 1);
+ grpc_arg args_to_add[2];
+ args_to_add[0] = grpc_server_credentials_to_arg(creds);
+ args_to_add[1] = grpc_security_connector_to_arg(&sc->base);
+ grpc_channel_args *args =
+ grpc_channel_args_copy_and_add(grpc_server_get_channel_args(server),
+ args_to_add, GPR_ARRAY_SIZE(args_to_add));
// Add server port.
- err = grpc_chttp2_server_add_port(&exec_ctx, server, addr, args,
- &handshaker_factory->base, &port_num);
+ err = grpc_chttp2_server_add_port(&exec_ctx, server, addr, args, &port_num);
done:
+ if (sc != NULL) {
+ GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &sc->base, "server");
+ }
grpc_exec_ctx_finish(&exec_ctx);
if (err != GRPC_ERROR_NONE) {
const char *msg = grpc_error_string(err);