Browse Source

feat: add Hysteria filter

master
Dnomd343 3 years ago
parent
commit
8b185ab00e
  1. 92
      ProxyFilter/Hysteria.py
  2. 3
      ProxyFilter/filter.py
  3. 49
      demo.py

92
ProxyFilter/Hysteria.py

@ -0,0 +1,92 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
from ProxyFilter import baseFunc
hysteriaFilterRules = {
'rootObject': {
'remark': {
'optional': False,
'default': '',
'type': str,
'format': baseFunc.toStr
},
'server': {
'optional': True,
'type': str,
'format': baseFunc.toHost,
'filter': baseFunc.isHost,
'errMsg': 'Illegal server address'
},
'port': {
'optional': True,
'type': int,
'format': baseFunc.toInt,
'filter': baseFunc.isPort,
'errMsg': 'Illegal port number'
},
'protocol': {
'optional': False,
'default': 'udp',
'type': str,
'format': baseFunc.toStr,
'filter': lambda protocol: protocol in ['udp', 'wechat-video', 'faketcp'],
'errMsg': 'Unknown Hysteria protocol'
},
'obfs': {
'optional': False,
'default': None,
'allowNone': True,
'type': str,
'format': baseFunc.toStr
},
'auth': {
'optional': False,
'default': None,
'allowNone': True,
'type': str,
'format': baseFunc.toStr
},
'sni': {
'optional': False,
'default': '',
'type': str,
'format': baseFunc.toStr
},
'alpn': {
'optional': False,
'default': None,
'allowNone': True,
'type': str,
'format': baseFunc.toStr
},
'verify': {
'optional': False,
'default': True,
'type': bool,
'format': baseFunc.toBool
}
}
}
def filte(rawInfo: dict, isExtra: bool) -> tuple[bool, str or dict]:
"""
Hysteria节点合法性检查
不合法:
return False, {reason}
合法:
return True, {
'type': 'hysteria',
...
}
"""
try:
if not isExtra: # 去除非必要参数
hysteriaFilterRules['rootObject'].pop('remark')
return baseFunc.ruleFilter(rawInfo, hysteriaFilterRules, {
'type': 'hysteria'
})
except:
return False, 'Unknown error'

3
ProxyFilter/filter.py

@ -8,6 +8,7 @@ from ProxyFilter import VLESS
from ProxyFilter import Trojan from ProxyFilter import Trojan
from ProxyFilter import TrojanGo from ProxyFilter import TrojanGo
from ProxyFilter import Brook from ProxyFilter import Brook
from ProxyFilter import Hysteria
def filte(raw: dict, isExtra: bool = False) -> tuple[bool, str or dict]: def filte(raw: dict, isExtra: bool = False) -> tuple[bool, str or dict]:
""" """
@ -40,6 +41,8 @@ def filte(raw: dict, isExtra: bool = False) -> tuple[bool, str or dict]:
return TrojanGo.trojanGoFilter(raw, isExtra) return TrojanGo.trojanGoFilter(raw, isExtra)
elif raw['type'] == 'brook': elif raw['type'] == 'brook':
return Brook.filte(raw, isExtra) return Brook.filte(raw, isExtra)
elif raw['type'] == 'hysteria':
return Hysteria.filte(raw, isExtra)
else: else:
return False, 'Unknown proxy type' return False, 'Unknown proxy type'
except: except:

49
demo.py

@ -1,24 +1,25 @@
import time import time
import ProxyBuilder as Builder import ProxyBuilder as Builder
import ProxyDecoder as Decoder import ProxyDecoder as Decoder
import ProxyFilter as Filter import ProxyFilter as Filter
import Check as Checker import Check as Checker
# url = 'brook://server?address=&insecure=&name=&password=password&server=1.2.3.4%3A9999&username=' # ret = Decoder.decode(url)
# url = 'brook://server?address=&insecure=&name=&password=password&server=%5B2001%3A4860%3A4860%3A%3A8888%5D%3A9999&username=' # print(ret)
# url = 'brook://wsserver?address=&insecure=&name=&password=password&username=&wsserver=ws%3A%2F%2F1.2.3.4%3A9999'
# url = 'brook://wsserver?address=&insecure=&name=&password=password&username=&wsserver=ws%3A%2F%2F%5B2001%3A4860%3A4860%3A%3A8888%5D%3A9999' info = {
# url = 'brook://wssserver?address=1.2.3.4%3A443&insecure=true&name=&password=password&username=&wssserver=wss%3A%2F%2Fhello.com%3A443' 'type': 'hysteria',
# url = 'brook://wsserver?address=1.2.3.4%3A443&name=&password=password&username=&wsserver=ws%3A%2F%2Fhello.com%3A443' 'server': '127.0.0.1',
'port': 443,
# url = 'ss://bf-cfb:test@192.168.100.1:8888#EXAMPLE' 'protocol': 'faketcp',
# url = 'ss://YmYtY2ZiOnRlc3QvIUAjOkAxOTIuMTY4LjEwMC4xOjg4ODg#example-server' 'obfs': 'dnomd343',
url = 'ss://cmM0LW1kNTpwYXNzd2Q@192.168.100.1:8888/?plugin=obfs-local%3Bobfs%3Dhttp#Example' 'auth': 'dnomd343',
'sni': 'local.343.re',
ret = Decoder.decode(url) 'alpn': 'h3',
print(ret) 'verify': False
}
status, ret = Filter.filte(ret, isExtra = True)
print(status) status, ret = Filter.filte(info, isExtra = True)
print(ret) print(status)
print(ret)

Loading…
Cancel
Save