1use core::time::Duration;
6
7use crate::arq::{ArqBounds, ReceiverBounds, SenderBounds};
8use crate::handshake_sm::HandshakeConfig;
9#[cfg(feature = "tokio")]
10use crate::io::{ChannelCapacities, CloseTimings, IoConfig, ListenerLimits};
11#[cfg(feature = "link")]
12use crate::link::LinkCadence;
13use broadcast_core::Profile;
14#[cfg(feature = "tokio")]
15use core::num::NonZeroUsize;
16
17const RECEIVER_MAX_TRACKED_WINDOW_EMBEDDED: u32 = 1 << 13;
19const RECEIVER_MAX_TRACKED_WINDOW_DEVICE: u32 = 1 << 15;
21const RECEIVER_MAX_TRACKED_WINDOW_SERVER: u32 = 1 << 18;
23const RECEIVER_MAX_TRACKED_WINDOW_HEADEND: u32 = 1 << 18;
25
26const RECEIVER_MAX_PENDING_SKIPS_EMBEDDED: usize = 64;
28const RECEIVER_MAX_PENDING_SKIPS_DEVICE: usize = 256;
30const RECEIVER_MAX_PENDING_SKIPS_SERVER: usize = 1024;
32const RECEIVER_MAX_PENDING_SKIPS_HEADEND: usize = 4096;
34
35const RECEIVER_MAX_OUTSTANDING_ACKS_EMBEDDED: usize = 64;
37const RECEIVER_MAX_OUTSTANDING_ACKS_DEVICE: usize = 256;
39const RECEIVER_MAX_OUTSTANDING_ACKS_SERVER: usize = 1024;
41const RECEIVER_MAX_OUTSTANDING_ACKS_HEADEND: usize = 4096;
43
44const SENDER_MAX_NAK_SEQS_PER_PACKET_EMBEDDED: usize = 1 << 12;
46const SENDER_MAX_NAK_SEQS_PER_PACKET_DEVICE: usize = 1 << 14;
48const SENDER_MAX_NAK_SEQS_PER_PACKET_SERVER: usize = 1 << 16;
50const SENDER_MAX_NAK_SEQS_PER_PACKET_HEADEND: usize = 1 << 16;
52
53const SENDER_MIN_RETRANSMIT_INTERVAL_EMBEDDED: Duration = Duration::from_millis(40);
55const SENDER_MIN_RETRANSMIT_INTERVAL_DEVICE: Duration = Duration::from_millis(30);
57const SENDER_MIN_RETRANSMIT_INTERVAL_SERVER: Duration = Duration::from_millis(20);
59const SENDER_MIN_RETRANSMIT_INTERVAL_HEADEND: Duration = Duration::from_millis(20);
61
62const SENDER_PACING_BURST_PACKETS_EMBEDDED: usize = 4;
64const SENDER_PACING_BURST_PACKETS_DEVICE: usize = 8;
66const SENDER_PACING_BURST_PACKETS_SERVER: usize = 16;
68const SENDER_PACING_BURST_PACKETS_HEADEND: usize = 32;
70
71#[cfg(feature = "tokio")]
72mod listener_values {
73 use super::*;
74 pub(super) const LISTENER_MAX_PENDING_EMBEDDED: usize = 16;
76 pub(super) const LISTENER_MAX_PENDING_DEVICE: usize = 64;
78 pub(super) const LISTENER_MAX_PENDING_SERVER: usize = 1024;
80 pub(super) const LISTENER_MAX_PENDING_HEADEND: usize = 4096;
82
83 pub(super) const LISTENER_PENDING_TICK_EMBEDDED: Duration = Duration::from_millis(250);
85 pub(super) const LISTENER_PENDING_TICK_DEVICE: Duration = Duration::from_millis(200);
87 pub(super) const LISTENER_PENDING_TICK_SERVER: Duration = Duration::from_millis(100);
89 pub(super) const LISTENER_PENDING_TICK_HEADEND: Duration = Duration::from_millis(100);
91
92 pub(super) const LISTENER_COOKIE_KEY_ROTATION_EMBEDDED: Duration = Duration::from_secs(120);
94 pub(super) const LISTENER_COOKIE_KEY_ROTATION_DEVICE: Duration = Duration::from_secs(90);
96 pub(super) const LISTENER_COOKIE_KEY_ROTATION_SERVER: Duration = Duration::from_secs(60);
98 pub(super) const LISTENER_COOKIE_KEY_ROTATION_HEADEND: Duration = Duration::from_secs(60);
100
101 pub(super) const LISTENER_RECENT_ACCEPT_TTL_EMBEDDED: Duration = Duration::from_secs(20);
103 pub(super) const LISTENER_RECENT_ACCEPT_TTL_DEVICE: Duration = Duration::from_secs(15);
105 pub(super) const LISTENER_RECENT_ACCEPT_TTL_SERVER: Duration = Duration::from_secs(10);
107 pub(super) const LISTENER_RECENT_ACCEPT_TTL_HEADEND: Duration = Duration::from_secs(10);
109}
110#[cfg(feature = "tokio")]
111use listener_values::*;
112
113const HANDSHAKE_LATENCY_EMBEDDED: Duration = Duration::from_millis(80);
115const HANDSHAKE_LATENCY_DEVICE: Duration = Duration::from_millis(120);
117const HANDSHAKE_LATENCY_SERVER: Duration = Duration::from_millis(120);
119const HANDSHAKE_LATENCY_HEADEND: Duration = Duration::from_millis(120);
121
122const HANDSHAKE_MTU_EMBEDDED: u32 = 1500;
124const HANDSHAKE_MTU_DEVICE: u32 = 1500;
126const HANDSHAKE_MTU_SERVER: u32 = 1500;
128const HANDSHAKE_MTU_HEADEND: u32 = 1500;
130
131const HANDSHAKE_FLOW_WINDOW_EMBEDDED: u32 = 1024;
133const HANDSHAKE_FLOW_WINDOW_DEVICE: u32 = 4096;
135const HANDSHAKE_FLOW_WINDOW_SERVER: u32 = 8192;
137const HANDSHAKE_FLOW_WINDOW_HEADEND: u32 = 8192;
139
140const HANDSHAKE_RETRANSMIT_AFTER_EMBEDDED: Duration = Duration::from_micros(250_000);
142const HANDSHAKE_RETRANSMIT_AFTER_DEVICE: Duration = Duration::from_micros(125_000);
144const HANDSHAKE_RETRANSMIT_AFTER_SERVER: Duration = Duration::from_micros(83_333);
146const HANDSHAKE_RETRANSMIT_AFTER_HEADEND: Duration = Duration::from_micros(83_333);
148
149const HANDSHAKE_MAX_RETRIES_EMBEDDED: u32 = 6;
151const HANDSHAKE_MAX_RETRIES_DEVICE: u32 = 8;
153const HANDSHAKE_MAX_RETRIES_SERVER: u32 = 12;
155const HANDSHAKE_MAX_RETRIES_HEADEND: u32 = 12;
157
158#[cfg(feature = "link")]
159const CADENCE_HANDSHAKE_RETRANSMIT: Duration = Duration::from_millis(250);
161#[cfg(feature = "link")]
162const CADENCE_KEEPALIVE: Duration = Duration::from_secs(1);
164#[cfg(feature = "link")]
165const CADENCE_KM_RESEND: Duration = Duration::from_millis(500);
167#[cfg(feature = "link")]
168const CADENCE_KMREQ_MIN_INTERVAL: Duration = Duration::from_millis(100);
170
171#[cfg(feature = "tokio")]
172mod io_values {
173 use super::*;
174 pub(super) const IO_MAX_DATAGRAM: usize = 1500;
176 pub(super) const IO_CONNECT_TIMEOUT_EMBEDDED: Duration = Duration::from_secs(5);
178 pub(super) const IO_CONNECT_TIMEOUT_DEVICE: Duration = Duration::from_secs(8);
180 pub(super) const IO_CONNECT_TIMEOUT_SERVER: Duration = Duration::from_secs(10);
182 pub(super) const IO_CONNECT_TIMEOUT_HEADEND: Duration = Duration::from_secs(10);
184 pub(super) const IO_HANDSHAKE_TIMEOUT_EMBEDDED: Duration = Duration::from_secs(3);
186 pub(super) const IO_HANDSHAKE_TIMEOUT_DEVICE: Duration = Duration::from_secs(3);
188 pub(super) const IO_HANDSHAKE_TIMEOUT_SERVER: Duration = Duration::from_secs(5);
190 pub(super) const IO_HANDSHAKE_TIMEOUT_HEADEND: Duration = Duration::from_secs(5);
192 pub(super) const IO_READ_IDLE_TIMEOUT_EMBEDDED: Duration = Duration::from_secs(5);
194 pub(super) const IO_READ_IDLE_TIMEOUT_DEVICE: Duration = Duration::from_secs(5);
196 pub(super) const IO_READ_IDLE_TIMEOUT_SERVER: Duration = Duration::from_secs(5);
198 pub(super) const IO_READ_IDLE_TIMEOUT_HEADEND: Duration = Duration::from_secs(10);
200 pub(super) const IO_WRITE_TIMEOUT_EMBEDDED: Duration = Duration::from_secs(5);
202 pub(super) const IO_WRITE_TIMEOUT_DEVICE: Duration = Duration::from_secs(5);
204 pub(super) const IO_WRITE_TIMEOUT_SERVER: Duration = Duration::from_secs(5);
206 pub(super) const IO_WRITE_TIMEOUT_HEADEND: Duration = Duration::from_secs(10);
208 pub(super) const IO_DRIFT_SAMPLE_COUNT_EMBEDDED: u32 = 256;
210 pub(super) const IO_DRIFT_SAMPLE_COUNT_DEVICE: u32 = 512;
212 pub(super) const IO_DRIFT_SAMPLE_COUNT_SERVER: u32 = 1000;
214 pub(super) const IO_DRIFT_SAMPLE_COUNT_HEADEND: u32 = 2000;
216 pub(super) const IO_MAX_BW: crate::livecc::MaxBwConfig =
218 crate::livecc::MaxBwConfig::Set(125_000_000);
219 pub(super) const CHANNEL_RX_EMBEDDED: NonZeroUsize = non_zero(512);
221 pub(super) const CHANNEL_RX_DEVICE: NonZeroUsize = non_zero(1024);
223 pub(super) const CHANNEL_RX_SERVER: NonZeroUsize = non_zero(4096);
225 pub(super) const CHANNEL_RX_HEADEND: NonZeroUsize = non_zero(16_384);
227 pub(super) const CHANNEL_UNROUTED_EMBEDDED: NonZeroUsize = non_zero(128);
229 pub(super) const CHANNEL_UNROUTED_DEVICE: NonZeroUsize = non_zero(256);
231 pub(super) const CHANNEL_UNROUTED_SERVER: NonZeroUsize = non_zero(1024);
233 pub(super) const CHANNEL_UNROUTED_HEADEND: NonZeroUsize = non_zero(4096);
235 pub(super) const CHANNEL_SEND_EMBEDDED: NonZeroUsize = non_zero(128);
237 pub(super) const CHANNEL_SEND_DEVICE: NonZeroUsize = non_zero(256);
239 pub(super) const CHANNEL_SEND_SERVER: NonZeroUsize = non_zero(1024);
241 pub(super) const CHANNEL_SEND_HEADEND: NonZeroUsize = non_zero(4096);
243 pub(super) const CHANNEL_DELIVER_EMBEDDED: NonZeroUsize = non_zero(512);
245 pub(super) const CHANNEL_DELIVER_DEVICE: NonZeroUsize = non_zero(1024);
247 pub(super) const CHANNEL_DELIVER_SERVER: NonZeroUsize = non_zero(4096);
249 pub(super) const CHANNEL_DELIVER_HEADEND: NonZeroUsize = non_zero(16_384);
251 pub(super) const CHANNEL_ACCEPT_EMBEDDED: NonZeroUsize = non_zero(8);
253 pub(super) const CHANNEL_ACCEPT_DEVICE: NonZeroUsize = non_zero(16);
255 pub(super) const CHANNEL_ACCEPT_SERVER: NonZeroUsize = non_zero(64);
257 pub(super) const CHANNEL_ACCEPT_HEADEND: NonZeroUsize = non_zero(256);
259
260 const fn non_zero(n: usize) -> NonZeroUsize {
263 match NonZeroUsize::new(n) {
264 Some(n) => n,
265 None => NonZeroUsize::MIN,
266 }
267 }
268}
269#[cfg(feature = "tokio")]
270use io_values::*;
271
272impl ReceiverBounds {
273 #[must_use]
275 pub fn for_profile(profile: Profile) -> Self {
276 Self {
277 max_tracked_window: profile.select(
278 RECEIVER_MAX_TRACKED_WINDOW_EMBEDDED,
279 RECEIVER_MAX_TRACKED_WINDOW_DEVICE,
280 RECEIVER_MAX_TRACKED_WINDOW_SERVER,
281 RECEIVER_MAX_TRACKED_WINDOW_HEADEND,
282 ),
283 max_pending_skips: profile.select(
284 RECEIVER_MAX_PENDING_SKIPS_EMBEDDED,
285 RECEIVER_MAX_PENDING_SKIPS_DEVICE,
286 RECEIVER_MAX_PENDING_SKIPS_SERVER,
287 RECEIVER_MAX_PENDING_SKIPS_HEADEND,
288 ),
289 max_outstanding_acks: profile.select(
290 RECEIVER_MAX_OUTSTANDING_ACKS_EMBEDDED,
291 RECEIVER_MAX_OUTSTANDING_ACKS_DEVICE,
292 RECEIVER_MAX_OUTSTANDING_ACKS_SERVER,
293 RECEIVER_MAX_OUTSTANDING_ACKS_HEADEND,
294 ),
295 }
296 }
297
298 #[must_use]
300 pub fn with_max_tracked_window(mut self, value: u32) -> Self {
301 self.max_tracked_window = value;
302 self
303 }
304
305 #[must_use]
307 pub fn with_max_pending_skips(mut self, value: usize) -> Self {
308 self.max_pending_skips = value;
309 self
310 }
311
312 #[must_use]
314 pub fn with_max_outstanding_acks(mut self, value: usize) -> Self {
315 self.max_outstanding_acks = value;
316 self
317 }
318}
319
320impl SenderBounds {
321 #[must_use]
323 pub fn for_profile(profile: Profile) -> Self {
324 Self {
325 max_nak_seqs_per_packet: profile.select(
326 SENDER_MAX_NAK_SEQS_PER_PACKET_EMBEDDED,
327 SENDER_MAX_NAK_SEQS_PER_PACKET_DEVICE,
328 SENDER_MAX_NAK_SEQS_PER_PACKET_SERVER,
329 SENDER_MAX_NAK_SEQS_PER_PACKET_HEADEND,
330 ),
331 min_retransmit_interval: profile.select(
332 SENDER_MIN_RETRANSMIT_INTERVAL_EMBEDDED,
333 SENDER_MIN_RETRANSMIT_INTERVAL_DEVICE,
334 SENDER_MIN_RETRANSMIT_INTERVAL_SERVER,
335 SENDER_MIN_RETRANSMIT_INTERVAL_HEADEND,
336 ),
337 pacing_burst_packets: profile.select(
338 SENDER_PACING_BURST_PACKETS_EMBEDDED,
339 SENDER_PACING_BURST_PACKETS_DEVICE,
340 SENDER_PACING_BURST_PACKETS_SERVER,
341 SENDER_PACING_BURST_PACKETS_HEADEND,
342 ),
343 }
344 }
345
346 #[must_use]
348 pub fn with_max_nak_seqs_per_packet(mut self, value: usize) -> Self {
349 self.max_nak_seqs_per_packet = value;
350 self
351 }
352
353 #[must_use]
355 pub fn with_min_retransmit_interval(mut self, value: Duration) -> Self {
356 self.min_retransmit_interval = value;
357 self
358 }
359
360 #[must_use]
362 pub fn with_pacing_burst_packets(mut self, value: usize) -> Self {
363 self.pacing_burst_packets = value;
364 self
365 }
366}
367
368impl ArqBounds {
369 #[must_use]
371 pub fn for_profile(profile: Profile) -> Self {
372 Self {
373 receiver: ReceiverBounds::for_profile(profile),
374 sender: SenderBounds::for_profile(profile),
375 }
376 }
377
378 #[must_use]
380 pub fn with_receiver(mut self, value: crate::arq::ReceiverBounds) -> Self {
381 self.receiver = value;
382 self
383 }
384
385 #[must_use]
387 pub fn with_sender(mut self, value: crate::arq::SenderBounds) -> Self {
388 self.sender = value;
389 self
390 }
391}
392
393#[cfg(feature = "tokio")]
394impl ListenerLimits {
395 #[must_use]
397 pub fn for_profile(profile: Profile) -> Self {
398 Self {
399 max_pending: profile.select(
400 LISTENER_MAX_PENDING_EMBEDDED,
401 LISTENER_MAX_PENDING_DEVICE,
402 LISTENER_MAX_PENDING_SERVER,
403 LISTENER_MAX_PENDING_HEADEND,
404 ),
405 pending_tick: profile.select(
406 LISTENER_PENDING_TICK_EMBEDDED,
407 LISTENER_PENDING_TICK_DEVICE,
408 LISTENER_PENDING_TICK_SERVER,
409 LISTENER_PENDING_TICK_HEADEND,
410 ),
411 cookie_key_rotation: profile.select(
412 LISTENER_COOKIE_KEY_ROTATION_EMBEDDED,
413 LISTENER_COOKIE_KEY_ROTATION_DEVICE,
414 LISTENER_COOKIE_KEY_ROTATION_SERVER,
415 LISTENER_COOKIE_KEY_ROTATION_HEADEND,
416 ),
417 recent_accept_ttl: profile.select(
418 LISTENER_RECENT_ACCEPT_TTL_EMBEDDED,
419 LISTENER_RECENT_ACCEPT_TTL_DEVICE,
420 LISTENER_RECENT_ACCEPT_TTL_SERVER,
421 LISTENER_RECENT_ACCEPT_TTL_HEADEND,
422 ),
423 }
424 }
425
426 #[must_use]
428 pub fn with_max_pending(mut self, value: usize) -> Self {
429 self.max_pending = value;
430 self
431 }
432
433 #[must_use]
435 pub fn with_pending_tick(mut self, value: Duration) -> Self {
436 self.pending_tick = value;
437 self
438 }
439
440 #[must_use]
442 pub fn with_cookie_key_rotation(mut self, value: Duration) -> Self {
443 self.cookie_key_rotation = value;
444 self
445 }
446
447 #[must_use]
449 pub fn with_recent_accept_ttl(mut self, value: Duration) -> Self {
450 self.recent_accept_ttl = value;
451 self
452 }
453}
454
455impl HandshakeConfig {
456 #[must_use]
459 pub fn for_profile(profile: Profile) -> Self {
460 Self::new(
461 profile.select(
462 HANDSHAKE_LATENCY_EMBEDDED,
463 HANDSHAKE_LATENCY_DEVICE,
464 HANDSHAKE_LATENCY_SERVER,
465 HANDSHAKE_LATENCY_HEADEND,
466 ),
467 profile.select(
468 HANDSHAKE_MTU_EMBEDDED,
469 HANDSHAKE_MTU_DEVICE,
470 HANDSHAKE_MTU_SERVER,
471 HANDSHAKE_MTU_HEADEND,
472 ),
473 profile.select(
474 HANDSHAKE_FLOW_WINDOW_EMBEDDED,
475 HANDSHAKE_FLOW_WINDOW_DEVICE,
476 HANDSHAKE_FLOW_WINDOW_SERVER,
477 HANDSHAKE_FLOW_WINDOW_HEADEND,
478 ),
479 profile.select(
480 HANDSHAKE_RETRANSMIT_AFTER_EMBEDDED,
481 HANDSHAKE_RETRANSMIT_AFTER_DEVICE,
482 HANDSHAKE_RETRANSMIT_AFTER_SERVER,
483 HANDSHAKE_RETRANSMIT_AFTER_HEADEND,
484 ),
485 profile.select(
486 HANDSHAKE_MAX_RETRIES_EMBEDDED,
487 HANDSHAKE_MAX_RETRIES_DEVICE,
488 HANDSHAKE_MAX_RETRIES_SERVER,
489 HANDSHAKE_MAX_RETRIES_HEADEND,
490 ),
491 )
492 }
493}
494
495#[cfg(feature = "link")]
496impl LinkCadence {
497 #[must_use]
500 pub fn for_profile(_profile: Profile) -> Self {
501 Self {
502 handshake_retransmit: CADENCE_HANDSHAKE_RETRANSMIT,
503 keepalive: CADENCE_KEEPALIVE,
504 km_resend: CADENCE_KM_RESEND,
505 kmreq_min_interval: CADENCE_KMREQ_MIN_INTERVAL,
506 }
507 }
508
509 #[must_use]
511 pub fn with_handshake_retransmit(mut self, handshake_retransmit: Duration) -> Self {
512 self.handshake_retransmit = handshake_retransmit;
513 self
514 }
515
516 #[must_use]
518 pub fn with_keepalive(mut self, keepalive: Duration) -> Self {
519 self.keepalive = keepalive;
520 self
521 }
522
523 #[must_use]
525 pub fn with_km_resend(mut self, km_resend: Duration) -> Self {
526 self.km_resend = km_resend;
527 self
528 }
529
530 #[must_use]
532 pub fn with_kmreq_min_interval(mut self, kmreq_min_interval: Duration) -> Self {
533 self.kmreq_min_interval = kmreq_min_interval;
534 self
535 }
536}
537
538#[cfg(feature = "tokio")]
539impl ChannelCapacities {
540 #[must_use]
542 pub fn for_profile(profile: Profile) -> Self {
543 Self {
544 rx: profile.select(
545 CHANNEL_RX_EMBEDDED,
546 CHANNEL_RX_DEVICE,
547 CHANNEL_RX_SERVER,
548 CHANNEL_RX_HEADEND,
549 ),
550 unrouted: profile.select(
551 CHANNEL_UNROUTED_EMBEDDED,
552 CHANNEL_UNROUTED_DEVICE,
553 CHANNEL_UNROUTED_SERVER,
554 CHANNEL_UNROUTED_HEADEND,
555 ),
556 send: profile.select(
557 CHANNEL_SEND_EMBEDDED,
558 CHANNEL_SEND_DEVICE,
559 CHANNEL_SEND_SERVER,
560 CHANNEL_SEND_HEADEND,
561 ),
562 deliver: profile.select(
563 CHANNEL_DELIVER_EMBEDDED,
564 CHANNEL_DELIVER_DEVICE,
565 CHANNEL_DELIVER_SERVER,
566 CHANNEL_DELIVER_HEADEND,
567 ),
568 accept: profile.select(
569 CHANNEL_ACCEPT_EMBEDDED,
570 CHANNEL_ACCEPT_DEVICE,
571 CHANNEL_ACCEPT_SERVER,
572 CHANNEL_ACCEPT_HEADEND,
573 ),
574 }
575 }
576
577 #[must_use]
579 pub fn with_rx(mut self, rx: NonZeroUsize) -> Self {
580 self.rx = rx;
581 self
582 }
583
584 #[must_use]
586 pub fn with_unrouted(mut self, unrouted: NonZeroUsize) -> Self {
587 self.unrouted = unrouted;
588 self
589 }
590
591 #[must_use]
593 pub fn with_send(mut self, send: NonZeroUsize) -> Self {
594 self.send = send;
595 self
596 }
597
598 #[must_use]
600 pub fn with_deliver(mut self, deliver: NonZeroUsize) -> Self {
601 self.deliver = deliver;
602 self
603 }
604
605 #[must_use]
607 pub fn with_accept(mut self, accept: NonZeroUsize) -> Self {
608 self.accept = accept;
609 self
610 }
611}
612
613#[cfg(feature = "tokio")]
614impl IoConfig {
615 #[must_use]
620 pub fn for_profile(profile: Profile) -> Self {
621 Self {
622 max_datagram: IO_MAX_DATAGRAM,
623 timeouts: broadcast_net::timeouts::Timeouts::new(
624 profile.select(
625 IO_CONNECT_TIMEOUT_EMBEDDED,
626 IO_CONNECT_TIMEOUT_DEVICE,
627 IO_CONNECT_TIMEOUT_SERVER,
628 IO_CONNECT_TIMEOUT_HEADEND,
629 ),
630 profile.select(
631 IO_HANDSHAKE_TIMEOUT_EMBEDDED,
632 IO_HANDSHAKE_TIMEOUT_DEVICE,
633 IO_HANDSHAKE_TIMEOUT_SERVER,
634 IO_HANDSHAKE_TIMEOUT_HEADEND,
635 ),
636 profile.select(
637 IO_READ_IDLE_TIMEOUT_EMBEDDED,
638 IO_READ_IDLE_TIMEOUT_DEVICE,
639 IO_READ_IDLE_TIMEOUT_SERVER,
640 IO_READ_IDLE_TIMEOUT_HEADEND,
641 ),
642 profile.select(
643 IO_WRITE_TIMEOUT_EMBEDDED,
644 IO_WRITE_TIMEOUT_DEVICE,
645 IO_WRITE_TIMEOUT_SERVER,
646 IO_WRITE_TIMEOUT_HEADEND,
647 ),
648 ),
649 km_refresh_thresholds: crate::km_refresh::KmRefreshThresholds::RECOMMENDED,
650 cadence: LinkCadence::for_profile(profile),
651 listener: ListenerLimits::for_profile(profile),
652 arq: ArqBounds::for_profile(profile),
653 drift_sample_count: profile.select(
654 IO_DRIFT_SAMPLE_COUNT_EMBEDDED,
655 IO_DRIFT_SAMPLE_COUNT_DEVICE,
656 IO_DRIFT_SAMPLE_COUNT_SERVER,
657 IO_DRIFT_SAMPLE_COUNT_HEADEND,
658 ),
659 channels: ChannelCapacities::for_profile(profile),
660 max_bw: IO_MAX_BW,
661 close: CloseTimings::for_profile(profile),
662 }
663 }
664}
665
666#[cfg(test)]
667mod tests {
668 use super::*;
669
670 #[test]
671 fn server_and_headend_literals_are_pinned() {
672 let arq = crate::arq::ArqBounds::for_profile(Profile::Server);
673 assert_eq!(arq.receiver.max_tracked_window, 1 << 18);
674 assert_eq!(arq.receiver.max_pending_skips, 1024);
675 assert_eq!(arq.receiver.max_outstanding_acks, 1024);
676 assert_eq!(arq.sender.max_nak_seqs_per_packet, 1 << 16);
677 assert_eq!(
678 arq.sender.min_retransmit_interval,
679 Duration::from_millis(20)
680 );
681 assert_eq!(arq.sender.pacing_burst_packets, 16);
682 let headend = crate::arq::ArqBounds::for_profile(Profile::Headend);
683 assert_eq!(headend.receiver.max_pending_skips, 4096);
684 assert_eq!(headend.sender.pacing_burst_packets, 32);
685 #[cfg(feature = "tokio")]
686 let listener = crate::io::ListenerLimits::for_profile(Profile::Server);
687 #[cfg(feature = "tokio")]
688 {
689 assert_eq!(listener.max_pending, 1024);
690 assert_eq!(listener.pending_tick, Duration::from_millis(100));
691 assert_eq!(listener.cookie_key_rotation, Duration::from_secs(60));
692 assert_eq!(listener.recent_accept_ttl, Duration::from_secs(10));
693 assert_eq!(
694 crate::io::ListenerLimits::for_profile(Profile::Headend).max_pending,
695 4096
696 );
697 }
698 let handshake = crate::handshake_sm::HandshakeConfig::for_profile(Profile::Server);
699 assert_eq!(handshake.latency, Duration::from_millis(120));
700 assert_eq!(handshake.mtu, 1500);
701 assert_eq!(handshake.max_flow_window_size, 8192);
702 assert_eq!(handshake.retransmit_after, Duration::from_micros(83_333));
703 assert_eq!(handshake.max_retries, 12);
704 assert_eq!(
705 crate::handshake_sm::HandshakeConfig::for_profile(Profile::Headend).mtu,
706 1500
707 );
708 }
709
710 #[cfg(feature = "tokio")]
711 #[test]
712 fn every_io_preset_validates_and_server_is_the_origin_value() {
713 for profile in Profile::ALL {
714 IoConfig::for_profile(profile)
715 .validate()
716 .unwrap_or_else(|e| panic!("{profile:?}: {e}"));
717 }
718 let server = IoConfig::for_profile(Profile::Server);
719 assert_eq!(server.max_datagram, 1500);
720 assert_eq!(server.drift_sample_count, 1000);
721 assert_eq!(server.timeouts.connect, Duration::from_secs(10));
722 assert_eq!(server.timeouts.write, Duration::from_secs(5));
723 assert_eq!(server.channels.rx.get(), 4096);
724 assert_eq!(server.channels.accept.get(), 64);
725 assert_eq!(server.max_bw, crate::livecc::MaxBwConfig::Set(125_000_000));
726 assert_eq!(server.cadence.keepalive, Duration::from_secs(1));
727 let rx = Profile::ALL.map(|p| ChannelCapacities::for_profile(p).rx);
728 assert!(rx.windows(2).all(|w| w[0] <= w[1]));
729 }
730
731 #[test]
732 fn capacities_grow_with_the_profile() {
733 let windows = Profile::ALL.map(|p| ReceiverBounds::for_profile(p).max_tracked_window);
734 assert!(windows.windows(2).all(|w| w[0] <= w[1]));
735 let skips = Profile::ALL.map(|p| ReceiverBounds::for_profile(p).max_pending_skips);
736 assert!(skips.windows(2).all(|w| w[0] <= w[1]));
737 #[cfg(feature = "tokio")]
738 {
739 let pending =
740 Profile::ALL.map(|p| crate::io::ListenerLimits::for_profile(p).max_pending);
741 assert!(pending.windows(2).all(|w| w[0] <= w[1]));
742 }
743 }
744}