chore: adjustable cwnd for cc in quic

This commit is contained in:
Larvan2 2023-06-18 00:47:26 +08:00
parent 61734e5cac
commit 6c8631d5cc
7 changed files with 101 additions and 86 deletions

View file

@ -49,6 +49,7 @@ type TuicOption struct {
FastOpen bool `proxy:"fast-open,omitempty"` FastOpen bool `proxy:"fast-open,omitempty"`
MaxOpenStreams int `proxy:"max-open-streams,omitempty"` MaxOpenStreams int `proxy:"max-open-streams,omitempty"`
CWND int `proxy:"cwnd,omitempty"`
SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"` SkipCertVerify bool `proxy:"skip-cert-verify,omitempty"`
Fingerprint string `proxy:"fingerprint,omitempty"` Fingerprint string `proxy:"fingerprint,omitempty"`
CustomCA string `proxy:"ca,omitempty"` CustomCA string `proxy:"ca,omitempty"`
@ -188,6 +189,10 @@ func NewTuic(option TuicOption) (*Tuic, error) {
option.MaxOpenStreams = 100 option.MaxOpenStreams = 100
} }
if option.CWND == 0 {
option.CWND = 32
}
packetOverHead := tuic.PacketOverHeadV4 packetOverHead := tuic.PacketOverHeadV4
if len(option.Token) == 0 { if len(option.Token) == 0 {
packetOverHead = tuic.PacketOverHeadV5 packetOverHead = tuic.PacketOverHeadV5
@ -272,6 +277,7 @@ func NewTuic(option TuicOption) (*Tuic, error) {
MaxUdpRelayPacketSize: option.MaxUdpRelayPacketSize, MaxUdpRelayPacketSize: option.MaxUdpRelayPacketSize,
FastOpen: option.FastOpen, FastOpen: option.FastOpen,
MaxOpenStreams: clientMaxOpenStreams, MaxOpenStreams: clientMaxOpenStreams,
CWND: option.CWND,
} }
t.client = tuic.NewPoolClientV4(clientOption) t.client = tuic.NewPoolClientV4(clientOption)
@ -286,6 +292,7 @@ func NewTuic(option TuicOption) (*Tuic, error) {
ReduceRtt: option.ReduceRtt, ReduceRtt: option.ReduceRtt,
MaxUdpRelayPacketSize: option.MaxUdpRelayPacketSize, MaxUdpRelayPacketSize: option.MaxUdpRelayPacketSize,
MaxOpenStreams: clientMaxOpenStreams, MaxOpenStreams: clientMaxOpenStreams,
CWND: option.CWND,
} }
t.client = tuic.NewPoolClientV5(clientOption) t.client = tuic.NewPoolClientV5(clientOption)

View file

