Browse Source

update: trace env for ss-rust

master^2
dnomd343 2 years ago
parent
commit
412750b75c
  1. 20
      Builder/Shadowsocks.py
  2. 4
      Dockerfile
  3. 33
      Tester/Shadowsocks.py

20
Builder/Shadowsocks.py

@ -29,21 +29,21 @@ def pluginUdp(plugin: str, pluginParam: str) -> bool: # whether the plugin uses
return True # UDP is assumed by default
def ssRust(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list]:
def ssRust(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]:
config = loadConfig(proxyInfo, socksInfo)
if isUdp: # proxy UDP traffic
config['mode'] = 'tcp_and_udp'
return config, ['ss-rust-local', '-v']
return config, ['ss-rust-local', '-v'], {'RUST_BACKTRACE': 'full'}
def ssLibev(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list]:
def ssLibev(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]:
config = loadConfig(proxyInfo, socksInfo)
if isUdp: # proxy UDP traffic
config['mode'] = 'tcp_and_udp'
return config, ['ss-libev-local', '-v']
return config, ['ss-libev-local', '-v'], {}
def ssPython(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list]:
def ssPython(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]:
config = loadConfig(proxyInfo, socksInfo)
if config['method'] in mbedtlsMethods: # mbedtls methods should use prefix `mbedtls:`
config['method'] = 'mbedtls:' + config['method']
@ -52,15 +52,15 @@ def ssPython(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list]
if not isUdp:
config['no_udp'] = True # UDP traffic is not proxied
config['shadowsocks'] = 'ss-python-local'
return config, ['ss-bootstrap-local', '--debug', '-vv']
return config, ['ss-bootstrap-local', '--debug', '-vv'], {}
def ssPythonLegacy(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list]:
def ssPythonLegacy(proxyInfo: dict, socksInfo: dict, isUdp: bool) -> tuple[dict, list, dict]:
config = loadConfig(proxyInfo, socksInfo)
if not isUdp:
config['no_udp'] = True # UDP traffic is not proxied
config['shadowsocks'] = 'ss-python-legacy-local'
return config, ['ss-bootstrap-local', '--debug', '-vv']
return config, ['ss-bootstrap-local', '--debug', '-vv'], {}
def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str, dict]:
@ -72,10 +72,10 @@ def load(proxyInfo: dict, socksInfo: dict, configFile: str) -> tuple[list, str,
for client in ssMethods: # traverse all shadowsocks client
if proxyInfo['method'] not in ssMethods[client]:
continue
ssConfig, ssClient = {
ssConfig, ssClient, ssEnv = {
'ss-rust': ssRust,
'ss-libev': ssLibev,
'ss-python': ssPython,
'ss-python-legacy': ssPythonLegacy
}[client](proxyInfo, socksInfo, isUdp) # generate config file
return ssClient + ['-c', configFile], json.dumps(ssConfig), {} # command, fileContent, envVar
return ssClient + ['-c', configFile], json.dumps(ssConfig), ssEnv # command, fileContent, envVar

4
Dockerfile

@ -53,7 +53,7 @@ COPY --from=build-base /apk/ /apk/
RUN wget https://github.com/shadowsocks/shadowsocks-rust/archive/refs/tags/v${SS_RUST}.tar.gz && \
tar xf v${SS_RUST}.tar.gz && /apk/build-base
WORKDIR ./shadowsocks-rust-${SS_RUST}/
RUN cargo update
RUN cargo fetch
RUN cargo build --target-dir ./ --release --bin sslocal --bin ssserver \
--features "stream-cipher aead-cipher-extra aead-cipher-2022 aead-cipher-2022-extra" && \
mv ./release/sslocal /tmp/ss-rust-local && mv ./release/ssserver /tmp/ss-rust-server && \
@ -169,7 +169,7 @@ RUN git submodule update --init --recursive && \
mv ./src/obfs-local ./src/obfs-server /plugins/
# Compile qtun
WORKDIR ../qtun/
RUN cargo update
RUN cargo fetch
RUN cargo build --target-dir ./ --release && \
mv ./release/qtun-client ./release/qtun-server /plugins/ && \
strip /plugins/*

33
Tester/Shadowsocks.py

@ -11,7 +11,7 @@ from Basis.Test import Settings
from Basis.Logger import logging
from Basis.Process import Process
from Basis.Functions import md5Sum, genFlag, getAvailablePort
from Basis.Constant import ssMethods, ssAllMethods, mbedtlsMethods
from Basis.Constant import PathEnv, ssMethods, ssAllMethods, mbedtlsMethods
def loadConfig(proxyInfo: dict) -> dict: # load basic config option
@ -27,21 +27,28 @@ def loadConfig(proxyInfo: dict) -> dict: # load basic config option
return config
def ssRust(proxyInfo: dict, isUdp: bool) -> tuple[dict, list]:
def addPathEnv(env: dict) -> dict:
return {
**env,
'PATH': PathEnv # add PATH env
}
def ssRust(proxyInfo: dict, isUdp: bool) -> tuple[dict, list, dict]:
config = loadConfig(proxyInfo)
if isUdp: # proxy UDP traffic
config['mode'] = 'tcp_and_udp'
return config, ['ss-rust-server', '-v']
return config, ['ss-rust-server', '-v'], {'RUST_BACKTRACE': 'full'}
def ssLibev(proxyInfo: dict, isUdp: bool) -> tuple[dict, list]:
def ssLibev(proxyInfo: dict, isUdp: bool) -> tuple[dict, list, dict]:
config = loadConfig(proxyInfo)
if isUdp: # proxy UDP traffic
config['mode'] = 'tcp_and_udp'
return config, ['ss-libev-server', '-v']
return config, ['ss-libev-server', '-v'], {}
def ssPython(proxyInfo: dict, isUdp: bool) -> tuple[dict, list]:
def ssPython(proxyInfo: dict, isUdp: bool) -> tuple[dict, list, dict]:
config = loadConfig(proxyInfo)
if config['method'] in mbedtlsMethods: # mbedtls methods should use prefix `mbedtls:`
config['method'] = 'mbedtls:' + config['method']
@ -50,15 +57,15 @@ def ssPython(proxyInfo: dict, isUdp: bool) -> tuple[dict, list]:
if not isUdp:
config['no_udp'] = True # UDP traffic is not proxied
config['shadowsocks'] = 'ss-python-server'
return config, ['ss-bootstrap-server', '--debug', '-vv']
return config, ['ss-bootstrap-server', '--debug', '-vv'], {}
def ssPythonLegacy(proxyInfo: dict, isUdp: bool) -> tuple[dict, list]:
def ssPythonLegacy(proxyInfo: dict, isUdp: bool) -> tuple[dict, list, dict]:
config = loadConfig(proxyInfo)
if not isUdp:
config['no_udp'] = True # UDP traffic is not proxied
config['shadowsocks'] = 'ss-python-legacy-server'
return config, ['ss-bootstrap-server', '--debug', '-vv']
return config, ['ss-bootstrap-server', '--debug', '-vv'], {}
def loadPassword(method: str) -> str:
@ -71,7 +78,7 @@ def loadPassword(method: str) -> str:
def loadClient(ssType: str, configFile: str, proxyInfo: dict, socksInfo: dict) -> Process:
ssConfig, ssClient = { # generate client start command and its config file
ssConfig, ssClient, ssEnv = { # generate client start command and its config file
'ss-rust': Shadowsocks.ssRust,
'ss-libev': Shadowsocks.ssLibev,
'ss-python': Shadowsocks.ssPython,
@ -81,11 +88,11 @@ def loadClient(ssType: str, configFile: str, proxyInfo: dict, socksInfo: dict) -
return Process(Settings['workDir'], cmd = ssClient + ['-c', clientFile], file = { # load client process
'path': clientFile,
'content': json.dumps(ssConfig)
}, isStart = False)
}, env = addPathEnv(ssEnv), isStart = False)
def loadServer(ssType: str, configFile: str, proxyInfo: dict) -> Process:
ssConfig, ssServer = { # generate server start command and its config file
ssConfig, ssServer, ssEnv = { # generate server start command and its config file
'ss-rust': ssRust,
'ss-libev': ssLibev,
'ss-python': ssPython,
@ -95,7 +102,7 @@ def loadServer(ssType: str, configFile: str, proxyInfo: dict) -> Process:
return Process(Settings['workDir'], cmd = ssServer + ['-c', serverFile], file = { # load server process
'path': serverFile,
'content': json.dumps(ssConfig)
}, isStart = False)
}, env = addPathEnv(ssEnv), isStart = False)
def loadTest(serverType: str, clientType: str, method: str, plugin: dict or None = None) -> dict:

Loading…
Cancel
Save