diff --git a/Filter/Brook.py b/Filter/Brook.py new file mode 100644 index 0000000..aecde39 --- /dev/null +++ b/Filter/Brook.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +from Basis.Filter import rulesFilter +from Basis.Functions import isHost, isPort +from Basis.Functions import toInt, toStr, toStrTidy, toBool + +secureObject = rulesFilter({ + 'verify': { + 'optional': True, + 'default': True, + 'type': bool, + 'format': toBool, + 'errMsg': 'Invalid verify option' + } +}) + +originObject = rulesFilter({ + 'type': { + 'type': str, + 'format': toStrTidy, + 'filter': lambda s: s == 'origin', + 'errMsg': 'Invalid Origin stream type' + }, + 'uot': { + 'optional': True, + 'default': False, + 'type': bool, + 'format': toBool, + 'errMsg': 'Invalid UoT option' + } +}) + +wsObject = rulesFilter({ + 'type': { + 'type': str, + 'format': toStrTidy, + 'filter': lambda s: s == 'ws', + 'errMsg': 'Invalid WebSocket stream type' + }, + 'host': { + 'optional': True, + 'default': '', + 'type': str, + 'format': toStrTidy, + 'errMsg': 'Invalid WebSocket host' + }, + 'path': { + 'optional': True, + 'default': '/ws', + 'type': str, + 'format': lambda s: toStr(s).strip(), + 'errMsg': 'Invalid WebSocket path' + }, + 'raw': { + 'optional': True, + 'default': False, + 'type': bool, + 'format': toBool, + 'errMsg': 'Invalid raw option' + }, + 'secure': { + 'optional': True, + 'default': None, + 'allowNone': True, + 'type': secureObject, + 'errMsg': 'Invalid secure options' + } +}) + +brookObject = rulesFilter({ + 'server': { + 'type': str, + 'format': toStrTidy, + 'filter': isHost, + 'errMsg': 'Invalid server address' + }, + 'port': { + 'type': int, + 'format': toInt, + 'filter': isPort, + 'errMsg': 'Invalid port number' + }, + 'passwd': { + 'type': str, + 'format': toStr, + 'errMsg': 'Invalid password content' + }, + 'stream': { + 'optional': True, + 'default': { + 'type': 'origin' + }, + 'multiSub': True, + 'type': { + 'origin': originObject, + 'ws': wsObject, + }, + 'errMsg': 'Invalid Brook stream' + } +}) diff --git a/demo.py b/demo.py index 0b3d3d0..941fe5d 100755 --- a/demo.py +++ b/demo.py @@ -9,6 +9,7 @@ from Filter.VMess import vmessObject from Filter.VLESS import vlessObject from Filter.Trojan import trojanObject from Filter.TrojanGo import trojanGoObject +from Filter.Brook import brookObject # pprint(ssObject, sort_dicts = False) # pprint(ssrObject, sort_dicts = False) @@ -16,6 +17,7 @@ from Filter.TrojanGo import trojanGoObject # pprint(vlessObject, sort_dicts = False) # pprint(trojanObject, sort_dicts = False) # pprint(trojanGoObject, sort_dicts = False) +# pprint(brookObject, sort_dicts = False) # pprint(filterObject, sort_dicts = False) ssProxy = { @@ -126,10 +128,26 @@ trojanGoProxy = { } } +brookProxy = { + 'server': '1.1.1.1', + 'port': 12345, + 'passwd': 'dnomd343', + 'stream': { + 'type': 'ws', + 'host': '343.re', + 'path': '/test', + 'raw': True, + 'secure': { + 'verify': ' 0' + } + }, +} + # 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(trojanGoProxy, trojanGoObject) +ret = Filter(brookProxy, brookObject) pprint(ret, sort_dicts = False) diff --git a/docs/ProxyObject/Brook.md b/docs/ProxyObject/Brook.md index d2c1fae..b78c67f 100644 --- a/docs/ProxyObject/Brook.md +++ b/docs/ProxyObject/Brook.md @@ -82,7 +82,7 @@ ### raw + 类型:*bool* -+ 说明:是否直接传输原始数据(即`--withoutBrookProtocol`) ++ 说明:传输原始数据(即 `--withoutBrookProtocol` ) + 缺省:`False` + 限制:无