From a68692314ed310eca176be00d452742a7d743f5d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 6 Mar 2022 11:29:14 +0800 Subject: [PATCH] feat: tester of Hysteria --- ProxyTester/Hysteria.py | 69 +++++++++++++++++++++++++++++++++++++++++ ProxyTester/tester.py | 3 ++ Test.py | 2 +- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 ProxyTester/Hysteria.py diff --git a/ProxyTester/Hysteria.py b/ProxyTester/Hysteria.py new file mode 100644 index 0000000..95b190b --- /dev/null +++ b/ProxyTester/Hysteria.py @@ -0,0 +1,69 @@ +#!/usr/bin/python +# -*- coding:utf-8 -*- + +import copy +import json + +testConfig = {} + +hysteriaProtocolList = [ + 'udp', + 'wechat-video', + 'faketcp', +] + + +def __hysteriaConfig(protocol: str, isObfs: bool, isAuth: bool) -> dict: + caption = 'Hysteria protocol ' + protocol + proxyInfo = { + 'type': 'hysteria', + 'server': testConfig['addr'], + 'port': testConfig['port'], + 'protocol': protocol, + 'sni': testConfig['host'] + } + serverConfig = { + 'listen': testConfig['bind'] + ':' + str(testConfig['port']), + 'protocol': protocol, + 'cert': testConfig['cert'], + 'key': testConfig['key'], + } + + if isObfs: + caption += ' (with obfs)' + proxyInfo['obfs'] = testConfig['passwd'] + serverConfig['obfs'] = testConfig['passwd'] + if isAuth: + caption += ' (with auth)' + proxyInfo['auth'] = testConfig['passwd'] + serverConfig['auth'] = { + 'mode': 'passwords', + 'config': [testConfig['passwd']] + } + + return { + 'caption': caption, + 'proxy': proxyInfo, + 'server': { + 'startCommand': ['hysteria', '-c', testConfig['file'], 'server'], + 'fileContent': json.dumps(serverConfig), + 'filePath': testConfig['file'], + 'envVar': {} + }, + 'aider': None + } + + +def test(config: dict) -> list: + global testConfig + testConfig = copy.deepcopy(config) + if testConfig['bind'].find(':') >= 0: + testConfig['bind'] = '[' + testConfig['bind'] + ']' + + testList = [] + for protocol in hysteriaProtocolList: + testList.append(__hysteriaConfig(protocol, False, False)) + testList.append(__hysteriaConfig(protocol, False, True)) + testList.append(__hysteriaConfig(protocol, True, False)) + testList.append(__hysteriaConfig(protocol, True, True)) + return testList diff --git a/ProxyTester/tester.py b/ProxyTester/tester.py index 4041b77..240ae73 100644 --- a/ProxyTester/tester.py +++ b/ProxyTester/tester.py @@ -8,6 +8,7 @@ from ProxyTester import VLESS from ProxyTester import Trojan from ProxyTester import TrojanGo from ProxyTester import Brook +from ProxyTester import Hysteria def test(key: str, config: dict) -> list: if key in ['ss', 'shadowsocks']: @@ -24,6 +25,8 @@ def test(key: str, config: dict) -> list: testObj = TrojanGo elif key == 'brook': testObj = Brook + elif key == 'hysteria': + testObj = Hysteria else: return [] return testObj.test(config) diff --git a/Test.py b/Test.py index 379f3be..af6b85f 100644 --- a/Test.py +++ b/Test.py @@ -56,7 +56,7 @@ def testObject(option: dict) -> None: # test target object checkResult = Checker.proxyTest({ # http check 'check': ['http'], 'info': option['proxy'] - }) + }, startDelay = 0.5) print(option['caption'], end=' -> ') if not checkResult['success']: # client build error print('\n--------------------------------------------------------------------------------------------------------------------------------')