|
|
|
@ -39,7 +39,7 @@ |
|
|
|
|
#include <grpc/support/string_util.h> |
|
|
|
|
#include <grpc/support/time.h> |
|
|
|
|
|
|
|
|
|
#include "src/core/lib/transport/hashtable.h" |
|
|
|
|
#include "src/core/lib/transport/mdstr_hash_table.h" |
|
|
|
|
#include "src/core/lib/transport/metadata.h" |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -63,7 +63,8 @@ static int bool_cmp(void* v1, void* v2) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static grpc_hash_table_vtable bool_vtable = {gpr_free, bool_copy, bool_cmp}; |
|
|
|
|
static grpc_mdstr_hash_table_vtable bool_vtable = {gpr_free, bool_copy, |
|
|
|
|
bool_cmp}; |
|
|
|
|
|
|
|
|
|
// timespec vtable
|
|
|
|
|
|
|
|
|
@ -78,8 +79,8 @@ static int timespec_cmp(void* v1, void* v2) { |
|
|
|
|
return gpr_time_cmp(*(gpr_timespec*)v1, *(gpr_timespec*)v2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static grpc_hash_table_vtable timespec_vtable = {gpr_free, timespec_copy, |
|
|
|
|
timespec_cmp}; |
|
|
|
|
static grpc_mdstr_hash_table_vtable timespec_vtable = {gpr_free, timespec_copy, |
|
|
|
|
timespec_cmp}; |
|
|
|
|
|
|
|
|
|
// int32 vtable
|
|
|
|
|
|
|
|
|
@ -98,7 +99,8 @@ static int int32_cmp(void* v1, void* v2) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static grpc_hash_table_vtable int32_vtable = {gpr_free, int32_copy, int32_cmp}; |
|
|
|
|
static grpc_mdstr_hash_table_vtable int32_vtable = {gpr_free, int32_copy, |
|
|
|
|
int32_cmp}; |
|
|
|
|
|
|
|
|
|
// Hash table keys.
|
|
|
|
|
#define GRPC_METHOD_CONFIG_WAIT_FOR_READY "grpc.wait_for_ready" // bool
|
|
|
|
@ -109,7 +111,7 @@ static grpc_hash_table_vtable int32_vtable = {gpr_free, int32_copy, int32_cmp}; |
|
|
|
|
"grpc.max_response_message_bytes" // int32
|
|
|
|
|
|
|
|
|
|
struct grpc_method_config { |
|
|
|
|
grpc_hash_table* table; |
|
|
|
|
grpc_mdstr_hash_table* table; |
|
|
|
|
grpc_mdstr* wait_for_ready_key; |
|
|
|
|
grpc_mdstr* timeout_key; |
|
|
|
|
grpc_mdstr* max_request_message_bytes_key; |
|
|
|
@ -129,7 +131,7 @@ grpc_method_config* grpc_method_config_create( |
|
|
|
|
grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES); |
|
|
|
|
method_config->max_response_message_bytes_key = |
|
|
|
|
grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES); |
|
|
|
|
grpc_hash_table_entry entries[4]; |
|
|
|
|
grpc_mdstr_hash_table_entry entries[4]; |
|
|
|
|
size_t num_entries = 0; |
|
|
|
|
if (wait_for_ready != NULL) { |
|
|
|
|
entries[num_entries].key = method_config->wait_for_ready_key; |
|
|
|
@ -155,17 +157,17 @@ grpc_method_config* grpc_method_config_create( |
|
|
|
|
entries[num_entries].vtable = &int32_vtable; |
|
|
|
|
++num_entries; |
|
|
|
|
} |
|
|
|
|
method_config->table = grpc_hash_table_create(num_entries, entries); |
|
|
|
|
method_config->table = grpc_mdstr_hash_table_create(num_entries, entries); |
|
|
|
|
return method_config; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config) { |
|
|
|
|
grpc_hash_table_ref(method_config->table); |
|
|
|
|
grpc_mdstr_hash_table_ref(method_config->table); |
|
|
|
|
return method_config; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_method_config_unref(grpc_method_config* method_config) { |
|
|
|
|
if (grpc_hash_table_unref(method_config->table)) { |
|
|
|
|
if (grpc_mdstr_hash_table_unref(method_config->table)) { |
|
|
|
|
GRPC_MDSTR_UNREF(method_config->wait_for_ready_key); |
|
|
|
|
GRPC_MDSTR_UNREF(method_config->timeout_key); |
|
|
|
|
GRPC_MDSTR_UNREF(method_config->max_request_message_bytes_key); |
|
|
|
@ -176,30 +178,32 @@ void grpc_method_config_unref(grpc_method_config* method_config) { |
|
|
|
|
|
|
|
|
|
int grpc_method_config_cmp(const grpc_method_config* method_config1, |
|
|
|
|
const grpc_method_config* method_config2) { |
|
|
|
|
return grpc_hash_table_cmp(method_config1->table, method_config2->table); |
|
|
|
|
return grpc_mdstr_hash_table_cmp(method_config1->table, |
|
|
|
|
method_config2->table); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const bool* grpc_method_config_get_wait_for_ready( |
|
|
|
|
const grpc_method_config* method_config) { |
|
|
|
|
return grpc_hash_table_get(method_config->table, |
|
|
|
|
method_config->wait_for_ready_key); |
|
|
|
|
return grpc_mdstr_hash_table_get(method_config->table, |
|
|
|
|
method_config->wait_for_ready_key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const gpr_timespec* grpc_method_config_get_timeout( |
|
|
|
|
const grpc_method_config* method_config) { |
|
|
|
|
return grpc_hash_table_get(method_config->table, method_config->timeout_key); |
|
|
|
|
return grpc_mdstr_hash_table_get(method_config->table, |
|
|
|
|
method_config->timeout_key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const int32_t* grpc_method_config_get_max_request_message_bytes( |
|
|
|
|
const grpc_method_config* method_config) { |
|
|
|
|
return grpc_hash_table_get(method_config->table, |
|
|
|
|
method_config->max_request_message_bytes_key); |
|
|
|
|
return grpc_mdstr_hash_table_get( |
|
|
|
|
method_config->table, method_config->max_request_message_bytes_key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const int32_t* grpc_method_config_get_max_response_message_bytes( |
|
|
|
|
const grpc_method_config* method_config) { |
|
|
|
|
return grpc_hash_table_get(method_config->table, |
|
|
|
|
method_config->max_response_message_bytes_key); |
|
|
|
|
return grpc_mdstr_hash_table_get( |
|
|
|
|
method_config->table, method_config->max_response_message_bytes_key); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -218,41 +222,41 @@ static int method_config_cmp(void* valuep1, void* valuep2) { |
|
|
|
|
return grpc_method_config_cmp(valuep1, valuep2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static const grpc_hash_table_vtable method_config_table_vtable = { |
|
|
|
|
static const grpc_mdstr_hash_table_vtable method_config_table_vtable = { |
|
|
|
|
method_config_unref, method_config_ref, method_config_cmp}; |
|
|
|
|
|
|
|
|
|
grpc_method_config_table* grpc_method_config_table_create( |
|
|
|
|
size_t num_entries, grpc_method_config_table_entry* entries) { |
|
|
|
|
grpc_hash_table_entry* hash_table_entries = |
|
|
|
|
gpr_malloc(sizeof(grpc_hash_table_entry) * num_entries); |
|
|
|
|
grpc_mdstr_hash_table_entry* hash_table_entries = |
|
|
|
|
gpr_malloc(sizeof(grpc_mdstr_hash_table_entry) * num_entries); |
|
|
|
|
for (size_t i = 0; i < num_entries; ++i) { |
|
|
|
|
hash_table_entries[i].key = entries[i].method_name; |
|
|
|
|
hash_table_entries[i].value = entries[i].method_config; |
|
|
|
|
hash_table_entries[i].vtable = &method_config_table_vtable; |
|
|
|
|
} |
|
|
|
|
grpc_method_config_table* method_config_table = |
|
|
|
|
grpc_hash_table_create(num_entries, hash_table_entries); |
|
|
|
|
grpc_mdstr_hash_table_create(num_entries, hash_table_entries); |
|
|
|
|
gpr_free(hash_table_entries); |
|
|
|
|
return method_config_table; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_method_config_table* grpc_method_config_table_ref( |
|
|
|
|
grpc_method_config_table* table) { |
|
|
|
|
return grpc_hash_table_ref(table); |
|
|
|
|
return grpc_mdstr_hash_table_ref(table); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void grpc_method_config_table_unref(grpc_method_config_table* table) { |
|
|
|
|
grpc_hash_table_unref(table); |
|
|
|
|
grpc_mdstr_hash_table_unref(table); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int grpc_method_config_table_cmp(const grpc_method_config_table* table1, |
|
|
|
|
const grpc_method_config_table* table2) { |
|
|
|
|
return grpc_hash_table_cmp(table1, table2); |
|
|
|
|
return grpc_mdstr_hash_table_cmp(table1, table2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
grpc_method_config* grpc_method_config_table_get_method_config( |
|
|
|
|
const grpc_method_config_table* table, const grpc_mdstr* path) { |
|
|
|
|
grpc_method_config* method_config = grpc_hash_table_get(table, path); |
|
|
|
|
grpc_method_config* method_config = grpc_mdstr_hash_table_get(table, path); |
|
|
|
|
// If we didn't find a match for the path, try looking for a wildcard
|
|
|
|
|
// entry (i.e., change "/service/method" to "/service/*").
|
|
|
|
|
if (method_config == NULL) { |
|
|
|
@ -265,7 +269,7 @@ grpc_method_config* grpc_method_config_table_get_method_config( |
|
|
|
|
buf[len + 1] = '\0'; |
|
|
|
|
grpc_mdstr* wildcard_path = grpc_mdstr_from_string(buf); |
|
|
|
|
gpr_free(buf); |
|
|
|
|
method_config = grpc_hash_table_get(table, wildcard_path); |
|
|
|
|
method_config = grpc_mdstr_hash_table_get(table, wildcard_path); |
|
|
|
|
GRPC_MDSTR_UNREF(wildcard_path); |
|
|
|
|
} |
|
|
|
|
return method_config; |
|
|
|
|