ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
acds.h
Go to the documentation of this file.
116#pragma once
117
118#include <stdint.h>
119#include <stdbool.h>
120#include "../../options/options.h"
121#include "../../network/packet/packet.h"
122#include "../../network/acip/protocol.h"
123#include "../../network/webrtc/stun.h"
124#include "../../network/webrtc/turn.h"
125
126#ifdef __cplusplus
127extern "C" {
128#endif
129
130// Pack network protocol structures tightly for wire format
131#ifdef _WIN32
132#pragma pack(push, 1)
133#endif
134
148
195typedef struct __attribute__((packed)) {
196 uint8_t identity_pubkey[32];
197 uint8_t signature[64];
198 uint64_t timestamp;
199
200 uint8_t capabilities;
201 uint8_t max_participants;
202 uint8_t session_type;
203
204 uint8_t has_password;
205 uint8_t password_hash[128];
206 uint8_t expose_ip_publicly;
208
209 uint8_t reserved_string_len;
210 // char reserved_string[]; ///< Variable length, follows if len > 0
211
212 // Multi-key protocol: tracks which key in sequence this is
213 uint8_t total_keys;
214 uint8_t key_index;
215
216 // Server connection information (where clients should connect)
217 // For DIRECT_TCP: server_address and server_port specify where to connect
218 // For WEBRTC: these fields are ignored, signaling happens through ACDS
219 char server_address[64];
220 uint16_t server_port;
222
259typedef struct __attribute__((packed)) {
260 uint8_t session_string_len;
261 char session_string[48];
262 uint8_t session_id[16];
264 uint64_t expires_at;
265
266 uint8_t stun_count;
267 uint8_t turn_count;
268 // Followed by: stun_server_t[stun_count], turn_server_t[turn_count]
270
301typedef struct __attribute__((packed)) {
302 uint8_t session_string_len;
303 char session_string[48];
305
340typedef struct __attribute__((packed)) {
341 uint8_t found;
342 uint8_t session_id[16];
343 uint8_t host_pubkey[32];
344 uint8_t capabilities;
345 uint8_t max_participants;
346 uint8_t current_participants;
347 uint8_t session_type;
348 uint8_t has_password;
349 uint64_t created_at;
350 uint64_t expires_at;
351
352 // ACDS Policy Flags (enforced by discovery server)
353 uint8_t require_server_verify;
354 uint8_t require_client_verify;
356
394typedef struct __attribute__((packed)) {
395 uint8_t session_string_len;
396 char session_string[48];
397 uint8_t identity_pubkey[32];
398 uint8_t signature[64];
399 uint64_t timestamp;
400
401 uint8_t has_password;
402 char password[128];
404
447typedef struct __attribute__((packed)) {
448 uint8_t success;
450 char error_message[128];
451
453 uint8_t session_id[16];
454 uint8_t initiator_id[16];
455
456 // Host status for discovery mode negotiation
457 uint8_t host_established;
458 uint8_t host_id[16];
459
460 // Peer information for host negotiation (only relevant if host_established == 0)
461 uint8_t peer_count;
462 // Followed by: uint8_t peer_ids[peer_count][16] (variable length)
463
464 // Server connection information (ONLY if success == 1 AND host_established == 1)
465 uint8_t session_type;
466 char server_address[64];
467 uint16_t server_port;
468
469 // TURN credentials for WebRTC NAT traversal (ONLY if session_type == SESSION_TYPE_WEBRTC)
470 // Generated by ACDS server using HMAC-SHA1 with shared secret
471 // Format follows RFC 5766 time-limited TURN authentication
472 char turn_username[128];
473 char turn_password[128];
475
487typedef struct __attribute__((packed)) {
488 uint8_t session_id[16];
489 uint8_t new_participant_id[16];
490 uint8_t new_participant_pubkey[32];
491 uint8_t current_participant_count;
493
504typedef struct __attribute__((packed)) {
505 uint8_t session_id[16];
506 uint8_t left_participant_id[16];
507 uint8_t was_host;
508 uint8_t remaining_count;
510
521typedef struct __attribute__((packed)) {
525
536typedef struct __attribute__((packed)) {
538 uint8_t signature[64];
540
551typedef struct __attribute__((packed)) {
554 uint8_t signature[64];
556
597typedef struct __attribute__((packed)) {
598 uint8_t session_id[16];
599 uint8_t sender_id[16];
600 uint8_t recipient_id[16];
601 uint8_t sdp_type;
602 uint16_t sdp_len;
603 // char sdp_data[]; ///< Variable length SDP string
605
644typedef struct __attribute__((packed)) {
646 uint8_t sender_id[16];
647 uint8_t recipient_id[16];
648 uint16_t candidate_len;
649 // char candidate[]; ///< Variable length ICE candidate
651
670typedef struct __attribute__((packed)) {
671 uint8_t identity_pubkey[32];
672 uint8_t signature[64];
673 uint64_t timestamp;
674 uint8_t string_len;
675 char string[48];
676 uint32_t duration_days;
678
688typedef struct __attribute__((packed)) {
689 uint8_t success;
691 char error_message[128];
692 uint64_t expires_at;
694
704typedef struct __attribute__((packed)) {
705 uint8_t identity_pubkey[32];
706 uint8_t signature[64];
707 uint64_t timestamp;
708 uint8_t string_len;
709 char string[48];
710 uint32_t duration_days;
712
722typedef struct __attribute__((packed)) {
723 uint8_t identity_pubkey[32];
724 uint8_t signature[64];
725 uint64_t timestamp;
726 uint8_t string_len;
727 char string[48];
729
764typedef struct __attribute__((packed)) {
766 uint8_t num_participants;
767 // Followed by: participant_entry_t[num_participants] (variable length)
768 // participant_entry_t {
769 // uint8_t participant_id[16];
770 // char address[64];
771 // uint16_t port;
772 // uint8_t connection_type;
773 // }
775
783typedef struct __attribute__((packed)) {
785 char address[64];
786 uint16_t port;
789
806typedef struct __attribute__((packed)) {
808 uint8_t from_participant_id[16];
809 uint8_t to_participant_id[16];
810 uint64_t round_number;
812
832
843
866typedef struct __attribute__((packed)) {
869
870 // NAT detection results
871 uint8_t has_public_ip;
872 uint8_t upnp_available;
873 uint8_t upnp_mapped_port[2];
874 uint8_t stun_nat_type;
875 uint8_t lan_reachable;
876 uint32_t stun_latency_ns;
877
878 // Bandwidth measurements (critical for host selection)
880 uint32_t download_kbps;
881 uint32_t rtt_to_acds_ns;
882 uint32_t jitter_ns;
883 uint8_t packet_loss_pct;
884
885 // Connection info
886 char public_address[64];
888
889 // ICE candidate summary
890 uint8_t ice_candidate_types;
892
904typedef struct __attribute__((packed)) {
906 uint8_t host_id[16];
907 char host_address[64];
908 uint16_t host_port;
911
922typedef struct __attribute__((packed)) {
924 uint8_t host_id[16];
925 char host_address[64];
926 uint16_t host_port;
929
946typedef struct __attribute__((packed)) {
949 uint8_t last_host_id[16];
950 uint32_t disconnect_reason;
951 uint64_t disconnect_time_ms;
953
974typedef struct __attribute__((packed)) {
976 uint8_t future_host_id[16];
977 char future_host_address[64];
978 uint16_t future_host_port;
980 uint64_t elected_at_round;
982
1001typedef struct __attribute__((packed)) {
1003 char error_message[256];
1005
1015typedef struct __attribute__((packed)) {
1016 uint8_t session_id[16];
1018 uint32_t test_size_bytes;
1019 uint64_t client_send_time_ns;
1021
1031typedef struct __attribute__((packed)) {
1032 uint32_t measured_upload_kbps;
1033 uint32_t measured_download_kbps;
1035 uint32_t jitter_ns;
1036 uint8_t packet_loss_pct;
1038
1050typedef struct __attribute__((packed)) {
1051 uint8_t session_id[16];
1053 uint64_t broadcast_id;
1054 uint16_t packet_type;
1056
1075
1085#define ACIP_MAX_SESSION_STRING_LEN 48
1086
1091#define ACIP_SESSION_EXPIRATION_MS (24ULL * 60 * 60 * 1000)
1092
1094#define ACIP_DISCOVERY_DEFAULT_PORT OPT_ACDS_PORT_INT_DEFAULT
1095
1097#define ACIP_HOST_DEFAULT_PORT OPT_PORT_INT_DEFAULT
1098
1107#define ACDS_OFFICIAL_SERVER_HOSTNAME "discovery-service.ascii-chat.com"
1108
1111#ifdef _WIN32
1112#pragma pack(pop)
1113#endif
1114
1115#ifdef __cplusplus
1116}
1117#endif
1118
/* acds */
asciichat_error_t error_code
acip_connection_type_t
Connection type for host announcement.
Definition acds.h:837
acip_bandwidth_test_t
Definition acds.h:1020
acip_string_renew_t
Definition acds.h:711
acip_session_join_t
Definition acds.h:403
acip_nat_type_t
NAT type classification for host selection.
Definition acds.h:825
acip_participant_joined_t
Definition acds.h:492
acip_participant_entry_t
Definition acds.h:788
acip_session_joined_t
Definition acds.h:474
acip_session_lookup_t
Definition acds.h:304
acip_future_host_elected_t
Definition acds.h:981
acip_host_designated_t
Definition acds.h:928
acip_bandwidth_result_t
Definition acds.h:1037
acip_participant_list_t
Definition acds.h:774
acip_error_t
Definition acds.h:1004
acip_string_reserved_t
Definition acds.h:693
acip_webrtc_ice_t
Definition acds.h:650
acip_error_code_t
ACIP error codes.
Definition acds.h:1064
acip_string_release_t
Definition acds.h:728
acip_host_lost_t
Definition acds.h:952
acip_host_announcement_t
Definition acds.h:910
acip_session_created_t
Definition acds.h:269
acip_broadcast_ack_t
Definition acds.h:1055
acip_webrtc_sdp_t
Definition acds.h:604
acip_session_reconnect_t
Definition acds.h:555
acip_participant_left_t
Definition acds.h:509
acip_session_create_t
Definition acds.h:221
acds_session_type_t
Session connection type.
Definition acds.h:144
acip_session_info_t
Definition acds.h:355
acip_session_leave_t
Definition acds.h:524
acip_ring_collect_t
Definition acds.h:811
acip_string_reserve_t
Definition acds.h:677
acip_nat_quality_t
Definition acds.h:891
acip_session_end_t
Definition acds.h:539
@ ACIP_CONNECTION_TYPE_TURN
TURN relay (fallback)
Definition acds.h:841
@ ACIP_CONNECTION_TYPE_UPNP
UPnP/NAT-PMP port mapping.
Definition acds.h:839
@ ACIP_CONNECTION_TYPE_DIRECT_PUBLIC
Direct public IP connection.
Definition acds.h:838
@ ACIP_CONNECTION_TYPE_STUN
STUN hole-punching.
Definition acds.h:840
@ ACIP_NAT_TYPE_RESTRICTED
Address-restricted cone NAT.
Definition acds.h:828
@ ACIP_NAT_TYPE_SYMMETRIC
Symmetric NAT (hardest, requires TURN)
Definition acds.h:830
@ ACIP_NAT_TYPE_FULL_CONE
Full cone NAT (easiest to traverse)
Definition acds.h:827
@ ACIP_NAT_TYPE_OPEN
No NAT (public IP)
Definition acds.h:826
@ ACIP_NAT_TYPE_PORT_RESTRICTED
Port-restricted cone NAT.
Definition acds.h:829
@ ACIP_ERROR_RATE_LIMITED
Too many requests from this IP.
Definition acds.h:1070
@ ACIP_ERROR_STRING_TAKEN
Requested string already reserved.
Definition acds.h:1071
@ ACIP_ERROR_STRING_INVALID
String format invalid.
Definition acds.h:1072
@ ACIP_ERROR_INTERNAL
Internal server error.
Definition acds.h:1073
@ ACIP_ERROR_INVALID_PASSWORD
Password verification failed.
Definition acds.h:1068
@ ACIP_ERROR_SESSION_NOT_FOUND
Session does not exist.
Definition acds.h:1066
@ ACIP_ERROR_SESSION_FULL
Session has reached max participants.
Definition acds.h:1067
@ ACIP_ERROR_INVALID_SIGNATURE
Identity signature invalid.
Definition acds.h:1069
@ ACIP_ERROR_NONE
No error (success)
Definition acds.h:1065
@ SESSION_TYPE_WEBRTC
WebRTC P2P mesh with STUN/TURN relay.
Definition acds.h:146
@ SESSION_TYPE_DIRECT_TCP
Direct TCP connection to server IP:port (default)
Definition acds.h:145
unsigned short uint16_t
Definition common.h:57
unsigned int uint32_t
Definition common.h:58
unsigned long long uint64_t
Definition common.h:59
unsigned char uint8_t
Definition common.h:56
uint8_t session_id[16]
ClangTool/LibTooling compatibility shim for stdbool.h.
Network quality metrics for a single participant.
Definition metrics.h:33
uint16_t public_port
Detected public port (network byte order)
Definition metrics.h:40
uint32_t rtt_ns
RTT to current host in nanoseconds (network byte order)
Definition metrics.h:37
uint8_t participant_id[16]
UUID of participant.
Definition metrics.h:34
char public_address[64]
Detected public IP address.
Definition metrics.h:39
uint8_t connection_type
Direct=0, UPnP=1, STUN=2, TURN=3.
Definition metrics.h:41
uint32_t upload_kbps
Upload bandwidth in Kbps (network byte order)
Definition metrics.h:36