Browse Source

update: support gRPC multi-mode

master
Dnomd343 3 years ago
parent
commit
e20ff16a2f
  1. 19
      ProxyBuilder/V2ray.py
  2. 19
      ProxyBuilder/Xray.py
  3. 8
      ProxyFilter/V2ray.py
  4. 5
      ProxyTester/Trojan.py
  5. 42
      ProxyTester/V2ray.py
  6. 5
      ProxyTester/VLESS.py
  7. 2
      Run.py
  8. 31
      docs/ProxyObject.md

19
ProxyBuilder/V2ray.py

@ -73,7 +73,7 @@ def kcpConfig(streamInfo: dict, secureFunc) -> dict: # mKCP传输方式配置
'kcpSettings': kcpObject 'kcpSettings': kcpObject
}, **secureFunc(streamInfo['secure'])} }, **secureFunc(streamInfo['secure'])}
def wsConfig(streamInfo: dict, edInPath: bool, secureFunc) -> dict: # WebSocket传输方式配置 def wsConfig(streamInfo: dict, secureFunc) -> dict: # WebSocket传输方式配置
wsObject = { wsObject = {
'path': streamInfo['path'] 'path': streamInfo['path']
} }
@ -81,14 +81,8 @@ def wsConfig(streamInfo: dict, edInPath: bool, secureFunc) -> dict: # WebSocket
wsObject['headers'] = {} wsObject['headers'] = {}
wsObject['headers']['Host'] = streamInfo['host'] wsObject['headers']['Host'] = streamInfo['host']
if streamInfo['ed'] is not None: if streamInfo['ed'] is not None:
if not edInPath:
wsObject['maxEarlyData'] = streamInfo['ed'] wsObject['maxEarlyData'] = streamInfo['ed']
wsObject['earlyDataHeaderName'] = 'Sec-WebSocket-Protocol' wsObject['earlyDataHeaderName'] = 'Sec-WebSocket-Protocol'
else: # ed参数写入路径 -> /...?ed=xxx
if wsObject['path'].find('?') == -1: # 原路径不带参数
wsObject['path'] += '?ed=' + str(streamInfo['ed'])
else:
wsObject['path'] += '&ed=' + str(streamInfo['ed'])
return {**{ return {**{
'network': 'ws', 'network': 'ws',
'wsSettings': wsObject 'wsSettings': wsObject
@ -118,11 +112,14 @@ def quicConfig(streamInfo: dict, secureFunc) -> dict: # QUIC传输方式配置
}, **secureFunc(streamInfo['secure'])} }, **secureFunc(streamInfo['secure'])}
def grpcConfig(streamInfo: dict, secureFunc) -> dict: # gRPC传输方式配置 def grpcConfig(streamInfo: dict, secureFunc) -> dict: # gRPC传输方式配置
return {**{ grpcObject = {
'network': 'grpc',
'grpcSettings': {
'serviceName': streamInfo['service'] 'serviceName': streamInfo['service']
} }
if streamInfo['mode'] == 'multi': # gRPC multi-mode not work in v2fly-core
grpcObject['multiMode'] = True
return {**{
'network': 'grpc',
'grpcSettings': grpcObject
}, **secureFunc(streamInfo['secure'])} }, **secureFunc(streamInfo['secure'])}
def v2rayStreamConfig(streamInfo: dict) -> dict: # 生成v2ray传输方式配置 def v2rayStreamConfig(streamInfo: dict) -> dict: # 生成v2ray传输方式配置
@ -132,7 +129,7 @@ def v2rayStreamConfig(streamInfo: dict) -> dict: # 生成v2ray传输方式配置
elif streamType == 'kcp': elif streamType == 'kcp':
return kcpConfig(streamInfo, __secureConfig) return kcpConfig(streamInfo, __secureConfig)
elif streamType == 'ws': elif streamType == 'ws':
return wsConfig(streamInfo, False, __secureConfig) return wsConfig(streamInfo, __secureConfig)
elif streamType == 'h2': elif streamType == 'h2':
return h2Config(streamInfo, __secureConfig) return h2Config(streamInfo, __secureConfig)
elif streamType == 'quic': elif streamType == 'quic':

19
ProxyBuilder/Xray.py

