Skip to content

Commit 26a03b0

Browse files
committed
fix: seed BBR with the connection's initial packet size (#1654)
1 parent bc766a2 commit 26a03b0

7 files changed

Lines changed: 27 additions & 4 deletions

File tree

app/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030

3131
require (
3232
github.com/andybalholm/brotli v1.1.0 // indirect
33-
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7 // indirect
33+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da // indirect
3434
github.com/caddyserver/zerossl v0.1.5 // indirect
3535
github.com/database64128/netx-go v0.0.0-20240905055117-62795b8b054a // indirect
3636
github.com/database64128/tfo-go/v2 v2.2.2 // indirect

app/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ github.com/apernet/quic-go v0.61.1-0.20260801004043-77a5d8509422 h1:wadOi5uenP4h
1010
github.com/apernet/quic-go v0.61.1-0.20260801004043-77a5d8509422/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
1111
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7 h1:5UR61A9dSed0FP58OoUr+1g27/7wSqkwzAS/1SirHNs=
1212
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
13+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da h1:4lAk9X1bg0LzJYX2GO8SIJgKvJGWy2jYHW5EjOW2sUc=
14+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
1315
github.com/apernet/sing-tun v0.2.6-0.20250920121535-299f04629986 h1:w62V0oOO2Do0vXeZkx7mgZ2YFuUaRcO6rNZewI3xzuE=
1416
github.com/apernet/sing-tun v0.2.6-0.20250920121535-299f04629986/go.mod h1:S5IydyLSN/QAfvY+r2GoomPJ6hidtXWm/Ad18sJVssk=
1517
github.com/caddyserver/certmagic v0.25.4 h1:8eIXh0HC3MsGnNo8One+BCxMGTbe5zb/oz+2KsxBFQg=

core/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.25.0
55
toolchain go1.25.1
66

77
require (
8-
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7
8+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da
99
github.com/stretchr/testify v1.11.1
1010
go.uber.org/goleak v1.3.0
1111
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842

core/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/apernet/quic-go v0.61.1-0.20260801004043-77a5d8509422 h1:wadOi5uenP4h
88
github.com/apernet/quic-go v0.61.1-0.20260801004043-77a5d8509422/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
99
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7 h1:5UR61A9dSed0FP58OoUr+1g27/7wSqkwzAS/1SirHNs=
1010
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
11+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da h1:4lAk9X1bg0LzJYX2GO8SIJgKvJGWy2jYHW5EjOW2sUc=
12+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
1113
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1214
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1315
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

core/internal/congestion/utils.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/apernet/hysteria/core/v2/internal/congestion/bbr"
88
"github.com/apernet/hysteria/core/v2/internal/congestion/brutal"
99
"github.com/apernet/quic-go"
10+
"github.com/apernet/quic-go/congestion"
1011
)
1112

1213
const (
@@ -36,11 +37,27 @@ func NormalizeBBRProfile(profile string) (string, error) {
3637
func UseBBR(conn *quic.Conn, profile bbr.Profile) {
3738
conn.SetCongestionControl(bbr.NewBbrSender(
3839
bbr.DefaultClock{},
39-
bbr.GetInitialPacketSize(conn.RemoteAddr()),
40+
seedPacketSize(conn.InitialPacketSize(), bbr.GetInitialPacketSize(conn.RemoteAddr())),
4041
profile,
4142
))
4243
}
4344

45+
// seedPacketSize picks the datagram size to seed a replacement congestion
46+
// controller with, given the size QUIC itself starts at and the guess derived
47+
// from the remote address.
48+
//
49+
// The seed must not exceed what QUIC actually starts at. If it does, the first
50+
// path MTU probe can land between the two: QUIC sees an increase and reports
51+
// it, but the controller sees a decrease, which it cannot represent. Taking the
52+
// smaller of the two keeps the address-based guess as a floor for connections
53+
// whose path we can't reason about, while never seeding above QUIC.
54+
func seedPacketSize(quicSize, byAddr congestion.ByteCount) congestion.ByteCount {
55+
if quicSize <= 0 {
56+
return byAddr
57+
}
58+
return min(quicSize, byAddr)
59+
}
60+
4461
func UseBrutal(conn *quic.Conn, tx uint64, disableLossCompensation bool) {
4562
conn.SetCongestionControl(brutal.NewBrutalSender(tx, disableLossCompensation))
4663
}

extras/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toolchain go1.25.1
66

77
require (
88
github.com/apernet/hysteria/core/v2 v2.0.0-00010101000000-000000000000
9-
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7
9+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da
1010
github.com/database64128/tfo-go/v2 v2.2.2
1111
github.com/hashicorp/golang-lru/v2 v2.0.7
1212
github.com/libp2p/go-nat v1.0.1-0.20250821073202-01afc089f138

extras/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/apernet/quic-go v0.61.1-0.20260801004043-77a5d8509422 h1:wadOi5uenP4h
88
github.com/apernet/quic-go v0.61.1-0.20260801004043-77a5d8509422/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
99
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7 h1:5UR61A9dSed0FP58OoUr+1g27/7wSqkwzAS/1SirHNs=
1010
github.com/apernet/quic-go v0.61.1-0.20260801011216-0ad2f221c8d7/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
11+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da h1:4lAk9X1bg0LzJYX2GO8SIJgKvJGWy2jYHW5EjOW2sUc=
12+
github.com/apernet/quic-go v0.61.1-0.20260803204750-bc12a60f32da/go.mod h1:x7qxEvX6MCVtDuBKHj3E+88+BtrbEMuAL5qGUKItjW8=
1113
github.com/database64128/netx-go v0.0.0-20240905055117-62795b8b054a h1:t4SDi0pmNkryzKdM4QF3o5vqSP4GRjeZD/6j3nyxNP0=
1214
github.com/database64128/netx-go v0.0.0-20240905055117-62795b8b054a/go.mod h1:7K2NQKbabB5mBl41vF6YayYl5g7YpDwc4dQ5iMpP3Lg=
1315
github.com/database64128/tfo-go/v2 v2.2.2 h1:BxynF4qGF5ct3DpPLEG62uyJZ3LQhqaf0Ken+kyy7PM=

0 commit comments

Comments
 (0)