ppaass_agent/
config.rs

1use std::path::PathBuf;
2
3use clap::{command, Parser};
4use serde::{Deserialize, Serialize};
5
6#[derive(Parser, Clone, Debug, Serialize, Deserialize)]
7#[command(
8    version,
9    about,
10    long_about = "The agent part of the ppaass application"
11)]
12pub struct AgentServerConfig {
13    /// The user token
14    #[arg(short, long, default_value = "user1")]
15    user_token: String,
16    /// Whether you use ip v6
17    #[arg(short = '6', long, default_value = "false")]
18    ipv6: bool,
19    /// Port of the ppaass proxy
20    #[arg(short, long, default_value = "10080")]
21    port: u16,
22    /// The root directory used to store the rsa
23    /// files for each user
24    #[arg(short, long, default_value = "./resources/rsa/")]
25    rsa_dir: PathBuf,
26    /// The threads number
27    #[arg(short, long, default_value = "128")]
28    worker_thread_number: usize,
29    /// Whether enable compressing
30    #[arg(short, long, default_value = "true")]
31    compress: bool,
32    /// The proxy addresses
33    #[arg(long, default_value = "64.176.193.76:80")]
34    proxy_addresses: Vec<String>,
35    /// The client receive buffer size
36    #[arg(long, default_value = "65536")]
37    client_receive_buffer_size: usize,
38    /// The proxy send buffer size
39    #[arg(long, default_value = "65536")]
40    proxy_send_buffer_size: usize,
41    /// The timeout for connect to proxy
42    #[arg(long, default_value = "120")]
43    connect_to_proxy_timeout: u64,
44    /// The max log level
45    #[arg(long, default_value = "ERROR")]
46    max_log_level: String,
47    /// The timeout for proxy connection read
48    #[arg(long, default_value = "120")]
49    proxy_connection_read_timeout: u64,
50    /// The timeout for proxy connection write
51    #[arg(long, default_value = "120")]
52    proxy_connection_write_timeout: u64,
53
54    #[arg(long, default_value = "120")]
55    client_connection_read_timeout: u64,
56    /// The timeout for proxy connection write
57    #[arg(long, default_value = "120")]
58    client_connection_write_timeout: u64,
59
60    /// The timeout for proxy connection write
61    #[arg(long, default_value = "1")]
62    server_signal_tick_interval: u64,
63}
64
65impl AgentServerConfig {
66    pub fn set_user_token(&mut self, user_token: String) {
67        self.user_token = user_token;
68    }
69    pub fn set_ipv6(&mut self, ipv6: bool) {
70        self.ipv6 = ipv6;
71    }
72    pub fn set_port(&mut self, port: u16) {
73        self.port = port;
74    }
75    pub fn set_rsa_dir(&mut self, rsa_dir: PathBuf) {
76        self.rsa_dir = rsa_dir;
77    }
78    pub fn set_worker_thread_number(&mut self, worker_thread_number: usize) {
79        self.worker_thread_number = worker_thread_number;
80    }
81    pub fn set_compress(&mut self, compress: bool) {
82        self.compress = compress;
83    }
84    pub fn set_proxy_addresses(&mut self, proxy_addresses: Vec<String>) {
85        self.proxy_addresses = proxy_addresses;
86    }
87    pub fn set_client_receive_buffer_size(&mut self, client_receive_buffer_size: usize) {
88        self.client_receive_buffer_size = client_receive_buffer_size;
89    }
90    pub fn set_proxy_send_buffer_size(&mut self, proxy_send_buffer_size: usize) {
91        self.proxy_send_buffer_size = proxy_send_buffer_size;
92    }
93    pub fn set_connect_to_proxy_timeout(&mut self, connect_to_proxy_timeout: u64) {
94        self.connect_to_proxy_timeout = connect_to_proxy_timeout;
95    }
96    pub fn set_max_log_level(&mut self, max_log_level: String) {
97        self.max_log_level = max_log_level;
98    }
99    pub fn set_proxy_connection_read_timeout(&mut self, proxy_connection_read_timeout: u64) {
100        self.proxy_connection_read_timeout = proxy_connection_read_timeout;
101    }
102    pub fn set_proxy_connection_write_timeout(&mut self, proxy_connection_write_timeout: u64) {
103        self.proxy_connection_write_timeout = proxy_connection_write_timeout;
104    }
105    pub fn user_token(&self) -> &str {
106        &self.user_token
107    }
108    pub fn ipv6(&self) -> bool {
109        self.ipv6
110    }
111    pub fn port(&self) -> u16 {
112        self.port
113    }
114    pub fn rsa_dir(&self) -> &PathBuf {
115        &self.rsa_dir
116    }
117    pub fn worker_thread_number(&self) -> usize {
118        self.worker_thread_number
119    }
120    pub fn compress(&self) -> bool {
121        self.compress
122    }
123    pub fn proxy_addresses(&self) -> &Vec<String> {
124        &self.proxy_addresses
125    }
126    pub fn client_receive_buffer_size(&self) -> usize {
127        self.client_receive_buffer_size
128    }
129    pub fn proxy_send_buffer_size(&self) -> usize {
130        self.proxy_send_buffer_size
131    }
132    pub fn connect_to_proxy_timeout(&self) -> u64 {
133        self.connect_to_proxy_timeout
134    }
135    pub fn max_log_level(&self) -> &str {
136        &self.max_log_level
137    }
138    pub fn proxy_connection_read_timeout(&self) -> u64 {
139        self.proxy_connection_read_timeout
140    }
141    pub fn proxy_connection_write_timeout(&self) -> u64 {
142        self.proxy_connection_write_timeout
143    }
144
145    pub fn client_connection_read_timeout(&self) -> u64 {
146        self.client_connection_read_timeout
147    }
148    pub fn client_connection_write_timeout(&self) -> u64 {
149        self.client_connection_write_timeout
150    }
151
152    pub fn set_client_connection_read_timeout(&mut self, client_connection_read_timeout: u64) {
153        self.client_connection_read_timeout = client_connection_read_timeout;
154    }
155
156    pub fn set_client_connection_write_timeout(&mut self, client_connection_write_timeout: u64) {
157        self.client_connection_write_timeout = client_connection_write_timeout;
158    }
159
160    pub fn server_signal_tick_interval(&self) -> u64 {
161        self.server_signal_tick_interval
162    }
163
164    pub fn set_server_signal_tick_interval(&mut self, server_signal_tick_interval: u64) {
165        self.server_signal_tick_interval = server_signal_tick_interval
166    }
167}