@ -28,6 +28,23 @@ def __secureConfig(secureInfo: dict or None) -> dict: # TLS/XTLS加密传输配
else: else:
raise Exception('Unknown secure type') raise Exception('Unknown secure type')
def wsConfig(streamInfo: dict, secureFunc) -> dict: # WebSocket传输方式配置
wsObject = {
'path': streamInfo['path']
}
if streamInfo['host'] != '':
wsObject['headers'] = {}
wsObject['headers']['Host'] = streamInfo['host']
if streamInfo['ed'] is not None: # ed参数写入路径 -> /...?ed=xxx
if wsObject['path'].find('?') == -1: # 原路径不带参数
wsObject['path'] += '?ed=' + str(streamInfo['ed'])
else:
wsObject['path'] += '&ed=' + str(streamInfo['ed'])
return {**{
'network': 'ws',
'wsSettings': wsObject
}, **secureFunc(streamInfo['secure'])}
def xrayStreamConfig(streamInfo: dict) -> dict: # 生成xray传输方式配置 def xrayStreamConfig(streamInfo: dict) -> dict: # 生成xray传输方式配置
streamType = streamInfo['type'] streamType = streamInfo['type']
if streamType == 'tcp': if streamType == 'tcp':
@ -35,7 +52,7 @@ def xrayStreamConfig(streamInfo: dict) -> dict: # 生成xray传输方式配置
elif streamType == 'kcp': elif streamType == 'kcp':
return V2ray.kcpConfig(streamInfo, __secureConfig) return V2ray.kcpConfig(streamInfo, __secureConfig)
elif streamType == 'ws': elif streamType == 'ws':
return V2ray.wsConfig(streamInfo, True, __secureConfig) return wsConfig(streamInfo, __secureConfig)
elif streamType == 'h2': elif streamType == 'h2':
return V2ray.h2Config(streamInfo, __secureConfig) return V2ray.h2Config(streamInfo, __secureConfig)
elif streamType == 'quic': elif streamType == 'quic':

8
ProxyFilter/V2ray.py

