libp2p_pubsub_core/config.rs
1use std::time::Duration;
2
3#[derive(Debug, Clone)]
4pub struct Config {
5 /// The maximum size of a RPC frame.
6 max_frame_size: usize,
7
8 /// The idle timeout of a connection.
9 connection_idle_timeout: Duration,
10
11 /// Time between each heartbeat.
12 heartbeat_interval: Duration,
13
14 /// Message cache capacity.
15 message_cache_capacity: usize,
16
17 /// Message cache entries Time-To-Live.
18 message_cache_ttl: Duration,
19}
20
21impl Default for Config {
22 fn default() -> Self {
23 Self {
24 max_frame_size: 65537,
25 connection_idle_timeout: Duration::from_secs(120),
26 heartbeat_interval: Duration::from_secs(1),
27 message_cache_capacity: 1024,
28 message_cache_ttl: Duration::from_secs(5),
29 }
30 }
31}
32
33impl Config {
34 /// The maximum byte size for each pubsub frame (default is 65536 bytes).
35 ///
36 /// This represents the maximum size of the entire protobuf payload. It must be at least
37 /// large enough to support basic control messages.
38 ///
39 /// Default is 65536 bytes.
40 pub fn max_frame_size(&self) -> usize {
41 self.max_frame_size
42 }
43
44 /// The time a connection is maintained to a peer without being in the mesh and without
45 /// send/receiving a message from. Connections that idle beyond this timeout are disconnected.
46 ///
47 /// Default is 120 seconds.
48 pub fn connection_idle_timeout(&self) -> Duration {
49 self.connection_idle_timeout
50 }
51
52 /// The time between each heartbeat.
53 ///
54 /// Default is 1 second.
55 pub fn heartbeat_interval(&self) -> Duration {
56 self.heartbeat_interval
57 }
58
59 /// The maximum number of messages to cache.
60 ///
61 /// Default is 1024.
62 pub fn message_cache_capacity(&self) -> usize {
63 self.message_cache_capacity
64 }
65
66 /// The time a message is kept in the cache.
67 ///
68 /// Default is 5 seconds.
69 pub fn message_cache_ttl(&self) -> Duration {
70 self.message_cache_ttl
71 }
72}