ppaass_v3_agent_core/
config.rs

1use ppaass_common::config::{
2    ConnectionPoolConfig, RetrieveConnectionConfig, RetrieveConnectionPoolConfig,
3    RetrieveServerConfig,
4};
5use serde::{Deserialize, Serialize};
6use std::path::PathBuf;
7#[derive(Serialize, Deserialize, Debug)]
8pub struct AgentConfig {
9    pub ip_v6: bool,
10    pub server_port: u16,
11    pub worker_thread_number: usize,
12    pub username: String,
13    pub log_dir: PathBuf,
14    pub log_name_prefix: String,
15    pub max_log_level: String,
16    pub user_dir: PathBuf,
17    pub agent_to_proxy_data_relay_buffer_size: usize,
18    pub proxy_to_agent_data_relay_buffer_size: usize,
19    pub proxy_frame_buffer_size: usize,
20    pub proxy_connect_timeout: u64,
21    pub user_info_repository_refresh_interval: u64,
22    pub connection_pool: Option<ConnectionPoolConfig>,
23}
24
25impl RetrieveConnectionConfig for AgentConfig {
26    fn frame_size(&self) -> usize {
27        self.proxy_frame_buffer_size
28    }
29    fn connect_timeout(&self) -> u64 {
30        self.proxy_connect_timeout
31    }
32}
33
34impl RetrieveConnectionPoolConfig for AgentConfig {
35    fn max_pool_size(&self) -> usize {
36        match self.connection_pool {
37            Some(ref pool) => pool.max_pool_size(),
38            None => 0,
39        }
40    }
41    fn fill_interval(&self) -> u64 {
42        match self.connection_pool {
43            Some(ref pool) => pool.fill_interval(),
44            None => 0,
45        }
46    }
47    fn check_interval(&self) -> u64 {
48        match self.connection_pool {
49            Some(ref pool) => pool.check_interval(),
50            None => 0,
51        }
52    }
53    fn connection_max_alive(&self) -> i64 {
54        match self.connection_pool {
55            Some(ref pool) => pool.connection_max_alive(),
56            None => 0,
57        }
58    }
59    fn heartbeat_timeout(&self) -> u64 {
60        match self.connection_pool {
61            Some(ref pool) => pool.heartbeat_timeout(),
62            None => 0,
63        }
64    }
65    fn retake_interval(&self) -> u64 {
66        match self.connection_pool {
67            Some(ref pool) => pool.retake_interval(),
68            None => 2,
69        }
70    }
71}
72
73impl RetrieveServerConfig for AgentConfig {
74    fn worker_thread_number(&self) -> usize {
75        self.worker_thread_number
76    }
77    fn server_port(&self) -> u16 {
78        self.server_port
79    }
80    fn ip_v6(&self) -> bool {
81        self.ip_v6
82    }
83}