@ -187,6 +187,14 @@ v2rayStreamRules = {
'type': str, 'type': str,
'format': baseFunc.toStr 'format': baseFunc.toStr
}, },
'mode': {
'optional': False,
'default': 'gun',
'type': str,
'format': baseFunc.toStrTidy,
'filter': lambda mode: mode in ['gun', 'multi'],
'errMsg': 'Unknown gRPC mode'
},
'secure': { 'secure': {
'optional': False, 'optional': False,
'default': None, 'default': None,

5
ProxyTester/Trojan.py

@ -140,4 +140,9 @@ def trojanTest(trojanConfig: dict) -> list:
streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host'])
result.append(loadTrojanStream(streamInfo, None)) result.append(loadTrojanStream(streamInfo, None))
streamInfo = Xray.loadGrpcStream(config['service'], multiMode = True)
result.append(loadTrojanStream(streamInfo, None))
streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host'])
result.append(loadTrojanStream(streamInfo, None))
return result return result

42
ProxyTester/V2ray.py

@ -24,13 +24,13 @@ httpHeader = {
} }
kcpSetting = { kcpSetting = {
"mtu": 1350, 'mtu': 1350,
"tti": 20, 'tti': 20,
"uplinkCapacity": 5, 'uplinkCapacity': 5,
"downlinkCapacity": 20, 'downlinkCapacity': 20,
"congestion": False, 'congestion': False,
"readBufferSize": 1, 'readBufferSize': 1,
"writeBufferSize": 1, 'writeBufferSize': 1,
} }
udpObfsList = [ udpObfsList = [
@ -165,16 +165,17 @@ def loadQuicStream(method: str, passwd: str, obfs: str) -> dict:
'server': { 'server': {
'network': 'quic', 'network': 'quic',
'quicSettings': { 'quicSettings': {
"security": method, 'security': method,
"key": passwd, 'key': passwd,
"header": { 'header': {
"type": obfs 'type': obfs
} }
} }
} }
} }
def loadGrpcStream(service: str) -> dict: def loadGrpcStream(service: str, multiMode: bool = False) -> dict:
if not multiMode:
return { return {
'caption': 'gRPC', 'caption': 'gRPC',
'client': { 'client': {
@ -184,7 +185,22 @@ def loadGrpcStream(service: str) -> dict:
'server': { 'server': {
'network': 'grpc', 'network': 'grpc',
'grpcSettings': { 'grpcSettings': {
"serviceName": service 'serviceName': service
}
}
}
return {
'caption': 'gRPC multi-mode',
'client': {
'type': 'grpc',
'service': service,
'mode': 'multi'
},
'server': {
'network': 'grpc',
'grpcSettings': {
'serviceName': service,
'multiMode': True # gRPC multi-mode not work in v2fly-core
} }
} }
} }

5
ProxyTester/VLESS.py

@ -101,4 +101,9 @@ def vlessTest(vlessConfig: dict) -> list:
streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host']) streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host'])
result.append(loadVlessStream(streamInfo, None)) result.append(loadVlessStream(streamInfo, None))
streamInfo = Xray.loadGrpcStream(config['service'], multiMode = True)
result.append(loadVlessStream(streamInfo, None))
streamInfo = Xray.addTlsConfig(streamInfo, config['cert'], config['key'], config['host'])
result.append(loadVlessStream(streamInfo, None))
return result return result

2
Run.py

@ -37,7 +37,7 @@ def __getCheckInfo() -> tuple[str or None, dict or None]:
key = checkList[0] # 选取首个任务 key = checkList[0] # 选取首个任务
taskContent = redisObject.get(key) # 获取任务信息 taskContent = redisObject.get(key) # 获取任务信息
redisObject.delete(key) # 删除任务记录 redisObject.delete(key) # 删除任务记录
tag = str(key[len(redisPrefix) + 8:], encoding = "utf-8") # {prefix}check-x-{tag} tag = str(key[len(redisPrefix) + 8:], encoding = 'utf-8') # {prefix}check-x-{tag}
except: except:
return None, None return None, None
try: try:

31
docs/ProxyObject.md

@ -424,6 +424,7 @@
{ {
'type': 'grpc', 'type': 'grpc',
'service': ..., 'service': ...,
'mode': ...,
'secure': ... 'secure': ...
} }
``` ```
@ -436,6 +437,14 @@
+ 可选值:不限 + 可选值:不限
+ 建议值:英文大小写字母、数字、下划线及英文句号组成 + 建议值:英文大小写字母、数字、下划线及英文句号组成
**mode**
+ 类型:*str*
+ 说明:gRPC传输模式
+ 缺省:'gun'
+ 可选值:`gun`,`multi`
+ 建议值:'multi'
**secure** **secure**
+ 类型:*None* / *secureObject* + 类型:*None* / *secureObject*
@ -738,6 +747,7 @@
{ {
'type': 'grpc', 'type': 'grpc',
'service': ..., 'service': ...,
'mode': ...,
'secure': ... 'secure': ...
} }
``` ```
@ -750,6 +760,14 @@
+ 可选值:不限 + 可选值:不限
+ 建议值:英文大小写字母、数字、下划线及英文句号组成 + 建议值:英文大小写字母、数字、下划线及英文句号组成
**mode**
+ 类型:*str*
+ 说明:gRPC传输模式
+ 缺省:'gun'
+ 可选值:`gun`,`multi`
+ 建议值:'multi'
**secure** **secure**
+ 类型:*None* / *tlsObject* + 类型:*None* / *tlsObject*
@ -814,7 +832,7 @@
+ 类型:*bool* + 类型:*bool*
+ 说明:是否验证服务端证书 + 说明:是否验证服务端证书
+ 缺省:True + 缺省:True
+ 可选值:True / False + 可选值:不限
+ 建议值:True + 建议值:True
### xtlsObject ### xtlsObject
@ -1096,6 +1114,7 @@
{ {
'type': 'grpc', 'type': 'grpc',
'service': ..., 'service': ...,
'mode': ...,
'secure': ... 'secure': ...
} }
``` ```
@ -1108,6 +1127,14 @@
+ 可选值:不限 + 可选值:不限
+ 建议值:英文大小写字母、数字、下划线及英文句号组成 + 建议值:英文大小写字母、数字、下划线及英文句号组成
**mode**
+ 类型:*str*
+ 说明:gRPC传输模式
+ 缺省:'gun'
+ 可选值:`gun`,`multi`
+ 建议值:'multi'
**secure** **secure**
+ 类型:*None* / *tlsObject* + 类型:*None* / *tlsObject*
@ -1172,7 +1199,7 @@
+ 类型:*bool* + 类型:*bool*
+ 说明:是否验证服务端证书 + 说明:是否验证服务端证书
+ 缺省:True + 缺省:True
+ 可选值:True / False + 可选值:不限
+ 建议值:True + 建议值:True
### xtlsObject ### xtlsObject

Loading…
Cancel
Save