diff --git a/examples/multi.server.toml b/examples/multi.server.toml index f62e38b..78034f4 100644 --- a/examples/multi.server.toml +++ b/examples/multi.server.toml @@ -27,6 +27,8 @@ users = [ {user = "a684455c-b14f-11ea-bf0d-42010aaa0004"} , {user = "a684455c-b1 # extra.tls_rejectUnknownSni = true # 这个开启了的话,防御效果更佳, 不过, 这要求你有真实证书 +#sockopt.bbr = true #用户空间的bbr拥塞控制, 仅限linux, see issue #237 + [[listen]] tag = "my_ws1" protocol = "vlesss" diff --git a/netLayer/sockopt.go b/netLayer/sockopt.go index 236ab80..9751040 100644 --- a/netLayer/sockopt.go +++ b/netLayer/sockopt.go @@ -9,6 +9,7 @@ import ( type Sockopt struct { TProxy bool `toml:"tproxy"` //only linux Somark int `toml:"mark"` //only linux + BBR bool `toml:"bbr"` //only linux Device string `toml:"device"` //fastopen 不予支持, 因为自己客户端在重重网关之下,不可能让层层网关都支持tcp fast open; diff --git a/netLayer/sockopt_linux.go b/netLayer/sockopt_linux.go index 8503400..33f359e 100644 --- a/netLayer/sockopt_linux.go +++ b/netLayer/sockopt_linux.go @@ -1,9 +1,10 @@ package netLayer import ( + "syscall" + "go.uber.org/zap" "golang.org/x/sys/unix" - "syscall" "github.com/e1732a364fed/v2ray_simple/utils" ) @@ -29,6 +30,14 @@ func SetSockOpt(fd int, sockopt *Sockopt, isudp bool, isipv6 bool) { bindToDevice(fd, sockopt.Device) } + if sockopt.BBR { + if err := syscall.SetsockoptString(fd, syscall.SOL_TCP, syscall.TCP_CONGESTION, "bbr"); err != nil { + if ce := utils.CanLogErr("bbr failed"); ce != nil { + ce.Write(zap.Error(err)) + } + } + } + } func bindToDevice(fd int, device string) {