|
ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
|
📦 Packet protocol handler with CRC validation, encryption, and compression More...
Go to the source code of this file.
Functions | |
| asciichat_error_t | packet_validate_header (const packet_header_t *header, uint16_t *pkt_type, uint32_t *pkt_len, uint32_t *expected_crc) |
| Validate packet header and return parsed information. | |
| asciichat_error_t | packet_validate_crc32 (const void *data, size_t len, uint32_t expected_crc) |
| Validate packet CRC32. | |
| asciichat_error_t | packet_send (socket_t sockfd, packet_type_t type, const void *data, size_t len) |
| Send a packet with proper header and CRC32. | |
| asciichat_error_t | packet_receive (socket_t sockfd, packet_type_t *type, void **data, size_t *len) |
| Receive a packet with proper header validation and CRC32 checking. | |
| asciichat_error_t | send_packet_secure (socket_t sockfd, packet_type_t type, const void *data, size_t len, crypto_context_t *crypto_ctx) |
| Send a packet with encryption and compression support. | |
| packet_recv_result_t | receive_packet_secure (socket_t sockfd, void *crypto_ctx, bool enforce_encryption, packet_envelope_t *envelope) |
| Receive a packet with decryption and decompression support. | |
| int | send_packet (socket_t sockfd, packet_type_t type, const void *data, size_t len) |
| Send a basic packet without encryption. | |
| int | receive_packet (socket_t sockfd, packet_type_t *type, void **data, size_t *len) |
| Receive a basic packet without encryption. | |
| int | send_ping_packet (socket_t sockfd) |
| Send a ping packet. | |
| int | send_pong_packet (socket_t sockfd) |
| Send a pong packet. | |
| int | send_clear_console_packet (socket_t sockfd) |
| Send a clear console packet. | |
| asciichat_error_t | packet_send_error (socket_t sockfd, const crypto_context_t *crypto_ctx, asciichat_error_t error_code, const char *message) |
| asciichat_error_t | packet_parse_error_message (const void *data, size_t len, asciichat_error_t *out_error_code, char *message_buffer, size_t message_buffer_size, size_t *out_message_length) |
| asciichat_error_t | packet_send_remote_log (socket_t sockfd, const crypto_context_t *crypto_ctx, log_level_t level, remote_log_direction_t direction, uint16_t flags, const char *message) |
| asciichat_error_t | packet_parse_remote_log (const void *data, size_t len, log_level_t *out_level, remote_log_direction_t *out_direction, uint16_t *out_flags, char *message_buffer, size_t message_buffer_size, size_t *out_message_length) |
| int | send_protocol_version_packet (socket_t sockfd, const protocol_version_packet_t *version) |
| Send protocol version packet. | |
| int | send_crypto_capabilities_packet (socket_t sockfd, const crypto_capabilities_packet_t *caps) |
| Send crypto capabilities packet. | |
| int | send_crypto_parameters_packet (socket_t sockfd, const crypto_parameters_packet_t *params) |
| Send crypto parameters packet. | |
| asciichat_error_t | send_audio_batch_packet (socket_t sockfd, const float *samples, int num_samples, int batch_count, crypto_context_t *crypto_ctx) |
| asciichat_error_t | av_send_audio_opus_batch (socket_t sockfd, const uint8_t *opus_data, size_t opus_size, const uint16_t *frame_sizes, int sample_rate, int frame_duration, int frame_count, crypto_context_t *crypto_ctx) |
| asciichat_error_t | send_ascii_frame_packet (socket_t sockfd, const char *frame_data, size_t frame_size) |
| asciichat_error_t | send_image_frame_packet (socket_t sockfd, const void *image_data, uint16_t width, uint16_t height, uint8_t format) |
📦 Packet protocol handler with CRC validation, encryption, and compression
Definition in file packet.c.
| asciichat_error_t av_send_audio_opus_batch | ( | socket_t | sockfd, |
| const uint8_t * | opus_data, | ||
| size_t | opus_size, | ||
| const uint16_t * | frame_sizes, | ||
| int | sample_rate, | ||
| int | frame_duration, | ||
| int | frame_count, | ||
| crypto_context_t * | crypto_ctx | ||
| ) |
Definition at line 1133 of file packet.c.
References buffer_pool_alloc(), buffer_pool_free(), and send_packet_secure().
| asciichat_error_t packet_parse_error_message | ( | const void * | data, |
| size_t | len, | ||
| asciichat_error_t * | out_error_code, | ||
| char * | message_buffer, | ||
| size_t | message_buffer_size, | ||
| size_t * | out_message_length | ||
| ) |
Definition at line 851 of file packet.c.
| asciichat_error_t packet_parse_remote_log | ( | const void * | data, |
| size_t | len, | ||
| log_level_t * | out_level, | ||
| remote_log_direction_t * | out_direction, | ||
| uint16_t * | out_flags, | ||
| char * | message_buffer, | ||
| size_t | message_buffer_size, | ||
| size_t * | out_message_length | ||
| ) |
Definition at line 950 of file packet.c.
Referenced by handle_remote_log_packet_from_client().
| asciichat_error_t packet_receive | ( | socket_t | sockfd, |
| packet_type_t * | type, | ||
| void ** | data, | ||
| size_t * | len | ||
| ) |
Receive a packet with proper header validation and CRC32 checking.
| sockfd | Socket file descriptor |
| type | Output: packet type |
| data | Output: packet data (allocated by caller, freed by caller) |
| len | Output: data length |
Definition at line 348 of file packet.c.
References buffer_pool_alloc(), buffer_pool_free(), packet_validate_crc32(), packet_validate_header(), and recv_with_timeout().
Referenced by discovery_session_process(), nat_measure_bandwidth(), and receive_packet().
| asciichat_error_t packet_send | ( | socket_t | sockfd, |
| packet_type_t | type, | ||
| const void * | data, | ||
| size_t | len | ||
| ) |
Send a packet with proper header and CRC32.
| sockfd | Socket file descriptor |
| type | Packet type |
| data | Packet data |
| len | Data length |
Definition at line 288 of file packet.c.
References send_with_timeout().
Referenced by discovery_session_become_host(), discovery_session_check_host_alive(), discovery_session_handle_host_disconnect(), discovery_session_stop(), nat_measure_bandwidth(), packet_send_error(), packet_send_remote_log(), send_ascii_frame_packet(), send_image_frame_packet(), send_packet(), send_packet_secure(), session_host_broadcast_frame(), and session_host_send_frame().
| asciichat_error_t packet_send_error | ( | socket_t | sockfd, |
| const crypto_context_t * | crypto_ctx, | ||
| asciichat_error_t | error_code, | ||
| const char * | message | ||
| ) |
Definition at line 804 of file packet.c.
References crypto_is_ready(), error_code, packet_send(), and send_packet_secure().
Referenced by disconnect_client_for_bad_data().
| asciichat_error_t packet_send_remote_log | ( | socket_t | sockfd, |
| const crypto_context_t * | crypto_ctx, | ||
| log_level_t | level, | ||
| remote_log_direction_t | direction, | ||
| uint16_t | flags, | ||
| const char * | message | ||
| ) |
Definition at line 893 of file packet.c.
References crypto_is_ready(), packet_send(), and send_packet_secure().
| asciichat_error_t packet_validate_crc32 | ( | const void * | data, |
| size_t | len, | ||
| uint32_t | expected_crc | ||
| ) |
Validate packet CRC32.
| data | Packet data |
| len | Data length |
| expected_crc | Expected CRC32 value |
Definition at line 258 of file packet.c.
Referenced by packet_receive().
| asciichat_error_t packet_validate_header | ( | const packet_header_t * | header, |
| uint16_t * | pkt_type, | ||
| uint32_t * | pkt_len, | ||
| uint32_t * | expected_crc | ||
| ) |
Validate packet header and return parsed information.
| header | Packet header to validate |
| pkt_type | Output: packet type |
| pkt_len | Output: packet length |
| expected_crc | Output: expected CRC32 |
Definition at line 77 of file packet.c.
Referenced by packet_receive().
| int receive_packet | ( | socket_t | sockfd, |
| packet_type_t * | type, | ||
| void ** | data, | ||
| size_t * | len | ||
| ) |
Receive a basic packet without encryption.
| sockfd | Socket file descriptor |
| type | Output: packet type |
| data | Output: packet data |
| len | Output: data length |
Definition at line 766 of file packet.c.
References packet_receive().
Referenced by acds_client_handler(), acds_session_create(), acds_session_join(), acds_session_lookup(), client_crypto_handshake(), crypto_handshake_client_auth_response_socket(), crypto_handshake_client_complete_socket(), crypto_handshake_client_key_exchange_socket(), crypto_handshake_server_auth_challenge_socket(), crypto_handshake_server_complete_socket(), discovery_session_process(), and server_crypto_handshake().
| packet_recv_result_t receive_packet_secure | ( | socket_t | sockfd, |
| void * | crypto_ctx, | ||
| bool | enforce_encryption, | ||
| packet_envelope_t * | envelope | ||
| ) |
Receive a packet with decryption and decompression support.
| sockfd | Socket file descriptor |
| crypto_ctx | Crypto context for decryption |
| enforce_encryption | Whether to require encryption |
| envelope | Output: received packet envelope |
Definition at line 566 of file packet.c.
References buffer_pool_alloc(), buffer_pool_free(), crypto_decrypt(), crypto_result_to_string(), and recv_with_timeout().
Referenced by acip_client_receive_and_dispatch(), acip_server_receive_and_dispatch(), and add_client().
| asciichat_error_t send_ascii_frame_packet | ( | socket_t | sockfd, |
| const char * | frame_data, | ||
| size_t | frame_size | ||
| ) |
Definition at line 1188 of file packet.c.
References buffer_pool_alloc(), buffer_pool_free(), and packet_send().
| asciichat_error_t send_audio_batch_packet | ( | socket_t | sockfd, |
| const float * | samples, | ||
| int | num_samples, | ||
| int | batch_count, | ||
| crypto_context_t * | crypto_ctx | ||
| ) |
Definition at line 1069 of file packet.c.
References buffer_pool_alloc(), buffer_pool_free(), and send_packet_secure().
| int send_clear_console_packet | ( | socket_t | sockfd | ) |
Send a clear console packet.
| sockfd | Socket file descriptor |
Definition at line 800 of file packet.c.
References send_packet().
| int send_crypto_capabilities_packet | ( | socket_t | sockfd, |
| const crypto_capabilities_packet_t * | caps | ||
| ) |
Send crypto capabilities packet.
| sockfd | Socket file descriptor |
| caps | Crypto capabilities packet |
Definition at line 1027 of file packet.c.
References send_packet().
Referenced by client_crypto_handshake(), and discovery_session_process().
| int send_crypto_parameters_packet | ( | socket_t | sockfd, |
| const crypto_parameters_packet_t * | params | ||
| ) |
Send crypto parameters packet.
| sockfd | Socket file descriptor |
| params | Crypto parameters packet |
Definition at line 1041 of file packet.c.
References send_packet().
Referenced by server_crypto_handshake().
| asciichat_error_t send_image_frame_packet | ( | socket_t | sockfd, |
| const void * | image_data, | ||
| uint16_t | width, | ||
| uint16_t | height, | ||
| uint8_t | format | ||
| ) |
Definition at line 1227 of file packet.c.
References buffer_pool_alloc(), buffer_pool_free(), and packet_send().
| int send_packet | ( | socket_t | sockfd, |
| packet_type_t | type, | ||
| const void * | data, | ||
| size_t | len | ||
| ) |
Send a basic packet without encryption.
| sockfd | Socket file descriptor |
| type | Packet type |
| data | Packet data |
| len | Data length |
Definition at line 753 of file packet.c.
References packet_send().
Referenced by acds_session_create(), acds_session_join(), acds_session_lookup(), acip_server_send_error(), client_crypto_handshake(), crypto_handshake_rekey_complete(), crypto_handshake_rekey_request(), crypto_handshake_rekey_response(), send_clear_console_packet(), send_crypto_capabilities_packet(), send_crypto_parameters_packet(), send_error_packet_message(), send_ping_packet(), send_pong_packet(), send_protocol_version_packet(), signaling_relay_ice(), signaling_relay_sdp(), and tcp_client_send_packet().
| asciichat_error_t send_packet_secure | ( | socket_t | sockfd, |
| packet_type_t | type, | ||
| const void * | data, | ||
| size_t | len, | ||
| crypto_context_t * | crypto_ctx | ||
| ) |
Send a packet with encryption and compression support.
| sockfd | Socket file descriptor |
| type | Packet type |
| data | Packet data |
| len | Data length |
| crypto_ctx | Crypto context for encryption |
Definition at line 431 of file packet.c.
References buffer_pool_alloc(), buffer_pool_free(), compress_data(), crypto_encrypt(), crypto_is_ready(), crypto_result_to_string(), packet_send(), and should_compress().
Referenced by av_send_audio_opus_batch(), packet_send_error(), packet_send_remote_log(), and send_audio_batch_packet().
| int send_ping_packet | ( | socket_t | sockfd | ) |
Send a ping packet.
| sockfd | Socket file descriptor |
Definition at line 782 of file packet.c.
References send_packet().
| int send_pong_packet | ( | socket_t | sockfd | ) |
Send a pong packet.
| sockfd | Socket file descriptor |
Definition at line 791 of file packet.c.
References send_packet().
| int send_protocol_version_packet | ( | socket_t | sockfd, |
| const protocol_version_packet_t * | version | ||
| ) |
Send protocol version packet.
| sockfd | Socket file descriptor |
| version | Protocol version packet |
Definition at line 1013 of file packet.c.
References send_packet().
Referenced by client_crypto_handshake(), discovery_session_process(), and server_crypto_handshake().