Browse Source

fix: IPv6 for Brook

master
Dnomd343 3 years ago
parent
commit
d0d767a757
  1. 2
      ProxyFilter/Brook.py
  2. 7
      ProxyFilter/baseFunc.py
  3. 14
      ProxyTester/Brook.py
  4. 3
      Test.py

2
ProxyFilter/Brook.py

@ -14,7 +14,7 @@ brookFilterRules = {
'server': { 'server': {
'optional': True, 'optional': True,
'type': str, 'type': str,
'format': baseFunc.toStrTidy, 'format': baseFunc.toHost,
'filter': baseFunc.isHost, 'filter': baseFunc.isHost,
'errMsg': 'Illegal server address' 'errMsg': 'Illegal server address'
}, },

7
ProxyFilter/baseFunc.py

@ -127,6 +127,13 @@ def toStrTidy(raw) -> str: # change to str with trim and lower
return toStr(raw).strip().lower() return toStr(raw).strip().lower()
def toHost(raw) -> str: # format to IP address or domain
raw = toStrTidy(raw)
if raw[:1] == '[' and raw[-1:] == ']': # [IPv6]
raw = raw[1:-1]
return raw
class filterException(Exception): # 检测异常 class filterException(Exception): # 检测异常
def __init__(self, reason): def __init__(self, reason):
self.reason = reason self.reason = reason

14
ProxyTester/Brook.py

@ -1,6 +1,8 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import copy
testConfig = {} testConfig = {}
def __originConfig() -> dict: def __originConfig() -> dict:
@ -8,7 +10,7 @@ def __originConfig() -> dict:
'caption': 'Brook original', 'caption': 'Brook original',
'client': { 'client': {
'type': 'brook', 'type': 'brook',
'server': testConfig['host'], 'server': testConfig['bind'],
'port': testConfig['port'], 'port': testConfig['port'],
'passwd': testConfig['passwd'] 'passwd': testConfig['passwd']
}, },
@ -25,7 +27,7 @@ def __wsConfig() -> dict:
'caption': 'Brook websocket', 'caption': 'Brook websocket',
'client': { 'client': {
'type': 'brook', 'type': 'brook',
'server': testConfig['host'], 'server': testConfig['bind'],
'port': testConfig['port'], 'port': testConfig['port'],
'passwd': testConfig['passwd'], 'passwd': testConfig['passwd'],
'ws': { 'ws': {
@ -47,7 +49,7 @@ def __wssConfig() -> dict:
'caption': 'Brook websocket with TLS', 'caption': 'Brook websocket with TLS',
'client': { 'client': {
'type': 'brook', 'type': 'brook',
'server': testConfig['host'], 'server': testConfig['bind'],
'port': testConfig['port'], 'port': testConfig['port'],
'passwd': testConfig['passwd'], 'passwd': testConfig['passwd'],
'ws': { 'ws': {
@ -60,7 +62,7 @@ def __wssConfig() -> dict:
}, },
'server': [ 'server': [
'brook', 'wssserver', 'brook', 'wssserver',
'--domainaddress', testConfig['host'] + ':' + str(testConfig['port']), '--domainaddress', testConfig['bind'] + ':' + str(testConfig['port']),
'--cert', testConfig['cert'], '--cert', testConfig['cert'],
'--certkey', testConfig['key'], '--certkey', testConfig['key'],
'--password', testConfig['passwd'], '--password', testConfig['passwd'],
@ -85,7 +87,9 @@ def __brookConfig(brookConfig: dict) -> dict:
def test(config: dict) -> list: def test(config: dict) -> list:
global testConfig global testConfig
testConfig = config testConfig = copy.deepcopy(config)
if testConfig['bind'].find(':') >= 0:
testConfig['bind'] = '[' + testConfig['bind'] + ']'
return [ return [
__brookConfig(__originConfig()), __brookConfig(__originConfig()),
__brookConfig(__wsConfig()), __brookConfig(__wsConfig()),

3
Test.py

@ -15,7 +15,8 @@ testConfig = {
'passwd': 'dnomd343', 'passwd': 'dnomd343',
'host': 'local.343.re', 'host': 'local.343.re',
'path': '/test', 'path': '/test',
'bind': '127.0.0.1', 'bind': '::1',
# 'bind': '127.0.0.1',
'service': 'dnomd343', 'service': 'dnomd343',
'file': '/tmp/proxycTest.json', 'file': '/tmp/proxycTest.json',
'cert': '/etc/ssl/certs/343.re/fullchain.pem', 'cert': '/etc/ssl/certs/343.re/fullchain.pem',

Loading…
Cancel
Save