@ -129,7 +129,6 @@ sniffer:
# 默认嗅探 80 # 默认嗅探 80
HTTP: # 需要嗅探的端口 HTTP: # 需要嗅探的端口
ports: [80, 8080-8880] ports: [80, 8080-8880]
# 可覆盖 sniffer.override-destination # 可覆盖 sniffer.override-destination
override-destination: true override-destination: true
@ -152,7 +151,6 @@ sniffer:
- "443" - "443"
# - 8000-9999 # - 8000-9999
tunnels: # one line config tunnels: # one line config
- tcp/udp,127.0.0.1:6553,114.114.114.114:53,proxy - tcp/udp,127.0.0.1:6553,114.114.114.114:53,proxy
- tcp,127.0.0.1:6666,rds.mysql.com:3306,vpn - tcp,127.0.0.1:6666,rds.mysql.com:3306,vpn
@ -162,7 +160,6 @@ tunnels: # one line config
target: target.com target: target.com
proxy: proxy proxy: proxy
# DNS配置 # DNS配置
dns: dns:
enable: false # 关闭将使用系统 DNS enable: false # 关闭将使用系统 DNS
@ -364,11 +361,13 @@ proxies: # socks5
port: 443 port: 443
cipher: chacha20-ietf-poly1305 cipher: chacha20-ietf-poly1305
password: [YOUR_SS_PASSWORD] password: [YOUR_SS_PASSWORD]
client-fingerprint: chrome # One of: chrome, ios, firefox or safari client-fingerprint:
chrome # One of: chrome, ios, firefox or safari
# 可以是chrome, ios, firefox, safari中的一个 # 可以是chrome, ios, firefox, safari中的一个
plugin: restls plugin: restls
plugin-opts: plugin-opts:
host: "www.microsoft.com" # Must be a TLS 1.3 server host:
"www.microsoft.com" # Must be a TLS 1.3 server
# 应当是一个TLS 1.3 服务器 # 应当是一个TLS 1.3 服务器
password: [YOUR_RESTLS_PASSWORD] password: [YOUR_RESTLS_PASSWORD]
version-hint: "tls13" version-hint: "tls13"
@ -385,11 +384,13 @@ proxies: # socks5
port: 443 port: 443
cipher: chacha20-ietf-poly1305 cipher: chacha20-ietf-poly1305
password: [YOUR_SS_PASSWORD] password: [YOUR_SS_PASSWORD]
client-fingerprint: chrome # One of: chrome, ios, firefox or safari client-fingerprint:
chrome # One of: chrome, ios, firefox or safari
# 可以是chrome, ios, firefox, safari中的一个 # 可以是chrome, ios, firefox, safari中的一个
plugin: restls plugin: restls
plugin-opts: plugin-opts:
host: "vscode.dev" # Must be a TLS 1.2 server host:
"vscode.dev" # Must be a TLS 1.2 server
# 应当是一个TLS 1.2 服务器 # 应当是一个TLS 1.2 服务器
password: [YOUR_RESTLS_PASSWORD] password: [YOUR_RESTLS_PASSWORD]
version-hint: "tls12" version-hint: "tls12"
@ -674,6 +675,7 @@ proxies: # socks5
request-timeout: 8000 request-timeout: 8000
udp-relay-mode: native # Available: "native", "quic". Default: "native" udp-relay-mode: native # Available: "native", "quic". Default: "native"
# congestion-controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic" # congestion-controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
# cwnd: 10 # default: 32
# max-udp-relay-packet-size: 1500 # max-udp-relay-packet-size: 1500
# fast-open: true # fast-open: true
# skip-cert-verify: true # skip-cert-verify: true
@ -967,7 +969,6 @@ listeners:
# - com.android.chrome # - com.android.chrome
# exclude_package: # 排除被路由的 Android 应用包名 # exclude_package: # 排除被路由的 Android 应用包名
# - com.android.captiveportallogin # - com.android.captiveportallogin
# 入口配置与 Listener 等价,传入流量将和 socks,mixed 等入口一样按照 mode 所指定的方式进行匹配处理 # 入口配置与 Listener 等价,传入流量将和 socks,mixed 等入口一样按照 mode 所指定的方式进行匹配处理
# shadowsocks,vmess 入口配置传入流量将和socks,mixed等入口一样按照mode所指定的方式进行匹配处理 # shadowsocks,vmess 入口配置传入流量将和socks,mixed等入口一样按照mode所指定的方式进行匹配处理
# ss-config: ss://2022-blake3-aes-256-gcm:vlmpIPSyHH6f4S8WVPdRIHIlzmB+GIRfoH3aNJ/t9Gg=@:23456 # ss-config: ss://2022-blake3-aes-256-gcm:vlmpIPSyHH6f4S8WVPdRIHIlzmB+GIRfoH3aNJ/t9Gg=@:23456

View file

