Browse Source

feat: Builder of Trojan-Go

master
Dnomd343 3 years ago
parent
commit
e64e41dac6
  1. 76
      ProxyBuilder/TrojanGo.py
  2. 3
      ProxyBuilder/builder.py
  3. 34
      demo.py

76
ProxyBuilder/TrojanGo.py

@ -0,0 +1,76 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
import json
def __tlsConfig(proxyInfo: dict) -> dict:
tlsConfig = {
'verify': proxyInfo['verify']
}
if proxyInfo['sni'] != '':
tlsConfig['sni'] = proxyInfo['sni']
if proxyInfo['alpn'] is not None:
tlsConfig['alpn'] = proxyInfo['alpn'].split(',')
return tlsConfig
def __wsConfig(proxyInfo: dict) -> dict:
if proxyInfo['ws'] is None:
return {
'enabled': False
}
wsConfig = {
'enabled': True,
'path': proxyInfo['ws']['path']
}
if proxyInfo['ws']['host'] != '':
wsConfig['host'] = proxyInfo['ws']['host']
return wsConfig
def __ssConfig(proxyInfo: dict) -> dict:
if proxyInfo['ss'] is None:
return {
'enabled': False
}
return {
'enabled': True,
'method': proxyInfo['ss']['method'],
'password': proxyInfo['ss']['passwd']
}
def __pluginConfig(proxyInfo: dict) -> dict:
if proxyInfo['plugin'] is None:
return {
'enabled': False
}
return {
'enabled': True,
'type': 'shadowsocks',
'command': proxyInfo['plugin']['type'],
'option': proxyInfo['plugin']['param']
}
def load(proxyInfo: dict, socksPort: int, configFile: str) -> tuple[list, str, dict]:
"""
Trojan-Go配置载入
proxyInfo: 节点信息
socksPort: 本地通讯端口
configFile: 配置文件路径
return startCommand, fileContent, envVar
"""
config = {
'run_type': 'client',
'local_addr': '127.0.0.1',
'local_port': socksPort,
'remote_addr': proxyInfo['server'],
'remote_port': proxyInfo['port'],
'password': [
proxyInfo['passwd']
],
'log_level': 0,
'ssl': __tlsConfig(proxyInfo),
'websocket': __wsConfig(proxyInfo),
'shadowsocks': __ssConfig(proxyInfo),
'transport_plugin': __pluginConfig(proxyInfo)
}
return ['trojan-go', '-config', configFile], json.dumps(config), {}

3
ProxyBuilder/builder.py

@ -13,6 +13,7 @@ from ProxyBuilder import ShadowsocksR
from ProxyBuilder import VMess
from ProxyBuilder import VLESS
from ProxyBuilder import Trojan
from ProxyBuilder import TrojanGo
libcPaths = [
'/usr/lib64/libc.so.6', # CentOS
@ -107,6 +108,8 @@ def build(proxyInfo: dict, configDir: str,
clientObj = VLESS
elif proxyInfo['type'] == 'trojan': # Trojan节点
clientObj = Trojan
elif proxyInfo['type'] == 'trojan-go': # Trojan-Go节点
clientObj = TrojanGo
else: # 未知类型
return False, 'Unknown proxy type'

34
demo.py

@ -1,3 +1,4 @@
import ProxyBuilder as Builder
import ProxyDecoder as Decoder
import ProxyFilter as Filter
import Check as Checker
@ -10,20 +11,29 @@ info = {
'sni': 'local.343.re',
'alpn': 'h2',
'verify': False,
'ws': {
'host': 'local.343.re',
'path': '/test'
},
'ss': {
'method': 'chacha20-ietf-poly1305',
'passwd': 'dnomd343'
},
'plugin': {
'type': 'obfs-local',
'param': 'obfs=http'
}
# 'ws': {
# 'host': 'local.343.re',
# 'path': '/test'
# },
# 'ss': {
# 'method': 'chacha20-ietf-poly1305',
# 'passwd': 'dnomd343'
# },
# 'plugin': {
# 'type': 'obfs-local',
# 'param': 'obfs=http'
# }
}
status, ret = Filter.filte(info, isExtra = True)
print(status)
print(ret)
# Builder.build(ret, '/tmp/ProxyC')
data = Checker.proxyTest({
'check': ['http'],
'info': ret
})
print(data)

Loading…
Cancel
Save