aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2017-03-31 17:22:06 -0700
committerGravatar Craig Tiller <ctiller@google.com>2017-03-31 17:22:06 -0700
commit6d4894e9d6cf72f0917c6cfdabb3d3a271433d34 (patch)
tree44185558d93d25305fb61c38c77283b6b6853f18 /src/core
parent9eb0fdec004f3f3e8a6ea93e1d8f7c1e0d92ec89 (diff)
optionalize max_age
Diffstat (limited to 'src/core')
-rw-r--r--src/core/ext/filters/max_age/max_age_filter.c (renamed from src/core/lib/channel/max_age_filter.c)33
-rw-r--r--src/core/ext/filters/max_age/max_age_filter.h (renamed from src/core/lib/channel/max_age_filter.h)0
-rw-r--r--src/core/lib/surface/init.c4
-rw-r--r--src/core/plugin_registry/grpc_plugin_registry.c4
-rw-r--r--src/core/plugin_registry/grpc_unsecure_plugin_registry.c4
5 files changed, 41 insertions, 4 deletions
diff --git a/src/core/lib/channel/max_age_filter.c b/src/core/ext/filters/max_age/max_age_filter.c
index c25481486c..b03cb0ba0a 100644
--- a/src/core/lib/channel/max_age_filter.c
+++ b/src/core/ext/filters/max_age/max_age_filter.c
@@ -37,7 +37,9 @@
#include <string.h>
#include "src/core/lib/channel/channel_args.h"
+#include "src/core/lib/channel/channel_stack_builder.h"
#include "src/core/lib/iomgr/timer.h"
+#include "src/core/lib/surface/channel_init.h"
#include "src/core/lib/transport/http2_errors.h"
#include "src/core/lib/transport/service_config.h"
@@ -384,3 +386,34 @@ const grpc_channel_filter grpc_max_age_filter = {
grpc_call_next_get_peer,
grpc_channel_next_get_info,
"max_age"};
+
+static bool maybe_add_max_age_filter(grpc_exec_ctx* exec_ctx,
+ grpc_channel_stack_builder* builder,
+ void* arg) {
+ const grpc_channel_args* channel_args =
+ grpc_channel_stack_builder_get_channel_arguments(builder);
+ const grpc_arg* a =
+ grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_AGE_MS);
+ bool enable = false;
+ if (a != NULL && a->type == GRPC_ARG_INTEGER && a->value.integer != INT_MAX) {
+ enable = true;
+ }
+ a = grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_IDLE_MS);
+ if (a != NULL && a->type == GRPC_ARG_INTEGER && a->value.integer != INT_MAX) {
+ enable = true;
+ }
+ if (enable) {
+ return grpc_channel_stack_builder_prepend_filter(
+ builder, &grpc_max_age_filter, NULL, NULL);
+ } else {
+ return true;
+ }
+}
+
+void grpc_max_age_filter_init(void) {
+ grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
+ GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
+ maybe_add_max_age_filter, NULL);
+}
+
+void grpc_max_age_filter_shutdown(void) {}
diff --git a/src/core/lib/channel/max_age_filter.h b/src/core/ext/filters/max_age/max_age_filter.h
index 93e357a88e..93e357a88e 100644
--- a/src/core/lib/channel/max_age_filter.h
+++ b/src/core/ext/filters/max_age/max_age_filter.h
diff --git a/src/core/lib/surface/init.c b/src/core/lib/surface/init.c
index b46ecac18d..91bd014a0e 100644
--- a/src/core/lib/surface/init.c
+++ b/src/core/lib/surface/init.c
@@ -47,7 +47,6 @@
#include "src/core/lib/channel/handshaker_registry.h"
#include "src/core/lib/channel/http_client_filter.h"
#include "src/core/lib/channel/http_server_filter.h"
-#include "src/core/lib/channel/max_age_filter.h"
#include "src/core/lib/channel/message_size_filter.h"
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/http/parser.h"
@@ -115,9 +114,6 @@ static void register_builtin_channel_init() {
GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
(void *)&grpc_server_deadline_filter);
grpc_channel_init_register_stage(
- GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, prepend_filter,
- (void *)&grpc_max_age_filter);
- grpc_channel_init_register_stage(
GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
prepend_filter, (void *)&grpc_message_size_filter);
grpc_channel_init_register_stage(
diff --git a/src/core/plugin_registry/grpc_plugin_registry.c b/src/core/plugin_registry/grpc_plugin_registry.c
index 596e3b7114..803a26b753 100644
--- a/src/core/plugin_registry/grpc_plugin_registry.c
+++ b/src/core/plugin_registry/grpc_plugin_registry.c
@@ -53,6 +53,8 @@ extern void grpc_load_reporting_plugin_init(void);
extern void grpc_load_reporting_plugin_shutdown(void);
extern void census_grpc_plugin_init(void);
extern void census_grpc_plugin_shutdown(void);
+extern void grpc_max_age_filter_init(void);
+extern void grpc_max_age_filter_shutdown(void);
void grpc_register_built_in_plugins(void) {
grpc_register_plugin(grpc_chttp2_plugin_init,
@@ -75,4 +77,6 @@ void grpc_register_built_in_plugins(void) {
grpc_load_reporting_plugin_shutdown);
grpc_register_plugin(census_grpc_plugin_init,
census_grpc_plugin_shutdown);
+ grpc_register_plugin(grpc_max_age_filter_init,
+ grpc_max_age_filter_shutdown);
}
diff --git a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c
index a05ebcb3af..e65fc2425d 100644
--- a/src/core/plugin_registry/grpc_unsecure_plugin_registry.c
+++ b/src/core/plugin_registry/grpc_unsecure_plugin_registry.c
@@ -53,6 +53,8 @@ extern void grpc_lb_policy_round_robin_init(void);
extern void grpc_lb_policy_round_robin_shutdown(void);
extern void census_grpc_plugin_init(void);
extern void census_grpc_plugin_shutdown(void);
+extern void grpc_max_age_filter_init(void);
+extern void grpc_max_age_filter_shutdown(void);
void grpc_register_built_in_plugins(void) {
grpc_register_plugin(grpc_chttp2_plugin_init,
@@ -75,4 +77,6 @@ void grpc_register_built_in_plugins(void) {
grpc_lb_policy_round_robin_shutdown);
grpc_register_plugin(census_grpc_plugin_init,
census_grpc_plugin_shutdown);
+ grpc_register_plugin(grpc_max_age_filter_init,
+ grpc_max_age_filter_shutdown);
}