mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
isolate socks settings
This commit is contained in:
parent
df9624a965
commit
436aaca6ab
43
infra/conf/cfgcommon/socketcfg/socket.go
Normal file
43
infra/conf/cfgcommon/socketcfg/socket.go
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
package socketcfg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/v2fly/v2ray-core/v4/transport/internet"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SocketConfig struct {
|
||||||
|
Mark int32 `json:"mark"`
|
||||||
|
TFO *bool `json:"tcpFastOpen"`
|
||||||
|
TProxy string `json:"tproxy"`
|
||||||
|
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
|
||||||
|
TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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,
|
||||||
|
Tproxy: tproxy,
|
||||||
|
AcceptProxyProtocol: c.AcceptProxyProtocol,
|
||||||
|
TcpKeepAliveInterval: c.TCPKeepAliveInterval,
|
||||||
|
}, nil
|
||||||
|
}
|
@ -3,6 +3,7 @@ package v4
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/loader"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/socketcfg"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/tlscfg"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon/tlscfg"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -283,43 +284,6 @@ func (p TransportProtocol) Build() (string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SocketConfig struct {
|
|
||||||
Mark int32 `json:"mark"`
|
|
||||||
TFO *bool `json:"tcpFastOpen"`
|
|
||||||
TProxy string `json:"tproxy"`
|
|
||||||
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
|
|
||||||
TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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,
|
|
||||||
Tproxy: tproxy,
|
|
||||||
AcceptProxyProtocol: c.AcceptProxyProtocol,
|
|
||||||
TcpKeepAliveInterval: c.TCPKeepAliveInterval,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type StreamConfig struct {
|
type StreamConfig struct {
|
||||||
Network *TransportProtocol `json:"network"`
|
Network *TransportProtocol `json:"network"`
|
||||||
Security string `json:"security"`
|
Security string `json:"security"`
|
||||||
@ -332,7 +296,7 @@ type StreamConfig struct {
|
|||||||
QUICSettings *QUICConfig `json:"quicSettings"`
|
QUICSettings *QUICConfig `json:"quicSettings"`
|
||||||
GunSettings *GunConfig `json:"gunSettings"`
|
GunSettings *GunConfig `json:"gunSettings"`
|
||||||
GRPCSettings *GunConfig `json:"grpcSettings"`
|
GRPCSettings *GunConfig `json:"grpcSettings"`
|
||||||
SocketSettings *SocketConfig `json:"sockopt"`
|
SocketSettings *socketcfg.SocketConfig `json:"sockopt"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
|
Loading…
Reference in New Issue
Block a user