-
Notifications
You must be signed in to change notification settings - Fork 356
/
kcptun_prepare.sh
292 lines (277 loc) · 7.59 KB
/
kcptun_prepare.sh
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# kcptun crypt
KCPTUN_CRYPT=(
aes
aes-128
aes-192
salsa20
blowfish
twofish
cast5
3des
tea
xtea
xor
sm4
none
)
# kcptun mode(no manual)
KCPTUN_MODE=(
fast3
fast2
fast
normal
)
get_input_port(){
# 设置 Kcptun 服务器监听端口 listen_port
while true
do
gen_random_prot
_read "请输入监听端口[1-65535] (默认: ${ran_prot}):"
listen_port="${inputInfo}"
[ -z "${listen_port}" ] && listen_port="${ran_prot}"
if ! judge_is_num "${listen_port}"; then
_echo -e "请输入一个有效数字."
continue
fi
if judge_is_zero_begin_num "${listen_port}"; then
_echo -e "请输入一个非0开头的数字."
continue
fi
if ! judge_num_in_range "${listen_port}" "65535"; then
_echo -e "请输入一个在1-65535之间的数字."
continue
fi
if judge_is_equal_num "${listen_port}" "${shadowsocksport}"; then
_echo -e "请输入一个与SS端口不同的数字."
continue
fi
kill_process_if_port_occupy "${listen_port}"
_echo -r " port = ${listen_port}"
break
done
}
get_input_password(){
# 设置 Kcptun 密码 key
gen_random_str
_read "请输入密码 (默认: ${ran_str12}):"
key="${inputInfo}"
[ -z "${key}" ] && key=${ran_str12}
_echo -r " key = ${key}"
}
get_input_crypt(){
# 设置 Kcptun 加密方式 crypt
generate_menu_logic "${KCPTUN_CRYPT[*]}" "加密方式" "13"
crypt="${optionValue}"
}
get_input_accelerate_mode(){
# 设置 Kcptun 加速模式 mode
generate_menu_logic "${KCPTUN_MODE[*]}" "加速模式" "2"
mode="${optionValue}"
_echo -t "加速模式和发送窗口大小共同决定了流量的损耗大小(manual未支持)."
}
get_input_mtu(){
# 设置 UDP 数据包的 MTU (最大传输单元)值
while true
do
_read "请设置 UDP 数据包的 MTU (最大传输单元)值 (默认: 1350):"
MTU="${inputInfo}"
[ -z "${MTU}" ] && MTU=1350
if ! judge_is_num "${MTU}"; then
_echo -e "请输入一个有效数字."
continue
fi
if judge_is_zero_begin_num "${MTU}"; then
_echo -e "请输入一个非0开头的数字."
continue
fi
if [ ${MTU} -lt 1 ]; then
_echo -e "请输入一个大于0的数."
continue
fi
_echo -r " MTU = ${MTU}"
break
done
}
get_input_sndwnd(){
# 设置发送窗口大小 sndwnd
while true
do
_read "请设置发送窗口(sndwnd)大小 (默认: 1024):"
sndwnd="${inputInfo}"
[ -z "${sndwnd}" ] && sndwnd=1024
if ! judge_is_num "${sndwnd}"; then
_echo -e "请输入一个有效数字."
continue
fi
if judge_is_zero_begin_num "${sndwnd}"; then
_echo -e "请输入一个非0开头的数字."
continue
fi
if [ ${sndwnd} -lt 1 ]; then
_echo -e "请输入一个大于0的数."
continue
fi
_echo -r " sndwnd = ${sndwnd}"
_echo -t "发送窗口过大会浪费过多流量."
break
done
}
get_input_rcvwnd(){
# 设置接收窗口大小 rcvwnd
while true
do
_read "请设置接收窗口(rcvwnd)大小 (默认: 1024):"
rcvwnd="${inputInfo}"
[ -z "${rcvwnd}" ] && rcvwnd=1024
if ! judge_is_num "${rcvwnd}"; then
_echo -e "请输入一个有效数字."
continue
fi
if judge_is_zero_begin_num "${rcvwnd}"; then
_echo -e "请输入一个非0开头的数字."
continue
fi
if [ ${rcvwnd} -lt 1 ]; then
_echo -e "请输入一个大于0的数."
continue
fi
_echo -r " rcvwnd = ${rcvwnd}"
break
done
}
get_input_datashard(){
# 设置前向纠错 datashard
while true
do
_read "请设置前向纠错(datashard) (默认: 10):"
datashard="${inputInfo}"
[ -z "${datashard}" ] && datashard=10
if ! judge_is_num "${datashard}"; then
_echo -e "请输入一个有效数字."
continue
fi
if judge_is_zero_begin_num "${datashard}"; then
_echo -e "请输入一个非0开头的数字."
continue
fi
if [ ${datashard} -lt 1 ]; then
_echo -e "请输入一个大于0的数."
continue
fi
_echo -r " datashard = ${datashard}"
_echo -t "该参数必须两端一致."
break
done
}
get_input_parityshard(){
# 设置前向纠错 parityshard
while true
do
_read "请设置前向纠错(parityshard) (默认: 3):"
parityshard="${inputInfo}"
[ -z "${parityshard}" ] && parityshard=3
if ! judge_is_num "${parityshard}"; then
_echo -e "请输入一个有效数字."
continue
fi
if judge_is_zero_begin_num "${parityshard}"; then
_echo -e "请输入一个非0开头的数字."
continue
fi
if [ ${parityshard} -lt 1 ]; then
_echo -e "请输入一个大于0的数."
continue
fi
_echo -r " parityshard = ${parityshard}"
_echo -t "该参数必须两端一致."
break
done
}
get_input_dscp(){
# 设置差分服务代码点 DSCP
while true
do
_read "请设置差分服务代码点(DSCP) (默认: 46):"
DSCP="${inputInfo}"
[ -z "${DSCP}" ] && DSCP=46
if ! judge_is_num "${DSCP}"; then
_echo -e "请输入一个有效数字."
continue
fi
if judge_is_zero_begin_num "${DSCP}"; then
_echo -e "请输入一个非0开头的数字."
continue
fi
if [ ${DSCP} -lt 1 ]; then
_echo -e "请输入一个大于0的数."
continue
fi
_echo -r " DSCP = ${DSCP}"
break
done
}
is_disable_nocomp(){
# 是否关闭数据压缩 nocomp
while true
do
_read "是否禁用数据压缩(nocomp) (默认: n) [y/n]:"
local yn="${inputInfo}"
[ -z "${yn}" ] && yn="N"
case "${yn:0:1}" in
y|Y)
nocomp='true'
;;
n|N)
nocomp='false'
;;
*)
_echo -e "输入有误,请重新输入!"
continue
;;
esac
_echo -r " nocomp = ${nocomp}"
break
done
}
is_enable_simulate_tcp_connection(){
if [[ ${nocomp} = true ]]; then
# 是否开启模拟TCP连接 TCP
while true
do
_read "是否开启模拟TCP连接(tcp) (默认: n) [y/n]:"
local yn="${inputInfo}"
[ -z "${yn}" ] && yn="N"
case "${yn:0:1}" in
y|Y)
KP_TCP='true'
;;
n|N)
KP_TCP='false'
;;
*)
_echo -e "输入有误,请重新输入!"
continue
;;
esac
_echo -r " tcp = ${KP_TCP}"
break
done
else
KP_TCP='false'
fi
}
install_prepare_libev_kcptun(){
get_input_port
firewallNeedOpenPort="${listen_port}"
get_input_password
get_input_crypt
get_input_accelerate_mode
get_input_mtu
get_input_sndwnd
get_input_rcvwnd
get_input_datashard
get_input_parityshard
get_input_dscp
is_disable_nocomp
is_enable_simulate_tcp_connection
}