|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🎯 Session registry for discovery service (lock-free RCU implementation) More...
Go to the source code of this file.
Data Structures | |
| struct | participant_t |
| Participant in a session. More... | |
| struct | session_entry |
| Session entry (RCU hash table node) More... | |
| struct | session_registry_t |
| Session registry (lock-free RCU) More... | |
Macros | |
| #define | MAX_PARTICIPANTS 8 |
| Maximum participants per session. | |
Typedefs | |
| typedef struct session_entry | session_entry_t |
| Session entry (RCU hash table node) | |
Functions | |
| asciichat_error_t | session_registry_init (session_registry_t *registry) |
| Initialize session registry. | |
| asciichat_error_t | session_create (session_registry_t *registry, const acip_session_create_t *req, const acds_config_t *config, acip_session_created_t *resp) |
| Create new session. | |
| asciichat_error_t | session_lookup (session_registry_t *registry, const char *session_string, const acds_config_t *config, acip_session_info_t *resp) |
| Lookup session by string. | |
| asciichat_error_t | session_join (session_registry_t *registry, const acip_session_join_t *req, const acds_config_t *config, acip_session_joined_t *resp) |
| Join existing session. | |
| asciichat_error_t | session_leave (session_registry_t *registry, const uint8_t session_id[16], const uint8_t participant_id[16]) |
| Leave session. | |
| void | session_cleanup_expired (session_registry_t *registry) |
| Clean up expired sessions. | |
| void | session_registry_destroy (session_registry_t *registry) |
| Destroy session registry. | |
🎯 Session registry for discovery service (lock-free RCU implementation)
In-memory hash table of active sessions with lock-free concurrent access. Uses liburcu for:
Sessions expire after 24 hours and are cleaned up by background thread. Fine-grained per-entry locking protects participant lists.
Definition in file session.h.
| #define MAX_PARTICIPANTS 8 |
| typedef struct session_entry session_entry_t |
Session entry (RCU hash table node)
Layout optimized for RCU:
| void session_cleanup_expired | ( | session_registry_t * | registry | ) |
Clean up expired sessions.
Removes sessions that have exceeded their 24-hour lifetime. Called periodically by background cleanup thread.
| registry | Session registry |
Definition at line 615 of file session.c.
References session_entry::created_at, session_entry::expires_at, session_entry::hash_node, log_debug, log_info, session_entry::rcu_head, session_entry::session_string, and session_registry_t::sessions.
| asciichat_error_t session_create | ( | session_registry_t * | registry, |
| const acip_session_create_t * | req, | ||
| const acds_config_t * | config, | ||
| acip_session_created_t * | resp | ||
| ) |
Create new session.
| registry | Session registry |
| req | Session creation request |
| resp | Session creation response (output) |
Definition at line 241 of file session.c.
References acds_string_generate(), acds_string_validate(), ACIP_MAX_SESSION_STRING_LEN, ACIP_SESSION_EXPIRATION_MS, ASCIICHAT_OK, session_entry::capabilities, session_entry::created_at, session_entry::current_participants, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_MEMORY, ERROR_PLATFORM_INIT, session_entry::expires_at, session_entry::expose_ip_publicly, session_entry::has_password, session_entry::hash_node, session_entry::host_pubkey, log_info, MAX_PARTICIPANTS, session_entry::max_participants, mutex_destroy(), mutex_init(), session_entry::participant_mutex, session_entry::password_hash, SAFE_FREE, SAFE_MALLOC, SAFE_STRNCPY, session_entry::server_address, session_entry::server_port, session_entry::session_id, session_entry::session_string, session_entry::session_type, session_registry_t::sessions, SET_ERRNO, acds_config_t::stun_count, and acds_config_t::turn_count.
| asciichat_error_t session_join | ( | session_registry_t * | registry, |
| const acip_session_join_t * | req, | ||
| const acds_config_t * | config, | ||
| acip_session_joined_t * | resp | ||
| ) |
Join existing session.
| registry | Session registry |
| req | Join request |
| config | ACDS server configuration (for TURN credentials) |
| resp | Join response (output) |
Definition at line 407 of file session.c.
References ACIP_ERROR_INVALID_PASSWORD, ACIP_ERROR_NONE, ACIP_ERROR_SESSION_FULL, ACIP_ERROR_SESSION_NOT_FOUND, ACIP_MAX_SESSION_STRING_LEN, ASCIICHAT_OK, session_entry::current_participants, ERROR_INVALID_PARAM, ERROR_MEMORY, session_entry::expose_ip_publicly, session_entry::has_password, participant_t::identity_pubkey, participant_t::joined_at, log_debug, log_error, log_info, log_warn, session_entry::max_participants, mutex_lock, mutex_unlock, participant_t::participant_id, session_entry::participant_mutex, session_entry::participants, turn_credentials_t::password, session_entry::password_hash, SAFE_MALLOC, SAFE_STRNCPY, session_entry::server_address, session_entry::server_port, session_entry::session_id, session_entry::session_type, SESSION_TYPE_WEBRTC, session_registry_t::sessions, SET_ERRNO, turn_generate_credentials(), acds_config_t::turn_secret, and turn_credentials_t::username.
| asciichat_error_t session_leave | ( | session_registry_t * | registry, |
| const uint8_t | session_id[16], | ||
| const uint8_t | participant_id[16] | ||
| ) |
Leave session.
| registry | Session registry |
| session_id | Session UUID |
| participant_id | Participant UUID |
Definition at line 559 of file session.c.
References ASCIICHAT_OK, session_entry::current_participants, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, session_entry::hash_node, log_info, MAX_PARTICIPANTS, session_entry::max_participants, mutex_lock, mutex_unlock, participant_id, session_entry::participant_mutex, session_entry::participants, session_entry::rcu_head, SAFE_FREE, session_id, session_entry::session_string, session_registry_t::sessions, and SET_ERRNO.
| asciichat_error_t session_lookup | ( | session_registry_t * | registry, |
| const char * | session_string, | ||
| const acds_config_t * | config, | ||
| acip_session_info_t * | resp | ||
| ) |
Lookup session by string.
| registry | Session registry |
| session_string | Session string to look up |
| config | ACDS server configuration (for policy flags) |
| resp | Session info response (output) |
Definition at line 349 of file session.c.
References ASCIICHAT_OK, session_entry::capabilities, session_entry::created_at, session_entry::current_participants, ERROR_INVALID_PARAM, session_entry::expires_at, session_entry::has_password, session_entry::host_pubkey, log_debug, session_entry::max_participants, acds_config_t::require_client_verify, acds_config_t::require_server_verify, session_entry::session_id, session_entry::session_type, session_registry_t::sessions, and SET_ERRNO.
| void session_registry_destroy | ( | session_registry_t * | registry | ) |
Destroy session registry.
| registry | Registry to destroy |
Definition at line 190 of file session.c.
References session_entry::hash_node, log_debug, log_info, log_warn, session_entry::rcu_head, and session_registry_t::sessions.
Referenced by acds_server_init(), and acds_server_shutdown().
| asciichat_error_t session_registry_init | ( | session_registry_t * | registry | ) |
Initialize session registry.
| registry | Registry structure to initialize |
Definition at line 169 of file session.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_MEMORY, log_info, session_registry_t::sessions, and SET_ERRNO.
Referenced by acds_server_init().