Browse Source

feat: VMess build framework

master
Dnomd343 3 years ago
parent
commit
5d4a99a06d
  1. 76
      ProxyBuilder/VMess.py

76
ProxyBuilder/VMess.py

@ -5,7 +5,7 @@ import json
logLevel = 'warning' logLevel = 'warning'
def __baseConfig(socksPort: int, outboundObject: dict) -> dict: def __baseConfig(socksPort: int, outboundObject: dict) -> dict: # v2ray配置生成
return { return {
'log': { 'log': {
'loglevel': logLevel 'loglevel': logLevel
@ -26,8 +26,76 @@ def __baseConfig(socksPort: int, outboundObject: dict) -> dict:
] ]
} }
def __vmessConfig(proxyInfo: dict) -> dict: def __secureConfig(secureInfo: dict or None) -> dict: # TLS加密传输配置
streamObject = {} if secureInfo is None:
return {}
return {
'security': 'tls',
'tlsSettings': {
'allowInsecure': not secureInfo['verify']
# sni
# alpn
}
}
def __tcpConfig(streamInfo: dict) -> dict: # TCP传输方式配置
tcpObject = {}
return {**{
'network': 'tcp',
'tcpSettings': tcpObject
}, **__secureConfig(streamInfo['secure'])}
def __kcpConfig(streamInfo: dict) -> dict: # mKCP传输方式配置
kcpObject = {}
return {**{
'network': 'kcp',
'kcpSettings': kcpObject
}, **__secureConfig(streamInfo['secure'])}
def __wsConfig(streamInfo: dict) -> dict: # WebSocket传输方式配置
wsObject = {}
return {**{
'network': 'ws',
'wsSettings': wsObject
}, **__secureConfig(streamInfo['secure'])}
def __h2Config(streamInfo: dict) -> dict: # HTTP/2传输方式配置
h2Object = {}
return {**{
'network': 'h2',
'httpSettings': h2Object
}, **__secureConfig(streamInfo['secure'])}
def __quicConfig(streamInfo: dict) -> dict: # QUIC传输方式配置
quicObject = {}
return {**{
'network': 'quic',
'quicSettings': quicObject
}, **__secureConfig(streamInfo['secure'])}
def __grpcConfig(streamInfo: dict) -> dict: # gRPC传输方式配置
grpcObject = {}
return {**{
'network': 'grpc',
'grpcSettings': grpcObject
}, **__secureConfig(streamInfo['secure'])}
def __vmessConfig(proxyInfo: dict) -> dict: # VMess节点配置
streamType = proxyInfo['stream']['type']
if streamType == 'tcp':
streamObject = __tcpConfig(proxyInfo['stream'])
elif streamType == 'kcp':
streamObject = __kcpConfig(proxyInfo['stream'])
elif streamType == 'ws':
streamObject = __wsConfig(proxyInfo['stream'])
elif streamType == 'h2':
streamObject = __h2Config(proxyInfo['stream'])
elif streamType == 'quic':
streamObject = __quicConfig(proxyInfo['stream'])
elif streamType == 'grpc':
streamObject = __grpcConfig(proxyInfo['stream'])
else:
raise Exception('Unknown stream type')
return { return {
'protocol': 'vmess', 'protocol': 'vmess',
'settings': { 'settings': {
@ -84,4 +152,4 @@ info = {
} }
ret = load(info, 1080, '/tmp/ProxyC/test.json') ret = load(info, 1080, '/tmp/ProxyC/test.json')
print(ret) print(ret[1])

Loading…
Cancel
Save