소스 검색

add `tcpcongestion` (#1234)

* add `tcpcongestion`

* Update sockopt_linux.go

* Update config.pb.go

* Update transport_internet.go

* Update config.pb.go

* Update transport_internet.go

* Update config.proto
xqzr 3 년 전
부모
커밋
8cf23f1947
4개의 변경된 파일17개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      infra/conf/transport_internet.go
  2. 1 0
      transport/internet/config.pb.go
  3. 2 0
      transport/internet/config.proto
  4. 12 0
      transport/internet/sockopt_linux.go

+ 2 - 0
infra/conf/transport_internet.go

@@ -533,6 +533,7 @@ type SocketConfig struct {
 	DialerProxy          string      `json:"dialerProxy"`
 	TCPKeepAliveInterval int32       `json:"tcpKeepAliveInterval"`
 	TCPKeepAliveIdle     int32       `json:"tcpKeepAliveIdle"`
+        TCPCongestion        string      `json:"tcpCongestion"`
 }
 
 // Build implements Buildable.
@@ -581,6 +582,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
 		DialerProxy:          c.DialerProxy,
 		TcpKeepAliveInterval: c.TCPKeepAliveInterval,
 		TcpKeepAliveIdle:     c.TCPKeepAliveIdle,
+                TcpCongestion:        c.TCPCongestion,
 	}, nil
 }
 

+ 1 - 0
transport/internet/config.pb.go

@@ -424,6 +424,7 @@ type SocketConfig struct {
 	DialerProxy                string         `protobuf:"bytes,9,opt,name=dialer_proxy,json=dialerProxy,proto3" json:"dialer_proxy,omitempty"`
 	TcpKeepAliveInterval       int32          `protobuf:"varint,10,opt,name=tcp_keep_alive_interval,json=tcpKeepAliveInterval,proto3" json:"tcp_keep_alive_interval,omitempty"`
 	TcpKeepAliveIdle           int32          `protobuf:"varint,11,opt,name=tcp_keep_alive_idle,json=tcpKeepAliveIdle,proto3" json:"tcp_keep_alive_idle,omitempty"`
+        TcpCongestion              string         `protobuf:"bytes,12,opt,name=tcp_congestion,json=tcpCongestion,proto3 json:"tcp_congestion,omitempty"`
 }
 
 func (x *SocketConfig) Reset() {

+ 2 - 0
transport/internet/config.proto

@@ -96,4 +96,6 @@ message SocketConfig {
   int32 tcp_keep_alive_interval = 10;
 
   int32 tcp_keep_alive_idle = 11;
+  
+  string tcp_congestion = 12;
 }

+ 12 - 0
transport/internet/sockopt_linux.go

@@ -77,6 +77,12 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
 				return newError("failed to unset SO_KEEPALIVE", err)
 			}
 		}
+
+                if config.TcpCongestion != "" {
+                        if err := syscall.SetsockoptString(int(fd), syscall.SOL_TCP, syscall.TCP_CONGESTION, config.TcpCongestion); err != nil {
+                                return newError("failed to set TCP_CONGESTION", err)
+                        }
+                }
 	}
 
 	if config.Tproxy.IsEnabled() {
@@ -121,6 +127,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
 				return newError("failed to unset SO_KEEPALIVE", err)
 			}
 		}
+
+                if config.TcpCongestion != "" {
+                        if err := syscall.SetsockoptString(int(fd), syscall.SOL_TCP, syscall.TCP_CONGESTION, config.TcpCongestion); err != nil {
+                                return newError("failed to set TCP_CONGESTION", err)
+                        }
+                }
 	}
 
 	if config.Tproxy.IsEnabled() {