@@ -18,21 +18,23 @@ import (
1818)
1919
2020type ServerConfig struct {
21- ConfigDir string `toml:"-"`
22- ConfigPath string `toml:"-"`
23- UDPHost string `toml:"UDP_HOST"`
24- UDPPort int `toml:"UDP_PORT"`
25- UDPReaders int `toml:"UDP_READERS"`
26- SocketBufferSize int `toml:"SOCKET_BUFFER_SIZE"`
27- MaxConcurrentRequests int `toml:"MAX_CONCURRENT_REQUESTS"`
28- DNSRequestWorkers int `toml:"DNS_REQUEST_WORKERS"`
29- MaxPacketSize int `toml:"MAX_PACKET_SIZE"`
30- DropLogIntervalSecs float64 `toml:"DROP_LOG_INTERVAL_SECONDS"`
31- Domain []string `toml:"DOMAIN"`
32- MinVPNLabelLength int `toml:"MIN_VPN_LABEL_LENGTH"`
33- DataEncryptionMethod int `toml:"DATA_ENCRYPTION_METHOD"`
34- EncryptionKeyFile string `toml:"ENCRYPTION_KEY_FILE"`
35- LogLevel string `toml:"LOG_LEVEL"`
21+ ConfigDir string `toml:"-"`
22+ ConfigPath string `toml:"-"`
23+ UDPHost string `toml:"UDP_HOST"`
24+ UDPPort int `toml:"UDP_PORT"`
25+ UDPReaders int `toml:"UDP_READERS"`
26+ SocketBufferSize int `toml:"SOCKET_BUFFER_SIZE"`
27+ MaxConcurrentRequests int `toml:"MAX_CONCURRENT_REQUESTS"`
28+ DNSRequestWorkers int `toml:"DNS_REQUEST_WORKERS"`
29+ MaxPacketSize int `toml:"MAX_PACKET_SIZE"`
30+ DropLogIntervalSecs float64 `toml:"DROP_LOG_INTERVAL_SECONDS"`
31+ Domain []string `toml:"DOMAIN"`
32+ MinVPNLabelLength int `toml:"MIN_VPN_LABEL_LENGTH"`
33+ SupportedUploadCompressionTypes []int `toml:"SUPPORTED_UPLOAD_COMPRESSION_TYPES"`
34+ SupportedDownloadCompressionTypes []int `toml:"SUPPORTED_DOWNLOAD_COMPRESSION_TYPES"`
35+ DataEncryptionMethod int `toml:"DATA_ENCRYPTION_METHOD"`
36+ EncryptionKeyFile string `toml:"ENCRYPTION_KEY_FILE"`
37+ LogLevel string `toml:"LOG_LEVEL"`
3638}
3739
3840func defaultServerConfig () ServerConfig {
@@ -41,19 +43,21 @@ func defaultServerConfig() ServerConfig {
4143 readers := min (max (runtime .NumCPU ()/ 2 , 1 ), 4 )
4244
4345 return ServerConfig {
44- UDPHost : "0.0.0.0" ,
45- UDPPort : 53 ,
46- UDPReaders : readers ,
47- SocketBufferSize : 8 * 1024 * 1024 ,
48- MaxConcurrentRequests : 4096 ,
49- DNSRequestWorkers : workers ,
50- MaxPacketSize : 65535 ,
51- DropLogIntervalSecs : 2.0 ,
52- Domain : nil ,
53- MinVPNLabelLength : 3 ,
54- DataEncryptionMethod : 1 ,
55- EncryptionKeyFile : "encrypt_key.txt" ,
56- LogLevel : "INFO" ,
46+ UDPHost : "0.0.0.0" ,
47+ UDPPort : 53 ,
48+ UDPReaders : readers ,
49+ SocketBufferSize : 8 * 1024 * 1024 ,
50+ MaxConcurrentRequests : 4096 ,
51+ DNSRequestWorkers : workers ,
52+ MaxPacketSize : 65535 ,
53+ DropLogIntervalSecs : 2.0 ,
54+ Domain : nil ,
55+ MinVPNLabelLength : 3 ,
56+ SupportedUploadCompressionTypes : []int {0 , 1 , 2 , 3 },
57+ SupportedDownloadCompressionTypes : []int {0 , 1 , 2 , 3 },
58+ DataEncryptionMethod : 1 ,
59+ EncryptionKeyFile : "encrypt_key.txt" ,
60+ LogLevel : "INFO" ,
5761 }
5862}
5963
@@ -110,6 +114,8 @@ func LoadServerConfig(filename string) (ServerConfig, error) {
110114 if cfg .MinVPNLabelLength <= 0 {
111115 cfg .MinVPNLabelLength = 3
112116 }
117+ cfg .SupportedUploadCompressionTypes = normalizeCompressionTypeList (cfg .SupportedUploadCompressionTypes )
118+ cfg .SupportedDownloadCompressionTypes = normalizeCompressionTypeList (cfg .SupportedDownloadCompressionTypes )
113119
114120 if cfg .DataEncryptionMethod < 0 || cfg .DataEncryptionMethod > 5 {
115121 cfg .DataEncryptionMethod = 1
@@ -143,3 +149,23 @@ func (c ServerConfig) EncryptionKeyPath() string {
143149 }
144150 return filepath .Join (c .ConfigDir , c .EncryptionKeyFile )
145151}
152+
153+ func normalizeCompressionTypeList (values []int ) []int {
154+ if len (values ) == 0 {
155+ return []int {0 }
156+ }
157+
158+ seen := [4 ]bool {}
159+ out := make ([]int , 0 , len (values ))
160+ for _ , value := range values {
161+ if value < 0 || value > 3 || seen [value ] {
162+ continue
163+ }
164+ seen [value ] = true
165+ out = append (out , value )
166+ }
167+ if len (out ) == 0 {
168+ return []int {0 }
169+ }
170+ return out
171+ }
0 commit comments