lawn_protocol/config/
mod.rs1pub use lawn_constants::logger::{LogFormat, LogLevel, Logger};
2use std::sync::Arc;
3use std::time::Duration;
4
5pub struct Config {
6 server: bool,
7 logger: Arc<dyn Logger + Send + Sync>,
8 max_messages_in_flight: u32,
9 closing_delay: Duration,
10}
11
12impl Config {
13 const ID_MASK: u32 = 0x7fffffff;
14
15 pub fn new(server: bool, logger: Arc<dyn Logger + Send + Sync>) -> Self {
16 Self {
17 server,
18 logger,
19 max_messages_in_flight: 1024,
20 closing_delay: Duration::from_millis(1000),
21 }
22 }
23
24 pub(crate) fn first_id(&self) -> u32 {
26 if self.server {
27 0x80000000
28 } else {
29 0
30 }
31 }
32
33 pub(crate) fn next_id(&self, id: u32) -> u32 {
35 let top_bit = if self.server { 0x80000000 } else { 0 };
36 ((id.wrapping_add(1)) & Self::ID_MASK) | top_bit
37 }
38
39 pub fn is_server(&self) -> bool {
40 self.server
41 }
42
43 pub fn max_messages_in_flight(&self) -> u32 {
44 self.max_messages_in_flight
45 }
46
47 pub fn closing_delay(&self) -> Duration {
48 self.closing_delay
49 }
50
51 pub fn logger(&self) -> Arc<dyn Logger + Send + Sync> {
52 self.logger.clone()
53 }
54}