mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 10:44:02 +03:00
Merge pull request #452 from 9seconds/tcp-bbr
Use TCP BBR in a best-effort mode
This commit is contained in:
@@ -23,5 +23,7 @@ func setCommonSocketOptions(conn *net.TCPConn, keepAliveConfig net.KeepAliveConf
|
||||
return fmt.Errorf("cannot setup SO_REUSEADDR/PORT: %w", err)
|
||||
}
|
||||
|
||||
setCongestionControl(rawConn)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//go:build linux
|
||||
|
||||
package network
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func setCongestionControl(conn syscall.RawConn) {
|
||||
conn.Control(func(fd uintptr) { //nolint: errcheck
|
||||
// BBR provides better throughput over lossy and high-latency links compared
|
||||
// to the default cubic, which is especially beneficial for mobile and
|
||||
// home internet clients. This is best-effort: silently ignored if the
|
||||
// kernel does not have tcp_bbr available.
|
||||
unix.SetsockoptString(int(fd), unix.IPPROTO_TCP, unix.TCP_CONGESTION, "bbr") //nolint: errcheck
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
//go:build !linux
|
||||
|
||||
package network
|
||||
|
||||
import "syscall"
|
||||
|
||||
func setCongestionControl(conn syscall.RawConn) {}
|
||||
Reference in New Issue
Block a user