Transport — mihomo
mihomo 把传输选项按协议分散到每个代理条目的 *-opts 块中。没有 集中化的传输结构体:传输选择由代理的 network 字段决定,对应的 选项块会被读取。
network 选择器
每个支持 TLS 的 mihomo 代理都有 network: 字段。取值:
| 取值 | 含义 |
|---|---|
tcp(默认) | 普通 TCP;忽略所有 *-opts 块。 |
ws | WebSocket —— 读 ws-opts。 |
http | 普通 HTTP 伪装(无 upgrade)—— 读 http-opts。 |
h2 | HTTP/2 —— 读 h2-opts。 |
grpc | gRPC over HTTP/2 —— 读 grpc-opts。 |
xhttp | XTLS HTTP 帧(与 Xray 兼容)—— 读 xhttp-opts。 |
部分协议额外支持其他组合(例如 Trojan 只支持 ws 与 grpc; VMess 增加 http 与 h2)。该矩阵在协议页面分别记录。
ws-opts
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
path | string | / | /<path> | WebSocket 路径。支持 `?ed=N` 早数据查询参数,与 Xray 约定一致。 |
headers | map[string]string | {} | {<header>: <value>} | upgrade 请求附加的 HTTP 头。 |
max-early-data | int | 0 | <bytes> | WS 握手完成前缓冲的最大 0-RTT 早数据字节数。 |
early-data-header-name | string | (unset) | <header name> | 服务端使用自定义头承载 base64 编码早数据时使用的头名。 |
v2ray-http-upgrade | bool | false | true | false | 使用 V2Ray HTTP-upgrade 传输替代真正 WebSocket —— 省去握手后的帧开销。 |
v2ray-http-upgrade-fast-open | bool | false | true | false | 把客户端载荷捎带在 HTTP-upgrade 请求里以省一次 RTT。 |
源码: adapter/outbound/vmess.go:94-101 · 锚定版本 v1.19.27 (5184081)
http-opts —— HTTP 伪装
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
method | string | GET | <HTTP method> | 伪装传输使用的 HTTP 方法。 |
path | []string | [/] | [/<path>] | 用于轮换的路径列表。客户端每次请求随机选一个。 |
headers | map[string][]string | {} | {<header>: [<value>]} | 头名 → 值列表的映射。客户端每次请求随机选一个值。 |
源码: adapter/outbound/vmess.go:74-78 · 锚定版本 v1.19.27 (5184081)
h2-opts —— HTTP/2
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
host | []string | [] | [<hostname>] | Host 头值列表。客户端每次请求随机选一个。 |
path | string | / | /<path> | HTTP 路径。 |
源码: adapter/outbound/vmess.go:80-83 · 锚定版本 v1.19.27 (5184081)
grpc-opts
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
grpc-service-name | string | (required) | <service name> | gRPC 服务名路径。 |
grpc-user-agent | string | (unset) | <UA string> | 覆盖 gRPC 客户端 User-Agent。 |
ping-interval | int | 0 | <seconds> | HTTP/2 PING 帧间隔。0 禁用。 |
max-connections | int | 0 | <int> | 最大并发 gRPC 通道数(mux fan-out)。 |
min-streams | int | 0 | <int> | 分配新通道前每通道的最小流数。 |
max-streams | int | 0 | <int> | 每通道的最大流数。 |
源码: adapter/outbound/vmess.go:85-92 · 锚定版本 v1.19.27 (5184081)
xhttp-opts
XHTTP 块承载 23 个字段,对应 Xray 的 SplitHTTP。最常用的是 path、host、mode,以及用于流量塑形的 x-padding-* 与会话相关 字段。复用设置位于嵌套子块 reuse-settings;非对称下行配置位于 download-settings。完整结构体(在所有支持 XHTTP 的代理间共享)见 VLESS — mihomo 页面。
示例
WebSocket —— 常见 VMess 形态:
proxies:
- name: vmess-ws
type: vmess
server: example.com
port: 443
uuid: <UUID>
cipher: auto
network: ws
tls: true
servername: example.com
ws-opts:
path: /vm
headers:
Host: example.com
max-early-data: 2048
early-data-header-name: Sec-WebSocket-ProtocolgRPC + REALITY(VLESS):
proxies:
- name: vless-grpc-reality
type: vless
server: example.com
port: 443
uuid: <UUID>
flow: xtls-rprx-vision
tls: true
servername: www.cloudflare.com
client-fingerprint: chrome
network: grpc
reality-opts:
public-key: <base64>
short-id: <hex>
grpc-opts:
grpc-service-name: GunServiceV2Ray HTTP-upgrade(WS 的低 CPU 替代):
proxies:
- name: vmess-httpupgrade
type: vmess
server: example.com
port: 443
uuid: <UUID>
cipher: auto
network: ws
tls: true
servername: example.com
ws-opts:
path: /up
v2ray-http-upgrade: true
v2ray-http-upgrade-fast-open: true说明
- mihomo 的
network: ws同时覆盖标准 WebSocket 与 V2Ray 风格的 HTTP-upgrade 传输(通过ws-opts中的v2ray-http-upgrade开关)。没有独立的network: httpupgrade取值。 network: http是 V2Ray 旧式的 HTTP 伪装(带伪方法的纯 HTTP/1.1)。不要与network: h2(真正的 HTTP/2)或network: xhttp(Xray 的现代 XTLS 帧)混淆。http-opts.path与http-opts.headers按请求随机化 —— mihomo 对每条新连接都从列表中各选一个值。ws-opts.v2ray-http-upgrade-fast-open通过把客户端载荷与 upgrade 请求一起发出节省一次 RTT。会先缓冲完整 upgrade 再回应的服务器 (部分负载均衡器)会拒绝该写法;部署前请充分测试。xhttp-opts是供需要与 Xraynetwork: splithttp服务器通信的 客户端使用的兼容路径。字段名与 Xray SplitHTTP 完全一致 (kebab-case 化)。
跨内核说明
- Xray-core 使用
streamSettings.network+ 每个传输的*Settings块。提供 TCP-with-header-obfs、mKCP、SplitHTTP 变体 (mihomo 不以同名暴露)。参见 Transport — Xray-core。 - sing-box 在每个代理上内嵌多态的
transport: { type, ... }块。参见 Transport — sing-box。
源码: adapter/outbound/vmess.go:74-101 · v1.19.27 (5184081)
