chore: adjustable cwnd for cc in quic

This commit is contained in:
Larvan2 2023-06-18 00:47:26 +08:00
parent 514d374b8c
commit 3eef1ee064
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
@ -177,7 +174,7 @@ dns:
- 8.8.8.8 - 8.8.8.8
- tls://1.12.12.12:853 - tls://1.12.12.12:853
- tls://223.5.5.5:853 - tls://223.5.5.5:853
- system # append DNS server from system configuration. If not found, it would print an error log and skip. - system # append DNS server from system configuration. If not found, it would print an error log and skip.
enhanced-mode: fake-ip # or redir-host enhanced-mode: fake-ip # or redir-host
fake-ip-range: 198.18.0.1/16 # fake-ip 池设置 fake-ip-range: 198.18.0.1/16 # fake-ip 池设置
@ -364,20 +361,22 @@ 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, ios, firefox, safari中的一个 chrome # One of: chrome, ios, firefox or 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:
# 应当是一个TLS 1.3 服务器 "www.microsoft.com" # Must be a TLS 1.3 server
password: [YOUR_RESTLS_PASSWORD] # 应当是一个TLS 1.3 服务器
version-hint: "tls13" password: [YOUR_RESTLS_PASSWORD]
# Control your post-handshake traffic through restls-script version-hint: "tls13"
# Hide proxy behaviors like "tls in tls". # Control your post-handshake traffic through restls-script
# see https://github.com/3andne/restls/blob/main/Restls-Script:%20Hide%20Your%20Proxy%20Traffic%20Behavior.md # Hide proxy behaviors like "tls in tls".
# 用restls剧本来控制握手后的行为隐藏"tls in tls"等特征 # see https://github.com/3andne/restls/blob/main/Restls-Script:%20Hide%20Your%20Proxy%20Traffic%20Behavior.md
# 详情https://github.com/3andne/restls/blob/main/Restls-Script:%20%E9%9A%90%E8%97%8F%E4%BD%A0%E7%9A%84%E4%BB%A3%E7%90%86%E8%A1%8C%E4%B8%BA.md # 用restls剧本来控制握手后的行为隐藏"tls in tls"等特征
restls-script: "300?100<1,400~100,350~100,600~100,300~200,300~100" # 详情https://github.com/3andne/restls/blob/main/Restls-Script:%20%E9%9A%90%E8%97%8F%E4%BD%A0%E7%9A%84%E4%BB%A3%E7%90%86%E8%A1%8C%E4%B8%BA.md
restls-script: "300?100<1,400~100,350~100,600~100,300~200,300~100"
- name: "ss-restls-tls12" - name: "ss-restls-tls12"
type: ss type: ss
@ -385,15 +384,17 @@ 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, ios, firefox, safari中的一个 chrome # One of: chrome, ios, firefox or safari
# 可以是chrome, ios, firefox, safari中的一个
plugin: restls plugin: restls
plugin-opts: plugin-opts:
host: "vscode.dev" # Must be a TLS 1.2 server host:
# 应当是一个TLS 1.2 服务器 "vscode.dev" # Must be a TLS 1.2 server
password: [YOUR_RESTLS_PASSWORD] # 应当是一个TLS 1.2 服务器
version-hint: "tls12" password: [YOUR_RESTLS_PASSWORD]
restls-script: "1000?100<1,500~100,350~100,600~100,400~200" version-hint: "tls12"
restls-script: "1000?100<1,500~100,350~100,600~100,400~200"
# vmess # vmess
# cipher支持 auto/aes-128-gcm/chacha20-poly1305/none # cipher支持 auto/aes-128-gcm/chacha20-poly1305/none
@ -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,