Browse Source

feat: builder of Trojan-Go

master
dnomd343 2 years ago
parent
commit
5e5e208c27
  1. 64
      Builder/TrojanGo.py
  2. 2
      Builder/__init__.py
  3. 24
      demo.py

64
Builder/TrojanGo.py

@ -0,0 +1,64 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
def sslConfig(proxyInfo: dict) -> dict:
return {**{
'verify': proxyInfo['verify']
}, **({} if proxyInfo['sni'] == '' else {
'sni': proxyInfo['sni']
}), **({} if proxyInfo['alpn'] is None else {
'alpn': proxyInfo['alpn'].split(',')
})}
def wsConfig(proxyInfo: dict) -> dict:
if proxyInfo['ws'] is None:
return {'enabled': False}
wsObject = {
'enabled': True,
'path': proxyInfo['ws']['path']
}
if proxyInfo['ws']['host'] != '':
wsObject['host'] = proxyInfo['ws']['host']
return wsObject
def ssConfig(proxyInfo: dict) -> dict:
return {**{
'enabled': False if proxyInfo['ss'] is None else True
}, **({} if proxyInfo['ss'] is None else {
'method': proxyInfo['ss']['method'],
'password': proxyInfo['ss']['passwd'],
})}
def pluginConfig(proxyInfo: dict) -> dict:
return {**{
'enabled': False if proxyInfo['plugin'] is None else True
}, **({} if proxyInfo['plugin'] is None else {
'type': 'shadowsocks',
'command': proxyInfo['plugin']['type'],
'option': proxyInfo['plugin']['param'],
})}
def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]:
trojanGoConfig = {
'run_type': 'client',
'local_addr': socksInfo['addr'],
'local_port': socksInfo['port'],
'remote_addr': proxyInfo['server'],
'remote_port': proxyInfo['port'],
'password': [
proxyInfo['passwd']
],
'log_level': 0, # 0 -> debug level
'ssl': sslConfig(proxyInfo),
'websocket': wsConfig(proxyInfo),
'shadowsocks': ssConfig(proxyInfo),
'transport_plugin': pluginConfig(proxyInfo)
}
return ['trojan-go', '-config', configFile], json.dumps(trojanGoConfig), {}

2
Builder/__init__.py

@ -7,6 +7,7 @@ import copy
from Builder import VMess from Builder import VMess
from Builder import VLESS from Builder import VLESS
from Builder import Trojan from Builder import Trojan
from Builder import TrojanGo
from Builder import Shadowsocks from Builder import Shadowsocks
from Builder import ShadowsocksR from Builder import ShadowsocksR
@ -21,6 +22,7 @@ clientEntry = {
'vmess': [VMess.load, '.json'], 'vmess': [VMess.load, '.json'],
'vless': [VLESS.load, '.json'], 'vless': [VLESS.load, '.json'],
'trojan': [Trojan.load, '.json'], 'trojan': [Trojan.load, '.json'],
'trojan-go': [TrojanGo.load, '.json'],
} }

24
demo.py

@ -76,11 +76,33 @@ proxyTrojan = {
} }
} }
proxyTrojanGo = {
'server': '127.0.0.1',
'port': 12345,
'passwd': 'dnomd343',
'sni': '343.re',
'alpn': None,
'verify': True,
'ws': {
'host': '343.re',
'path': '/test',
},
'ss': {
'method': 'AES-128-GCM',
'passwd': 'dnomd343',
},
'plugin': {
'type': 'obfs-local',
'param': 'obfs=http;obfs-host=www.bing.com'
},
}
# client = Builder('ss', proxySS) # client = Builder('ss', proxySS)
# client = Builder('ssr', proxySSR) # client = Builder('ssr', proxySSR)
# client = Builder('vmess', proxyVMess) # client = Builder('vmess', proxyVMess)
# client = Builder('vless', proxyVLESS) # client = Builder('vless', proxyVLESS)
client = Builder('trojan', proxyTrojan) # client = Builder('trojan', proxyTrojan)
client = Builder('trojan-go', proxyTrojanGo)
logging.critical(client.id) logging.critical(client.id)
logging.critical(client.proxyType) logging.critical(client.proxyType)

Loading…
Cancel
Save