Skip to content

Commit 0b62ece

Browse files
committed
添加 vless + kcp协议
1 parent 87f32a7 commit 0b62ece

File tree

5 files changed

+56
-43
lines changed

5 files changed

+56
-43
lines changed

v2ray

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# bash completion for v2ray/xray
22
function _auto_tab() {
33
local options_array=("start" "stop" "restart" "status" "update" "update.sh" "add" "del" "info" "port" "tls" "tfo" "stream" "iptables" "cdn" "stats" "clean" "log" "new" "rm" "-h" "-v" "help" "version")
4-
local add_array=("wechat" "utp" "srtp" "dtls" "wireguard" "socks" "mtproto" "ss" "vless_tcp" "vless_tls" "vless_ws" "vless_xtls" "trojan" "ss" "quic" "h2" "tcp" "tcp_host" "ws")
4+
local add_array=("wechat" "utp" "srtp" "dtls" "wireguard" "socks" "mtproto" "ss" "vless_tcp" "vless_tls" "vless_ws" "vless_xtls" "trojan" "ss" "quic" "h2" "tcp" "tcp_host" "ws" "vless_kcp" "vless_utp" "vless_srtp" "vless_dtls" "vless_wechat" "vless_wireguard")
55
local log_array=("access" "a" "error" "e")
66
local cur prev
77

v2ray_util/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '3.9.4'
1+
__version__ = '3.10.0'
22

33
import sys
44
if "xray" in sys.argv[0]:

v2ray_util/config_modify/stream.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def __init__(self, group_tag='A', group_index=-1):
2828
(StreamType.MTPROTO, "MTProto"),
2929
(StreamType.SS, "Shadowsocks"),
3030
(StreamType.QUIC, "Quic"),
31+
(StreamType.VLESS_KCP, "VLESS + mkcp"),
32+
(StreamType.VLESS_UTP, "VLESS + mKCP + utp"),
33+
(StreamType.VLESS_SRTP, "VLESS + mKCP + srtp"),
34+
(StreamType.VLESS_WECHAT, "VLESS + mKCP + wechat-video"),
35+
(StreamType.VLESS_DTLS, "VLESS + mKCP + dtls"),
36+
(StreamType.VLESS_WG, "VLESS + mKCP + wireguard"),
3137
(StreamType.VLESS_TCP, "VLESS_TCP"),
3238
(StreamType.VLESS_TLS, "VLESS_TLS"),
3339
(StreamType.VLESS_WS, "VLESS_WS"),
@@ -139,7 +145,7 @@ def modify(group=None, sType=None):
139145
else:
140146
choice = int(choice)
141147
if choice > 0 and choice <= len(sm.stream_type):
142-
if sm.stream_type[choice - 1][1] in ("MTProto", "Shadowsocks") and group.tls == 'tls':
148+
if sm.stream_type[choice - 1][1] in ("MTProto", "Shadowsocks") and group.tls in ('tls', 'xtls'):
143149
print(_("{} MTProto/Shadowsocks not support https, close tls success!".format(run_type.capitalize())))
144150
sm.select(sm.stream_type[choice - 1][0])
145151
print(_("modify protocol success"))

v2ray_util/util_core/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ class StreamType(Enum):
6767
KCP_DTLS = 'dtls'
6868
KCP_WECHAT = 'wechat'
6969
KCP_WG = 'wireguard'
70+
VLESS_KCP = 'vless_kcp'
71+
VLESS_UTP = 'vless_utp'
72+
VLESS_SRTP = 'vless_srtp'
73+
VLESS_DTLS = 'vless_dtls'
74+
VLESS_WECHAT = 'vless_wechat'
75+
VLESS_WG = 'vless_wireguard'
7076
VLESS_TCP = 'vless_tcp'
7177
VLESS_TLS = 'vless_tls'
7278
VLESS_WS = 'vless_ws'

v2ray_util/util_core/writer.py

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,36 @@ def to_mtproto(self, template_json):
107107
routing_bind["inboundTag"][0] = self.group_tag
108108
rules.append(routing_bind)
109109

110+
def to_kcp(self, header_type):
111+
self.part_json["streamSettings"] = self.load_template('kcp.json')
112+
type_str = "none"
113+
if "utp" in header_type:
114+
type_str = "utp"
115+
elif "srtp" in header_type:
116+
type_str = "srtp"
117+
elif "dtls" in header_type:
118+
type_str = "dtls"
119+
elif "wechat" in header_type:
120+
type_str = "wechat-video"
121+
elif "wireguard" in header_type:
122+
type_str = "wireguard"
123+
self.part_json["streamSettings"]["kcpSettings"]["header"]["type"] = type_str
124+
125+
def to_vmess(self, header_type):
126+
self.to_kcp(header_type)
127+
self.part_json["protocol"] = "vmess"
128+
self.part_json["settings"] = {
129+
"clients": [
130+
{
131+
"alterId": 0,
132+
"id": str(uuid.uuid1())
133+
}
134+
]
135+
}
136+
110137
def write(self, **kw):
111138
security_backup, tls_settings_backup, origin_protocol, domain = "", "", None, ""
139+
no_tls_group = (StreamType.MTPROTO, StreamType.SS)
112140

113141
if self.part_json['protocol'] == 'shadowsocks':
114142
origin_protocol = StreamType.SS
@@ -126,7 +154,7 @@ def write(self, **kw):
126154
elif self.part_json['protocol'] == 'trojan':
127155
origin_protocol = StreamType.TROJAN
128156

129-
if origin_protocol != StreamType.MTPROTO and origin_protocol != StreamType.SS:
157+
if origin_protocol not in no_tls_group:
130158
security_backup = self.part_json["streamSettings"]["security"]
131159
if origin_protocol == StreamType.VLESS_XTLS:
132160
tls_settings_backup = self.part_json["streamSettings"]["xtlsSettings"]
@@ -139,36 +167,8 @@ def write(self, **kw):
139167
if origin_protocol == StreamType.MTPROTO and origin_protocol != self.stream_type:
140168
clean_mtproto_tag(self.config, self.group_index)
141169

142-
#原来是socks/mtproto/shadowsocks/vless/trojan/xtls协议 则先切换为标准的inbound
143-
if origin_protocol in (StreamType.MTPROTO, StreamType.SOCKS, StreamType.SS, StreamType.VLESS_TLS, StreamType.VLESS_TCP, StreamType.TROJAN, StreamType.VLESS_XTLS):
144-
vmess = self.load_template('server.json')
145-
vmess["inbounds"][0]["port"] = self.part_json["port"]
146-
if "allocate" in self.part_json:
147-
vmess["inbounds"][0]["allocate"] = self.part_json["allocate"]
148-
self.part_json = vmess["inbounds"][0]
149-
150-
if self.stream_type == StreamType.KCP:
151-
self.part_json["streamSettings"] = self.load_template('kcp.json')
152-
153-
elif self.stream_type == StreamType.KCP_UTP:
154-
self.part_json["streamSettings"] = self.load_template('kcp.json')
155-
self.part_json["streamSettings"]["kcpSettings"]["header"]["type"] = "utp"
156-
157-
elif self.stream_type == StreamType.KCP_SRTP:
158-
self.part_json["streamSettings"] = self.load_template('kcp.json')
159-
self.part_json["streamSettings"]["kcpSettings"]["header"]["type"] = "srtp"
160-
161-
elif self.stream_type == StreamType.KCP_WECHAT:
162-
self.part_json["streamSettings"] = self.load_template('kcp.json')
163-
self.part_json["streamSettings"]["kcpSettings"]["header"]["type"] = "wechat-video"
164-
165-
elif self.stream_type == StreamType.KCP_DTLS:
166-
self.part_json["streamSettings"] = self.load_template('kcp.json')
167-
self.part_json["streamSettings"]["kcpSettings"]["header"]["type"] = "dtls"
168-
169-
elif self.stream_type == StreamType.KCP_WG:
170-
self.part_json["streamSettings"] = self.load_template('kcp.json')
171-
self.part_json["streamSettings"]["kcpSettings"]["header"]["type"] = "wireguard"
170+
if "KCP" in self.stream_type.name:
171+
self.to_vmess(self.stream_type.value)
172172

173173
elif self.stream_type == StreamType.TCP:
174174
self.part_json["streamSettings"] = self.load_template('tcp.json')
@@ -215,7 +215,7 @@ def write(self, **kw):
215215
ws["wsSettings"]["headers"]["Host"] = kw['host']
216216
self.part_json["streamSettings"] = ws
217217

218-
elif self.stream_type in (StreamType.VLESS_TCP, StreamType.VLESS_TLS, StreamType.VLESS_XTLS, StreamType.VLESS_WS):
218+
elif "vless" in self.stream_type.value:
219219
vless = self.load_template('vless.json')
220220
vless["clients"][0]["id"] = str(uuid.uuid1())
221221
if self.stream_type == StreamType.VLESS_XTLS:
@@ -230,12 +230,15 @@ def write(self, **kw):
230230
if "host" in kw:
231231
ws["wsSettings"]["headers"]["Host"] = kw['host']
232232
self.part_json["streamSettings"] = ws
233+
elif self.stream_type in (StreamType.VLESS_KCP, StreamType.VLESS_UTP, StreamType.VLESS_SRTP, StreamType.VLESS_DTLS, StreamType.VLESS_WECHAT, StreamType.VLESS_WG):
234+
self.to_kcp(self.stream_type.value)
235+
self.part_json["streamSettings"]["kcpSettings"]["seed"] = ''.join(random.sample(string.ascii_letters + string.digits, 8))
233236
else:
234237
self.part_json["streamSettings"] = self.load_template('tcp.json')
235238
self.save()
236239
alpn = ["http/1.1"]
237240
# tls的设置
238-
if self.stream_type != StreamType.VLESS_TCP:
241+
if self.stream_type in (StreamType.VLESS_XTLS, StreamType.VLESS_WS, StreamType.VLESS_TLS):
239242
if not "certificates" in tls_settings_backup:
240243
from ..config_modify.tls import TLSModifier
241244
if self.stream_type == StreamType.VLESS_XTLS:
@@ -291,18 +294,16 @@ def write(self, **kw):
291294
self.part_json["streamSettings"]["security"] = "xtls"
292295
self.part_json["streamSettings"]["xtlsSettings"] = tls_settings_backup
293296
del self.part_json["streamSettings"]["tlsSettings"]
294-
elif (self.stream_type != StreamType.MTPROTO and origin_protocol != StreamType.MTPROTO
295-
and self.stream_type != StreamType.SS and origin_protocol != StreamType.SS):
297+
elif self.stream_type not in no_tls_group and origin_protocol not in no_tls_group:
296298
self.part_json["streamSettings"]["security"] = "tls" if security_backup == "xtls" else security_backup
297299
self.part_json["streamSettings"]["tlsSettings"] = tls_settings_backup
298300

299-
if domain:
301+
if domain and self.stream_type not in no_tls_group:
300302
self.part_json["domain"] = domain
301303

302-
apln_list = (StreamType.VLESS_TLS, StreamType.VLESS_TCP, StreamType.TROJAN, StreamType.VLESS_XTLS)
303-
if origin_protocol in apln_list and self.stream_type not in apln_list:
304-
if "alpn" in self.part_json["streamSettings"]["tlsSettings"]:
305-
del self.part_json["streamSettings"]["tlsSettings"]["alpn"]
304+
apln_list = (StreamType.VLESS_TLS, StreamType.TROJAN, StreamType.VLESS_XTLS)
305+
if "streamSettings" in self.part_json and "alpn" in self.part_json["streamSettings"]["tlsSettings"] and self.stream_type not in apln_list:
306+
del self.part_json["streamSettings"]["tlsSettings"]["alpn"]
306307

307308
self.config["inbounds"][self.group_index] = self.part_json
308309
self.save()

0 commit comments

Comments
 (0)