2021-09-04 07:52:13 -04:00
|
|
|
package socketcfg
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2021-10-28 06:34:19 -04:00
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/transport/internet"
|
2021-09-04 07:52:13 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type SocketConfig struct {
|
2021-09-10 04:18:26 -04:00
|
|
|
Mark uint32 `json:"mark"`
|
2021-09-04 07:52:13 -04:00
|
|
|
TFO *bool `json:"tcpFastOpen"`
|
|
|
|
TProxy string `json:"tproxy"`
|
|
|
|
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
|
|
|
|
TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"`
|
2021-11-20 12:31:50 -05:00
|
|
|
TCPKeepAliveIdle int32 `json:"tcpKeepAliveIdle"`
|
2021-09-26 12:29:44 -04:00
|
|
|
TFOQueueLength uint32 `json:"tcpFastOpenQueueLength"`
|
2021-09-04 07:52:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build implements Buildable.
|
|
|
|
func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
|
|
|
|
var tfoSettings internet.SocketConfig_TCPFastOpenState
|
|
|
|
if c.TFO != nil {
|
|
|
|
if *c.TFO {
|
|
|
|
tfoSettings = internet.SocketConfig_Enable
|
|
|
|
} else {
|
|
|
|
tfoSettings = internet.SocketConfig_Disable
|
|
|
|
}
|
|
|
|
}
|
2021-09-26 12:29:44 -04:00
|
|
|
|
|
|
|
tfoQueueLength := c.TFOQueueLength
|
|
|
|
if tfoQueueLength == 0 {
|
|
|
|
tfoQueueLength = 4096
|
|
|
|
}
|
|
|
|
|
2021-09-04 07:52:13 -04:00
|
|
|
var tproxy internet.SocketConfig_TProxyMode
|
|
|
|
switch strings.ToLower(c.TProxy) {
|
|
|
|
case "tproxy":
|
|
|
|
tproxy = internet.SocketConfig_TProxy
|
|
|
|
case "redirect":
|
|
|
|
tproxy = internet.SocketConfig_Redirect
|
|
|
|
default:
|
|
|
|
tproxy = internet.SocketConfig_Off
|
|
|
|
}
|
|
|
|
|
|
|
|
return &internet.SocketConfig{
|
|
|
|
Mark: c.Mark,
|
|
|
|
Tfo: tfoSettings,
|
2021-09-26 12:29:44 -04:00
|
|
|
TfoQueueLength: tfoQueueLength,
|
2021-09-04 07:52:13 -04:00
|
|
|
Tproxy: tproxy,
|
|
|
|
AcceptProxyProtocol: c.AcceptProxyProtocol,
|
|
|
|
TcpKeepAliveInterval: c.TCPKeepAliveInterval,
|
2021-11-20 12:31:50 -05:00
|
|
|
TcpKeepAliveIdle: c.TCPKeepAliveIdle,
|
2021-09-04 07:52:13 -04:00
|
|
|
}, nil
|
|
|
|
}
|