You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
1.3 KiB

#!/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), {}