@ -21,6 +21,7 @@
# include <list>
# include <list>
# include "absl/log/check.h"
# include "absl/log/check.h"
# include "absl/log/log.h"
# include "absl/strings/numbers.h"
# include "absl/strings/numbers.h"
# include "upb/mem/arena.hpp"
# include "upb/mem/arena.hpp"
@ -205,13 +206,13 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
alts_tsi_handshaker * handshaker = client - > handshaker ;
alts_tsi_handshaker * handshaker = client - > handshaker ;
// Invalid input check.
// Invalid input check.
if ( client - > cb = = nullptr ) {
if ( client - > cb = = nullptr ) {
gpr_log ( GPR_ERROR ,
LOG ( ERROR )
" client->cb is nullptr in alts_tsi_handshaker_handle_response() " ) ;
< < " client->cb is nullptr in alts_tsi_handshaker_handle_response() " ;
return ;
return ;
}
}
if ( handshaker = = nullptr ) {
if ( handshaker = = nullptr ) {
gpr_log ( GPR_ERROR ,
LOG ( ERROR )
" handshaker is nullptr in alts_tsi_handshaker_handle_response() " ) ;
< < " handshaker is nullptr in alts_tsi_handshaker_handle_response() " ;
handle_response_done (
handle_response_done (
client , TSI_INTERNAL_ERROR ,
client , TSI_INTERNAL_ERROR ,
" handshaker is nullptr in alts_tsi_handshaker_handle_response() " ,
" handshaker is nullptr in alts_tsi_handshaker_handle_response() " ,
@ -220,14 +221,14 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
}
}
// TSI handshake has been shutdown.
// TSI handshake has been shutdown.
if ( alts_tsi_handshaker_has_shutdown ( handshaker ) ) {
if ( alts_tsi_handshaker_has_shutdown ( handshaker ) ) {
gpr_log ( GPR_INFO , " TSI handshake shutdown " ) ;
LOG ( INFO ) < < " TSI handshake shutdown " ;
handle_response_done ( client , TSI_HANDSHAKE_SHUTDOWN ,
handle_response_done ( client , TSI_HANDSHAKE_SHUTDOWN ,
" TSI handshake shutdown " , nullptr , 0 , nullptr ) ;
" TSI handshake shutdown " , nullptr , 0 , nullptr ) ;
return ;
return ;
}
}
// Check for failed grpc read.
// Check for failed grpc read.
if ( ! is_ok | | client - > inject_read_failure ) {
if ( ! is_ok | | client - > inject_read_failure ) {
gpr_log ( GPR_INFO , " read failed on grpc call to handshaker service " ) ;
LOG ( INFO ) < < " read failed on grpc call to handshaker service " ;
handle_response_done ( client , TSI_INTERNAL_ERROR ,
handle_response_done ( client , TSI_INTERNAL_ERROR ,
" read failed on grpc call to handshaker service " ,
" read failed on grpc call to handshaker service " ,
nullptr , 0 , nullptr ) ;
nullptr , 0 , nullptr ) ;
@ -249,7 +250,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
client - > recv_buffer = nullptr ;
client - > recv_buffer = nullptr ;
// Invalid handshaker response check.
// Invalid handshaker response check.
if ( resp = = nullptr ) {
if ( resp = = nullptr ) {
gpr_log ( GPR_ERROR , " alts_tsi_utils_deserialize_response() failed " ) ;
LOG ( ERROR ) < < " alts_tsi_utils_deserialize_response() failed " ;
handle_response_done ( client , TSI_DATA_CORRUPTED ,
handle_response_done ( client , TSI_DATA_CORRUPTED ,
" alts_tsi_utils_deserialize_response() failed " ,
" alts_tsi_utils_deserialize_response() failed " ,
nullptr , 0 , nullptr ) ;
nullptr , 0 , nullptr ) ;
@ -258,7 +259,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
const grpc_gcp_HandshakerStatus * resp_status =
const grpc_gcp_HandshakerStatus * resp_status =
grpc_gcp_HandshakerResp_status ( resp ) ;
grpc_gcp_HandshakerResp_status ( resp ) ;
if ( resp_status = = nullptr ) {
if ( resp_status = = nullptr ) {
gpr_log ( GPR_ERROR , " No status in HandshakerResp " ) ;
LOG ( ERROR ) < < " No status in HandshakerResp " ;
handle_response_done ( client , TSI_DATA_CORRUPTED ,
handle_response_done ( client , TSI_DATA_CORRUPTED ,
" No status in HandshakerResp " , nullptr , 0 , nullptr ) ;
" No status in HandshakerResp " , nullptr , 0 , nullptr ) ;
return ;
return ;
@ -281,7 +282,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
tsi_result status =
tsi_result status =
alts_tsi_handshaker_result_create ( resp , client - > is_client , & result ) ;
alts_tsi_handshaker_result_create ( resp , client - > is_client , & result ) ;
if ( status ! = TSI_OK ) {
if ( status ! = TSI_OK ) {
gpr_log ( GPR_ERROR , " alts_tsi_handshaker_result_create() failed " ) ;
LOG ( ERROR ) < < " alts_tsi_handshaker_result_create() failed " ;
handle_response_done ( client , status ,
handle_response_done ( client , status ,
" alts_tsi_handshaker_result_create() failed " ,
" alts_tsi_handshaker_result_create() failed " ,
nullptr , 0 , nullptr ) ;
nullptr , 0 , nullptr ) ;
@ -299,7 +300,7 @@ void alts_handshaker_client_handle_response(alts_handshaker_client* c,
if ( details . size > 0 ) {
if ( details . size > 0 ) {
error = absl : : StrCat ( " Status " , code , " from handshaker service: " ,
error = absl : : StrCat ( " Status " , code , " from handshaker service: " ,
absl : : string_view ( details . data , details . size ) ) ;
absl : : string_view ( details . data , details . size ) ) ;
gpr_log ( GPR_ERROR , " %s " , error . c_str ( ) ) ;
LOG ( ERROR ) < < error ;
}
}
}
}
// TODO(apolcyn): consider short ciruiting handle_response_done and
// TODO(apolcyn): consider short ciruiting handle_response_done and
@ -357,7 +358,7 @@ static tsi_result continue_make_grpc_call(alts_grpc_handshaker_client* client,
if ( client - > grpc_caller ( client - > call , ops , static_cast < size_t > ( op - ops ) ,
if ( client - > grpc_caller ( client - > call , ops , static_cast < size_t > ( op - ops ) ,
& client - > on_handshaker_service_resp_recv ) ! =
& client - > on_handshaker_service_resp_recv ) ! =
GRPC_CALL_OK ) {
GRPC_CALL_OK ) {
gpr_log ( GPR_ERROR , " Start batch operation failed " ) ;
LOG ( ERROR ) < < " Start batch operation failed " ;
return TSI_INTERNAL_ERROR ;
return TSI_INTERNAL_ERROR ;
}
}
return TSI_OK ;
return TSI_OK ;
@ -544,21 +545,21 @@ static grpc_byte_buffer* get_serialized_start_client(
static tsi_result handshaker_client_start_client ( alts_handshaker_client * c ) {
static tsi_result handshaker_client_start_client ( alts_handshaker_client * c ) {
if ( c = = nullptr ) {
if ( c = = nullptr ) {
gpr_log ( GPR_ERROR , " client is nullptr in handshaker_client_start_client() " ) ;
LOG ( ERROR ) < < " client is nullptr in handshaker_client_start_client() " ;
return TSI_INVALID_ARGUMENT ;
return TSI_INVALID_ARGUMENT ;
}
}
grpc_byte_buffer * buffer = get_serialized_start_client ( c ) ;
grpc_byte_buffer * buffer = get_serialized_start_client ( c ) ;
alts_grpc_handshaker_client * client =
alts_grpc_handshaker_client * client =
reinterpret_cast < alts_grpc_handshaker_client * > ( c ) ;
reinterpret_cast < alts_grpc_handshaker_client * > ( c ) ;
if ( buffer = = nullptr ) {
if ( buffer = = nullptr ) {
gpr_log ( GPR_ERROR , " get_serialized_start_client() failed " ) ;
LOG ( ERROR ) < < " get_serialized_start_client() failed " ;
return TSI_INTERNAL_ERROR ;
return TSI_INTERNAL_ERROR ;
}
}
handshaker_client_send_buffer_destroy ( client ) ;
handshaker_client_send_buffer_destroy ( client ) ;
client - > send_buffer = buffer ;
client - > send_buffer = buffer ;
tsi_result result = make_grpc_call ( & client - > base , true /* is_start */ ) ;
tsi_result result = make_grpc_call ( & client - > base , true /* is_start */ ) ;
if ( result ! = TSI_OK ) {
if ( result ! = TSI_OK ) {
gpr_log ( GPR_ERROR , " make_grpc_call() failed " ) ;
LOG ( ERROR ) < < " make_grpc_call() failed " ;
}
}
return result ;
return result ;
}
}
@ -603,21 +604,21 @@ static grpc_byte_buffer* get_serialized_start_server(
static tsi_result handshaker_client_start_server ( alts_handshaker_client * c ,
static tsi_result handshaker_client_start_server ( alts_handshaker_client * c ,
grpc_slice * bytes_received ) {
grpc_slice * bytes_received ) {
if ( c = = nullptr | | bytes_received = = nullptr ) {
if ( c = = nullptr | | bytes_received = = nullptr ) {
gpr_log ( GPR_ERROR , " Invalid arguments to handshaker_client_start_server() " ) ;
LOG ( ERROR ) < < " Invalid arguments to handshaker_client_start_server() " ;
return TSI_INVALID_ARGUMENT ;
return TSI_INVALID_ARGUMENT ;
}
}
alts_grpc_handshaker_client * client =
alts_grpc_handshaker_client * client =
reinterpret_cast < alts_grpc_handshaker_client * > ( c ) ;
reinterpret_cast < alts_grpc_handshaker_client * > ( c ) ;
grpc_byte_buffer * buffer = get_serialized_start_server ( c , bytes_received ) ;
grpc_byte_buffer * buffer = get_serialized_start_server ( c , bytes_received ) ;
if ( buffer = = nullptr ) {
if ( buffer = = nullptr ) {
gpr_log ( GPR_ERROR , " get_serialized_start_server() failed " ) ;
LOG ( ERROR ) < < " get_serialized_start_server() failed " ;
return TSI_INTERNAL_ERROR ;
return TSI_INTERNAL_ERROR ;
}
}
handshaker_client_send_buffer_destroy ( client ) ;
handshaker_client_send_buffer_destroy ( client ) ;
client - > send_buffer = buffer ;
client - > send_buffer = buffer ;
tsi_result result = make_grpc_call ( & client - > base , true /* is_start */ ) ;
tsi_result result = make_grpc_call ( & client - > base , true /* is_start */ ) ;
if ( result ! = TSI_OK ) {
if ( result ! = TSI_OK ) {
gpr_log ( GPR_ERROR , " make_grpc_call() failed " ) ;
LOG ( ERROR ) < < " make_grpc_call() failed " ;
}
}
return result ;
return result ;
}
}
@ -640,7 +641,7 @@ static grpc_byte_buffer* get_serialized_next(grpc_slice* bytes_received) {
static tsi_result handshaker_client_next ( alts_handshaker_client * c ,
static tsi_result handshaker_client_next ( alts_handshaker_client * c ,
grpc_slice * bytes_received ) {
grpc_slice * bytes_received ) {
if ( c = = nullptr | | bytes_received = = nullptr ) {
if ( c = = nullptr | | bytes_received = = nullptr ) {
gpr_log ( GPR_ERROR , " Invalid arguments to handshaker_client_next() " ) ;
LOG ( ERROR ) < < " Invalid arguments to handshaker_client_next() " ;
return TSI_INVALID_ARGUMENT ;
return TSI_INVALID_ARGUMENT ;
}
}
alts_grpc_handshaker_client * client =
alts_grpc_handshaker_client * client =
@ -649,14 +650,14 @@ static tsi_result handshaker_client_next(alts_handshaker_client* c,
client - > recv_bytes = grpc_core : : CSliceRef ( * bytes_received ) ;
client - > recv_bytes = grpc_core : : CSliceRef ( * bytes_received ) ;
grpc_byte_buffer * buffer = get_serialized_next ( bytes_received ) ;
grpc_byte_buffer * buffer = get_serialized_next ( bytes_received ) ;
if ( buffer = = nullptr ) {
if ( buffer = = nullptr ) {
gpr_log ( GPR_ERROR , " get_serialized_next() failed " ) ;
LOG ( ERROR ) < < " get_serialized_next() failed " ;
return TSI_INTERNAL_ERROR ;
return TSI_INTERNAL_ERROR ;
}
}
handshaker_client_send_buffer_destroy ( client ) ;
handshaker_client_send_buffer_destroy ( client ) ;
client - > send_buffer = buffer ;
client - > send_buffer = buffer ;
tsi_result result = make_grpc_call ( & client - > base , false /* is_start */ ) ;
tsi_result result = make_grpc_call ( & client - > base , false /* is_start */ ) ;
if ( result ! = TSI_OK ) {
if ( result ! = TSI_OK ) {
gpr_log ( GPR_ERROR , " make_grpc_call() failed " ) ;
LOG ( ERROR ) < < " make_grpc_call() failed " ;
}
}
return result ;
return result ;
}
}
@ -716,7 +717,7 @@ alts_handshaker_client* alts_grpc_handshaker_client_create(
void * user_data , alts_handshaker_client_vtable * vtable_for_testing ,
void * user_data , alts_handshaker_client_vtable * vtable_for_testing ,
bool is_client , size_t max_frame_size , std : : string * error ) {
bool is_client , size_t max_frame_size , std : : string * error ) {
if ( channel = = nullptr | | handshaker_service_url = = nullptr ) {
if ( channel = = nullptr | | handshaker_service_url = = nullptr ) {
gpr_log ( GPR_ERROR , " Invalid arguments to alts_handshaker_client_create() " ) ;
LOG ( ERROR ) < < " Invalid arguments to alts_handshaker_client_create() " ;
return nullptr ;
return nullptr ;
}
}
alts_grpc_handshaker_client * client = new alts_grpc_handshaker_client ( ) ;
alts_grpc_handshaker_client * client = new alts_grpc_handshaker_client ( ) ;
@ -891,8 +892,7 @@ tsi_result alts_handshaker_client_start_client(alts_handshaker_client* client) {
client - > vtable - > client_start ! = nullptr ) {
client - > vtable - > client_start ! = nullptr ) {
return client - > vtable - > client_start ( client ) ;
return client - > vtable - > client_start ( client ) ;
}
}
gpr_log ( GPR_ERROR ,
LOG ( ERROR ) < < " client or client->vtable has not been initialized properly " ;
" client or client->vtable has not been initialized properly " ) ;
return TSI_INVALID_ARGUMENT ;
return TSI_INVALID_ARGUMENT ;
}
}
@ -902,8 +902,7 @@ tsi_result alts_handshaker_client_start_server(alts_handshaker_client* client,
client - > vtable - > server_start ! = nullptr ) {
client - > vtable - > server_start ! = nullptr ) {
return client - > vtable - > server_start ( client , bytes_received ) ;
return client - > vtable - > server_start ( client , bytes_received ) ;
}
}
gpr_log ( GPR_ERROR ,
LOG ( ERROR ) < < " client or client->vtable has not been initialized properly " ;
" client or client->vtable has not been initialized properly " ) ;
return TSI_INVALID_ARGUMENT ;
return TSI_INVALID_ARGUMENT ;
}
}
@ -913,8 +912,7 @@ tsi_result alts_handshaker_client_next(alts_handshaker_client* client,
client - > vtable - > next ! = nullptr ) {
client - > vtable - > next ! = nullptr ) {
return client - > vtable - > next ( client , bytes_received ) ;
return client - > vtable - > next ( client , bytes_received ) ;
}
}
gpr_log ( GPR_ERROR ,
LOG ( ERROR ) < < " client or client->vtable has not been initialized properly " ;
" client or client->vtable has not been initialized properly " ) ;
return TSI_INVALID_ARGUMENT ;
return TSI_INVALID_ARGUMENT ;
}
}