ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
acds.h
Go to the documentation of this file.
4#include <ascii-chat/common.h>
120
121#pragma once
122
123#include <stdint.h>
124#include <stdbool.h>
130
131#ifdef __cplusplus
132extern "C" {
133#endif
134
135// Pack network protocol structures tightly for wire format
136#ifdef _WIN32
137#pragma pack(push, 1)
138#endif
139
153
159
200typedef struct __attribute__((packed)) {
201 uint8_t identity_pubkey[ED25519_PUBLIC_KEY_SIZE];
203 uint64_t timestamp;
204
205 uint8_t capabilities;
206 uint8_t max_participants;
207 uint8_t session_type;
208
209 uint8_t has_password;
210 uint8_t password_hash[ACIP_PASSWORD_HASH_SIZE];
211 uint8_t expose_ip_publicly;
213
214 uint8_t reserved_string_len;
215 // char reserved_string[]; ///< Variable length, follows if len > 0
216
217 // Multi-key protocol: tracks which key in sequence this is
218 uint8_t total_keys;
219 uint8_t key_index;
220
221 // Server connection information (where clients should connect)
222 // For DIRECT_TCP: server_address and server_port specify where to connect
223 // For WEBRTC: these fields are ignored, signaling happens through ACDS
224 char server_address[ACIP_ADDRESS_SIZE];
225 uint16_t server_port;
227
264typedef struct __attribute__((packed)) {
265 uint8_t session_string_len;
266 char session_string[ACIP_MAX_SESSION_STRING_LEN];
269 uint64_t expires_at;
270
271 uint8_t stun_count;
272 uint8_t turn_count;
273 // Followed by: stun_server_t[stun_count], turn_server_t[turn_count]
275
280
306typedef struct __attribute__((packed)) {
307 uint8_t session_string_len;
308 char session_string[ACIP_MAX_SESSION_STRING_LEN];
310
345typedef struct __attribute__((packed)) {
346 uint8_t found;
348 uint8_t host_pubkey[ED25519_PUBLIC_KEY_SIZE];
349 uint8_t capabilities;
350 uint8_t max_participants;
351 uint8_t current_participants;
352 uint8_t session_type;
353 uint8_t has_password;
354 uint64_t created_at;
355 uint64_t expires_at;
356
357 // ACDS Policy Flags (enforced by discovery server)
358 uint8_t require_server_verify;
359 uint8_t require_client_verify;
361
399typedef struct __attribute__((packed)) {
400 uint8_t session_string_len;
401 char session_string[ACIP_MAX_SESSION_STRING_LEN];
402 uint8_t identity_pubkey[ED25519_PUBLIC_KEY_SIZE];
404 uint64_t timestamp;
405
406 uint8_t has_password;
407 char password[ACIP_PASSWORD_SIZE];
409
452typedef struct __attribute__((packed)) {
453 uint8_t success;
454 uint8_t error_code;
455 char error_message[ACIP_ERROR_MESSAGE_SIZE];
456
459 uint8_t initiator_id[SESSION_ID_SIZE];
460
461 // Host status for discovery mode negotiation
462 uint8_t host_established;
463 uint8_t host_id[SESSION_ID_SIZE];
464
465 // Peer information for host negotiation (only relevant if host_established == 0)
466 uint8_t peer_count;
467 // Followed by: uint8_t peer_ids[peer_count][16] (variable length)
468
469 // Server connection information (ONLY if success == 1 AND host_established == 1)
470 uint8_t session_type;
471 char server_address[ACIP_ADDRESS_SIZE];
472 uint16_t server_port;
473
474 // TURN credentials for WebRTC NAT traversal (ONLY if session_type == SESSION_TYPE_WEBRTC)
475 // Generated by ACDS server using HMAC-SHA1 with shared secret
476 // Format follows RFC 5766 time-limited TURN authentication
477 char turn_username[ACIP_TURN_AUTH_SIZE];
478 char turn_password[ACIP_PASSWORD_SIZE];
480
492typedef struct __attribute__((packed)) {
494 uint8_t new_participant_id[SESSION_ID_SIZE];
495 uint8_t new_participant_pubkey[ED25519_PUBLIC_KEY_SIZE];
496 uint8_t current_participant_count;
498
509typedef struct __attribute__((packed)) {
511 uint8_t left_participant_id[SESSION_ID_SIZE];
512 uint8_t was_host;
513 uint8_t remaining_count;
515
526typedef struct __attribute__((packed)) {
530
541typedef struct __attribute__((packed)) {
545
556typedef struct __attribute__((packed)) {
561
563
569
602typedef struct __attribute__((packed)) {
604 uint8_t sender_id[SESSION_ID_SIZE];
605 uint8_t recipient_id[SESSION_ID_SIZE];
606 uint8_t sdp_type;
607 uint16_t sdp_len;
608 // char sdp_data[]; ///< Variable length SDP string
610
649typedef struct __attribute__((packed)) {
651 uint8_t sender_id[SESSION_ID_SIZE];
652 uint8_t recipient_id[SESSION_ID_SIZE];
653 uint16_t candidate_len;
654 // char candidate[]; ///< Variable length ICE candidate
656
658
664
675typedef struct __attribute__((packed)) {
676 uint8_t identity_pubkey[ED25519_PUBLIC_KEY_SIZE];
678 uint64_t timestamp;
679 uint8_t string_len;
680 char string[ACIP_MAX_SESSION_STRING_LEN];
681 uint32_t duration_days;
683
693typedef struct __attribute__((packed)) {
694 uint8_t success;
695 uint8_t error_code;
696 char error_message[ACIP_ERROR_MESSAGE_SIZE];
697 uint64_t expires_at;
699
709typedef struct __attribute__((packed)) {
710 uint8_t identity_pubkey[ED25519_PUBLIC_KEY_SIZE];
712 uint64_t timestamp;
713 uint8_t string_len;
714 char string[ACIP_MAX_SESSION_STRING_LEN];
715 uint32_t duration_days;
717
727typedef struct __attribute__((packed)) {
728 uint8_t identity_pubkey[ED25519_PUBLIC_KEY_SIZE];
730 uint64_t timestamp;
731 uint8_t string_len;
732 char string[ACIP_MAX_SESSION_STRING_LEN];
734
736
754
769typedef struct __attribute__((packed)) {
771 uint8_t num_participants;
772 // Followed by: participant_entry_t[num_participants] (variable length)
773 // participant_entry_t {
774 // uint8_t participant_id[16];
775 // char address[ACIP_ADDRESS_SIZE];
776 // uint16_t port;
777 // uint8_t connection_type;
778 // }
780
788typedef struct __attribute__((packed)) {
790 char address[ACIP_ADDRESS_SIZE];
791 uint16_t port;
794
811typedef struct __attribute__((packed)) {
813 uint8_t from_participant_id[SESSION_ID_SIZE];
814 uint8_t to_participant_id[SESSION_ID_SIZE];
815 uint64_t round_number;
817
819
825
837
848
871typedef struct __attribute__((packed)) {
874
875 // NAT detection results
876 uint8_t has_public_ip;
877 uint8_t upnp_available;
878 uint8_t upnp_mapped_port[2];
879 uint8_t stun_nat_type;
880 uint8_t lan_reachable;
881 uint32_t stun_latency_ns;
882
883 // Bandwidth measurements (critical for host selection)
885 uint32_t download_kbps;
886 uint32_t rtt_to_acds_ns;
887 uint32_t jitter_ns;
888 uint8_t packet_loss_pct;
889
890 // Connection info
893
894 // ICE candidate summary
895 uint8_t ice_candidate_types;
897
909typedef struct __attribute__((packed)) {
911 uint8_t host_id[SESSION_ID_SIZE];
912 char host_address[ACIP_ADDRESS_SIZE];
913 uint16_t host_port;
915 uint32_t generation;
916 uint32_t sequence;
918
929typedef struct __attribute__((packed)) {
931 uint8_t host_id[SESSION_ID_SIZE];
932 char host_address[ACIP_ADDRESS_SIZE];
933 uint16_t host_port;
935 uint32_t generation;
936 uint32_t sequence;
938
955typedef struct __attribute__((packed)) {
958 uint8_t last_host_id[SESSION_ID_SIZE];
959 uint32_t disconnect_reason;
960 uint64_t disconnect_time_ms;
962
983typedef struct __attribute__((packed)) {
985 uint8_t future_host_id[SESSION_ID_SIZE];
986 char future_host_address[ACIP_ADDRESS_SIZE];
987 uint16_t future_host_port;
989 uint64_t elected_at_round;
991
993
999
1010typedef struct __attribute__((packed)) {
1011 uint8_t error_code;
1012 char error_message[ACIP_SIGNAL_ERROR_MESSAGE_SIZE];
1014
1024typedef struct __attribute__((packed)) {
1027 uint32_t test_size_bytes;
1028 uint64_t client_send_time_ns;
1030
1040typedef struct __attribute__((packed)) {
1041 uint32_t measured_upload_kbps;
1042 uint32_t measured_download_kbps;
1044 uint32_t jitter_ns;
1045 uint8_t packet_loss_pct;
1047
1059typedef struct __attribute__((packed)) {
1062 uint64_t broadcast_id;
1063 uint16_t packet_type;
1065
1084
1086
1092
1094
1099#define ACIP_SESSION_EXPIRATION_MS (24ULL * 60 * 60 * 1000)
1100
1102#define ACIP_DISCOVERY_DEFAULT_PORT OPT_ACDS_PORT_INT_DEFAULT
1103
1105#define ACIP_HOST_DEFAULT_PORT OPT_PORT_INT_DEFAULT
1106
1115#define ACDS_OFFICIAL_SERVER_HOSTNAME "discovery-service.ascii-chat.com"
1116
1118
1119#ifdef _WIN32
1120#pragma pack(pop)
1121#endif
1122
1123#ifdef __cplusplus
1124}
1125#endif
1126 /* acds */
#define ACIP_PASSWORD_SIZE
Definition acds_sizes.h:8
#define ACIP_ADDRESS_SIZE
Definition acds_sizes.h:7
#define ACIP_MAX_SESSION_STRING_LEN
Definition acds_sizes.h:6
#define ACIP_ERROR_MESSAGE_SIZE
Definition acds_sizes.h:10
#define ACIP_TURN_AUTH_SIZE
Definition acds_sizes.h:12
#define ACIP_PASSWORD_HASH_SIZE
Definition acds_sizes.h:9
#define ACIP_SIGNAL_ERROR_MESSAGE_SIZE
Definition acds_sizes.h:11
⚙️ Common definitions, error codes, macros, and types shared throughout the application
unsigned short uint16_t
Definition common.h:61
unsigned int uint32_t
Definition common.h:62
unsigned long long uint64_t
Definition common.h:63
unsigned char uint8_t
Definition common.h:60
#define SESSION_ID_SIZE
acip_connection_type_t
Connection type for host announcement.
Definition acds.h:842
acip_bandwidth_test_t
Definition acds.h:1029
acip_string_renew_t
Definition acds.h:716
acip_session_join_t
Definition acds.h:408
acip_nat_type_t
NAT type classification for host selection.
Definition acds.h:830
acip_participant_joined_t
Definition acds.h:497
acip_participant_entry_t
Definition acds.h:793
acip_session_joined_t
Definition acds.h:479
acip_session_lookup_t
Definition acds.h:309
acip_future_host_elected_t
Definition acds.h:990
acip_host_designated_t
Definition acds.h:937
acip_bandwidth_result_t
Definition acds.h:1046
acip_participant_list_t
Definition acds.h:779
acip_error_t
Definition acds.h:1013
acip_string_reserved_t
Definition acds.h:698
acip_webrtc_ice_t
Definition acds.h:655
acip_error_code_t
ACIP error codes.
Definition acds.h:1073
acip_string_release_t
Definition acds.h:733
acip_host_lost_t
Definition acds.h:961
acip_host_announcement_t
Definition acds.h:917
acip_session_created_t
Definition acds.h:274
acip_broadcast_ack_t
Definition acds.h:1064
acip_webrtc_sdp_t
Definition acds.h:609
acip_session_reconnect_t
Definition acds.h:560
acip_participant_left_t
Definition acds.h:514
acip_session_create_t
Definition acds.h:226
acds_session_type_t
Session connection type.
Definition acds.h:149
acip_session_info_t
Definition acds.h:360
acip_session_leave_t
Definition acds.h:529
acip_ring_collect_t
Definition acds.h:816
acip_string_reserve_t
Definition acds.h:682
acip_nat_quality_t
Definition acds.h:896
acip_session_end_t
Definition acds.h:544
@ ACIP_CONNECTION_TYPE_TURN
TURN relay (fallback).
Definition acds.h:846
@ ACIP_CONNECTION_TYPE_UPNP
UPnP/NAT-PMP port mapping.
Definition acds.h:844
@ ACIP_CONNECTION_TYPE_DIRECT_PUBLIC
Direct public IP connection.
Definition acds.h:843
@ ACIP_CONNECTION_TYPE_STUN
STUN hole-punching.
Definition acds.h:845
@ ACIP_NAT_TYPE_RESTRICTED
Address-restricted cone NAT.
Definition acds.h:833
@ ACIP_NAT_TYPE_SYMMETRIC
Symmetric NAT (hardest, requires TURN).
Definition acds.h:835
@ ACIP_NAT_TYPE_FULL_CONE
Full cone NAT (easiest to traverse).
Definition acds.h:832
@ ACIP_NAT_TYPE_OPEN
No NAT (public IP).
Definition acds.h:831
@ ACIP_NAT_TYPE_PORT_RESTRICTED
Port-restricted cone NAT.
Definition acds.h:834
@ ACIP_ERROR_RATE_LIMITED
Too many requests from this IP.
Definition acds.h:1079
@ ACIP_ERROR_STRING_TAKEN
Requested string already reserved.
Definition acds.h:1080
@ ACIP_ERROR_STRING_INVALID
String format invalid.
Definition acds.h:1081
@ ACIP_ERROR_INTERNAL
Internal server error.
Definition acds.h:1082
@ ACIP_ERROR_INVALID_PASSWORD
Password verification failed.
Definition acds.h:1077
@ ACIP_ERROR_SESSION_NOT_FOUND
Session does not exist.
Definition acds.h:1075
@ ACIP_ERROR_SESSION_FULL
Session has reached max participants.
Definition acds.h:1076
@ ACIP_ERROR_INVALID_SIGNATURE
Identity signature invalid.
Definition acds.h:1078
@ ACIP_ERROR_NONE
No error (success).
Definition acds.h:1074
@ SESSION_TYPE_WEBRTC
WebRTC P2P mesh with STUN/TURN relay.
Definition acds.h:151
@ SESSION_TYPE_DIRECT_TCP
Direct TCP connection to server IP:port (default).
Definition acds.h:150
ascii-chat Binary Network Protocol (complete system including ACIP discovery service)
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
#define ED25519_SIGNATURE_SIZE
Ed25519 signature size in bytes.
Definition sizes.h:37
#define ED25519_PUBLIC_KEY_SIZE
Ed25519 public key size in bytes.
Definition sizes.h:33
uint8_t session_id[SESSION_ID_SIZE]
Network quality metrics for a single participant.
Definition metrics.h:36
uint16_t public_port
Detected public port (network byte order).
Definition metrics.h:43
uint32_t rtt_ns
RTT to current host in nanoseconds (network byte order).
Definition metrics.h:40
char public_address[IP_ADDRESS_BUFFER_SIZE]
Detected public IP address.
Definition metrics.h:42
uint8_t connection_type
Direct=0, UPnP=1, STUN=2, TURN=3.
Definition metrics.h:44
uint8_t participant_id[SESSION_ID_SIZE]
UUID of participant.
Definition metrics.h:37
uint32_t upload_kbps
Upload bandwidth in Kbps (network byte order).
Definition metrics.h:39