From 837246510f68792b476d222e68309181fdb73f80 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 5 Mar 2022 23:58:48 +0800 Subject: [PATCH] feat: add Hysteria builder --- ProxyBuilder/Hysteria.py | 44 ++++++++++++++++++++++++++++++++++++++++ ProxyBuilder/builder.py | 3 +++ demo.py | 12 +++++++---- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 ProxyBuilder/Hysteria.py diff --git a/ProxyBuilder/Hysteria.py b/ProxyBuilder/Hysteria.py new file mode 100644 index 0000000..2b4e833 --- /dev/null +++ b/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), {} diff --git a/ProxyBuilder/builder.py b/ProxyBuilder/builder.py index 5206eb4..049dd4a 100644 --- a/ProxyBuilder/builder.py +++ b/ProxyBuilder/builder.py @@ -16,6 +16,7 @@ from ProxyBuilder import VLESS from ProxyBuilder import Trojan from ProxyBuilder import TrojanGo from ProxyBuilder import Brook +from ProxyBuilder import Hysteria libcPaths = [ '/usr/lib/libc.so.6', # CentOS @@ -125,6 +126,8 @@ def build(proxyInfo: dict, configDir: str, clientObj = TrojanGo elif proxyInfo['type'] == 'brook': # Brook节点 clientObj = Brook + elif proxyInfo['type'] == 'hysteria': # Hysteria节点 + clientObj = Hysteria else: # 未知类型 return False, 'Unknown proxy type' diff --git a/demo.py b/demo.py index e2f6e7d..fef58ff 100644 --- a/demo.py +++ b/demo.py @@ -13,13 +13,17 @@ info = { 'server': '127.0.0.1', 'port': 443, 'protocol': 'faketcp', - 'obfs': 'dnomd343', + 'obfs': '770091573', 'auth': 'dnomd343', - 'sni': 'local.343.re', - 'alpn': 'h3', - 'verify': False + 'sni': 'local.343.re' } status, ret = Filter.filte(info, isExtra = True) print(status) print(ret) + +result = Checker.proxyTest({ + 'check': ['http'], + 'info': ret +}) +print(result)