Browse Source

feat: tester of Hysteria

master
Dnomd343 3 years ago
parent
commit
a68692314e
  1. 69
      ProxyTester/Hysteria.py
  2. 3
      ProxyTester/tester.py
  3. 2
      Test.py

69
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

3
ProxyTester/tester.py

@ -8,6 +8,7 @@ from ProxyTester import VLESS
from ProxyTester import Trojan from ProxyTester import Trojan
from ProxyTester import TrojanGo from ProxyTester import TrojanGo
from ProxyTester import Brook from ProxyTester import Brook
from ProxyTester import Hysteria
def test(key: str, config: dict) -> list: def test(key: str, config: dict) -> list:
if key in ['ss', 'shadowsocks']: if key in ['ss', 'shadowsocks']:
@ -24,6 +25,8 @@ def test(key: str, config: dict) -> list:
testObj = TrojanGo testObj = TrojanGo
elif key == 'brook': elif key == 'brook':
testObj = Brook testObj = Brook
elif key == 'hysteria':
testObj = Hysteria
else: else:
return [] return []
return testObj.test(config) return testObj.test(config)

2
Test.py

@ -56,7 +56,7 @@ def testObject(option: dict) -> None: # test target object
checkResult = Checker.proxyTest({ # http check checkResult = Checker.proxyTest({ # http check
'check': ['http'], 'check': ['http'],
'info': option['proxy'] 'info': option['proxy']
}) }, startDelay = 0.5)
print(option['caption'], end=' -> ') print(option['caption'], end=' -> ')
if not checkResult['success']: # client build error if not checkResult['success']: # client build error
print('\n--------------------------------------------------------------------------------------------------------------------------------') print('\n--------------------------------------------------------------------------------------------------------------------------------')

Loading…
Cancel
Save