| 1 |
. |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#ifndef RIST_RIST_PRIVATE_H |
| 9 |
#define RIST_RIST_PRIVATE_H |
| 10 |
|
| 11 |
#include "common/attributes.h" |
| 12 |
|
| 13 |
#include <stdint.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <sys/types.h> |
| 16 |
#include <string.h> |
| 17 |
#include <stdlib.h> |
| 18 |
#include <stdbool.h> |
| 19 |
#include "stdio-shim.h" |
| 20 |
#include <fcntl.h> |
| 21 |
#include <inttypes.h> |
| 22 |
#include <stddef.h> |
| 23 |
#include "time-shim.h" |
| 24 |
#include "pthread-shim.h" |
| 25 |
#include "socket-shim.h" |
| 26 |
#include "libevsocket.h" |
| 27 |
#include "librist.h" |
| 28 |
#include "librist/transport.h" |
| 29 |
#include "udpsocket.h" |
| 30 |
#include "crypto/psk.h" |
| 31 |
#include <errno.h> |
| 32 |
#include <stdatomic.h> |
| 33 |
#include "librist/logging.h" |
| 34 |
#include "proto/gre.h" |
| 35 |
#include "proto/adv.h" |
| 36 |
|
| 37 |
struct cJSON; |
| 38 |
|
| 39 |
#undef RIST_DEPRECATED |
| 40 |
|
| 41 |
#define UINT16_SIZE (UINT16_MAX + 1) |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
static inline uint32_t rist_seq_gap(uint32_t current, uint32_t last, |
| 48 |
bool short_seq) |
| 49 |
{ |
| 50 |
uint32_t gap = current - last; |
| 51 |
return short_seq ? (gap & UINT16_MAX) : gap; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
static inline uint32_t rist_seq_next(uint32_t last, bool short_seq) |
| 57 |
{ |
| 58 |
uint32_t next = last + 1; |
| 59 |
return short_seq ? (next & UINT16_MAX) : next; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
#define RIST_SERVER_QUEUE_BUFFERS ((UINT16_SIZE) * 8) |
| 71 |
#define RIST_RECOVERY_QUEUE_MAX ((uint64_t)(UINT16_SIZE) << 16) |
| 72 |
#define RIST_RETRY_QUEUE_BUFFERS ((UINT16_SIZE) * 4) |
| 73 |
#define RIST_OOB_QUEUE_BUFFERS ((UINT16_SIZE) * 2) |
| 74 |
#define RIST_DATAOUT_QUEUE_BUFFERS (1024) |
| 75 |
|
| 76 |
#define RIST_MAX_PACKET_SIZE (10000) |
| 77 |
#define RIST_RTT_MIN (3) |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
#define RIST_MAX_JITTER (5) |
| 82 |
#define RIST_PING_INTERVAL (100) |
| 83 |
#define RIST_PBKDF2_HMAC_SHA256_ITERATIONS (1024) |
| 84 |
#define RIST_AES_KEY_REUSE_TIMES UINT32_MAX |
| 85 |
#define RIST_MAX_HOSTNAME (128) |
| 86 |
#define RTCP_FB_FCI_GENERIC_NACK_SIZE (4) |
| 87 |
#define RIST_MAX_NACKS (200) |
| 88 |
#define RIST_MAX_NACKS_BYTES RIST_MAX_NACKS*RTCP_FB_FCI_GENERIC_NACK_SIZE |
| 89 |
|
| 90 |
|
| 91 |
#define RIST_MAX_HEADER_SIZE 32 |
| 92 |
#define CHECK_BIT(var,pos) !!((var) & (1<<(pos))) |
| 93 |
|
| 94 |
#define BYTE_TO_BINARY_PATTERN "%c%c%c%c%c%c%c%c" |
| 95 |
#define BYTE_TO_BINARY(byte) \ |
| 96 |
(byte & 0x80 ? '1' : '0'), \ |
| 97 |
(byte & 0x40 ? '1' : '0'), \ |
| 98 |
(byte & 0x20 ? '1' : '0'), \ |
| 99 |
(byte & 0x10 ? '1' : '0'), \ |
| 100 |
(byte & 0x08 ? '1' : '0'), \ |
| 101 |
(byte & 0x04 ? '1' : '0'), \ |
| 102 |
(byte & 0x02 ? '1' : '0'), \ |
| 103 |
(byte & 0x01 ? '1' : '0') |
| 104 |
|
| 105 |
#define STALE_FLOW_TIME (60L * 1000L * RIST_CLOCK) |
| 106 |
|
| 107 |
enum rist_peer_state { |
| 108 |
RIST_PEER_STATE_IDLE = 0, |
| 109 |
RIST_PEER_STATE_PING = 1, |
| 110 |
RIST_PEER_STATE_CONNECT = 2 |
| 111 |
}; |
| 112 |
struct rist_buffer { |
| 113 |
void *data; |
| 114 |
size_t size; |
| 115 |
uint8_t type; |
| 116 |
uint16_t src_port; |
| 117 |
uint16_t dst_port; |
| 118 |
uint64_t source_time; |
| 119 |
int8_t use_seq; |
| 120 |
uint32_t seq; |
| 121 |
uint16_t seq_rtp; |
| 122 |
|
| 123 |
uint64_t time; |
| 124 |
uint64_t packet_time; |
| 125 |
uint64_t target_output_time; |
| 126 |
|
| 127 |
uint8_t fragment_number; |
| 128 |
uint8_t fragment_final; |
| 129 |
|
| 130 |
uint64_t last_retry_request; |
| 131 |
uint8_t transmit_count; |
| 132 |
uint16_t ts_null_bytes; |
| 133 |
struct rist_peer *peer; |
| 134 |
|
| 135 |
struct rist_buffer *next_free; |
| 136 |
size_t alloc_size; |
| 137 |
bool free; |
| 138 |
bool retry_queued; |
| 139 |
}; |
| 140 |
|
| •141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
static inline int rist_recovery_depth_platform_max(void) |
| 147 |
{ |
| 148 |
const uint64_t per = (uint64_t)sizeof(struct rist_buffer *) + sizeof(uint32_t); |
| 149 |
const uint64_t limit = (uint64_t)SIZE_MAX / per; |
| 150 |
int depth = RIST_RECOVERY_DEPTH_MAX; |
| 151 |
while (depth > RIST_RECOVERY_DEPTH_MIN && |
| 152 |
((uint64_t)UINT16_SIZE << depth) > limit) |
| 153 |
depth--; |
| 154 |
return depth; |
| 155 |
} |
| 156 |
|
| 157 |
struct rist_missing_buffer { |
| 158 |
uint32_t seq; |
| 159 |
uint64_t next_nack; |
| 160 |
uint64_t insertion_time; |
| 161 |
uint32_t nack_count; |
| 162 |
struct rist_peer *peer; |
| 163 |
struct rist_missing_buffer *next; |
| 164 |
}; |
| 165 |
|
| 166 |
struct rist_bandwidth_estimation { |
| 167 |
size_t bytes; |
| 168 |
size_t bytes_fast; |
| 169 |
uint64_t last_bitrate_calctime; |
| 170 |
uint64_t last_bitrate_calctime_fast; |
| 171 |
size_t eight_times_bitrate_fast; |
| 172 |
size_t eight_times_bitrate; |
| 173 |
size_t bitrate; |
| 174 |
size_t bitrate_fast; |
| 175 |
}; |
| 176 |
|
| 177 |
struct rist_peer_flow_stats { |
| 178 |
uint32_t lost; |
| 179 |
uint32_t received; |
| 180 |
uint32_t dupe; |
| 181 |
uint32_t dropped_full; |
| 182 |
uint32_t dropped_late; |
| 183 |
size_t buffer_duration_count; |
| 184 |
uint32_t buffer_duration[2048]; |
| 185 |
|
| 186 |
uint32_t missing; |
| 187 |
uint32_t retries; |
| 188 |
uint32_t recovered; |
| 189 |
uint32_t reordered; |
| 190 |
uint32_t dups; |
| 191 |
uint32_t recovered_0nack; |
| 192 |
uint32_t recovered_1nack; |
| 193 |
uint32_t recovered_2nack; |
| 194 |
uint32_t recovered_3nack; |
| 195 |
uint32_t recovered_morenack; |
| 196 |
uint32_t recovered_sum; |
| 197 |
uint32_t recovered_average; |
| 198 |
int32_t recovered_slope; |
| 199 |
uint32_t recovered_slope_inverted; |
| 200 |
|
| 201 |
|
| 202 |
uint64_t min_ips; |
| 203 |
uint64_t max_ips; |
| 204 |
uint64_t cur_ips; |
| 205 |
uint32_t avg_count; |
| 206 |
uint64_t total_ips; |
| 207 |
|
| 208 |
|
| 209 |
uint64_t received_bytes; |
| 210 |
}; |
| 211 |
|
| 212 |
struct rist_peer_sender_stats { |
| 213 |
uint64_t sent; |
| 214 |
uint32_t received; |
| 215 |
uint32_t retrans; |
| 216 |
uint32_t bloat_skip; |
| 217 |
uint32_t bandwidth_skip; |
| 218 |
uint32_t retrans_skip; |
| 219 |
uint64_t ts_null; |
| 220 |
uint64_t sent_bytes; |
| 221 |
uint64_t retransmitted_bytes; |
| 222 |
}; |
| 223 |
|
| 224 |
struct rist_peer_receiver_stats { |
| 225 |
uint32_t sent_rtcp; |
| 226 |
uint32_t received_rtcp; |
| 227 |
uint64_t received; |
| 228 |
uint64_t ts_null; |
| 229 |
uint64_t received_bytes; |
| 230 |
}; |
| 231 |
|
| 232 |
struct nacks { |
| 233 |
uint32_t array[RIST_MAX_NACKS]; |
| 234 |
size_t counter; |
| 235 |
}; |
| 236 |
|
| 237 |
struct rist_flow { |
| 238 |
atomic_int shutdown; |
| 239 |
int max_output_jitter; |
| 240 |
|
| 241 |
struct rist_buffer **receiver_queue; |
| 242 |
|
| 243 |
pthread_rwlock_t queue_lock; |
| 244 |
|
| 245 |
bool receiver_queue_has_items; |
| 246 |
bool flow_auto_buffer_scaling; |
| 247 |
bool currently_scaling_buffer; |
| 248 |
atomic_ulong receiver_queue_size; |
| 249 |
uint64_t recovery_buffer_ticks; |
| 250 |
uint64_t stats_report_time; |
| 251 |
atomic_ulong receiver_queue_output_idx; |
| 252 |
size_t receiver_queue_max; |
| 253 |
bool flag_flow_buffer_start; |
| 254 |
|
| 255 |
|
| 256 |
struct rist_missing_buffer *missing; |
| 257 |
struct rist_missing_buffer *missing_tail; |
| 258 |
uint32_t missing_counter; |
| 259 |
|
| 260 |
struct rist_peer_flow_stats stats_instant; |
| 261 |
struct rist_peer_flow_stats stats_total; |
| 262 |
struct rist_bandwidth_estimation bw; |
| 263 |
struct rist_bandwidth_estimation bw_tsnull; |
| 264 |
struct rist_bandwidth_estimation bw_rejected; |
| 265 |
struct rist_bandwidth_estimation bw_retries; |
| 266 |
uint64_t stats_next_time; |
| 267 |
uint64_t checks_next_time; |
| 268 |
|
| 269 |
|
| 270 |
uint32_t missing_counter_max; |
| 271 |
|
| 272 |
uint32_t flow_id; |
| 273 |
uint32_t flow_id_actual; |
| 274 |
int dead; |
| 275 |
struct rist_flow *next; |
| 276 |
struct rist_peer **peer_lst; |
| 277 |
size_t peer_lst_len; |
| 278 |
uint32_t last_seq_output; |
| 279 |
uint64_t last_seq_output_source_time; |
| 280 |
uint32_t last_seq_found; |
| 281 |
intptr_t receiver_id; |
| 282 |
intptr_t sender_id; |
| 283 |
uint64_t last_ipstats_time; |
| 284 |
uint64_t last_output_time; |
| 285 |
uint64_t max_source_time; |
| 286 |
uint64_t too_late_ctr; |
| 287 |
|
| 288 |
size_t offset_recalc_sample_count; |
| 289 |
uint64_t offset_recalc_samples[2048]; |
| 290 |
|
| 291 |
int64_t time_offset; |
| 292 |
int64_t time_offset_old; |
| 293 |
uint64_t time_offset_changed_ts; |
| 294 |
uint64_t last_packet_ts; |
| 295 |
bool rtc_timing_mode; |
| 296 |
|
| 297 |
bool authenticated; |
| 298 |
|
| 299 |
|
| 300 |
pthread_t receiver_thread; |
| 301 |
bool receiver_thread_running; |
| 302 |
|
| 303 |
pthread_cond_t condition; |
| 304 |
pthread_mutex_t mutex; |
| 305 |
|
| 306 |
|
| 307 |
bool short_seq; |
| 308 |
|
| 309 |
|
| 310 |
bool merge_auto_enabled; |
| 311 |
|
| 312 |
|
| 313 |
uint64_t session_timeout; |
| 314 |
uint64_t flow_timeout; |
| 315 |
uint64_t last_recv_ts; |
| 316 |
|
| 317 |
|
| 318 |
struct rist_data_block **dataout_fifo_queue; |
| 319 |
size_t dataout_fifo_queue_bytesize; |
| 320 |
atomic_ulong dataout_fifo_queue_read_index; |
| 321 |
atomic_ulong dataout_fifo_queue_write_index; |
| 322 |
atomic_bool fifo_overflow; |
| 323 |
|
| 324 |
|
| 325 |
struct nacks nacks; |
| 326 |
struct rist_logging_settings *logging_settings; |
| 327 |
}; |
| 328 |
|
| 329 |
struct rist_retry { |
| 330 |
struct rist_peer *peer; |
| 331 |
uint64_t insert_time; |
| 332 |
uint32_t seq; |
| 333 |
bool active; |
| 334 |
}; |
| 335 |
|
| 336 |
struct rist_common_ctx { |
| 337 |
atomic_int shutdown; |
| 338 |
atomic_bool startup_complete; |
| 339 |
|
| 340 |
|
| 341 |
intptr_t sender_id; |
| 342 |
intptr_t receiver_id; |
| 343 |
struct rist_logging_settings *logging_settings; |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
struct rist_flow *FLOWS; |
| 348 |
pthread_mutex_t flows_lock; |
| 349 |
|
| 350 |
|
| 351 |
struct evsocket_ctx *evctx; |
| 352 |
|
| 353 |
|
| 354 |
int rist_max_jitter; |
| 355 |
|
| 356 |
|
| 357 |
int recovery_rtt_multiplier; |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
size_t recovery_queue_max; |
| 364 |
|
| 365 |
|
| 366 |
struct rist_peer *PEERS; |
| 367 |
pthread_mutex_t peerlist_lock; |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
struct { |
| 372 |
uint8_t enc[RIST_MAX_PACKET_SIZE]; |
| 373 |
uint8_t dec[RIST_MAX_PACKET_SIZE]; |
| 374 |
uint8_t recv[RIST_MAX_PACKET_SIZE]; |
| 375 |
uint8_t recv_npd[RIST_MAX_PACKET_SIZE]; |
| 376 |
uint8_t rtcp[RIST_MAX_PACKET_SIZE]; |
| 377 |
} buf; |
| 378 |
struct rist_buffer *rist_free_buffer; |
| 379 |
pthread_mutex_t rist_free_buffer_mutex; |
| 380 |
uint64_t rist_free_buffer_count; |
| 381 |
|
| 382 |
|
| 383 |
uint64_t nacks_next_time; |
| 384 |
uint64_t stats_report_time; |
| 385 |
|
| 386 |
enum rist_profile profile; |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
atomic_bool profile_locked; |
| 391 |
uint8_t cname[RIST_MAX_HOSTNAME]; |
| 392 |
|
| 393 |
|
| 394 |
uint32_t seq; |
| 395 |
uint16_t seq_rtp; |
| 396 |
|
| 397 |
|
| 398 |
uint32_t adv_ssrc_base; |
| 399 |
uint32_t adv_seq_protected; |
| 400 |
uint32_t adv_seq_unprotected; |
| 401 |
|
| 402 |
|
| 403 |
uint32_t peer_counter; |
| 404 |
|
| 405 |
|
| 406 |
struct { |
| 407 |
int (*conn_cb)(void *arg, const char* connecting_ip, uint16_t connecting_port, const char* local_ip, uint16_t local_port, struct rist_peer *peer); |
| 408 |
int (*disconn_cb)(void *arg, struct rist_peer *peer); |
| 409 |
void *arg; |
| 410 |
} auth; |
| 411 |
|
| 412 |
|
| 413 |
int (*oob_data_callback)(void *arg, const struct rist_oob_block *oob_block); |
| 414 |
void *oob_data_callback_argument; |
| 415 |
bool oob_data_enabled; |
| 416 |
struct rist_peer *oob_current_peer; |
| 417 |
|
| 418 |
int (*stats_callback)(void *arg, const struct rist_stats *stats_container); |
| 419 |
void *stats_callback_argument; |
| 420 |
pthread_mutex_t stats_lock; |
| 421 |
|
| 422 |
pthread_rwlock_t oob_queue_lock; |
| 423 |
struct rist_buffer *oob_queue[RIST_OOB_QUEUE_BUFFERS]; |
| 424 |
size_t oob_queue_bytesize; |
| 425 |
uint16_t oob_queue_read_index; |
| 426 |
uint16_t oob_queue_write_index; |
| 427 |
|
| 428 |
bool debug; |
| 429 |
uint32_t birthtime_rtp_offset; |
| 430 |
|
| 431 |
|
| 432 |
struct rist_transport_ops transport; |
| 433 |
bool transport_active; |
| 434 |
|
| 435 |
|
| 436 |
connection_status_callback_t connection_status_callback; |
| 437 |
void *connection_status_callback_argument; |
| 438 |
|
| 439 |
rist_thread_callback_func_t thread_callback; |
| 440 |
void *thread_callback_arg; |
| 441 |
}; |
| 442 |
|
| 443 |
struct rist_receiver { |
| 444 |
|
| 445 |
pthread_cond_t condition; |
| 446 |
pthread_mutex_t mutex; |
| 447 |
|
| 448 |
|
| 449 |
receiver_data_callback2_t receiver_data_callback; |
| 450 |
void *receiver_data_callback_argument; |
| 451 |
int receiver_data_ready_notify_fd; |
| 452 |
|
| 453 |
*/ |
| 454 |
int receiver_data_fd; |
| 455 |
uint32_t receiver_data_fd_flags; |
| 456 |
atomic_uint_fast64_t data_fd_rx_packets; |
| 457 |
atomic_uint_fast64_t data_fd_rx_bytes; |
| 458 |
|
| 459 |
|
| 460 |
receiver_session_timeout_callback_t receiver_session_timeout_callback; |
| 461 |
void *receiver_session_timeout_callback_argument; |
| 462 |
|
| 463 |
|
| 464 |
receiver_flow_attr_callback_t receiver_flow_attr_callback; |
| 465 |
void *receiver_flow_attr_callback_argument; |
| 466 |
|
| 467 |
|
| 468 |
bool protocol_running; |
| 469 |
pthread_t receiver_thread; |
| 470 |
|
| 471 |
|
| 472 |
intptr_t id; |
| 473 |
|
| 474 |
|
| 475 |
struct rist_common_ctx common; |
| 476 |
|
| 477 |
enum rist_nack_type nack_type; |
| 478 |
|
| 479 |
bool simulate_loss; |
| 480 |
uint16_t loss_percentage; |
| 481 |
uint32_t fifo_queue_size; |
| 482 |
|
| 483 |
uint32_t merge_mode; |
| 484 |
uint64_t stats_pairs_merged; |
| 485 |
uint64_t stats_orphan_first_delivered; |
| 486 |
uint64_t stats_orphan_last_delivered; |
| 487 |
}; |
| 488 |
|
| 489 |
struct rist_sender { |
| 490 |
|
| 491 |
uint32_t adv_flow_id; |
| 492 |
|
| 493 |
|
| 494 |
uint32_t recovery_maxbitrate_max; |
| 495 |
uint32_t max_nacksperloop; |
| 496 |
bool null_packet_suppression; |
| 497 |
|
| 498 |
uint32_t split_mode; |
| 499 |
uint64_t stats_pairs_emitted; |
| 500 |
uint64_t stats_split_fallback_not_ts; |
| 501 |
|
| 502 |
|
| 503 |
bool protocol_running; |
| 504 |
pthread_t sender_thread; |
| 505 |
|
| 506 |
pthread_cond_t condition; |
| 507 |
pthread_mutex_t mutex; |
| 508 |
|
| 509 |
bool sender_initialized; |
| 510 |
uint32_t total_weight; |
| 511 |
struct rist_buffer **sender_queue; |
| 512 |
size_t sender_queue_bytesize; |
| 513 |
size_t sender_queue_size; |
| 514 |
size_t sender_queue_timelength; |
| 515 |
size_t sender_buffer_size; |
| 516 |
size_t sender_queue_delete_index; |
| 517 |
atomic_ulong sender_queue_read_index; |
| 518 |
atomic_ulong sender_queue_write_index; |
| 519 |
size_t sender_queue_max; |
| 520 |
int weight_counter; |
| 521 |
uint64_t last_datagram_time; |
| 522 |
bool simulate_loss; |
| 523 |
uint16_t loss_percentage; |
| 524 |
uint64_t stats_next_time; |
| 525 |
uint64_t checks_next_time; |
| 526 |
uint32_t session_timeout; |
| 527 |
|
| 528 |
|
| 529 |
struct rist_retry *sender_retry_queue; |
| 530 |
size_t sender_retry_queue_write_index; |
| 531 |
size_t sender_retry_queue_read_index; |
| 532 |
size_t sender_retry_queue_size; |
| 533 |
uint64_t cooldown_time; |
| 534 |
int cooldown_mode; |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
uint32_t *seq_index; |
| 539 |
size_t sender_recover_min_time; |
| 540 |
size_t sender_queue_buffer_size; |
| 541 |
|
| 542 |
|
| 543 |
intptr_t id; |
| 544 |
|
| 545 |
|
| 546 |
struct timeval time; |
| 547 |
|
| 548 |
|
| 549 |
struct rist_common_ctx common; |
| 550 |
|
| 551 |
|
| 552 |
struct rist_peer **peer_lst; |
| 553 |
size_t peer_lst_len; |
| 554 |
|
| 555 |
|
| 556 |
pthread_mutex_t queue_lock; |
| 557 |
|
| 558 |
|
| 559 |
int (*sender_stats_callback)(void *arg, uint16_t version, char *stats_json, uint32_t json_size); |
| 560 |
void *sender_stats_callback_argument; |
| 561 |
uint64_t stats_report_time; |
| 562 |
|
| 563 |
*/ |
| 564 |
int data_fd; |
| 565 |
size_t data_fd_max_packet_size; |
| 566 |
uint32_t data_fd_flags; |
| 567 |
pthread_t data_fd_thread; |
| 568 |
bool data_fd_thread_started; |
| 569 |
atomic_uint_fast64_t data_fd_tx_packets; |
| 570 |
atomic_uint_fast64_t data_fd_tx_bytes; |
| 571 |
}; |
| 572 |
|
| 573 |
enum rist_ctx_mode { |
| 574 |
RIST_SENDER_MODE, |
| 575 |
RIST_RECEIVER_MODE |
| 576 |
}; |
| 577 |
|
| 578 |
struct rist_ctx { |
| 579 |
enum rist_ctx_mode mode; |
| 580 |
struct rist_sender *sender_ctx; |
| 581 |
struct rist_receiver *receiver_ctx; |
| 582 |
}; |
| 583 |
|
| 584 |
struct rist_peer { |
| 585 |
|
| 586 |
pthread_mutex_t peer_lock; |
| 587 |
struct rist_peer *next; |
| 588 |
struct rist_peer *prev; |
| 589 |
|
| 590 |
|
| 591 |
struct rist_peer *peer_rtcp; |
| 592 |
struct rist_peer *peer_data; |
| 593 |
bool handled_first; |
| 594 |
bool is_rtcp; |
| 595 |
bool is_data; |
| 596 |
|
| 597 |
bool echo_enabled; |
| 598 |
|
| 599 |
|
| 600 |
struct rist_peer *parent; |
| 601 |
struct rist_peer *sibling_prev; |
| 602 |
struct rist_peer *sibling_next; |
| 603 |
struct rist_peer *child; |
| 604 |
uint32_t child_alive_count; |
| 605 |
|
| 606 |
|
| 607 |
struct rist_flow *flow; |
| 608 |
|
| 609 |
|
| 610 |
uint32_t adv_flow_id; |
| 611 |
|
| 612 |
|
| 613 |
uint32_t adv_peer_id; |
| 614 |
uint32_t peer_ssrc; |
| 615 |
|
| 616 |
char receiver_name[RIST_MAX_HOSTNAME]; |
| 617 |
|
| 618 |
|
| 619 |
struct rist_peer_config config; |
| 620 |
uint64_t sender_max_buffer_ticks; |
| 621 |
uint64_t recovery_buffer_ticks; |
| 622 |
|
| 623 |
bool buffer_bloat_active; |
| 624 |
|
| 625 |
bool receiver_mode; |
| 626 |
|
| 627 |
int sd; |
| 628 |
|
| 629 |
|
| 630 |
bool authenticated; |
| 631 |
|
| 632 |
|
| 633 |
uint32_t seq; |
| 634 |
uint64_t eight_times_rtt; |
| 635 |
uint32_t w_count; |
| 636 |
|
| 637 |
|
| 638 |
uint64_t last_rtt; |
| 639 |
|
| 640 |
|
| 641 |
uint32_t missing_counter_max; |
| 642 |
|
| 643 |
|
| 644 |
bool supports_otf_passphrase_change; |
| 645 |
struct rist_key key_tx; |
| 646 |
struct rist_key key_rx; |
| 647 |
bool key_rx_odd_active; |
| 648 |
bool key_tx_odd_active; |
| 649 |
struct rist_key key_tx_odd; |
| 650 |
struct rist_key key_rx_odd; |
| 651 |
bool rolling_over_passphrase; |
| 652 |
struct eapsrp_ctx *eap_ctx; |
| 653 |
int eap_authentication_state; |
| 654 |
uint8_t rist_gre_version; |
| 655 |
|
| 656 |
|
| 657 |
bool is_advanced; |
| 658 |
bool remote_supports_advanced; |
| 659 |
|
| 660 |
|
| 661 |
bool compression; |
| 662 |
|
| 663 |
|
| 664 |
uint16_t local_port; |
| 665 |
uint16_t remote_port; |
| 666 |
union { |
| 667 |
struct sockaddr address; |
| 668 |
struct sockaddr_in inaddr; |
| 669 |
struct sockaddr_in6 inaddr6; |
| 670 |
struct sockaddr_storage storage; |
| 671 |
} u; |
| 672 |
socklen_t address_len; |
| 673 |
uint16_t address_family; |
| 674 |
uint16_t state; |
| 675 |
char miface[128]; |
| 676 |
|
| 677 |
|
| 678 |
struct timeval expire; |
| 679 |
bool send_keepalive; |
| 680 |
struct evsocket_event *event_recv; |
| 681 |
|
| 682 |
|
| 683 |
bool listening; |
| 684 |
|
| 685 |
bool multicast_sender; |
| 686 |
bool multicast_receiver; |
| 687 |
|
| 688 |
|
| 689 |
struct rist_sender *sender_ctx; |
| 690 |
struct rist_receiver *receiver_ctx; |
| 691 |
|
| 692 |
|
| 693 |
bool is_reflector_publisher; |
| 694 |
|
| 695 |
|
| 696 |
uint64_t cooldown_time; |
| 697 |
|
| 698 |
|
| 699 |
struct rist_peer_sender_stats stats_sender_instant; |
| 700 |
struct rist_peer_sender_stats stats_sender_total; |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
struct rist_peer_receiver_stats stats_receiver_instant; |
| 705 |
struct rist_peer_receiver_stats stats_receiver_total; |
| 706 |
|
| 707 |
int dead; |
| 708 |
int timed_out; |
| 709 |
uint64_t dead_since; |
| 710 |
|
| 711 |
uint64_t last_rebind_time; |
| 712 |
uint32_t rebind_attempts; |
| 713 |
uint64_t birthtime_peer; |
| 714 |
uint64_t birthtime_local; |
| 715 |
|
| 716 |
|
| 717 |
struct rist_bandwidth_estimation bw; |
| 718 |
struct rist_bandwidth_estimation retry_bw; |
| 719 |
struct rist_bandwidth_estimation ts_nulls_bw; |
| 720 |
|
| 721 |
|
| 722 |
atomic_bool shutdown; |
| 723 |
|
| 724 |
|
| 725 |
uint32_t rtcp_keepalive_interval; |
| 726 |
uint64_t next_periodic_rtcp; |
| 727 |
uint64_t next_keepalive_packet; |
| 728 |
uint64_t next_flow_attr; |
| 729 |
uint64_t session_timeout; |
| 730 |
uint64_t last_pkt_received; |
| 731 |
uint64_t last_sender_report_time; |
| 732 |
uint64_t last_sender_report_ts; |
| 733 |
uint64_t ts_null_bytes; |
| 734 |
|
| 735 |
char *url; |
| 736 |
char cname[RIST_MAX_HOSTNAME]; |
| 737 |
uint8_t mac_addr[6]; |
| 738 |
bool send_first_connection_event; |
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
uint64_t last_pmtu_error_log; |
| 744 |
|
| 745 |
uint64_t log_repeat_timer; |
| 746 |
|
| 747 |
uint8_t data[SIZEOF_GRE_KEEPALIVE]; |
| 748 |
|
| 749 |
}; |
| 750 |
|
| 751 |
static inline struct rist_common_ctx *rist_struct_get_common(struct rist_ctx *ctx) { |
| 752 |
if (RIST_UNLIKELY(!ctx)) |
| 753 |
return NULL; |
| 754 |
if (ctx->mode == RIST_SENDER_MODE && ctx->sender_ctx) |
| 755 |
return &ctx->sender_ctx->common; |
| 756 |
else if (ctx->mode == RIST_RECEIVER_MODE && ctx->receiver_ctx) |
| 757 |
return &ctx->receiver_ctx->common; |
| 758 |
else |
| 759 |
return NULL; |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
RIST_PRIV void rist_receiver_flow_statistics(struct rist_receiver *ctx, struct rist_flow *flow); |
| 764 |
RIST_PRIV struct cJSON *rist_sender_peer_statistics(struct rist_peer *peer); |
| 765 |
RIST_PRIV void rist_sender_flow_statistics(struct rist_sender *ctx); |
| 766 |
RIST_PRIV void rist_delete_flow(struct rist_receiver *ctx, struct rist_flow *f); |
| 767 |
RIST_PRIV void rist_receiver_missing(struct rist_flow *f, struct rist_peer *peer,uint64_t nack_time, uint32_t seq, uint64_t rtt); |
| 768 |
RIST_PRIV int rist_receiver_associate_flow(struct rist_peer *p, uint32_t flow_id); |
| 769 |
RIST_PRIV size_t rist_best_rtt_index(struct rist_flow *f); |
| 770 |
RIST_PRIV struct rist_buffer *rist_new_buffer(struct rist_common_ctx *ctx, const void *buf, size_t len, uint8_t type, uint32_t seq, uint64_t source_time, uint16_t src_port, uint16_t dst_port); |
| 771 |
RIST_PRIV void free_rist_buffer(struct rist_common_ctx *ctx, struct rist_buffer *b); |
| 772 |
RIST_PRIV void rist_calculate_bitrate(size_t len, struct rist_bandwidth_estimation *bw); |
| 773 |
RIST_PRIV void rist_refresh_flow_bitrate(struct rist_bandwidth_estimation *bw); |
| 774 |
RIST_PRIV void empty_receiver_queue(struct rist_flow *f, struct rist_common_ctx *ctx); |
| 775 |
RIST_PRIV void rist_flush_missing_flow_queue(struct rist_flow *flow); |
| 776 |
|
| 777 |
|
| 778 |
RIST_PRIV void rist_peer_authenticate(struct rist_peer *peer); |
| 779 |
RIST_PRIV void rist_shutdown_peer(struct rist_peer *peer); |
| 780 |
RIST_PRIV void rist_print_inet_info(char *prefix, struct rist_peer *peer); |
| 781 |
RIST_PRIV void rist_peer_rtcp(struct evsocket_ctx *ctx, void *arg); |
| 782 |
RIST_PRIV void rist_populate_cname(struct rist_peer *peer); |
| 783 |
RIST_PRIV void free_data_block(struct rist_data_block **const block); |
| 784 |
|
| 785 |
|
| 786 |
RIST_PRIV PTHREAD_START_FUNC(sender_pthread_protocol, arg); |
| 787 |
RIST_PRIV PTHREAD_START_FUNC(receiver_pthread_protocol, arg); |
| 788 |
RIST_PRIV int rist_max_jitter_set(struct rist_common_ctx *ctx, int t); |
| 789 |
RIST_PRIV int rist_recovery_rtt_multiplier_set_internal(struct rist_common_ctx *ctx, int multiplier); |
| 790 |
RIST_PRIV int parse_url_options(const char *url, struct rist_peer_config *output_peer_config); |
| 791 |
RIST_PRIV int parse_url_udp_options(const char *url, struct rist_udp_config *output_udp_config); |
| 792 |
RIST_PRIV struct rist_peer *rist_receiver_peer_insert_local(struct rist_receiver *ctx, |
| 793 |
const struct rist_peer_config *config); |
| 794 |
RIST_PRIV void rist_sender_destroy_local(struct rist_sender *ctx); |
| 795 |
RIST_PRIV void rist_receiver_destroy_local(struct rist_receiver *ctx); |
| 796 |
RIST_PRIV struct rist_peer *rist_sender_peer_insert_local(struct rist_sender *ctx, |
| 797 |
const struct rist_peer_config *config, bool b_rtcp); |
| 798 |
RIST_PRIV void rist_fsm_init_comm(struct rist_peer *peer); |
| 799 |
RIST_PRIV int rist_oob_enqueue(struct rist_common_ctx *ctx, struct rist_peer *peer, const void *buf, size_t len); |
| 800 |
RIST_PRIV int init_common_ctx(struct rist_common_ctx *ctx, enum rist_profile profile); |
| 801 |
RIST_PRIV void init_advanced_state(struct rist_common_ctx *ctx); |
| 802 |
RIST_PRIV int rist_peer_remove(struct rist_common_ctx *ctx, struct rist_peer *peer, struct rist_peer **next); |
| 803 |
RIST_PRIV int rist_auth_handler(struct rist_common_ctx *ctx, |
| 804 |
int (*conn_cb)(void *arg, const char *connecting_ip, uint16_t connecting_port, const char *local_ip, uint16_t local_port, struct rist_peer *peer), |
| 805 |
int (*disconn_cb)(void *arg, struct rist_peer *peer), |
| 806 |
void *arg); |
| 807 |
RIST_PRIV void sender_peer_append(struct rist_sender *ctx, struct rist_peer *peer); |
| 808 |
|
| 809 |
|
| 810 |
RIST_PRIV struct rist_common_ctx *get_cctx(struct rist_peer *peer); |
| 811 |
|
| 812 |
|
| 813 |
static inline void peer_append(struct rist_peer *p) |
| 814 |
{ |
| 815 |
struct rist_common_ctx *cctx = get_cctx(p); |
| 816 |
struct rist_peer **PEERS = &cctx->PEERS; |
| 817 |
struct rist_peer *plist = *PEERS; |
| 818 |
if (!plist) |
| 819 |
{ |
| 820 |
*PEERS = p; |
| 821 |
return; |
| 822 |
} |
| 823 |
if (p->parent) |
| 824 |
{ |
| 825 |
struct rist_peer *peer = p->parent; |
| 826 |
if (!peer->child) { |
| 827 |
peer->child = p; |
| 828 |
if (peer->sender_ctx) |
| 829 |
peer->sender_ctx->total_weight += p->config.weight; |
| 830 |
} |
| 831 |
else |
| 832 |
{ |
| 833 |
struct rist_peer *child = peer->child; |
| 834 |
while (child) |
| 835 |
{ |
| 836 |
if (!child->sibling_next) |
| 837 |
{ |
| 838 |
child->sibling_next = p; |
| 839 |
p->sibling_prev = child; |
| 840 |
break; |
| 841 |
} |
| 842 |
child = child->sibling_next; |
| 843 |
} |
| 844 |
} |
| 845 |
++peer->child_alive_count; |
| 846 |
} |
| 847 |
while (plist) |
| 848 |
{ |
| 849 |
if (!plist->next) |
| 850 |
{ |
| 851 |
p->prev = plist; |
| 852 |
plist->next = p; |
| 853 |
return; |
| 854 |
} |
| 855 |
plist = plist->next; |
| 856 |
} |
| 857 |
} |
| 858 |
|
| 859 |
#endif |