Hunter0x7c7
2022-08-11 b8230139fb40edea387617b6accd8371e37eda58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package socketcfg
 
import (
    "strings"
 
    "github.com/v2fly/v2ray-core/v5/transport/internet"
)
 
type SocketConfig struct {
    Mark                 uint32 `json:"mark"`
    TFO                  *bool  `json:"tcpFastOpen"`
    TProxy               string `json:"tproxy"`
    AcceptProxyProtocol  bool   `json:"acceptProxyProtocol"`
    TCPKeepAliveInterval int32  `json:"tcpKeepAliveInterval"`
    TCPKeepAliveIdle     int32  `json:"tcpKeepAliveIdle"`
    TFOQueueLength       uint32 `json:"tcpFastOpenQueueLength"`
    BindToDevice         string `json:"bindToDevice"`
    RxBufSize            uint64 `json:"rxBufSize"`
    TxBufSize            uint64 `json:"txBufSize"`
    ForceBufSize         bool   `json:"forceBufSize"`
}
 
// 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
        }
    }
 
    tfoQueueLength := c.TFOQueueLength
    if tfoQueueLength == 0 {
        tfoQueueLength = 4096
    }
 
    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,
        TfoQueueLength:       tfoQueueLength,
        Tproxy:               tproxy,
        AcceptProxyProtocol:  c.AcceptProxyProtocol,
        TcpKeepAliveInterval: c.TCPKeepAliveInterval,
        TcpKeepAliveIdle:     c.TCPKeepAliveIdle,
        RxBufSize:            int64(c.RxBufSize),
        TxBufSize:            int64(c.TxBufSize),
        ForceBufSize:         c.ForceBufSize,
        BindToDevice:         c.BindToDevice,
    }, nil
}