Reviewer feedback

pull/15678/head
ncteisen 7 years ago
parent f82e28fb6f
commit 1198d8dfc6
  1. 39
      src/core/ext/filters/client_channel/client_channel.cc
  2. 9
      src/core/ext/filters/client_channel/http_connect_handshaker.cc
  3. 4
      src/core/ext/filters/client_channel/http_proxy.cc
  4. 30
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  5. 4
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc
  6. 4
      src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc
  7. 4
      src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc
  8. 5
      src/core/ext/filters/client_channel/lb_policy_factory.cc
  9. 13
      src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
  10. 7
      src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc
  11. 5
      src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc
  12. 5
      src/core/ext/filters/client_channel/subchannel.cc
  13. 4
      src/core/ext/filters/deadline/deadline_filter.cc
  14. 36
      src/core/ext/filters/http/client/http_client_filter.cc
  15. 4
      src/core/ext/filters/http/http_filters_plugin.cc
  16. 3
      src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc
  17. 13
      src/core/ext/filters/max_age/max_age_filter.cc
  18. 5
      src/core/ext/filters/message_size/message_size_filter.cc
  19. 5
      src/core/ext/transport/chttp2/client/authority.cc
  20. 5
      src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
  21. 8
      src/core/ext/transport/cronet/transport/cronet_transport.cc
  22. 25
      src/core/lib/channel/channel_args.h
  23. 6
      src/core/lib/iomgr/resource_quota.cc
  24. 15
      src/core/lib/iomgr/tcp_client_posix.cc
  25. 5
      src/core/lib/iomgr/tcp_server_custom.cc
  26. 8
      src/core/lib/iomgr/tcp_server_posix.cc
  27. 16
      src/core/lib/iomgr/tcp_server_utils_posix_common.cc
  28. 7
      src/core/lib/iomgr/udp_server.cc
  29. 5
      src/core/lib/security/context/security_context.cc
  30. 1
      src/core/lib/security/context/security_context.h
  31. 10
      src/core/lib/security/credentials/credentials.cc
  32. 5
      src/core/lib/security/credentials/credentials.h
  33. 5
      src/core/lib/security/credentials/fake/fake_credentials.cc
  34. 11
      src/core/lib/security/credentials/google_default/google_default_credentials.cc
  35. 5
      src/core/lib/security/security_connector/security_connector.cc
  36. 3
      src/core/lib/security/security_connector/security_connector.h
  37. 5
      src/core/lib/security/transport/target_authority_table.cc
  38. 5
      test/core/end2end/fixtures/h2_http_proxy.cc
  39. 3
      test/core/end2end/fixtures/http_proxy_fixture.cc

