哈哈哈
This commit is contained in:
@@ -14,7 +14,6 @@ from worker import config
|
||||
from worker.tasks.registry import register_all_handlers
|
||||
from worker.ws_client import WorkerWSClient
|
||||
from tunnel.client import TunnelClient
|
||||
from worker.config import get_tunnel_server_host
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
@@ -64,6 +63,16 @@ def _local_port_from_bit_api(bit_api_base: str) -> int:
|
||||
return config.TUNNEL_LOCAL_PORT
|
||||
|
||||
|
||||
def _extract_host_from_ws_url(ws_url: str) -> str:
|
||||
"""从 WebSocket URL (如 ws://8.137.99.82:9000/ws) 中提取 host。"""
|
||||
try:
|
||||
from urllib.parse import urlparse
|
||||
p = urlparse(ws_url)
|
||||
return p.hostname or "127.0.0.1"
|
||||
except Exception:
|
||||
return "127.0.0.1"
|
||||
|
||||
|
||||
async def run(args):
|
||||
# 注册所有任务处理器
|
||||
register_all_handlers()
|
||||
@@ -79,16 +88,18 @@ async def run(args):
|
||||
tunnel_enabled = config.TUNNEL_ENABLED and not args.no_tunnel
|
||||
tunnel_client = None
|
||||
if tunnel_enabled:
|
||||
# 从命令行 --server 参数中提取云服务器 host(而非配置文件默认值)
|
||||
tunnel_host = _extract_host_from_ws_url(args.server)
|
||||
tunnel_client = TunnelClient(
|
||||
server_host=get_tunnel_server_host(),
|
||||
server_host=tunnel_host,
|
||||
control_port=config.TUNNEL_CONTROL_PORT,
|
||||
stream_port=config.TUNNEL_STREAM_PORT,
|
||||
worker_id=args.worker_id,
|
||||
local_port=_local_port_from_bit_api(args.bit_api),
|
||||
)
|
||||
logger.info(
|
||||
"隧道已启用: 暴露本地 %s -> 云服务器 (worker_id=%s)",
|
||||
_local_port_from_bit_api(args.bit_api), args.worker_id,
|
||||
"隧道已启用: 暴露本地 %s -> %s (worker_id=%s)",
|
||||
_local_port_from_bit_api(args.bit_api), tunnel_host, args.worker_id,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user