架构
RelayCore 作为一个 Rust workspace 组织,包含多个 crate,每个都有特定的职责。
高层概述
┌─────────────────────────────────────────────────────────────┐
│ ADAPTER LAYER │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────┐ │
│ │ HTTP API│ │ MCP │ │ Tauri │ │ Embedded │ │
│ └────┬────┘ └────┬────┘ └────┬────┘ └──────┬──────┘ │
│ └────────────┴─────────────┴─────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │relay-core-runtime│ │
│ │(State, Events) │ │
│ └────────┬─────────┘ │
│ │ │
└────────────────────────┼────────────────────────────────────┘
│
┌───────────────────┼───────────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────────┐ ┌──────────────┐
│ lib │ │ storage │ │ script │
│ (engine) │ │ (SQLite) │ │ (Deno/V8) │
└──────────┘ └──────────────┘ └──────────────┘ 核心 Crate
relay-core-runtime (公开)
主要 API crate。提供 CoreState 用于状态编排、代理生命周期管理、规则评估和事件分发。
relay-core-http (公开)
REST + SSE 适配器。通过 HTTP 和 JSON API 以及 Server-Sent Events 实时更新暴露 CoreState。
relay-core-probe (Beta)
MCP 适配器。为 AI 代理暴露工具,以编程方式观察和控制代理。
relay-core-cli (Beta)
带 TUI 的独立 CLI 二进制文件。提供用于运行代理和管理规则/流量的终端界面。
relay-core-lib (内部)
核心拦截引擎。处理 HTTP/HTTPS 代理、WebSocket、MITM 和 TLS 以及规则引擎。
relay-core-storage (内部)
SQLite 持久化。处理带有 LRU 缓存的流存储和审计日志。
relay-core-script (内部)
用于动态请求/响应修改的 Deno/V8 JavaScript 运行时。
数据流
- 客户端连接到代理(例如
curl --proxy http://localhost:8080 https://example.com) relay-core-lib捕获请求- 根据流评估规则
- 对于 HTTPS:MITM 拦截和解密
- 流存储在
relay-core-storage - 通过 CoreState 事件总线发布事件
- 适配器(HTTP API、MCP、CLI)可以通过 CoreState 查询/控制
配置
RelayCore 从 ~/.relay-core/config.toml 读取配置:
[proxy]
port = 8080
bind_address = "0.0.0.0"
[storage]
sqlite_path = "~/.relay-core/flows.db"
max_flows = 10000
[mcp]
enabled = true
port = 25519