@ -4,6 +4,7 @@ import (
"github.com/Dreamacro/clash/transport/tuic/congestion" "github.com/Dreamacro/clash/transport/tuic/congestion"
"github.com/metacubex/quic-go" "github.com/metacubex/quic-go"
c "github.com/metacubex/quic-go/congestion"
) )
const ( const (
@ -11,7 +12,8 @@ const (
DefaultConnectionReceiveWindow = 67108864 // 64 MB/s DefaultConnectionReceiveWindow = 67108864 // 64 MB/s
) )
func SetCongestionController(quicConn quic.Connection, cc string) { func SetCongestionController(quicConn quic.Connection, cc string, cwnd int) {
CWND := c.ByteCount(cwnd)
switch cc { switch cc {
case "cubic": case "cubic":
quicConn.SetCongestionControl( quicConn.SetCongestionControl(
@ -36,7 +38,7 @@ func SetCongestionController(quicConn quic.Connection, cc string) {
congestion.NewBBRSender( congestion.NewBBRSender(
congestion.DefaultClock{}, congestion.DefaultClock{},
congestion.GetInitialPacketSize(quicConn.RemoteAddr()), congestion.GetInitialPacketSize(quicConn.RemoteAddr()),
congestion.InitialCongestionWindow*congestion.InitialMaxDatagramSize, CWND*congestion.InitialMaxDatagramSize,
congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize, congestion.DefaultBBRMaxCongestionWindow*congestion.InitialMaxDatagramSize,
), ),
) )

View file

@ -36,6 +36,7 @@ type ClientOption struct {
MaxUdpRelayPacketSize int MaxUdpRelayPacketSize int
FastOpen bool FastOpen bool
MaxOpenStreams int64 MaxOpenStreams int64
CWND int
} }
type clientImpl struct { type clientImpl struct {
@ -91,7 +92,7 @@ func (t *clientImpl) getQuicConn(ctx context.Context, dialer C.Dialer, dialFn co
return nil, err return nil, err
} }
common.SetCongestionController(quicConn, t.CongestionController) common.SetCongestionController(quicConn, t.CongestionController, t.CWND)
go func() { go func() {
_ = t.sendAuthentication(quicConn) _ = t.sendAuthentication(quicConn)

View file

@ -33,6 +33,7 @@ type ServerOption struct {
CongestionController string CongestionController string
AuthenticationTimeout time.Duration AuthenticationTimeout time.Duration
MaxUdpRelayPacketSize int MaxUdpRelayPacketSize int
CWND int
} }
type Server struct { type Server struct {
@ -57,7 +58,7 @@ func (s *Server) Serve() error {
if err != nil { if err != nil {
return err return err
} }
common.SetCongestionController(conn, s.CongestionController) common.SetCongestionController(conn, s.CongestionController, s.CWND)
h := &serverHandler{ h := &serverHandler{
Server: s, Server: s,
quicConn: conn, quicConn: conn,

View file

@ -33,6 +33,7 @@ type ClientOption struct {
ReduceRtt bool ReduceRtt bool
MaxUdpRelayPacketSize int MaxUdpRelayPacketSize int
MaxOpenStreams int64 MaxOpenStreams int64
CWND int
} }
type clientImpl struct { type clientImpl struct {
@ -88,7 +89,7 @@ func (t *clientImpl) getQuicConn(ctx context.Context, dialer C.Dialer, dialFn co
return nil, err return nil, err
} }
common.SetCongestionController(quicConn, t.CongestionController) common.SetCongestionController(quicConn, t.CongestionController, t.CWND)
go func() { go func() {
_ = t.sendAuthentication(quicConn) _ = t.sendAuthentication(quicConn)

View file

@ -6,6 +6,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"fmt" "fmt"
"net" "net"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -32,6 +33,7 @@ type ServerOption struct {
CongestionController string CongestionController string
AuthenticationTimeout time.Duration AuthenticationTimeout time.Duration
MaxUdpRelayPacketSize int MaxUdpRelayPacketSize int
CWND int
} }
type Server struct { type Server struct {
@ -56,7 +58,7 @@ func (s *Server) Serve() error {
if err != nil { if err != nil {
return err return err
} }
common.SetCongestionController(conn, s.CongestionController) common.SetCongestionController(conn, s.CongestionController, s.CWND)
h := &serverHandler{ h := &serverHandler{
Server: s, Server: s,
quicConn: conn, quicConn: conn,