Skip to content

Hysteria2:Brutal 协商与官方实现不一致,服务端未设 brutalUp 时忽略客户端声明的下行 #7353

Closed

Description

@driftray

完整性要求

  • 我读完了 issue 模板中的所有注释,确保填写符合要求。
  • 我保证阅读了文档,了解所有我编写的配置文件项的含义,而不是大量堆砌看似有用的选项或默认值。
  • 我提供了完整的配置文件和日志,而不是出于自己的判断只给出截取的部分。
  • 我搜索了 issues, 没有发现已提出的类似问题。
  • 问题在 Release 最新的版本上可以成功复现

描述

Xray 的 Hysteria2 在默认 brutal 模式下,Brutal 的启用条件和官方 Hysteria 不一致。

官方实现(依据 app/v2.13.0 源码,未运行官方程序实测):

  • 服务端:客户端声明了下行就使用 Brutal,服务端配置了上限时取较小值(server.go#L178-L196)。
  • 客户端:服务端的 Rx 为 0 时,按客户端自己的上行使用 Brutal(client.go#L149-L162)。

Xray 的两端都要求 quicParams.BrutalUp 和对端声明的值同时不为 0,否则使用 BBR(hub.go#L78-L83、dialer.go#L207-L212)。

结果是服务端未配置 brutalUp 时,客户端声明的下行不起作用,下载方向使用 BBR;服务端未配置 brutalDown 时,Xray 客户端上传也使用 BBR。FinalMask 文档也说明协商行为和 Hysteria brutal 一致,服务端为 0 表示不限制客户端。

建议和官方保持一致:

  • 服务端:对端声明的下行为 0 时使用 BBR;否则按该值使用 Brutal,brutalUp 不为 0 时作为上限。
  • 客户端:brutalUp 为 0 时使用 BBR;否则按 brutalUp 使用 Brutal,服务端的 Rx 不为 0 时作为上限。

如果当前行为是有意设计,也请更新文档。

重现方式

Xray 26.10.31 (a4a3dff, linux/amd64)。服务端和客户端运行在同一台机器上,经 127.0.0.1 传输。证书是 openssl 生成的 ECDSA P-256 自签证书。

本地启动一个 HTTP 测速服务(127.0.0.1:18081),分别测 4 秒下载和上传:

curl -o /dev/null -m 4 --socks5-hostname 127.0.0.1:18080 http://127.0.0.1:18081/
curl -o /dev/null -m 4 --socks5-hostname 127.0.0.1:18080 -T up.bin http://127.0.0.1:18081/up

日志里没有拥塞算法的信息,这里按速率判断:这台机器 BBR 约 150 Mbps,Brutal 组被限制在 20 Mbps 以下。下表各组只有 finalmask.quicParams 不同。

服务端 quicParams 客户端 quicParams 官方实现(按源码) Xray 下载 (Mbps) Xray 上传 (Mbps) Xray 实际
无 无 两向 BBR 167.3 130.1 两向 BBR
无 brutalDown: 20 mbps 下载 Brutal 20 163.0 161.1 两向 BBR
brutalUp: 40 mbps brutalDown: 20 mbps 下载 Brutal 20 11.9 182.6 下载 Brutal
brutalUp: 20 mbps brutalDown: 80 mbps 下载 Brutal 20 11.6 156.3 下载 Brutal
brutalUp: 20 mbps 无 两向 BBR 145.0 154.8 两向 BBR
无 brutalUp: 20 mbps 上传 Brutal 20 171.0 163.2 两向 BBR
brutalDown: 20 mbps brutalUp: 40 mbps 上传 Brutal 20 149.5 18.2 上传 Brutal
无 brutalUp、brutalDown 均为 20 mbps 两向 Brutal 20 164.6 176.6 两向 BBR

下方的配置和日志对应最后一行。

客户端配置

Details

{
  "log": {"loglevel": "debug", "dnsLog": true},
  "inbounds": [{
    "listen": "127.0.0.1", "port": 18080, "protocol": "socks",
    "settings": {"udp": false}
  }],
  "outbounds": [{
    "protocol": "hysteria",
    "settings": {"version": 2, "address": "127.0.0.1", "port": 18443},
    "streamSettings": {
      "network": "hysteria",
      "security": "tls",
      "tlsSettings": {
        "serverName": "t.example.com",
        "alpn": ["h3"],
        "pinnedPeerCertSha256": "e88633993fae4d3e57babbcf6ccbf3dbebde37d3591fca6c9251e491a931eaca"
      },
      "hysteriaSettings": {"version": 2, "auth": "t3st"},
      "finalmask": {"quicParams": {"brutalUp": "20 mbps", "brutalDown": "20 mbps"}}
    }
  }]
}

服务端配置

Details

{
  "log": {"loglevel": "debug", "dnsLog": true},
  "inbounds": [{
    "listen": "127.0.0.1", "port": 18443, "protocol": "hysteria",
    "settings": {"version": 2, "users": [{"auth": "t3st", "email": "a@t"}]},
    "streamSettings": {
      "network": "hysteria",
      "security": "tls",
      "tlsSettings": {
        "alpn": ["h3"],
        "certificates": [{"certificateFile": "/tmp/hy2-test/c.pem", "keyFile": "/tmp/hy2-test/k.pem"}]
      },
      "hysteriaSettings": {"version": 2, "udpIdleTimeout": 60}
    }
  }],
  "outbounds": [{"protocol": "freedom", "settings": {"finalRules": [{"action": "allow"}]}}]
}

客户端日志

Details

Xray 26.10.31 (Xray, Penetrates Everything.) a4a3dff (go1.27.3 linux/amd64)
A unified platform for anti-censorship.
2026/11/09 03:33:33.206432 [Info] infra/conf/serial: Reading config: &{Name:c.json Format:json}
2026/11/09 03:33:33.207335 [Debug] app/log: Logger started
2026/11/09 03:33:33.207525 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:18080
2026/11/09 03:33:33.207764 [Info] transport/internet/tcp: listening tcp on 127.0.0.1:18080
2026/11/09 03:33:33.208457 [Warning] core: Xray 26.10.31 started
2026/11/09 03:33:34.641317 [Info] [2569907973] proxy/socks: TCP Connect request to tcp:127.0.0.1:18081
2026/11/09 03:33:34.641352 [Info] [2569907973] app/dispatcher: default route for tcp:127.0.0.1:18081
2026/11/09 03:33:34.641398 from tcp:127.0.0.1:53148 accepted tcp:127.0.0.1:18081
2026/11/09 03:33:34.643335 [Debug] [2569907973] transport/internet: dialing to udp:127.0.0.1:18443
2026/11/09 03:33:34.648986 [Debug] transport/internet/hysteria: ECHAccepted false
2026/11/09 03:33:34.649017 [Info] [2569907973] proxy/hysteria: tunneling request to tcp:127.0.0.1:18081 via TCP:127.0.0.1:18443
2026/11/09 03:33:38.693126 [Info] [2569907973] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/hysteria: connection ends > write tcp 127.0.0.1:18080->127.0.0.1:53148: write: broken pipe
2026/11/09 03:33:38.704641 [Info] [237567497] proxy/socks: TCP Connect request to tcp:127.0.0.1:18081
2026/11/09 03:33:38.704673 [Info] [237567497] app/dispatcher: default route for tcp:127.0.0.1:18081
2026/11/09 03:33:38.704683 from tcp:127.0.0.1:53156 accepted tcp:127.0.0.1:18081
2026/11/09 03:33:38.704685 [Info] [237567497] proxy/hysteria: tunneling request to tcp:127.0.0.1:18081 via TCP:127.0.0.1:18443

服务端日志

Details

Xray 26.10.31 (Xray, Penetrates Everything.) a4a3dff (go1.27.3 linux/amd64)
A unified platform for anti-censorship.
2026/11/09 03:33:33.210114 [Info] infra/conf/serial: Reading config: &{Name:s.json Format:json}
2026/11/09 03:33:33.213321 [Debug] app/log: Logger started
2026/11/09 03:33:33.213346 [Debug] app/proxyman/inbound: creating stream worker on 127.0.0.1:18443
2026/11/09 03:33:33.216100 [Warning] core: Xray 26.10.31 started
2026/11/09 03:33:34.649568 [Info] [2020976812] proxy/hysteria: tunnelling request to tcp:127.0.0.1:18081
2026/11/09 03:33:34.649699 [Info] [2020976812] app/dispatcher: default route for tcp:127.0.0.1:18081
2026/11/09 03:33:34.649708 [Info] [2020976812] transport/internet/tcp: dialing TCP to tcp:127.0.0.1:18081
2026/11/09 03:33:34.649712 [Debug] [2020976812] transport/internet: dialing to tcp:127.0.0.1:18081
2026/11/09 03:33:34.649861 from 127.0.0.1:34887 accepted tcp:127.0.0.1:18081 email: a@t
2026/11/09 03:33:34.650097 [Info] [2020976812] proxy/freedom: connection opened to tcp:127.0.0.1:18081, local endpoint 127.0.0.1:34754, remote endpoint 127.0.0.1:18081
2026/11/09 03:33:34.650108 [Debug] [2020976812] proxy: CopyRawConn (maybe) readv
2026/11/09 03:33:38.693985 [Info] [2020976812] app/proxyman/outbound: app/proxyman/outbound: failed to process outbound traffic > proxy/freedom: connection ends > proxy: failed to process response > stream 4 canceled by remote with error co(此行输出被截断)
2026/11/09 03:33:38.705195 [Info] [1332442071] proxy/hysteria: tunnelling request to tcp:127.0.0.1:18081
2026/11/09 03:33:38.705255 [Info] [1332442071] app/dispatcher: default route for tcp:127.0.0.1:18081
2026/11/09 03:33:38.705284 [Info] [1332442071] transport/internet/tcp: dialing TCP to tcp:127.0.0.1:18081
2026/11/09 03:33:38.705292 [Debug] [1332442071] transport/internet: dialing to tcp:127.0.0.1:18081
2026/11/09 03:33:38.705348 from 127.0.0.1:34887 accepted tcp:127.0.0.1:18081 email: a@t
2026/11/09 03:33:38.705438 [Info] [1332442071] proxy/freedom: connection opened to tcp:127.0.0.1:18081, local endpoint 127.0.0.1:34762, remote endpoint 127.0.0.1:18081
2026/11/09 03:33:38.705448 [Debug] [1332442071] proxy: CopyRawConn (maybe) readv
2026/11/09 03:33:42.795475 [Debug] app/log: Logger closing

Activity

  1. LjhAUMEM commented on Nov 9, 2026

    @LjhAUMEM
    Contributor

    感谢反馈,顺便更新下2.13

  2. LjhAUMEM commented on Nov 9, 2026

    @LjhAUMEM
    Contributor

    Brutal 组被限制在 20 Mbps 以下

    还可以当限速器使用,好思路

  3. driftray commented on Nov 9, 2026

    @driftray
    Author

    感谢!

    还需要改一下客户端的 dialer.go:服务端未设置 brutalDown 时,客户端设置了 brutalUp 仍会回落 BBR,而官方客户端在这种情况下会按客户端设置的上行使用 Brutal。

    https://github.com/XTLS/Xray-core/blob/v26.11.9/transport/internet/hysteria/dialer.go#L207-L212

  4. LjhAUMEM commented on Nov 10, 2026

    @LjhAUMEM
    Contributor

    done,其实就是反过来

    客户端

    if tx == 0 {
    	congestion.UseBBR(conn, bbr.Profile(quicParams.BbrProfile))
    } else {
    	if remote_rx > 0 {
    		tx = min(tx, remote_rx)
    	}
    	congestion.UseBrutal(conn, tx, quicParams.BrutalDisableLossCompensation)
    }

    服务端

    if remote_rx == 0 {
    	congestion.UseBBR(conn, bbr.Profile(quicParams.BbrProfile))
    } else {
    	if tx > 0 {
    		remote_rx = min(remote_rx, tx)
    	}
    	congestion.UseBrutal(conn, remote_rx, quicParams.BrutalDisableLossCompensation)
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions