Browse Source

feat: add Hysteria builder

master
Dnomd343 3 years ago
parent
commit
837246510f
  1. 44
      ProxyBuilder/Hysteria.py
  2. 3
      ProxyBuilder/builder.py
  3. 12
      demo.py

44
ProxyBuilder/Hysteria.py

@ -0,0 +1,44 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import copy
import json
defaultUpSpeed = 10000
defaultDownSpeed = 10000
def load(proxyInfo: dict, socksPort: int, configFile: str) -> tuple[list, str or None, dict]:
"""
Hysteria配置载入
proxyInfo: 节点信息
socksPort: 本地通讯端口
configFile: 配置文件路径
return startCommand, fileContent, envVar
"""
proxyInfo = copy.deepcopy(proxyInfo)
if proxyInfo['server'].find(':') >= 0:
proxyInfo['server'] = '[' + proxyInfo['server'] + ']' # IPv6
config = {
'server': proxyInfo['server'] + ':' + str(proxyInfo['port']),
'protocol': proxyInfo['protocol'],
'up_mbps': defaultUpSpeed,
'down_mbps': defaultDownSpeed,
'socks5': {
'listen': '127.0.0.1:' + str(socksPort)
}
}
if proxyInfo['obfs'] is not None:
config['obfs'] = proxyInfo['obfs']
if proxyInfo['auth'] is not None:
config['auth_str'] = proxyInfo['auth']
if proxyInfo['sni'] != '':
config['server_name'] = proxyInfo['sni']
if proxyInfo['alpn'] is not None:
config['alpn'] = proxyInfo['alpn']
if not proxyInfo['verify']:
config['insecure'] = True
return ['hysteria', '-c', configFile, 'client'], json.dumps(config), {}

3
ProxyBuilder/builder.py

@ -16,6 +16,7 @@ from ProxyBuilder import VLESS
from ProxyBuilder import Trojan from ProxyBuilder import Trojan
from ProxyBuilder import TrojanGo from ProxyBuilder import TrojanGo
from ProxyBuilder import Brook from ProxyBuilder import Brook
from ProxyBuilder import Hysteria
libcPaths = [ libcPaths = [
'/usr/lib/libc.so.6', # CentOS '/usr/lib/libc.so.6', # CentOS
@ -125,6 +126,8 @@ def build(proxyInfo: dict, configDir: str,
clientObj = TrojanGo clientObj = TrojanGo
elif proxyInfo['type'] == 'brook': # Brook节点 elif proxyInfo['type'] == 'brook': # Brook节点
clientObj = Brook clientObj = Brook
elif proxyInfo['type'] == 'hysteria': # Hysteria节点
clientObj = Hysteria
else: # 未知类型 else: # 未知类型
return False, 'Unknown proxy type' return False, 'Unknown proxy type'

12
demo.py

@ -13,13 +13,17 @@ info = {
'server': '127.0.0.1', 'server': '127.0.0.1',
'port': 443, 'port': 443,
'protocol': 'faketcp', 'protocol': 'faketcp',
'obfs': 'dnomd343', 'obfs': '770091573',
'auth': 'dnomd343', 'auth': 'dnomd343',
'sni': 'local.343.re', 'sni': 'local.343.re'
'alpn': 'h3',
'verify': False
} }
status, ret = Filter.filte(info, isExtra = True) status, ret = Filter.filte(info, isExtra = True)
print(status) print(status)
print(ret) print(ret)
result = Checker.proxyTest({
'check': ['http'],
'info': ret
})
print(result)

Loading…
Cancel
Save