#include <grpc/support/port_platform.h>
#include "src/core/tsi/alts/handshaker/alts_handshaker_client.h"
#include <list>
#include "upb/upb.hpp"
#include <grpc/byte_buffer.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "src/core/lib/gprpp/crash.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/slice/slice_internal.h"
#include "src/core/lib/surface/call.h"
#include "src/core/lib/surface/channel.h"
#include "src/core/tsi/alts/handshaker/alts_shared_resource.h"
#include "src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h"
#include "src/core/tsi/alts/handshaker/alts_tsi_utils.h"
#define TSI_ALTS_INITIAL_BUFFER_SIZE …
const int kHandshakerClientOpNum = …;
struct alts_handshaker_client { … };
struct recv_message_result { … };
alts_grpc_handshaker_client;
static void handshaker_client_send_buffer_destroy(
alts_grpc_handshaker_client* client) { … }
static bool is_handshake_finished_properly(grpc_gcp_HandshakerResp* resp) { … }
static void alts_grpc_handshaker_client_unref(
alts_grpc_handshaker_client* client) { … }
static void maybe_complete_tsi_next(
alts_grpc_handshaker_client* client, bool receive_status_finished,
recv_message_result* pending_recv_message_result) { … }
static void handle_response_done(alts_grpc_handshaker_client* client,
tsi_result status, std::string error,
const unsigned char* bytes_to_send,
size_t bytes_to_send_size,
tsi_handshaker_result* result) { … }
void alts_handshaker_client_handle_response(alts_handshaker_client* c,
bool is_ok) { … }
static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client,
bool is_start) { … }
namespace {
class HandshakeQueue { … };
gpr_once g_queued_handshakes_init = …;
HandshakeQueue* g_client_handshake_queue;
HandshakeQueue* g_server_handshake_queue;
void DoHandshakeQueuesInit(void) { … }
void RequestHandshake(alts_grpc_handshaker_client* client, bool is_client) { … }
void HandshakeDone(bool is_client) { … }
};
static tsi_result make_grpc_call(alts_handshaker_client* c, bool is_start) { … }
static void on_status_received(void* arg, grpc_error_handle error) { … }
static grpc_byte_buffer* get_serialized_handshaker_req(
grpc_gcp_HandshakerReq* req, upb_Arena* arena) { … }
static grpc_byte_buffer* get_serialized_start_client(
alts_handshaker_client* c) { … }
static tsi_result handshaker_client_start_client(alts_handshaker_client* c) { … }
static grpc_byte_buffer* get_serialized_start_server(
alts_handshaker_client* c, grpc_slice* bytes_received) { … }
static tsi_result handshaker_client_start_server(alts_handshaker_client* c,
grpc_slice* bytes_received) { … }
static grpc_byte_buffer* get_serialized_next(grpc_slice* bytes_received) { … }
static tsi_result handshaker_client_next(alts_handshaker_client* c,
grpc_slice* bytes_received) { … }
static void handshaker_client_shutdown(alts_handshaker_client* c) { … }
static void handshaker_call_unref(void* arg, grpc_error_handle ) { … }
static void handshaker_client_destruct(alts_handshaker_client* c) { … }
static const alts_handshaker_client_vtable vtable = …;
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, std::string* error) { … }
namespace grpc_core {
namespace internal {
void alts_handshaker_client_set_grpc_caller_for_testing(
alts_handshaker_client* c, alts_grpc_caller caller) { … }
grpc_byte_buffer* alts_handshaker_client_get_send_buffer_for_testing(
alts_handshaker_client* c) { … }
grpc_byte_buffer** alts_handshaker_client_get_recv_buffer_addr_for_testing(
alts_handshaker_client* c) { … }
grpc_metadata_array* alts_handshaker_client_get_initial_metadata_for_testing(
alts_handshaker_client* c) { … }
void alts_handshaker_client_set_recv_bytes_for_testing(
alts_handshaker_client* c, grpc_slice* recv_bytes) { … }
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, bool inject_read_failure) { … }
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) { … }
void alts_handshaker_client_set_vtable_for_testing(
alts_handshaker_client* c, alts_handshaker_client_vtable* vtable) { … }
alts_tsi_handshaker* alts_handshaker_client_get_handshaker_for_testing(
alts_handshaker_client* c) { … }
void alts_handshaker_client_set_cb_for_testing(
alts_handshaker_client* c, tsi_handshaker_on_next_done_cb cb) { … }
grpc_closure* alts_handshaker_client_get_closure_for_testing(
alts_handshaker_client* c) { … }
void alts_handshaker_client_ref_for_testing(alts_handshaker_client* c) { … }
void alts_handshaker_client_on_status_received_for_testing(
alts_handshaker_client* c, grpc_status_code status,
grpc_error_handle error) { … }
}
}
tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client) { … }
tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client,
grpc_slice* bytes_received) { … }
tsi_result alts_handshaker_client_next(alts_handshaker_client* client,
grpc_slice* bytes_received) { … }
void alts_handshaker_client_shutdown(alts_handshaker_client* client) { … }
void alts_handshaker_client_destroy(alts_handshaker_client* c) { … }