cloudpub_common/
constants.rs

1use backoff::ExponentialBackoff;
2use std::time::Duration;
3
4/// Application-layer heartbeat interval in secs
5pub const DEFAULT_HEARTBEAT_INTERVAL_SECS: u64 = 30;
6pub const DEFAULT_HEARTBEAT_TIMEOUT_SECS: u64 = 40;
7
8pub const DATA_BUFFER_SIZE: usize = 16384; // 16 KiB, a reasonable size for data buffers
9pub const DATA_CHANNEL_SIZE: usize = 1024; // Packets in data channel
10pub const CONTROL_CHANNEL_SIZE: usize = 1024; // Packets in control channel
11
12/// Client
13pub const DEFAULT_CLIENT_RETRY_INTERVAL_SECS: u64 = 60;
14pub const DEFAULT_CLIENT_DATA_CHANNEL_CAPACITY: u32 = DATA_BUFFER_SIZE as u32 * 4;
15
16/// Server
17pub const BACKLOG_SIZE: usize = 1024; // The capacity TCP incoming conn backlog
18pub const HANDSHAKE_TIMEOUT: u64 = 5; // Timeout for transport handshake
19
20/// TCP
21pub const DEFAULT_NODELAY: bool = true;
22pub const DEFAULT_KEEPALIVE_SECS: u64 = 20;
23pub const DEFAULT_KEEPALIVE_INTERVAL: u64 = 8;
24pub const MESSAGE_TIMEOUT_SECS: u64 = 60;
25
26// FIXME: Determine reasonable size
27/// UDP MTU. Currently far larger than necessary
28pub const UDP_BUFFER_SIZE: usize = 2048;
29pub const UDP_SENDQ_SIZE: usize = 1024;
30pub const UDP_TIMEOUT: u64 = 60;
31
32// Pingora service param
33pub const LISTENERS_PER_FD: usize = 1;
34
35pub fn listen_backoff() -> ExponentialBackoff {
36    ExponentialBackoff {
37        max_elapsed_time: None,
38        max_interval: Duration::from_secs(1),
39        ..Default::default()
40    }
41}
42
43pub fn run_control_chan_backoff(interval: u64) -> ExponentialBackoff {
44    ExponentialBackoff {
45        randomization_factor: 0.2,
46        max_elapsed_time: None,
47        multiplier: 3.0,
48        max_interval: Duration::from_secs(interval),
49        ..Default::default()
50    }
51}