Go to the documentation of this file.
35 #define TSI_FAKE_FRAME_HEADER_SIZE 4
36 #define TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE 64
37 #define TSI_FAKE_DEFAULT_FRAME_SIZE 16384
38 #define TSI_FAKE_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE 256
88 "CLIENT_INIT",
"SERVER_INIT",
"CLIENT_FINISHED",
"SERVER_FINISHED"};
118 buf[3] =
static_cast<unsigned char>((
value >> 24) & 0xFF);
119 buf[2] =
static_cast<unsigned char>((
value >> 16) & 0xFF);
120 buf[1] =
static_cast<unsigned char>((
value >> 8) & 0xFF);
121 buf[0] =
static_cast<unsigned char>((
value)&0xFF);
130 for (
size_t i = 0;
i < sb->
count;
i++) {
132 if (remaining <= slice_length) {
139 remaining -= slice_length;
153 frame->needs_draining = needs_draining;
154 if (!needs_draining)
frame->size = 0;
160 if (
frame->data ==
nullptr) {
164 }
else if (
frame->size >
frame->allocated_size) {
165 unsigned char* new_data =
167 frame->data = new_data;
176 size_t* incoming_bytes_size,
178 size_t available_size = *incoming_bytes_size;
179 size_t to_read_size = 0;
180 const unsigned char* bytes_cursor = incoming_bytes;
183 if (
frame->data ==
nullptr) {
191 if (to_read_size > available_size) {
194 bytes_cursor += available_size;
195 frame->offset += available_size;
196 *incoming_bytes_size =
static_cast<size_t>(bytes_cursor - incoming_bytes);
200 bytes_cursor += to_read_size;
201 frame->offset += to_read_size;
202 available_size -= to_read_size;
208 if (to_read_size > available_size) {
210 frame->offset += available_size;
211 bytes_cursor += available_size;
212 *incoming_bytes_size =
static_cast<size_t>(bytes_cursor - incoming_bytes);
216 bytes_cursor += to_read_size;
217 *incoming_bytes_size =
static_cast<size_t>(bytes_cursor - incoming_bytes);
226 size_t* outgoing_bytes_size,
228 size_t to_write_size =
frame->size -
frame->offset;
230 if (*outgoing_bytes_size < to_write_size) {
232 frame->offset += *outgoing_bytes_size;
236 *outgoing_bytes_size = to_write_size;
262 const unsigned char* unprotected_bytes,
263 size_t* unprotected_bytes_size,
264 unsigned char* protected_output_frames,
265 size_t* protected_output_frames_size) {
271 size_t saved_output_size = *protected_output_frames_size;
272 size_t drained_size = 0;
273 size_t* num_bytes_written = protected_output_frames_size;
274 *num_bytes_written = 0;
277 if (
frame->needs_draining) {
278 drained_size = saved_output_size - *num_bytes_written;
281 *num_bytes_written += drained_size;
282 protected_output_frames += drained_size;
285 *unprotected_bytes_size = 0;
294 if (
frame->size == 0) {
296 size_t written_in_frame_size = 0;
317 drained_size = saved_output_size - *num_bytes_written;
319 *num_bytes_written += drained_size;
326 size_t* protected_output_frames_size,
size_t* still_pending_size) {
331 if (!
frame->needs_draining) {
335 frame->needs_draining = 1;
340 protected_output_frames_size,
frame);
342 *still_pending_size =
frame->size -
frame->offset;
348 size_t* protected_frames_bytes_size,
unsigned char* unprotected_bytes,
349 size_t* unprotected_bytes_size) {
354 size_t saved_output_size = *unprotected_bytes_size;
355 size_t drained_size = 0;
356 size_t* num_bytes_written = unprotected_bytes_size;
357 *num_bytes_written = 0;
360 if (
frame->needs_draining) {
363 drained_size = saved_output_size - *num_bytes_written;
365 unprotected_bytes += drained_size;
366 *num_bytes_written += drained_size;
369 *protected_frames_bytes_size = 0;
379 protected_frames_bytes_size,
frame);
389 drained_size = saved_output_size - *num_bytes_written;
391 *num_bytes_written += drained_size;
416 if (
self ==
nullptr || unprotected_slices ==
nullptr ||
417 protected_slices ==
nullptr) {
423 while (unprotected_slices->
length > 0) {
441 if (
self ==
nullptr || unprotected_slices ==
nullptr ||
442 protected_slices ==
nullptr) {
470 if (min_progress_size !=
nullptr) {
474 *min_progress_size = 1;
482 if (
self ==
nullptr)
return;
540 size_t* max_output_protected_frame_size,
556 size_t* bytes_size) {
559 *bytes_size =
result->unused_bytes_size;
581 const unsigned char* unused_bytes,
size_t unused_bytes_size,
583 if ((unused_bytes_size > 0 && unused_bytes ==
nullptr) ||
584 handshaker_result ==
nullptr) {
589 if (unused_bytes_size > 0) {
591 static_cast<unsigned char*
>(
gpr_malloc(unused_bytes_size));
592 memcpy(
result->unused_bytes, unused_bytes, unused_bytes_size);
594 result->unused_bytes_size = unused_bytes_size;
595 *handshaker_result = &
result->base;
613 const char* msg_string =
616 reinterpret_cast<unsigned char*
>(
const_cast<char*
>(msg_string)),
668 if (received_msg != expected_msg) {
704 size_t received_bytes_size,
const unsigned char** bytes_to_send,
708 if ((received_bytes_size > 0 && received_bytes ==
nullptr) ||
709 bytes_to_send ==
nullptr || bytes_to_send_size ==
nullptr ||
710 handshaker_result ==
nullptr) {
718 size_t consumed_bytes_size = received_bytes_size;
719 if (received_bytes_size > 0) {
721 &consumed_bytes_size);
732 offset += sent_bytes_size;
742 *bytes_to_send_size =
offset;
746 *handshaker_result =
nullptr;
749 const unsigned char* unused_bytes =
nullptr;
750 size_t unused_bytes_size = received_bytes_size - consumed_bytes_size;
751 if (unused_bytes_size > 0) {
752 unused_bytes = received_bytes + consumed_bytes_size;
761 self->handshaker_result_created =
true;
798 size_t* max_protected_frame_size) {
800 grpc_core::Zalloc<tsi_fake_frame_protector>();
803 : *max_protected_frame_size;
809 size_t* max_protected_frame_size) {
817 : *max_protected_frame_size;
static tsi_result fake_handshaker_process_bytes_from_peer(tsi_handshaker *self, const unsigned char *bytes, size_t *bytes_size)
const char * tsi_security_level_to_string(tsi_security_level security_level)
#define TSI_FAKE_FRAME_HEADER_SIZE
static const tsi_handshaker_result_vtable handshaker_result_vtable
const tsi_handshaker_vtable * vtable
GPRAPI void grpc_slice_buffer_move_into(grpc_slice_buffer *src, grpc_slice_buffer *dst)
static tsi_result fake_zero_copy_grpc_protector_protect(tsi_zero_copy_grpc_protector *self, grpc_slice_buffer *unprotected_slices, grpc_slice_buffer *protected_slices)
static tsi_result fake_protector_unprotect(tsi_frame_protector *self, const unsigned char *protected_frames_bytes, size_t *protected_frames_bytes_size, unsigned char *unprotected_bytes, size_t *unprotected_bytes_size)
tsi_handshaker_result base
tsi_peer_property * properties
static void tsi_fake_frame_ensure_size(tsi_fake_frame *frame)
static tsi_result fake_handshaker_next(tsi_handshaker *self, const unsigned char *received_bytes, size_t received_bytes_size, const unsigned char **bytes_to_send, size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result, tsi_handshaker_on_next_done_cb, void *)
size_t outgoing_bytes_buffer_size
grpc_core::TraceFlag tsi_tracing_enabled(false, "tsi")
static void fake_handshaker_result_destroy(tsi_handshaker_result *self)
tsi_fake_frame incoming_frame
@ TSI_FAKE_CLIENT_FINISHED
@ TSI_FAKE_HANDSHAKE_MESSAGE_MAX
const tsi_zero_copy_grpc_protector_vtable * vtable
static tsi_result fake_handshaker_result_create_zero_copy_grpc_protector(const tsi_handshaker_result *, size_t *max_output_protected_frame_size, tsi_zero_copy_grpc_protector **protector)
#define TSI_SECURITY_LEVEL_PEER_PROPERTY
GPRAPI void gpr_free(void *ptr)
#define GRPC_SLICE_MALLOC(len)
static tsi_result fake_handshaker_result_get_unused_bytes(const tsi_handshaker_result *self, const unsigned char **bytes, size_t *bytes_size)
GPRAPI void * gpr_malloc(size_t size)
#define TSI_FAKE_FRAME_INITIAL_ALLOCATED_SIZE
tsi_handshaker * tsi_create_fake_handshaker(int is_client)
tsi_fake_handshake_message next_message_to_send
tsi_fake_frame outgoing_frame
static tsi_result fake_handshaker_result_create_frame_protector(const tsi_handshaker_result *, size_t *max_output_protected_frame_size, tsi_frame_protector **protector)
#define GRPC_TRACE_FLAG_ENABLED(f)
static const char * tsi_fake_handshake_message_strings[]
static const tsi_handshaker_vtable handshaker_vtable
static void store32_little_endian(uint32_t value, unsigned char *buf)
grpc_slice_buffer header_sb
#define TSI_FAKE_HANDSHAKER_OUTGOING_BUFFER_INITIAL_SIZE
GPRAPI void * gpr_zalloc(size_t size)
#define TSI_FAKE_CERTIFICATE_TYPE
static size_t frame_length(size_t payload_length)
static uint32_t read_frame_size(const grpc_slice_buffer *sb)
static const tsi_zero_copy_grpc_protector_vtable zero_copy_grpc_protector_vtable
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static tsi_result fake_zero_copy_grpc_protector_unprotect(tsi_zero_copy_grpc_protector *self, grpc_slice_buffer *protected_slices, grpc_slice_buffer *unprotected_slices, int *min_progress_size)
GPRAPI void * gpr_realloc(void *p, size_t size)
static const char * tsi_fake_handshake_message_to_string(int msg)
tsi_zero_copy_grpc_protector base
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
#define TSI_FAKE_DEFAULT_FRAME_SIZE
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)
unsigned char * outgoing_bytes_buffer
static void tsi_fake_frame_reset(tsi_fake_frame *frame, int needs_draining)
#define GRPC_SLICE_START_PTR(slice)
static tsi_result fake_handshaker_get_result(tsi_handshaker *self)
static tsi_result tsi_fake_frame_decode(const unsigned char *incoming_bytes, size_t *incoming_bytes_size, tsi_fake_frame *frame)
static tsi_result fake_protector_protect_flush(tsi_frame_protector *self, unsigned char *protected_output_frames, size_t *protected_output_frames_size, size_t *still_pending_size)
tsi_fake_frame unprotect_frame
static tsi_result tsi_fake_frame_encode(unsigned char *outgoing_bytes, size_t *outgoing_bytes_size, tsi_fake_frame *frame)
static void fake_zero_copy_grpc_protector_destroy(tsi_zero_copy_grpc_protector *self)
tsi_fake_frame protect_frame
static tsi_result tsi_fake_handshake_message_from_string(const char *msg_string, tsi_fake_handshake_message *msg)
GPRAPI void grpc_slice_buffer_init(grpc_slice_buffer *sb)
static uint32_t load32_little_endian(const unsigned char *buf)
#define GRPC_SLICE_LENGTH(slice)
static void tsi_fake_frame_destruct(tsi_fake_frame *frame)
GPRAPI void grpc_slice_buffer_add(grpc_slice_buffer *sb, grpc_slice slice)
tsi_zero_copy_grpc_protector * tsi_create_fake_zero_copy_grpc_protector(size_t *max_protected_frame_size)
const char * tsi_result_to_string(tsi_result result)
static tsi_result fake_zero_copy_grpc_protector_max_frame_size(tsi_zero_copy_grpc_protector *self, size_t *max_frame_size)
static tsi_result fake_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self, unsigned char *bytes, size_t *bytes_size)
grpc_slice_buffer protected_sb
const tsi_frame_protector_vtable * vtable
static tsi_result fake_handshaker_result_get_frame_protector_type(const tsi_handshaker_result *, tsi_frame_protector_type *frame_protector_type)
static void frame(frame_handler *handler, unsigned char *payload, size_t payload_length, size_t write_length)
tsi_frame_protector * tsi_create_fake_frame_protector(size_t *max_protected_frame_size)
GPRAPI void grpc_slice_buffer_move_first(grpc_slice_buffer *src, size_t n, grpc_slice_buffer *dst)
int needs_incoming_message
uint32_t tsi_fake_zero_copy_grpc_protector_next_frame_size(const grpc_slice_buffer *protected_slices)
static tsi_result fake_protector_protect(tsi_frame_protector *self, const unsigned char *unprotected_bytes, size_t *unprotected_bytes_size, unsigned char *protected_output_frames, size_t *protected_output_frames_size)
void grpc_slice_buffer_destroy_internal(grpc_slice_buffer *sb)
static tsi_result tsi_fake_frame_set_data(unsigned char *data, size_t data_size, tsi_fake_frame *frame)
@ TSI_FRAME_PROTECTOR_NORMAL_OR_ZERO_COPY
static void fake_protector_destroy(tsi_frame_protector *self)
#define TSI_CERTIFICATE_TYPE_PEER_PROPERTY
static tsi_result fake_handshaker_result_create(const unsigned char *unused_bytes, size_t unused_bytes_size, tsi_handshaker_result **handshaker_result)
unsigned char * unused_bytes
static const tsi_frame_protector_vtable frame_protector_vtable
void tsi_peer_destruct(tsi_peer *self)
void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer *sb)
static tsi_result fake_handshaker_result_extract_peer(const tsi_handshaker_result *, tsi_peer *peer)
@ TSI_FAKE_SERVER_FINISHED
tsi_fake_handshake_message
static void fake_handshaker_destroy(tsi_handshaker *self)
tsi_result tsi_construct_string_peer_property_from_cstring(const char *name, const char *value, tsi_peer_property *property)
tsi_result tsi_construct_peer(size_t property_count, tsi_peer *peer)
@ TSI_HANDSHAKE_IN_PROGRESS
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:22