-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.rs
198 lines (173 loc) · 4.71 KB
/
config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
use std::net::SocketAddr;
use plug2proxy::{
config::MatchServerUrlOrConfig,
route::{
config::{InFallbackRuleConfig, InRuleConfig, OutOutputConfig, OutRuleConfig},
rule::{BuiltInLabel, Label},
},
utils::OneOrMany,
};
use crate::constants::{
fake_ip_dns_address_default, geolite2_url_default, transparent_proxy_address_default,
transparent_proxy_traffic_mark_default, tunneling_http2_connections_default,
};
#[derive(serde::Deserialize)]
pub struct InConfig {
#[serde(default)]
pub dns_resolver: InDnsResolverConfig,
#[serde(default)]
pub fake_ip_dns: InFakeIpDnsConfig,
#[serde(default)]
pub transparent_proxy: InTransparentProxyConfig,
pub tunneling: InTunnelingConfig,
#[serde(default)]
pub routing: InRoutingConfig,
}
#[derive(serde::Deserialize)]
pub struct InDnsResolverConfig {
pub server: Option<OneOrMany<String>>,
}
#[allow(clippy::derivable_impls)]
impl Default for InDnsResolverConfig {
fn default() -> Self {
Self { server: None }
}
}
#[derive(serde::Deserialize)]
pub struct InFakeIpDnsConfig {
#[serde(default = "fake_ip_dns_address_default")]
pub listen: SocketAddr,
}
impl Default for InFakeIpDnsConfig {
fn default() -> Self {
Self {
listen: fake_ip_dns_address_default(),
}
}
}
#[derive(serde::Deserialize)]
pub struct InTransparentProxyConfig {
#[serde(default = "transparent_proxy_address_default")]
pub listen: SocketAddr,
#[serde(default = "transparent_proxy_traffic_mark_default")]
pub traffic_mark: u32,
}
impl Default for InTransparentProxyConfig {
fn default() -> Self {
Self {
listen: transparent_proxy_address_default(),
traffic_mark: transparent_proxy_traffic_mark_default(),
}
}
}
#[derive(serde::Deserialize)]
pub struct InTunnelingConfig {
pub stun_server: Option<OneOrMany<String>>,
pub match_server: MatchServerUrlOrConfig,
#[serde(default)]
pub http2: InTunnelingHttp2Config,
#[serde(default)]
pub quic: InTunnelingQuicConfig,
}
#[derive(serde::Deserialize)]
pub struct InTunnelingHttp2Config {
#[serde(default = "true_default")]
pub enabled: bool,
#[serde(default = "tunneling_http2_connections_default")]
pub connections: usize,
pub priority: Option<i64>,
}
impl Default for InTunnelingHttp2Config {
fn default() -> Self {
Self {
enabled: true,
connections: tunneling_http2_connections_default(),
priority: None,
}
}
}
#[derive(serde::Deserialize)]
pub struct InTunnelingQuicConfig {
#[serde(default = "true_default")]
pub enabled: bool,
pub priority: Option<i64>,
}
impl Default for InTunnelingQuicConfig {
fn default() -> Self {
Self {
enabled: true,
priority: None,
}
}
}
#[derive(serde::Deserialize)]
pub struct InRoutingConfig {
#[serde(default)]
pub geolite2: InRoutingGeoLite2Config,
#[serde(default = "in_routing_rules_default")]
pub rules: Vec<InRuleConfig>,
}
impl Default for InRoutingConfig {
fn default() -> Self {
Self {
geolite2: Default::default(),
rules: in_routing_rules_default(),
}
}
}
#[derive(serde::Deserialize)]
pub struct InRoutingGeoLite2Config {
#[serde(default = "geolite2_url_default")]
pub url: String,
pub update_interval: Option<String>,
}
impl Default for InRoutingGeoLite2Config {
fn default() -> Self {
Self {
url: geolite2_url_default(),
update_interval: None,
}
}
}
#[derive(serde::Deserialize)]
pub struct OutConfig {
pub tunneling: OutTunnelingConfig,
#[serde(default)]
pub outputs: Vec<OutOutputConfig>,
#[serde(default)]
pub routing: OutRoutingConfig,
}
#[derive(serde::Deserialize)]
pub struct OutTunnelingConfig {
pub label: Option<OneOrMany<Label>>,
pub stun_server: Option<OneOrMany<String>>,
pub match_server: MatchServerUrlOrConfig,
#[serde(default)]
pub http2: OutTunnelingHttp2Config,
#[serde(default)]
pub quic: OutTunnelingQuicConfig,
}
#[derive(Default, serde::Deserialize)]
pub struct OutTunnelingHttp2Config {
pub priority: Option<i64>,
}
#[derive(Default, serde::Deserialize)]
pub struct OutTunnelingQuicConfig {
pub priority: Option<i64>,
}
#[derive(Default, serde::Deserialize)]
pub struct OutRoutingConfig {
#[serde(default)]
pub priority: i64,
#[serde(default)]
pub rules: Vec<OutRuleConfig>,
}
fn in_routing_rules_default() -> Vec<InRuleConfig> {
vec![InRuleConfig::Fallback(InFallbackRuleConfig {
out: OneOrMany::One(Label::BuiltIn(BuiltInLabel::Direct)),
tag: None,
})]
}
fn true_default() -> bool {
true
}