Browse Source

feat: filter of Hysteria

master
dnomd343 2 years ago
parent
commit
9bc21035ad
  1. 86
      Filter/Hysteria.py
  2. 18
      demo.py

86
Filter/Hysteria.py

@ -0,0 +1,86 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from Basis.Filter import rulesFilter
from Basis.Functions import isHost, isPort
from Basis.Constant import hysteriaProtocols
from Basis.Functions import toInt, toStr, toStrTidy, toBool
hysteriaObject = rulesFilter({
'server': {
'type': str,
'format': toStrTidy,
'filter': isHost,
'errMsg': 'Invalid server address'
},
'port': {
'type': int,
'format': toInt,
'filter': isPort,
'errMsg': 'Invalid port number'
},
'protocol': {
'optional': True,
'default': 'udp',
'type': str,
'format': lambda s: toStrTidy(s).replace('_', '-'),
'filter': lambda s: s in hysteriaProtocols,
'errMsg': 'Unknown Hysteria protocol'
},
'obfs': {
'optional': True,
'default': None,
'allowNone': True,
'type': str,
'format': toStr,
'errMsg': 'Invalid obfs content'
},
'passwd': {
'optional': True,
'default': None,
'allowNone': True,
'type': str,
'format': toStr,
'errMsg': 'Invalid password content'
},
'up': {
'optional': True,
'default': 10,
'type': int,
'format': toInt,
'filter': lambda i: i > 0,
'errMsg': 'Invalid upload speed option'
},
'down': {
'optional': True,
'default': 50,
'type': int,
'format': toInt,
'filter': lambda i: i > 0,
'errMsg': 'Invalid download speed option'
},
'sni': {
'optional': True,
'default': '',
'type': str,
'format': toStrTidy,
'errMsg': 'Invalid SNI content'
},
'alpn': {
'optional': True,
'default': None,
'allowNone': True,
'type': str,
'format': toStrTidy,
'errMsg': 'Invalid alpn option'
},
'verify': {
'optional': True,
'default': True,
'type': bool,
'format': toBool,
'errMsg': 'Invalid verify option'
}
})

18
demo.py

@ -10,6 +10,7 @@ from Filter.VLESS import vlessObject
from Filter.Trojan import trojanObject
from Filter.TrojanGo import trojanGoObject
from Filter.Brook import brookObject
from Filter.Hysteria import hysteriaObject
# pprint(ssObject, sort_dicts = False)
# pprint(ssrObject, sort_dicts = False)
@ -18,6 +19,7 @@ from Filter.Brook import brookObject
# pprint(trojanObject, sort_dicts = False)
# pprint(trojanGoObject, sort_dicts = False)
# pprint(brookObject, sort_dicts = False)
# pprint(hysteriaObject, sort_dicts = False)
# pprint(filterObject, sort_dicts = False)
ssProxy = {
@ -143,11 +145,25 @@ brookProxy = {
},
}
hysteriaProxy = {
'server': '1.1.1.1',
'port': 12345,
'protocol': 'faketcp',
'obfs': '1234',
'passwd': 'dnomd343',
'up': 100,
'down': 500,
'sni': '343.re',
'alpn': 'h3',
'verify': 'FALSE',
}
# ret = Filter(ssProxy, ssObject)
# ret = Filter(ssrProxy, ssrObject)
# ret = Filter(vmessProxy, vmessObject)
# ret = Filter(vlessProxy, vlessObject)
# ret = Filter(trojanProxy, trojanObject)
# ret = Filter(trojanGoProxy, trojanGoObject)
ret = Filter(brookProxy, brookObject)
# ret = Filter(brookProxy, brookObject)
ret = Filter(hysteriaProxy, hysteriaObject)
pprint(ret, sort_dicts = False)

Loading…
Cancel
Save