This repository has been archived by the owner on Apr 3, 2022. It is now read-only.
/
v2genConf.go
143 lines (111 loc) · 2.56 KB
/
v2genConf.go
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
package v2gen
import (
"errors"
"fmt"
"io/ioutil"
"os"
"strings"
)
func InitV2GenConf(p string) error {
// If user config exist
if _, err := os.Stat(p); os.IsNotExist(err) {
return ioutil.WriteFile(p, []byte(DefaultV2GenConf), 0644)
}
fmt.Println("=====================")
fmt.Print("File already exists, if rewrite it?(y)es/(N)o: ")
var ifContinue string
_, err := fmt.Scanf("%s", &ifContinue)
if err != nil {
return err
}
fmt.Println("=====================")
if ifContinue == "y" || ifContinue == "Y" {
return ioutil.WriteFile(p, []byte(DefaultV2GenConf), 0644)
}
return errors.New("file already exists")
}
func ParseV2GenConf(b []byte) map[string]string {
V2GenSettings := make(map[string]string)
// file to lines
lines := strings.Split(string(b), "\n")
for _, s := range lines {
s = strings.TrimLeft(s, " ")
s = strings.TrimLeft(s, "\t")
if s == "" {
continue
}
if s[0] == '#' {
continue
}
// Split "k v" to {k,v}
line := strings.FieldsFunc(s, func(r rune) bool {
if r == ' ' || r == '\t' {
return true
}
return false
})
// check if is {k,v}
if len(line) != 2 {
continue
}
line[0] = strings.TrimRight(line[0], ":")
V2GenSettings[line[0]] = line[1] // Set Settings[k]=v
}
return V2GenSettings
}
const DefaultV2GenConf = `
#####################
# v2gen user config #
#####################
# V2Ray log level
# ( debug | info | warning | error | none )
loglevel: warning
# Socks port
socksPort: 1080
# Http port
httpPort: 1081
# If allow UDP traffic
# ( true | false )
udp: true
# Security
# ( aes-128-gcm | aes-256-gcm | chacha20-poly1305 | auto | none )
security: aes-256-gcm
# If enable mux
# ( true | false )
mux: true
# Mux concurrency num
concurrency: 8
# DNS server
dns1: https://1.1.1.1/dns-query
dns2: https://dns.quad9.net/dns-query
# If China sites and ips directly connect
# ( true | false )
china: true
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#@ NOTICE: @
#@ The following settings may NOT work on every node @
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# If allow insecure connection ( true | false )
allowInsecure: false
# KCP mtu num
mtu: 1350
# KCP tti num
tti: 20
# KCP max upload speed
# Unit: MB/s
up: 5
# KCP max download speed
# Unit: MB/s
down: 20
# If enable UDP congestion control ( true | false )
congestion: false
# Read buffer size
# Unit: MB
readBufferSize: 1
# Write buffer size
# Unit: MB
writeBufferSize: 1
##############################
# Thank you for using v2gen! #
##############################
`