|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
Per-client state management and lifecycle orchestration. More...
Go to the source code of this file.
Data Structures | |
| struct | client_manager_t |
| Global client manager structure for server-side client coordination. More... | |
Typedefs | |
| typedef struct server_context_t | server_context_t |
Functions | |
| int | add_client (server_context_t *server_ctx, socket_t socket, const char *client_ip, int port) |
| int | add_webrtc_client (server_context_t *server_ctx, acip_transport_t *transport, const char *client_ip) |
| int | remove_client (server_context_t *server_ctx, uint32_t client_id) |
| client_info_t * | find_client_by_id (uint32_t client_id) |
| client_info_t * | find_client_by_socket (socket_t socket) |
| Find client by socket descriptor using linear search. | |
| void | cleanup_client_media_buffers (client_info_t *client) |
| void | cleanup_client_packet_queues (client_info_t *client) |
| void * | client_receive_thread (void *arg) |
| void | stop_client_threads (client_info_t *client) |
| int | process_encrypted_packet (client_info_t *client, packet_type_t *type, void **data, size_t *len, uint32_t *sender_id) |
| void | process_decrypted_packet (client_info_t *client, packet_type_t type, void *data, size_t len) |
| void | initialize_client_info (client_info_t *client) |
Variables | |
| client_manager_t | g_client_manager |
| Global client manager singleton - central coordination point. | |
| rwlock_t | g_client_manager_rwlock |
| Reader-writer lock protecting the global client manager. | |
Per-client state management and lifecycle orchestration.
This header provides server-specific client management functions. The client_info_t structure and network logging macros are defined in lib/network/client.h.
Definition in file src/server/client.h.
| typedef struct server_context_t server_context_t |
Definition at line 16 of file src/server/client.h.
| int add_client | ( | server_context_t * | server_ctx, |
| socket_t | socket, | ||
| const char * | client_ip, | ||
| int | port | ||
| ) |
| int add_webrtc_client | ( | server_context_t * | server_ctx, |
| acip_transport_t * | transport, | ||
| const char * | client_ip | ||
| ) |
| void cleanup_client_media_buffers | ( | client_info_t * | client | ) |
Definition at line 1851 of file src/server/client.c.
References audio_ring_buffer_destroy(), ERROR_INVALID_PARAM, client_info::incoming_audio_buffer, client_info::incoming_video_buffer, opus_codec_destroy(), client_info::opus_decoder, client_info::outgoing_video_buffer, SAFE_FREE, client_info::send_buffer, client_info::send_buffer_size, SET_ERRNO, and video_frame_buffer_destroy().
| void cleanup_client_packet_queues | ( | client_info_t * | client | ) |
Definition at line 1887 of file src/server/client.c.
References client_info::audio_queue, and packet_queue_destroy().
| void * client_receive_thread | ( | void * | arg | ) |
Definition at line 1240 of file src/server/client.c.
References acip_server_receive_and_dispatch(), client_info::active, asciichat_errno_cleanup(), ASCIICHAT_OK, client_info::audio_render_thread_running, client_info::client_id, asciichat_error_context_t::code, asciichat_error_context_t::context_message, client_info::display_name, ERROR_CRYPTO, ERROR_NETWORK, g_server_should_exit, HAS_ERRNO, INVALID_SOCKET_VALUE, log_debug, log_error, log_error_client, log_warn, client_info::protocol_disconnect_requested, client_info::send_thread_running, should_exit(), client_info::socket, client_info::transport, and client_info::video_render_thread_running.
| client_info_t * find_client_by_id | ( | uint32_t | client_id | ) |
| client_info_t * find_client_by_socket | ( | socket_t | socket | ) |
Find client by socket descriptor using linear search.
This function provides socket-based client lookup, primarily used during connection establishment before client IDs are assigned. Less efficient than find_client_by_id() but necessary for socket-based operations.
PERFORMANCE CHARACTERISTICS:
USAGE PATTERNS:
| socket | Platform-abstracted socket descriptor to search for |
Definition at line 289 of file src/server/client.c.
References client_info::active, client_manager_t::clients, g_client_manager, g_client_manager_rwlock, MAX_CLIENTS, rwlock_rdlock, rwlock_rdunlock, and client_info::socket.
| void initialize_client_info | ( | client_info_t * | client | ) |
| void process_decrypted_packet | ( | client_info_t * | client, |
| packet_type_t | type, | ||
| void * | data, | ||
| size_t | len | ||
| ) |
Process a decrypted packet from a client
| client | Client info structure |
| type | Packet type |
| data | Packet data |
| len | Packet length |
Definition at line 2390 of file src/server/client.c.
References acip_send_pong(), ASCIICHAT_OK, check_and_record_packet_rate_limit(), client_info::client_id, client_info::client_ip, disconnect_client_for_bad_data(), ERROR_NETWORK, g_rate_limiter, handle_audio_batch_packet(), handle_audio_opus_batch_packet(), handle_audio_packet(), handle_client_capabilities_packet(), handle_client_join_packet(), handle_client_leave_packet(), handle_image_frame_packet(), handle_protocol_version_packet(), handle_remote_log_packet_from_client(), handle_stream_start_packet(), handle_stream_stop_packet(), HOST_TO_NET_U16, HOST_TO_NET_U32, mutex_lock, mutex_unlock, NET_TO_HOST_U32, PACKET_TYPE_AUDIO, PACKET_TYPE_AUDIO_BATCH, PACKET_TYPE_AUDIO_OPUS, PACKET_TYPE_AUDIO_OPUS_BATCH, PACKET_TYPE_CLIENT_CAPABILITIES, PACKET_TYPE_CLIENT_JOIN, PACKET_TYPE_CLIENT_LEAVE, PACKET_TYPE_IMAGE_FRAME, PACKET_TYPE_PING, PACKET_TYPE_PONG, PACKET_TYPE_PROTOCOL_VERSION, PACKET_TYPE_REMOTE_LOG, PACKET_TYPE_STREAM_START, PACKET_TYPE_STREAM_STOP, read_u32_unaligned, client_info::send_mutex, SET_ERRNO, client_info::socket, client_info::transport, write_u16_unaligned, and write_u32_unaligned.
| int process_encrypted_packet | ( | client_info_t * | client, |
| packet_type_t * | type, | ||
| void ** | data, | ||
| size_t * | len, | ||
| uint32_t * | sender_id | ||
| ) |
Process an encrypted packet from a client
| client | Client info structure |
| type | Pointer to packet type (will be updated with decrypted type) |
| data | Pointer to packet data (will be updated with decrypted data) |
| len | Pointer to packet length (will be updated with decrypted length) |
| sender_id | Pointer to sender ID (will be updated with decrypted sender ID) |
Definition at line 1923 of file src/server/client.c.
References buffer_pool_alloc(), buffer_pool_free(), client_info::client_id, packet_header_t::client_id, crypto_server_decrypt_packet(), crypto_server_is_ready(), ERROR_CRYPTO, log_error, NET_TO_HOST_U16, NET_TO_HOST_U32, SET_ERRNO, and packet_header_t::type.
| int remove_client | ( | server_context_t * | server_ctx, |
| uint32_t | client_id | ||
| ) |
Referenced by server_main().
| void stop_client_threads | ( | client_info_t * | client | ) |
Definition at line 1832 of file src/server/client.c.
References client_info::active, asciichat_thread_is_initialized(), asciichat_thread_join(), ERROR_INVALID_PARAM, client_info::receive_thread, client_info::send_thread, client_info::send_thread_running, and SET_ERRNO.
|
extern |
Global client manager singleton - central coordination point.
This is the primary data structure for managing all connected clients. It serves as the bridge between main.c's connection accept loop and the per-client threading architecture.
STRUCTURE COMPONENTS:
THREAD SAFETY: Protected by g_client_manager_rwlock for concurrent access
Definition at line 189 of file src/server/client.c.
|
extern |
Reader-writer lock protecting the global client manager.
This lock enables high-performance concurrent access patterns:
USAGE PATTERN:
Definition at line 204 of file src/server/client.c.