@ -327,15 +327,13 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) {
if (chand->resolver_result != nullptr) {
if (chand->resolver != nullptr) {
// Find LB policy name.
const grpc_arg* channel_arg = grpc_channel_args_find(
const char* lb_policy_name = grpc_channel_args_get_string(
chand->resolver_result, GRPC_ARG_LB_POLICY_NAME);
const char* lb_policy_name = grpc_channel_arg_get_string(channel_arg);
// Special case: If at least one balancer address is present, we use
// the grpclb policy, regardless of what the resolver actually specified.
channel_arg =
grpc_channel_args_find(chand->resolver_result, GRPC_ARG_LB_ADDRESSES);
grpc_lb_addresses* addresses =
grpc_channel_arg_get_pointer<grpc_lb_addresses>(channel_arg);
grpc_channel_args_get_pointer<grpc_lb_addresses>(
chand->resolver_result, GRPC_ARG_LB_ADDRESSES);
if (addresses != nullptr) {
bool found_balancer_address = false;
for (size_t i = 0; i < addresses->num_addresses; ++i) {
@ -400,18 +398,15 @@ static void on_resolver_result_changed_locked(void* arg, grpc_error* error) {
// The copy will be saved in chand->lb_policy_name below.
lb_policy_name_dup = gpr_strdup(lb_policy_name);
// Find service config.
channel_arg = grpc_channel_args_find(chand->resolver_result,
GRPC_ARG_SERVICE_CONFIG);
service_config_json =
gpr_strdup(grpc_channel_arg_get_string(channel_arg));
service_config_json = gpr_strdup(grpc_channel_args_get_string(
chand->resolver_result, GRPC_ARG_SERVICE_CONFIG));
if (service_config_json != nullptr) {
grpc_core::UniquePtr<grpc_core::ServiceConfig> service_config =
grpc_core::ServiceConfig::Create(service_config_json);
if (service_config != nullptr) {
if (chand->enable_retries) {
channel_arg = grpc_channel_args_find(chand->resolver_result,
GRPC_ARG_SERVER_URI);
const char* server_uri = grpc_channel_arg_get_string(channel_arg);
const char* server_uri = grpc_channel_args_get_string(
chand->resolver_result, GRPC_ARG_SERVER_URI);
GPR_ASSERT(server_uri != nullptr);
grpc_uri* uri = grpc_uri_parse(server_uri, true);
GPR_ASSERT(uri->path[0] != '\0');
@ -648,18 +643,16 @@ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem,
"client_channel");
grpc_client_channel_start_backup_polling(chand->interested_parties);
// Record max per-RPC retry buffer size.
const grpc_arg* arg = grpc_channel_args_find(
args->channel_args, GRPC_ARG_PER_RPC_RETRY_BUFFER_SIZE);
chand->per_rpc_retry_buffer_size = (size_t)grpc_channel_arg_get_integer(
arg, {DEFAULT_PER_RPC_RETRY_BUFFER_SIZE, 0, INT_MAX});
chand->per_rpc_retry_buffer_size = (size_t)grpc_channel_args_get_integer(
args->channel_args, GRPC_ARG_PER_RPC_RETRY_BUFFER_SIZE,
{DEFAULT_PER_RPC_RETRY_BUFFER_SIZE, 0, INT_MAX});
// Record enable_retries.
arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_ENABLE_RETRIES);
chand->enable_retries = grpc_channel_arg_get_bool(arg, true);
chand->enable_retries = grpc_channel_args_get_bool(
args->channel_args, GRPC_ARG_ENABLE_RETRIES, true);
// Record client channel factory.
arg = grpc_channel_args_find(args->channel_args,
GRPC_ARG_CLIENT_CHANNEL_FACTORY);
grpc_client_channel_factory* client_channel_factory =
grpc_channel_arg_get_pointer<grpc_client_channel_factory>(arg);
grpc_channel_args_get_pointer<grpc_client_channel_factory>(
args->channel_args, GRPC_ARG_CLIENT_CHANNEL_FACTORY);
if (client_channel_factory == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Missing or malformed client channel factory in args for client "
@ -668,8 +661,8 @@ static grpc_error* cc_init_channel_elem(grpc_channel_element* elem,
grpc_client_channel_factory_ref(client_channel_factory);
chand->client_channel_factory = client_channel_factory;
// Get server name to resolve, using proxy mapper if needed.
arg = grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVER_URI);
char* server_uri = grpc_channel_arg_get_string(arg);
char* server_uri =
grpc_channel_args_get_string(args->channel_args, GRPC_ARG_SERVER_URI);
if (server_uri == nullptr) {
return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"Missing or malformed server uri in args for client channel filter");

@ -254,9 +254,8 @@ static void http_connect_handshaker_do_handshake(
reinterpret_cast<http_connect_handshaker*>(handshaker_in);
// Check for HTTP CONNECT channel arg.
// If not found, invoke on_handshake_done without doing anything.
const grpc_arg* arg =
grpc_channel_args_find(args->args, GRPC_ARG_HTTP_CONNECT_SERVER);
char* server_name = grpc_channel_arg_get_string(arg);
char* server_name =
grpc_channel_args_get_string(args->args, GRPC_ARG_HTTP_CONNECT_SERVER);
if (server_name == nullptr) {
// Set shutdown to true so that subsequent calls to
// http_connect_handshaker_shutdown() do nothing.
@ -267,8 +266,8 @@ static void http_connect_handshaker_do_handshake(
return;
}
// Get headers from channel args.
arg = grpc_channel_args_find(args->args, GRPC_ARG_HTTP_CONNECT_HEADERS);
char* arg_header_string = grpc_channel_arg_get_string(arg);
char* arg_header_string =
grpc_channel_args_get_string(args->args, GRPC_ARG_HTTP_CONNECT_HEADERS);
grpc_http_header* headers = nullptr;
size_t num_headers = 0;
char** header_strings = nullptr;

@ -88,9 +88,7 @@ done:
* should be used.
*/
bool http_proxy_enabled(const grpc_channel_args* args) {
const grpc_arg* arg =
grpc_channel_args_find(args, GRPC_ARG_ENABLE_HTTP_PROXY);
return grpc_channel_arg_get_bool(arg, true);
return grpc_channel_args_get_bool(args, GRPC_ARG_ENABLE_HTTP_PROXY, true);
}
static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper,

@ -1045,8 +1045,8 @@ GrpcLb::GrpcLb(const grpc_lb_addresses* addresses,
grpc_combiner_scheduler(args.combiner));
grpc_connectivity_state_init(&state_tracker_, GRPC_CHANNEL_IDLE, "grpclb");
// Record server name.
const grpc_arg* arg = grpc_channel_args_find(args.args, GRPC_ARG_SERVER_URI);
const char* server_uri = grpc_channel_arg_get_string(arg);
const char* server_uri =
grpc_channel_args_get_string(args.args, GRPC_ARG_SERVER_URI);
GPR_ASSERT(server_uri != nullptr);
grpc_uri* uri = grpc_uri_parse(server_uri, true);
GPR_ASSERT(uri->path[0] != '\0');
@ -1058,12 +1058,12 @@ GrpcLb::GrpcLb(const grpc_lb_addresses* addresses,
}
grpc_uri_destroy(uri);
// Record LB call timeout.
arg = grpc_channel_args_find(args.args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS);
lb_call_timeout_ms_ = grpc_channel_arg_get_integer(arg, {0, 0, INT_MAX});
lb_call_timeout_ms_ = grpc_channel_args_get_integer(
args.args, GRPC_ARG_GRPCLB_CALL_TIMEOUT_MS, {0, 0, INT_MAX});
// Record fallback timeout.
arg = grpc_channel_args_find(args.args, GRPC_ARG_GRPCLB_FALLBACK_TIMEOUT_MS);
lb_fallback_timeout_ms_ = grpc_channel_arg_get_integer(
arg, {GRPC_GRPCLB_DEFAULT_FALLBACK_TIMEOUT_MS, 0, INT_MAX});
lb_fallback_timeout_ms_ = grpc_channel_args_get_integer(
args.args, GRPC_ARG_GRPCLB_FALLBACK_TIMEOUT_MS,
{GRPC_GRPCLB_DEFAULT_FALLBACK_TIMEOUT_MS, 0, INT_MAX});
// Process channel args.
ProcessChannelArgsLocked(*args.args);
}
@ -1284,9 +1284,9 @@ void GrpcLb::NotifyOnStateChangeLocked(grpc_connectivity_state* current,
}
void GrpcLb::ProcessChannelArgsLocked(const grpc_channel_args& args) {
const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES);
const grpc_lb_addresses* addresses =
grpc_channel_arg_get_pointer<grpc_lb_addresses>(arg);
grpc_channel_args_get_pointer<grpc_lb_addresses>(&args,
GRPC_ARG_LB_ADDRESSES);
if (GPR_UNLIKELY(addresses == nullptr)) {
// Ignore this update.
gpr_log(
@ -1860,11 +1860,10 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory {
OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
const LoadBalancingPolicy::Args& args) const override {
/* Count the number of gRPC-LB addresses. There must be at least one. */
const grpc_arg* arg =
grpc_channel_args_find(args.args, GRPC_ARG_LB_ADDRESSES);
grpc_lb_addresses* addresses =
grpc_channel_arg_get_pointer<grpc_lb_addresses>(arg);
if (addresses) {
grpc_channel_args_get_pointer<grpc_lb_addresses>(args.args,
GRPC_ARG_LB_ADDRESSES);
if (addresses == nullptr) {
return nullptr;
}
size_t num_grpclb_addrs = 0;
@ -1893,9 +1892,8 @@ bool maybe_add_client_load_reporting_filter(grpc_channel_stack_builder* builder,
void* arg) {
const grpc_channel_args* args =
grpc_channel_stack_builder_get_channel_arguments(builder);
const grpc_arg* channel_arg =
grpc_channel_args_find(args, GRPC_ARG_LB_POLICY_NAME);
const char* lb_policy = grpc_channel_arg_get_string(channel_arg);
const char* lb_policy =
grpc_channel_args_get_string(args, GRPC_ARG_LB_POLICY_NAME);
if (lb_policy != nullptr && strcmp(lb_policy, "grpclb") == 0) {
return grpc_channel_stack_builder_append_filter(
builder, (const grpc_channel_filter*)arg, nullptr, nullptr);

@ -72,9 +72,9 @@ grpc_channel_args* grpc_lb_policy_grpclb_modify_lb_channel_args(
grpc_arg args_to_add[2];
size_t num_args_to_add = 0;
// Add arg for targets info table.
const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_LB_ADDRESSES);
grpc_lb_addresses* addresses =
grpc_channel_arg_get_pointer<grpc_lb_addresses>(arg);
grpc_channel_args_get_pointer<grpc_lb_addresses>(args,
GRPC_ARG_LB_ADDRESSES);
GPR_ASSERT(addresses != nullptr);
grpc_core::RefCountedPtr<grpc_core::TargetAuthorityTable>
target_authority_table = grpc_core::CreateTargetAuthorityTable(addresses);

@ -281,9 +281,9 @@ void PickFirst::PingOneLocked(grpc_closure* on_initiate, grpc_closure* on_ack) {
}
void PickFirst::UpdateLocked(const grpc_channel_args& args) {
const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES);
const grpc_lb_addresses* addresses =
grpc_channel_arg_get_pointer<const grpc_lb_addresses>(arg);
grpc_channel_args_get_pointer<const grpc_lb_addresses>(
&args, GRPC_ARG_LB_ADDRESSES);
if (addresses == nullptr) {
if (subchannel_list_ == nullptr) {
// If we don't have a current subchannel list, go into TRANSIENT FAILURE.

@ -607,9 +607,9 @@ void RoundRobin::PingOneLocked(grpc_closure* on_initiate,
}
void RoundRobin::UpdateLocked(const grpc_channel_args& args) {
const grpc_arg* arg = grpc_channel_args_find(&args, GRPC_ARG_LB_ADDRESSES);
grpc_lb_addresses* addresses =
grpc_channel_arg_get_pointer<grpc_lb_addresses>(arg);
grpc_channel_args_get_pointer<grpc_lb_addresses>(&args,
GRPC_ARG_LB_ADDRESSES);
if (GPR_UNLIKELY(addresses == nullptr)) {
gpr_log(GPR_ERROR, "[RR %p] update provided no addresses; ignoring", this);
// If we don't have a current subchannel list, go into TRANSIENT_FAILURE.

@ -147,7 +147,6 @@ grpc_arg grpc_lb_addresses_create_channel_arg(
grpc_lb_addresses* grpc_lb_addresses_find_channel_arg(
const grpc_channel_args* channel_args) {
const grpc_arg* lb_addresses_arg =
grpc_channel_args_find(channel_args, GRPC_ARG_LB_ADDRESSES);
return grpc_channel_arg_get_pointer<grpc_lb_addresses>(lb_addresses_arg);
return grpc_channel_args_get_pointer<grpc_lb_addresses>(
channel_args, GRPC_ARG_LB_ADDRESSES);
}

@ -140,14 +140,11 @@ AresDnsResolver::AresDnsResolver(const ResolverArgs& args)
dns_server_ = gpr_strdup(args.uri->authority);
}
channel_args_ = grpc_channel_args_copy(args.args);
const grpc_arg* arg = grpc_channel_args_find(
channel_args_, GRPC_ARG_SERVICE_CONFIG_DISABLE_RESOLUTION);
request_service_config_ = !grpc_channel_arg_get_integer(
arg, (grpc_integer_options){false, false, true});
arg = grpc_channel_args_find(channel_args_,
GRPC_ARG_DNS_MIN_TIME_BETWEEN_RESOLUTIONS_MS);
min_time_between_resolutions_ =
grpc_channel_arg_get_integer(arg, {1000, 0, INT_MAX});
request_service_config_ = !grpc_channel_args_get_bool(
channel_args_, GRPC_ARG_SERVICE_CONFIG_DISABLE_RESOLUTION, false);
min_time_between_resolutions_ = grpc_channel_args_get_integer(
channel_args_, GRPC_ARG_DNS_MIN_TIME_BETWEEN_RESOLUTIONS_MS,
{1000, 0, INT_MAX});
interested_parties_ = grpc_pollset_set_create();
if (args.pollset_set != nullptr) {
grpc_pollset_set_add_pollset_set(interested_parties_, args.pollset_set);

@ -116,10 +116,9 @@ NativeDnsResolver::NativeDnsResolver(const ResolverArgs& args)
if (path[0] == '/') ++path;
name_to_resolve_ = gpr_strdup(path);
channel_args_ = grpc_channel_args_copy(args.args);
const grpc_arg* arg = grpc_channel_args_find(
args.args, GRPC_ARG_DNS_MIN_TIME_BETWEEN_RESOLUTIONS_MS);
min_time_between_resolutions_ =
grpc_channel_arg_get_integer(arg, {1000, 0, INT_MAX});
min_time_between_resolutions_ = grpc_channel_args_get_integer(
args.args, GRPC_ARG_DNS_MIN_TIME_BETWEEN_RESOLUTIONS_MS,
{1000, 0, INT_MAX});
interested_parties_ = grpc_pollset_set_create();
if (args.pollset_set != nullptr) {
grpc_pollset_set_add_pollset_set(interested_parties_, args.pollset_set);

@ -259,9 +259,8 @@ grpc_arg FakeResolverResponseGenerator::MakeChannelArg(
FakeResolverResponseGenerator* FakeResolverResponseGenerator::GetFromArgs(
const grpc_channel_args* args) {
const grpc_arg* arg =
grpc_channel_args_find(args, GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR);
return grpc_channel_arg_get_pointer<FakeResolverResponseGenerator>(arg);
return grpc_channel_args_get_pointer<FakeResolverResponseGenerator>(
args, GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR);
}
//

@ -736,9 +736,8 @@ void grpc_get_subchannel_address_arg(const grpc_channel_args* args,
}
const char* grpc_get_subchannel_address_uri_arg(const grpc_channel_args* args) {
const grpc_arg* addr_arg =
grpc_channel_args_find(args, GRPC_ARG_SUBCHANNEL_ADDRESS);
const char* addr_str = grpc_channel_arg_get_string(addr_arg);
const char* addr_str =
grpc_channel_args_get_string(args, GRPC_ARG_SUBCHANNEL_ADDRESS);
GPR_ASSERT(addr_str != nullptr); // Should have been set by LB policy.
return addr_str;
}

@ -358,8 +358,8 @@ const grpc_channel_filter grpc_server_deadline_filter = {
};
bool grpc_deadline_checking_enabled(const grpc_channel_args* channel_args) {
return grpc_channel_arg_get_bool(
grpc_channel_args_find(channel_args, GRPC_ARG_ENABLE_DEADLINE_CHECKS),
return grpc_channel_args_get_bool(
channel_args, GRPC_ARG_ENABLE_DEADLINE_CHECKS,
!grpc_channel_args_want_minimal_stack(channel_args));
}

@ -437,18 +437,14 @@ static void destroy_call_elem(grpc_call_element* elem,
grpc_closure* ignored) {}
static grpc_mdelem scheme_from_args(const grpc_channel_args* channel_args) {
size_t i;
grpc_mdelem valid_schemes[] = {GRPC_MDELEM_SCHEME_HTTP,
GRPC_MDELEM_SCHEME_HTTPS};
if (channel_args != nullptr) {
const grpc_arg* arg =
grpc_channel_args_find(channel_args, GRPC_ARG_HTTP2_SCHEME);
char* scheme = grpc_channel_arg_get_string(arg);
if (scheme != nullptr) {
for (i = 0; i < GPR_ARRAY_SIZE(valid_schemes); i++) {
if (0 == grpc_slice_str_cmp(GRPC_MDVALUE(valid_schemes[i]), scheme)) {
return valid_schemes[i];
}
char* scheme =
grpc_channel_args_get_string(channel_args, GRPC_ARG_HTTP2_SCHEME);
if (scheme != nullptr) {
for (size_t i = 0; i < GPR_ARRAY_SIZE(valid_schemes); i++) {
if (0 == grpc_slice_str_cmp(GRPC_MDVALUE(valid_schemes[i]), scheme)) {
return valid_schemes[i];
}
}
}
@ -457,14 +453,9 @@ static grpc_mdelem scheme_from_args(const grpc_channel_args* channel_args) {
static size_t max_payload_size_from_args(
const grpc_channel_args* channel_args) {
if (channel_args != nullptr) {
const grpc_arg* arg =
grpc_channel_args_find(channel_args, GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET);
// TODO(mark): is 0 a correct minimum for this value?
return grpc_channel_arg_get_integer(
arg, {kMaxPayloadSizeForGet, 0, kMaxPayloadSizeForGet});
}
return kMaxPayloadSizeForGet;
return grpc_channel_args_get_integer(
channel_args, GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET,
{kMaxPayloadSizeForGet, 0, kMaxPayloadSizeForGet});
}
static grpc_slice user_agent_from_args(const grpc_channel_args* args,
@ -476,9 +467,8 @@ static grpc_slice user_agent_from_args(const grpc_channel_args* args,
gpr_strvec_init(&v);
const grpc_arg* arg =
grpc_channel_args_find(args, GRPC_ARG_PRIMARY_USER_AGENT_STRING);
char* user_agent_str = grpc_channel_arg_get_string(arg);
char* user_agent_str =
grpc_channel_args_get_string(args, GRPC_ARG_PRIMARY_USER_AGENT_STRING);
if (user_agent_str != nullptr) {
if (!is_first) gpr_strvec_add(&v, gpr_strdup(" "));
is_first = 0;
@ -491,8 +481,8 @@ static grpc_slice user_agent_from_args(const grpc_channel_args* args,
is_first = 0;
gpr_strvec_add(&v, tmp);
arg = grpc_channel_args_find(args, GRPC_ARG_SECONDARY_USER_AGENT_STRING);
user_agent_str = grpc_channel_arg_get_string(arg);
user_agent_str =
grpc_channel_args_get_string(args, GRPC_ARG_SECONDARY_USER_AGENT_STRING);
if (user_agent_str != nullptr) {
gpr_strvec_add(&v, gpr_strdup(" "));
gpr_strvec_add(&v, gpr_strdup(user_agent_str));

@ -48,8 +48,8 @@ static bool maybe_add_optional_filter(grpc_channel_stack_builder* builder,
optional_filter* filtarg = static_cast<optional_filter*>(arg);
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
bool enable = grpc_channel_arg_get_bool(
grpc_channel_args_find(channel_args, filtarg->control_channel_arg),
bool enable = grpc_channel_args_get_bool(
channel_args, filtarg->control_channel_arg,
!grpc_channel_args_want_minimal_stack(channel_args));
return enable ? grpc_channel_stack_builder_prepend_filter(
builder, filtarg->filter, nullptr, nullptr)

@ -33,8 +33,7 @@
#include "src/core/lib/surface/channel_init.h"
static bool is_load_reporting_enabled(const grpc_channel_args* a) {
return grpc_channel_arg_get_bool(
grpc_channel_args_find(a, GRPC_ARG_ENABLE_LOAD_REPORTING), false);
return grpc_channel_args_get_bool(a, GRPC_ARG_ENABLE_LOAD_REPORTING, false);
}
static bool maybe_add_server_load_reporting_filter(

@ -519,13 +519,12 @@ static bool maybe_add_max_age_filter(grpc_channel_stack_builder* builder,
void* arg) {
const grpc_channel_args* channel_args =
grpc_channel_stack_builder_get_channel_arguments(builder);
bool enable =
grpc_channel_arg_get_integer(
grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_AGE_MS),
MAX_CONNECTION_AGE_INTEGER_OPTIONS) != INT_MAX ||
grpc_channel_arg_get_integer(
grpc_channel_args_find(channel_args, GRPC_ARG_MAX_CONNECTION_IDLE_MS),
MAX_CONNECTION_IDLE_INTEGER_OPTIONS) != INT_MAX;
bool enable = grpc_channel_args_get_integer(
channel_args, GRPC_ARG_MAX_CONNECTION_AGE_MS,
MAX_CONNECTION_AGE_INTEGER_OPTIONS) != INT_MAX ||
grpc_channel_args_get_integer(
channel_args, GRPC_ARG_MAX_CONNECTION_IDLE_MS,
MAX_CONNECTION_IDLE_INTEGER_OPTIONS) != INT_MAX;
if (enable) {
return grpc_channel_stack_builder_prepend_filter(
builder, &grpc_max_age_filter, nullptr, nullptr);

@ -254,9 +254,8 @@ static grpc_error* init_channel_elem(grpc_channel_element* elem,
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
chand->limits = get_message_size_limits(args->channel_args);
// Get method config table from channel args.
const grpc_arg* channel_arg =
grpc_channel_args_find(args->channel_args, GRPC_ARG_SERVICE_CONFIG);
const char* service_config_str = grpc_channel_arg_get_string(channel_arg);
const char* service_config_str =
grpc_channel_args_get_string(args->channel_args, GRPC_ARG_SERVICE_CONFIG);
if (service_config_str != nullptr) {
grpc_core::UniquePtr<grpc_core::ServiceConfig> service_config =
grpc_core::ServiceConfig::Create(service_config_str);

@ -28,9 +28,8 @@ grpc_channel_args* grpc_default_authority_add_if_not_present(
size_t num_new_args = 0;
grpc_core::UniquePtr<char> default_authority;
if (!has_default_authority) {
const grpc_arg* server_uri_arg =
grpc_channel_args_find(args, GRPC_ARG_SERVER_URI);
const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg);
const char* server_uri_str =
grpc_channel_args_get_string(args, GRPC_ARG_SERVER_URI);
GPR_ASSERT(server_uri_str != nullptr);
default_authority =
grpc_core::ResolverRegistry::GetDefaultAuthority(server_uri_str);

@ -64,9 +64,8 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
return nullptr;
}
// To which address are we connecting? By default, use the server URI.
const grpc_arg* server_uri_arg =
grpc_channel_args_find(args->args, GRPC_ARG_SERVER_URI);
const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg);
const char* server_uri_str =
grpc_channel_args_get_string(args->args, GRPC_ARG_SERVER_URI);
GPR_ASSERT(server_uri_str != nullptr);
grpc_uri* server_uri =
grpc_uri_parse(server_uri_str, true /* supress errors */);

@ -1450,12 +1450,8 @@ grpc_transport* grpc_create_cronet_transport(void* engine, const char* target,
}
strcpy(ct->host, target);
ct->use_packet_coalescing = true;
if (args) {
const grpc_arg* arg =
grpc_channel_args_find(args, GRPC_ARG_USE_CRONET_PACKET_COALESCING);
ct->use_packet_coalescing = grpc_channel_arg_get_bool(arg, false);
}
ct->use_packet_coalescing = grpc_channel_args_get_bool(
args, GRPC_ARG_USE_CRONET_PACKET_COALESCING, true);
return &ct->base;

@ -111,17 +111,29 @@ typedef struct grpc_integer_options {
/** Returns the value of \a arg, subject to the contraints in \a options. */
int grpc_channel_arg_get_integer(const grpc_arg* arg,
const grpc_integer_options options);
/** convinience helper for the above that finds the arg first. */
inline int grpc_channel_args_get_integer(const grpc_channel_args* args,
const char* name,
const grpc_integer_options options) {
return grpc_channel_arg_get_integer(grpc_channel_args_find(args, name),
options);
}
/** Returns the value of \a arg if \a arg is of type GRPC_ARG_STRING.
Otherwise, emits a warning log, and returns nullptr.
If arg is nullptr, returns nullptr, and does not emit a warning. */
char* grpc_channel_arg_get_string(const grpc_arg* arg);
/** convinience helper for the above that finds the arg first. */
inline char* grpc_channel_args_get_string(const grpc_channel_args* args,
const char* name) {
return grpc_channel_arg_get_string(grpc_channel_args_find(args, name));
}
/** Returns the value of \a arg if \a arg is of type GRPC_ARG_POINTER
Otherwise, emits a warning log, and returns nullptr.
If arg is nullptr, returns nullptr, and does not emit a warning. */
template <typename Type>
Type* grpc_channel_arg_get_pointer(const grpc_arg* arg) {
inline Type* grpc_channel_arg_get_pointer(const grpc_arg* arg) {
if (arg == nullptr) return nullptr;
if (arg->type != GRPC_ARG_POINTER) {
gpr_log(GPR_ERROR, "%s ignored: it must be an pointer", arg->key);
@ -129,8 +141,19 @@ Type* grpc_channel_arg_get_pointer(const grpc_arg* arg) {
}
return static_cast<Type*>(arg->value.pointer.p);
}
/** convinience helper for the above that finds the arg first. */
template <typename Type>
inline Type* grpc_channel_args_get_pointer(const grpc_channel_args* args,
const char* name) {
return grpc_channel_arg_get_pointer<Type>(grpc_channel_args_find(args, name));
}
bool grpc_channel_arg_get_bool(const grpc_arg* arg, bool default_value);
inline bool grpc_channel_args_get_bool(const grpc_channel_args* args,
const char* name, bool default_value) {
return grpc_channel_arg_get_bool(grpc_channel_args_find(args, name),
default_value);
}
// Helpers for creating channel args.
grpc_arg grpc_channel_arg_string_create(char* name, char* value);

@ -671,10 +671,8 @@ size_t grpc_resource_quota_peek_size(grpc_resource_quota* resource_quota) {
grpc_resource_quota* grpc_resource_quota_from_channel_args(
const grpc_channel_args* channel_args) {
const grpc_arg* arg =
grpc_channel_args_find(channel_args, GRPC_ARG_RESOURCE_QUOTA);
grpc_resource_quota* rq =
grpc_channel_arg_get_pointer<grpc_resource_quota>(arg);
grpc_resource_quota* rq = grpc_channel_args_get_pointer<grpc_resource_quota>(
channel_args, GRPC_ARG_RESOURCE_QUOTA);
return rq == nullptr ? grpc_resource_quota_create(nullptr) : rq;
}

@ -66,6 +66,7 @@ typedef struct {
static grpc_error* prepare_socket(const grpc_resolved_address* addr, int fd,
const grpc_channel_args* channel_args) {
grpc_error* err = GRPC_ERROR_NONE;
grpc_socket_mutator* mutator = nullptr;
GPR_ASSERT(fd >= 0);
@ -79,15 +80,11 @@ static grpc_error* prepare_socket(const grpc_resolved_address* addr, int fd,
}
err = grpc_set_socket_no_sigpipe_if_possible(fd);
if (err != GRPC_ERROR_NONE) goto error;
if (channel_args) {
const grpc_arg* arg =
grpc_channel_args_find(channel_args, GRPC_ARG_SOCKET_MUTATOR);
grpc_socket_mutator* mutator =
grpc_channel_arg_get_pointer<grpc_socket_mutator>(arg);
if (mutator) {
err = grpc_set_socket_with_mutator(fd, mutator);
if (err != GRPC_ERROR_NONE) goto error;
}
mutator = grpc_channel_args_get_pointer<grpc_socket_mutator>(
channel_args, GRPC_ARG_SOCKET_MUTATOR);
if (mutator != nullptr) {
err = grpc_set_socket_with_mutator(fd, mutator);
if (err != GRPC_ERROR_NONE) goto error;
}
goto done;

@ -81,9 +81,8 @@ static grpc_error* tcp_server_create(grpc_closure* shutdown_complete,
const grpc_channel_args* args,
grpc_tcp_server** server) {
grpc_tcp_server* s = (grpc_tcp_server*)gpr_malloc(sizeof(grpc_tcp_server));
const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_RESOURCE_QUOTA);
grpc_resource_quota* rq =
grpc_channel_arg_get_pointer<grpc_resource_quota>(arg);
grpc_resource_quota* rq = grpc_channel_args_get_pointer<grpc_resource_quota>(
args, GRPC_ARG_RESOURCE_QUOTA);
s->resource_quota = rq == nullptr ? grpc_resource_quota_create(nullptr) : rq;
gpr_ref_init(&s->refs, 1);
s->on_accept_cb = nullptr;

@ -63,14 +63,12 @@ static grpc_error* tcp_server_create(grpc_closure* shutdown_complete,
s->so_reuseport = grpc_is_socket_reuse_port_supported();
s->expand_wildcard_addrs = false;
for (size_t i = 0; i < (args == nullptr ? 0 : args->num_args); i++) {
// TODO(roth): I chose that these both default to true. Is this reasonable?
// Before they would create errors, so this is actually making the
// restrictions more lenient.
if (0 == strcmp(GRPC_ARG_ALLOW_REUSEPORT, args->args[i].key)) {
s->so_reuseport = grpc_channel_arg_get_bool(&args->args[i], true);
s->so_reuseport = grpc_channel_arg_get_bool(
&args->args[i], grpc_is_socket_reuse_port_supported());
} else if (0 == strcmp(GRPC_ARG_EXPAND_WILDCARD_ADDRS, args->args[i].key)) {
s->expand_wildcard_addrs =
grpc_channel_arg_get_bool(&args->args[i], true);
grpc_channel_arg_get_bool(&args->args[i], false);
}
}
gpr_ref_init(&s->refs, 1);

@ -150,6 +150,7 @@ grpc_error* grpc_tcp_server_prepare_socket(grpc_tcp_server* s, int fd,
bool so_reuseport, int* port) {
grpc_resolved_address sockname_temp;
grpc_error* err = GRPC_ERROR_NONE;
grpc_socket_mutator* mutator = nullptr;
GPR_ASSERT(fd >= 0);
@ -170,16 +171,11 @@ grpc_error* grpc_tcp_server_prepare_socket(grpc_tcp_server* s, int fd,
}
err = grpc_set_socket_no_sigpipe_if_possible(fd);
if (err != GRPC_ERROR_NONE) goto error;
if (s->channel_args) {
const grpc_arg* arg =
grpc_channel_args_find(s->channel_args, GRPC_ARG_SOCKET_MUTATOR);
grpc_socket_mutator* mutator =
grpc_channel_arg_get_pointer<grpc_socket_mutator>(arg);
if (mutator) {
err = grpc_set_socket_with_mutator(fd, mutator);
if (err != GRPC_ERROR_NONE) goto error;
}
mutator = grpc_channel_args_get_pointer<grpc_socket_mutator>(
s->channel_args, GRPC_ARG_SOCKET_MUTATOR);
if (mutator != nullptr) {
err = grpc_set_socket_with_mutator(fd, mutator);
if (err != GRPC_ERROR_NONE) goto error;
}
if (bind(fd, reinterpret_cast<grpc_sockaddr*>(const_cast<char*>(addr->addr)),

@ -197,11 +197,8 @@ struct grpc_udp_server {
};
static grpc_socket_factory* get_socket_factory(const grpc_channel_args* args) {
if (args) {
const grpc_arg* arg = grpc_channel_args_find(args, GRPC_ARG_SOCKET_FACTORY);
return grpc_channel_arg_get_pointer<grpc_socket_factory>(arg);
}
return nullptr;
return grpc_channel_args_get_pointer<grpc_socket_factory>(
args, GRPC_ARG_SOCKET_FACTORY);
}
grpc_udp_server* grpc_udp_server_create(const grpc_channel_args* args) {

@ -328,7 +328,6 @@ grpc_arg grpc_auth_context_to_arg(grpc_auth_context* p) {
grpc_auth_context* grpc_find_auth_context_in_args(
const grpc_channel_args* channel_args) {
const grpc_arg* arg =
grpc_channel_args_find(channel_args, GRPC_AUTH_CONTEXT_ARG);
return grpc_channel_arg_get_pointer<grpc_auth_context>(arg);
return grpc_channel_args_get_pointer<grpc_auth_context>(
channel_args, GRPC_AUTH_CONTEXT_ARG);
}

@ -108,7 +108,6 @@ void grpc_server_security_context_destroy(void* ctx);
#define GRPC_AUTH_CONTEXT_ARG "grpc.auth_context"
grpc_arg grpc_auth_context_to_arg(grpc_auth_context* c);
grpc_auth_context* grpc_auth_context_from_arg(const grpc_arg* arg);
grpc_auth_context* grpc_find_auth_context_in_args(
const grpc_channel_args* args);

@ -170,9 +170,8 @@ grpc_arg grpc_channel_credentials_to_arg(
grpc_channel_credentials* grpc_channel_credentials_find_in_args(
const grpc_channel_args* channel_args) {
const grpc_arg* arg =
grpc_channel_args_find(channel_args, GRPC_ARG_CHANNEL_CREDENTIALS);
return grpc_channel_arg_get_pointer<grpc_channel_credentials>(arg);
return grpc_channel_args_get_pointer<grpc_channel_credentials>(
channel_args, GRPC_ARG_CHANNEL_CREDENTIALS);
}
grpc_server_credentials* grpc_server_credentials_ref(
@ -249,7 +248,6 @@ grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials* p) {
grpc_server_credentials* grpc_find_server_credentials_in_args(
const grpc_channel_args* channel_args) {
const grpc_arg* arg =
grpc_channel_args_find(channel_args, GRPC_SERVER_CREDENTIALS_ARG);
return grpc_channel_arg_get_pointer<grpc_server_credentials>(arg);
return grpc_channel_args_get_pointer<grpc_server_credentials>(
channel_args, GRPC_SERVER_CREDENTIALS_ARG);
}

@ -131,10 +131,6 @@ grpc_channel_credentials_duplicate_without_call_credentials(
/* Util to encapsulate the channel credentials in a channel arg. */
grpc_arg grpc_channel_credentials_to_arg(grpc_channel_credentials* credentials);
/* Util to get the channel credentials from a channel arg. */
grpc_channel_credentials* grpc_channel_credentials_from_arg(
const grpc_arg* arg);
/* Util to find the channel credentials from channel args. */
grpc_channel_credentials* grpc_channel_credentials_find_in_args(
const grpc_channel_args* args);
@ -227,7 +223,6 @@ void grpc_server_credentials_unref(grpc_server_credentials* creds);
#define GRPC_SERVER_CREDENTIALS_ARG "grpc.server_credentials"
grpc_arg grpc_server_credentials_to_arg(grpc_server_credentials* c);
grpc_server_credentials* grpc_server_credentials_from_arg(const grpc_arg* arg);
grpc_server_credentials* grpc_find_server_credentials_in_args(
const grpc_channel_args* args);

@ -84,9 +84,8 @@ grpc_arg grpc_fake_transport_expected_targets_arg(char* expected_targets) {
const char* grpc_fake_transport_get_expected_targets(
const grpc_channel_args* args) {
const grpc_arg* expected_target_arg =
grpc_channel_args_find(args, GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS);
return grpc_channel_arg_get_string(expected_target_arg);
return grpc_channel_args_get_string(args,
GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS);
}
/* -- Metadata-only test credentials. -- */

@ -79,13 +79,10 @@ static grpc_security_status google_default_create_security_connector(
grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
grpc_google_default_channel_credentials* c =
reinterpret_cast<grpc_google_default_channel_credentials*>(creds);
bool is_grpclb_load_balancer = grpc_channel_arg_get_bool(
grpc_channel_args_find(args, GRPC_ARG_ADDRESS_IS_GRPCLB_LOAD_BALANCER),
false);
bool is_backend_from_grpclb_load_balancer = grpc_channel_arg_get_bool(
grpc_channel_args_find(
args, GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER),
false);
bool is_grpclb_load_balancer = grpc_channel_args_get_bool(
args, GRPC_ARG_ADDRESS_IS_GRPCLB_LOAD_BALANCER, false);
bool is_backend_from_grpclb_load_balancer = grpc_channel_args_get_bool(
args, GRPC_ARG_ADDRESS_IS_BACKEND_FROM_GRPCLB_LOAD_BALANCER, false);
bool use_alts =
is_grpclb_load_balancer || is_backend_from_grpclb_load_balancer;
grpc_security_status status = GRPC_SECURITY_ERROR;

@ -257,9 +257,8 @@ grpc_arg grpc_security_connector_to_arg(grpc_security_connector* sc) {
grpc_security_connector* grpc_security_connector_find_in_args(
const grpc_channel_args* channel_args) {
const grpc_arg* arg =
grpc_channel_args_find(channel_args, GRPC_ARG_SECURITY_CONNECTOR);
return grpc_channel_arg_get_pointer<grpc_security_connector>(arg);
return grpc_channel_args_get_pointer<grpc_security_connector>(
channel_args, GRPC_ARG_SECURITY_CONNECTOR);
}
static tsi_client_certificate_request_type

@ -99,9 +99,6 @@ int grpc_security_connector_cmp(grpc_security_connector* sc,
/* Util to encapsulate the connector in a channel arg. */
grpc_arg grpc_security_connector_to_arg(grpc_security_connector* sc);
/* Util to get the connector from a channel arg. */
grpc_security_connector* grpc_security_connector_from_arg(const grpc_arg* arg);
/* Util to find the connector from channel args. */
grpc_security_connector* grpc_security_connector_find_in_args(
const grpc_channel_args* args);

@ -59,9 +59,8 @@ grpc_arg CreateTargetAuthorityTableChannelArg(TargetAuthorityTable* table) {
TargetAuthorityTable* FindTargetAuthorityTableInArgs(
const grpc_channel_args* args) {
const grpc_arg* arg =
grpc_channel_args_find(args, GRPC_ARG_TARGET_AUTHORITY_TABLE);
return grpc_channel_arg_get_pointer<TargetAuthorityTable>(arg);
return grpc_channel_args_get_pointer<TargetAuthorityTable>(
args, GRPC_ARG_TARGET_AUTHORITY_TABLE);
}
} // namespace grpc_core

@ -69,9 +69,8 @@ void chttp2_init_client_fullstack(grpc_end2end_test_fixture* f,
char* proxy_uri;
/* If testing for proxy auth, add credentials to proxy uri */
const grpc_arg* proxy_auth_arg =
grpc_channel_args_find(client_args, GRPC_ARG_HTTP_PROXY_AUTH_CREDS);
const char* proxy_auth_str = grpc_channel_arg_get_string(proxy_auth_arg);
const char* proxy_auth_str =
grpc_channel_args_get_string(client_args, GRPC_ARG_HTTP_PROXY_AUTH_CREDS);
if (proxy_auth_str == nullptr) {
gpr_asprintf(&proxy_uri, "http://%s",
grpc_end2end_http_proxy_get_proxy_name(ffd->proxy));

@ -411,9 +411,8 @@ static void on_read_request_done(void* arg, grpc_error* error) {
return;
}
// If proxy auth is being used, check if the header is present and as expected
const grpc_arg* proxy_auth_arg = grpc_channel_args_find(
char* proxy_auth_str = grpc_channel_args_get_string(
conn->proxy->channel_args, GRPC_ARG_HTTP_PROXY_AUTH_CREDS);
char* proxy_auth_str = grpc_channel_arg_get_string(proxy_auth_arg);
if (proxy_auth_str != nullptr) {
bool client_authenticated = false;
for (size_t i = 0; i < conn->http_request.hdr_count; i++) {

Loading…
Cancel
Save