Go to the documentation of this file.
27 #include <grpc/byte_buffer.h>
39 #define TSI_ALTS_INITIAL_BUFFER_SIZE 256
115 client->send_buffer =
nullptr;
126 if (
client->base.vtable !=
nullptr &&
127 client->base.vtable->destruct !=
nullptr) {
132 client->send_buffer =
nullptr;
133 client->recv_buffer =
nullptr;
150 client->receive_status_finished |= receive_status_finished;
151 if (pending_recv_message_result !=
nullptr) {
153 client->pending_recv_message_result = pending_recv_message_result;
155 if (
client->pending_recv_message_result ==
nullptr) {
158 const bool have_final_result =
159 client->pending_recv_message_result->result !=
nullptr ||
161 if (have_final_result && !
client->receive_status_finished) {
168 r =
client->pending_recv_message_result;
169 client->pending_recv_message_result =
nullptr;
172 r->bytes_to_send_size,
r->result);
178 const unsigned char* bytes_to_send,
179 size_t bytes_to_send_size,
183 p->bytes_to_send = bytes_to_send;
184 p->bytes_to_send_size = bytes_to_send_size;
199 if (
client->cb ==
nullptr) {
201 "client->cb is nullptr in alts_tsi_handshaker_handle_response()");
204 if (handshaker ==
nullptr) {
206 "handshaker is nullptr in alts_tsi_handshaker_handle_response()");
222 if (recv_buffer ==
nullptr) {
224 "recv_buffer is nullptr in alts_tsi_handshaker_handle_response()");
232 client->recv_buffer =
nullptr;
234 if (
resp ==
nullptr) {
241 if (resp_status ==
nullptr) {
247 unsigned char* bytes_to_send =
nullptr;
248 size_t bytes_to_send_size = 0;
249 if (out_frames.
size > 0) {
250 bytes_to_send_size = out_frames.
size;
251 while (bytes_to_send_size >
client->buffer_size) {
253 client->buffer =
static_cast<unsigned char*
>(
257 bytes_to_send =
client->buffer;
288 bytes_to_send, bytes_to_send_size,
result);
302 &
client->handshake_status_details;
310 &
client->on_status_received);
321 &
client->recv_initial_metadata;
335 &
client->on_handshaker_service_resp_recv) !=
348 class HandshakeQueue {
350 explicit HandshakeQueue(
size_t max_outstanding_handshakes)
351 : max_outstanding_handshakes_(max_outstanding_handshakes) {}
356 if (outstanding_handshakes_ == max_outstanding_handshakes_) {
358 queued_handshakes_.push_back(
client);
362 ++outstanding_handshakes_;
367 void HandshakeDone() {
371 if (queued_handshakes_.empty()) {
373 --outstanding_handshakes_;
377 client = queued_handshakes_.front();
378 queued_handshakes_.pop_front();
385 std::list<alts_grpc_handshaker_client*> queued_handshakes_;
386 size_t outstanding_handshakes_ = 0;
387 const size_t max_outstanding_handshakes_;
399 HandshakeQueue* g_client_handshake_queue;
400 HandshakeQueue* g_server_handshake_queue;
402 void DoHandshakeQueuesInit(
void) {
403 const size_t per_queue_max_outstanding_handshakes = 40;
404 g_client_handshake_queue =
405 new HandshakeQueue(per_queue_max_outstanding_handshakes);
406 g_server_handshake_queue =
407 new HandshakeQueue(per_queue_max_outstanding_handshakes);
411 gpr_once_init(&g_queued_handshakes_init, DoHandshakeQueuesInit);
412 HandshakeQueue*
queue =
413 is_client ? g_client_handshake_queue : g_server_handshake_queue;
417 void HandshakeDone(
bool is_client) {
418 HandshakeQueue*
queue =
419 is_client ? g_client_handshake_queue : g_server_handshake_queue;
420 queue->HandshakeDone();
447 char* status_details =
450 "alts_grpc_handshaker_client:%p on_status_received "
451 "status:%d details:|%s| error:|%s|",
458 HandshakeDone(
client->is_client);
468 if (
buf ==
nullptr) {
499 client_version,
arena.ptr(), &
client->options->rpc_versions);
502 reinterpret_cast<const char*
>(
507 ->target_account_list_head;
508 while (
ptr !=
nullptr) {
523 gpr_log(
GPR_ERROR,
"client is nullptr in handshaker_client_start_client()");
573 server_version,
arena.ptr(), &
client->options->rpc_versions);
582 gpr_log(
GPR_ERROR,
"Invalid arguments to handshaker_client_start_server()");
644 if (
client->call !=
nullptr) {
660 if (
client->call !=
nullptr) {
676 grpc_schedule_on_exec_ctx),
693 bool is_client,
size_t max_frame_size) {
694 if (
channel ==
nullptr || handshaker_service_url ==
nullptr) {
701 vtable_for_testing ==
nullptr ? &
vtable : vtable_for_testing;
703 client->handshaker = handshaker;
707 client->user_data = user_data;
710 client->is_client = is_client;
715 client->max_frame_size = max_frame_size;
727 grpc_schedule_on_exec_ctx);
729 grpc_schedule_on_exec_ctx);
738 GPR_ASSERT(c !=
nullptr && caller !=
nullptr);
741 client->grpc_caller = caller;
749 return client->send_buffer;
757 return &
client->recv_buffer;
765 return &
client->recv_initial_metadata;
783 client->handshaker = handshaker;
785 client->user_data = user_data;
786 client->recv_buffer = recv_buffer;
792 void* user_data,
bool has_sent_start_message,
grpc_slice* recv_bytes) {
798 if (recv_bytes !=
nullptr) {
802 client->handshaker) == has_sent_start_message);
819 return client->handshaker;
835 return &
client->on_handshaker_service_resp_recv;
852 gpr_once_init(&g_queued_handshakes_init, DoHandshakeQueuesInit);
865 client->vtable->client_start !=
nullptr) {
869 "client or client->vtable has not been initialized properly");
876 client->vtable->server_start !=
nullptr) {
880 "client or client->vtable has not been initialized properly");
887 client->vtable->next !=
nullptr) {
891 "client or client->vtable has not been initialized properly");
897 client->vtable->shutdown !=
nullptr) {
const UPB_INLINE grpc_gcp_HandshakerResult * grpc_gcp_HandshakerResp_result(const grpc_gcp_HandshakerResp *msg)
#define GRPC_CLOSURE_INIT(closure, cb, cb_arg, scheduler)
grpc_call_error(* alts_grpc_caller)(grpc_call *call, const grpc_op *ops, size_t nops, grpc_closure *tag)
tsi_result alts_handshaker_client_start_server(alts_handshaker_client *client, grpc_slice *bytes_received)
struct grpc_gcp_NextHandshakeMessageReq grpc_gcp_NextHandshakeMessageReq
GRPCAPI void grpc_alts_credentials_options_destroy(grpc_alts_credentials_options *options)
size_t bytes_to_send_size
void alts_handshaker_client_set_cb_for_testing(alts_handshaker_client *c, tsi_handshaker_on_next_done_cb cb)
const unsigned char * bytes_to_send
struct grpc_byte_buffer * send_message
UPB_INLINE void grpc_gcp_StartClientHandshakeReq_set_handshake_security_protocol(grpc_gcp_StartClientHandshakeReq *msg, int32_t value)
struct grpc_gcp_HandshakerStatus grpc_gcp_HandshakerStatus
grpc_metadata_array * trailing_metadata
void alts_handshaker_client_ref_for_testing(alts_handshaker_client *c)
static void handshaker_client_shutdown(alts_handshaker_client *c)
grpc_status_code * status
bool receive_status_finished
GRPCAPI grpc_byte_buffer * grpc_raw_byte_buffer_create(grpc_slice *slices, size_t nslices)
const grpc_slice & grpc_slice_ref_internal(const grpc_slice &slice)
static grpc_byte_buffer * get_serialized_start_server(alts_handshaker_client *c, grpc_slice *bytes_received)
return memset(p, 0, total)
UPB_INLINE bool grpc_gcp_StartClientHandshakeReq_add_record_protocols(grpc_gcp_StartClientHandshakeReq *msg, upb_StringView val, upb_Arena *arena)
UPB_INLINE bool grpc_gcp_StartClientHandshakeReq_add_application_protocols(grpc_gcp_StartClientHandshakeReq *msg, upb_StringView val, upb_Arena *arena)
grpc_slice handshake_status_details
GPRAPI grpc_slice grpc_slice_from_copied_string(const char *source)
struct grpc_op::grpc_op_data::grpc_op_send_initial_metadata send_initial_metadata
grpc_byte_buffer ** alts_handshaker_client_get_recv_buffer_addr_for_testing(alts_handshaker_client *c)
struct grpc_pollset_set grpc_pollset_set
static void handshaker_client_destruct(alts_handshaker_client *c)
static void alts_grpc_handshaker_client_unref(alts_grpc_handshaker_client *client)
void grpc_gcp_RpcProtocolVersions_assign_from_struct(grpc_gcp_RpcProtocolVersions *versions, upb_Arena *arena, const grpc_gcp_rpc_protocol_versions *value)
GPRAPI void gpr_free(void *ptr)
GPRAPI int grpc_slice_cmp(grpc_slice a, grpc_slice b)
static int bytes_received
static grpc_byte_buffer * get_serialized_next(grpc_slice *bytes_received)
static void start_server(void)
UPB_INLINE uint32_t grpc_gcp_HandshakerResp_bytes_consumed(const grpc_gcp_HandshakerResp *msg)
static grpc_byte_buffer * get_serialized_handshaker_req(grpc_gcp_HandshakerReq *req, upb_Arena *arena)
static const alts_handshaker_client_vtable vtable
#define GRPC_CLOSURE_CREATE(cb, cb_arg, scheduler)
UPB_INLINE void grpc_gcp_StartClientHandshakeReq_set_max_frame_size(grpc_gcp_StartClientHandshakeReq *msg, uint32_t value)
static void on_status_received(void *arg, grpc_error_handle error)
UPB_INLINE struct grpc_gcp_Identity * grpc_gcp_StartClientHandshakeReq_add_target_identities(grpc_gcp_StartClientHandshakeReq *msg, upb_Arena *arena)
alts_handshaker_client * alts_grpc_handshaker_client_create(alts_tsi_handshaker *handshaker, grpc_channel *channel, const char *handshaker_service_url, grpc_pollset_set *interested_parties, grpc_alts_credentials_options *options, const grpc_slice &target_name, grpc_iomgr_cb_func grpc_cb, tsi_handshaker_on_next_done_cb cb, void *user_data, alts_handshaker_client_vtable *vtable_for_testing, bool is_client, size_t max_frame_size)
alts_tsi_handshaker * handshaker
static grpc_byte_buffer * get_serialized_start_client(alts_handshaker_client *c)
grpc_byte_buffer * recv_buffer
grpc_alts_credentials_options * options
void alts_handshaker_client_handle_response(alts_handshaker_client *c, bool is_ok)
struct grpc_op::grpc_op_data::grpc_op_recv_message recv_message
grpc_core::ScopedArenaPtr arena
union grpc_op::grpc_op_data data
struct grpc_gcp_HandshakerReq grpc_gcp_HandshakerReq
GPRAPI void gpr_once_init(gpr_once *once, void(*init_function)(void))
grpc_metadata_array recv_initial_metadata
GPRAPI void * gpr_zalloc(size_t size)
struct grpc_gcp_ServerHandshakeParameters grpc_gcp_ServerHandshakeParameters
void alts_handshaker_client_shutdown(alts_handshaker_client *client)
GRPCAPI void grpc_metadata_array_destroy(grpc_metadata_array *array)
#define ALTS_HANDSHAKER_SERVICE_URL_FOR_TESTING
UPB_INLINE void grpc_gcp_Identity_set_service_account(grpc_gcp_Identity *msg, upb_StringView value)
struct grpc_byte_buffer ** recv_message
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
wrapped_grpc_channel * channel
@ GRPC_OP_RECV_INITIAL_METADATA
static void handshaker_call_unref(void *arg, grpc_error_handle)
UPB_INLINE bool grpc_gcp_StartServerHandshakeReq_handshake_parameters_set(grpc_gcp_StartServerHandshakeReq *msg, int32_t key, grpc_gcp_ServerHandshakeParameters *val, upb_Arena *a)
GPRAPI void * gpr_realloc(void *p, size_t size)
struct grpc_gcp_HandshakerResp grpc_gcp_HandshakerResp
def c_str(s, encoding='ascii')
void alts_handshaker_client_check_fields_for_testing(alts_handshaker_client *c, tsi_handshaker_on_next_done_cb cb, void *user_data, bool has_sent_start_message, grpc_slice *recv_bytes)
GRPCAPI void grpc_call_unref(grpc_call *call)
UPB_INLINE struct grpc_gcp_NextHandshakeMessageReq * grpc_gcp_HandshakerReq_mutable_next(grpc_gcp_HandshakerReq *msg, upb_Arena *arena)
void alts_handshaker_client_set_vtable_for_testing(alts_handshaker_client *c, alts_handshaker_client_vtable *vtable)
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
tsi_result alts_handshaker_client_start_client(alts_handshaker_client *client)
grpc_status_code handshake_status_code
struct grpc_call grpc_call
grpc_byte_buffer * alts_handshaker_client_get_send_buffer_for_testing(alts_handshaker_client *c)
struct grpc_gcp_StartServerHandshakeReq grpc_gcp_StartServerHandshakeReq
void(* tsi_handshaker_on_next_done_cb)(tsi_result status, void *user_data, const unsigned char *bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result *handshaker_result)
void alts_tsi_handshaker_result_set_unused_bytes(tsi_handshaker_result *result, grpc_slice *recv_bytes, size_t bytes_consumed)
#define GRPC_SLICE_START_PTR(slice)
grpc_closure * alts_handshaker_client_get_closure_for_testing(alts_handshaker_client *c)
GPRAPI grpc_slice grpc_slice_from_static_string(const char *source)
const int kHandshakerClientOpNum
GPRAPI grpc_slice grpc_empty_slice(void)
tsi_result alts_handshaker_client_next(alts_handshaker_client *client, grpc_slice *bytes_received)
UPB_INLINE upb_StringView grpc_gcp_HandshakerStatus_details(const grpc_gcp_HandshakerStatus *msg)
grpc_gcp_HandshakerResp * alts_tsi_utils_deserialize_response(grpc_byte_buffer *resp_buffer, upb_Arena *arena)
alts_tsi_handshaker * alts_handshaker_client_get_handshaker_for_testing(alts_handshaker_client *c)
static void start_client(void)
UPB_INLINE grpc_gcp_ServerHandshakeParameters * grpc_gcp_ServerHandshakeParameters_new(upb_Arena *arena)
struct grpc_gcp_RpcProtocolVersions grpc_gcp_RpcProtocolVersions
bool alts_tsi_handshaker_get_has_sent_start_message_for_testing(alts_tsi_handshaker *handshaker)
UPB_INLINE bool grpc_gcp_ServerHandshakeParameters_add_record_protocols(grpc_gcp_ServerHandshakeParameters *msg, upb_StringView val, upb_Arena *arena)
UPB_INLINE struct grpc_gcp_RpcProtocolVersions * grpc_gcp_StartClientHandshakeReq_mutable_rpc_versions(grpc_gcp_StartClientHandshakeReq *msg, upb_Arena *arena)
static void handle_response_done(alts_grpc_handshaker_client *client, tsi_result status, const unsigned char *bytes_to_send, size_t bytes_to_send_size, tsi_handshaker_result *result)
UPB_INLINE upb_StringView grpc_gcp_HandshakerResp_out_frames(const grpc_gcp_HandshakerResp *msg)
#define GRPC_SLICE_LENGTH(slice)
UPB_INLINE bool grpc_gcp_StartServerHandshakeReq_add_application_protocols(grpc_gcp_StartServerHandshakeReq *msg, upb_StringView val, upb_Arena *arena)
grpc_slice * status_details
tsi_result alts_tsi_handshaker_result_create(grpc_gcp_HandshakerResp *resp, bool is_client, tsi_handshaker_result **result)
static grpc_slice details
GPRAPI char * grpc_slice_to_c_string(grpc_slice s)
tsi_handshaker_result * result
void alts_handshaker_client_set_recv_bytes_for_testing(alts_handshaker_client *c, grpc_slice *recv_bytes)
struct grpc_gcp_Identity grpc_gcp_Identity
grpc_alts_credentials_options * grpc_alts_credentials_options_copy(const grpc_alts_credentials_options *options)
GPRAPI grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t len)
#define ALTS_APPLICATION_PROTOCOL
#define GRPC_PROPAGATE_DEFAULTS
static tsi_result make_grpc_call(alts_handshaker_client *c, bool is_start)
alts_handshaker_client base
UPB_INLINE grpc_gcp_HandshakerReq * grpc_gcp_HandshakerReq_new(upb_Arena *arena)
struct alts_grpc_handshaker_client alts_grpc_handshaker_client
void alts_handshaker_client_destroy(alts_handshaker_client *c)
@ GRPC_OP_SEND_INITIAL_METADATA
std::string grpc_error_std_string(grpc_error_handle error)
struct grpc_op::grpc_op_data::grpc_op_send_message send_message
#define TSI_ALTS_INITIAL_BUFFER_SIZE
void alts_handshaker_client_set_grpc_caller_for_testing(alts_handshaker_client *c, alts_grpc_caller caller)
grpc_closure on_status_received
bool alts_tsi_handshaker_has_shutdown(alts_tsi_handshaker *handshaker)
grpc_call * grpc_channel_create_pollset_set_call(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_pollset_set *pollset_set, const grpc_slice &method, const grpc_slice *host, grpc_core::Timestamp deadline, void *reserved)
static void handshaker_client_send_buffer_destroy(alts_grpc_handshaker_client *client)
static tsi_result handshaker_client_start_client(alts_handshaker_client *c)
AllocList * next[kMaxLevel]
struct grpc_op::grpc_op_data::grpc_op_recv_status_on_client recv_status_on_client
void(* grpc_iomgr_cb_func)(void *arg, grpc_error_handle error)
UPB_INLINE void grpc_gcp_StartClientHandshakeReq_set_target_name(grpc_gcp_StartClientHandshakeReq *msg, upb_StringView value)
UPB_INLINE upb_StringView upb_StringView_FromDataAndSize(const char *data, size_t size)
UPB_INLINE void grpc_gcp_StartServerHandshakeReq_set_max_frame_size(grpc_gcp_StartServerHandshakeReq *msg, uint32_t value)
union grpc_slice::grpc_slice_data data
#define ALTS_RECORD_PROTOCOL
UPB_INLINE void grpc_gcp_StartServerHandshakeReq_set_in_bytes(grpc_gcp_StartServerHandshakeReq *msg, upb_StringView value)
GRPCAPI void grpc_byte_buffer_destroy(grpc_byte_buffer *bb)
UPB_INLINE struct grpc_gcp_StartServerHandshakeReq * grpc_gcp_HandshakerReq_mutable_server_start(grpc_gcp_HandshakerReq *msg, upb_Arena *arena)
void alts_handshaker_client_set_fields_for_testing(alts_handshaker_client *c, alts_tsi_handshaker *handshaker, tsi_handshaker_on_next_done_cb cb, void *user_data, grpc_byte_buffer *recv_buffer, grpc_status_code status)
recv_message_result * pending_recv_message_result
tsi_handshaker_on_next_done_cb cb
grpc_metadata_array * alts_handshaker_client_get_initial_metadata_for_testing(alts_handshaker_client *c)
static void Run(const DebugLocation &location, grpc_closure *closure, grpc_error_handle error)
tsi_result alts_tsi_utils_convert_to_tsi_result(grpc_status_code code)
struct grpc_channel grpc_channel
grpc_closure on_handshaker_service_resp_recv
#define ALTS_SERVICE_METHOD
UPB_INLINE upb_StringView upb_StringView_FromString(const char *data)
void alts_handshaker_client_on_status_received_for_testing(alts_handshaker_client *c, grpc_status_code status, grpc_error_handle error)
grpc_call_error grpc_call_start_batch_and_execute(grpc_call *call, const grpc_op *ops, size_t nops, grpc_closure *closure)
alts_grpc_caller grpc_caller
static constexpr Timestamp InfFuture()
GPRAPI void gpr_ref_init(gpr_refcount *r, int n)
struct grpc_op::grpc_op_data::grpc_op_recv_initial_metadata recv_initial_metadata
static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client *client, bool is_start)
UPB_INLINE char * grpc_gcp_HandshakerReq_serialize(const grpc_gcp_HandshakerReq *msg, upb_Arena *arena, size_t *len)
static tsi_result handshaker_client_start_server(alts_handshaker_client *c, grpc_slice *bytes_received)
GPRAPI int gpr_unref(gpr_refcount *r)
static void maybe_complete_tsi_next(alts_grpc_handshaker_client *client, bool receive_status_finished, recv_message_result *pending_recv_message_result)
struct grpc_gcp_StartClientHandshakeReq grpc_gcp_StartClientHandshakeReq
@ GRPC_OP_RECV_STATUS_ON_CLIENT
const UPB_INLINE grpc_gcp_HandshakerStatus * grpc_gcp_HandshakerResp_status(const grpc_gcp_HandshakerResp *msg)
UPB_INLINE uint32_t grpc_gcp_HandshakerStatus_code(const grpc_gcp_HandshakerStatus *msg)
UPB_INLINE void grpc_gcp_NextHandshakeMessageReq_set_in_bytes(grpc_gcp_NextHandshakeMessageReq *msg, upb_StringView value)
static tsi_result handshaker_client_next(alts_handshaker_client *c, grpc_slice *bytes_received)
UPB_INLINE struct grpc_gcp_RpcProtocolVersions * grpc_gcp_StartServerHandshakeReq_mutable_rpc_versions(grpc_gcp_StartServerHandshakeReq *msg, upb_Arena *arena)
static void Run(const DebugLocation &location, grpc_closure *closure, grpc_error_handle error)
GPRAPI void gpr_ref(gpr_refcount *r)
const alts_handshaker_client_vtable * vtable
OPENSSL_EXPORT pem_password_cb * cb
UPB_INLINE struct grpc_gcp_StartClientHandshakeReq * grpc_gcp_HandshakerReq_mutable_client_start(grpc_gcp_HandshakerReq *msg, upb_Arena *arena)
void grpc_slice_unref_internal(const grpc_slice &slice)
GRPCAPI void grpc_metadata_array_init(grpc_metadata_array *array)
static bool is_handshake_finished_properly(grpc_gcp_HandshakerResp *resp)
GPRAPI grpc_slice grpc_slice_copy(grpc_slice s)
void grpc_call_cancel_internal(grpc_call *call)
grpc_byte_buffer * send_buffer
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:41