mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-02-02 06:48:14 -05:00
Merge remote-tracking branch 'origin/dev_new' into dev_new
This commit is contained in:
commit
dbef310b19
@ -24,23 +24,23 @@ func NewConnCounter(conn net.Conn, s *TrafficStorage) net.Conn {
|
|||||||
ExtendedConn: bufio.NewExtendedConn(conn),
|
ExtendedConn: bufio.NewExtendedConn(conn),
|
||||||
storage: s,
|
storage: s,
|
||||||
readFunc: func(n int64) {
|
readFunc: func(n int64) {
|
||||||
s.DownCounter.Add(n)
|
s.UpCounter.Add(n)
|
||||||
},
|
},
|
||||||
writeFunc: func(n int64) {
|
writeFunc: func(n int64) {
|
||||||
s.UpCounter.Add(n)
|
s.DownCounter.Add(n)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnCounter) Read(b []byte) (n int, err error) {
|
func (c *ConnCounter) Read(b []byte) (n int, err error) {
|
||||||
n, err = c.ExtendedConn.Read(b)
|
n, err = c.ExtendedConn.Read(b)
|
||||||
c.storage.DownCounter.Store(int64(n))
|
c.storage.UpCounter.Store(int64(n))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnCounter) Write(b []byte) (n int, err error) {
|
func (c *ConnCounter) Write(b []byte) (n int, err error) {
|
||||||
n, err = c.ExtendedConn.Write(b)
|
n, err = c.ExtendedConn.Write(b)
|
||||||
c.storage.UpCounter.Store(int64(n))
|
c.storage.DownCounter.Store(int64(n))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ func (c *ConnCounter) ReadBuffer(buffer *buf.Buffer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if buffer.Len() > 0 {
|
if buffer.Len() > 0 {
|
||||||
c.storage.DownCounter.Add(int64(buffer.Len()))
|
c.storage.UpCounter.Add(int64(buffer.Len()))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ func (c *ConnCounter) WriteBuffer(buffer *buf.Buffer) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if dataLen > 0 {
|
if dataLen > 0 {
|
||||||
c.storage.UpCounter.Add(dataLen)
|
c.storage.DownCounter.Add(dataLen)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -95,10 +95,10 @@ func NewPacketConnCounter(conn network.PacketConn, s *TrafficStorage) network.Pa
|
|||||||
PacketConn: conn,
|
PacketConn: conn,
|
||||||
storage: s,
|
storage: s,
|
||||||
readFunc: func(n int64) {
|
readFunc: func(n int64) {
|
||||||
s.DownCounter.Add(n)
|
s.UpCounter.Add(n)
|
||||||
},
|
},
|
||||||
writeFunc: func(n int64) {
|
writeFunc: func(n int64) {
|
||||||
s.UpCounter.Add(n)
|
s.DownCounter.Add(n)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ func (p *PacketConnCounter) ReadPacket(buff *buf.Buffer) (destination M.Socksadd
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.storage.DownCounter.Add(int64(buff.Len()))
|
p.storage.UpCounter.Add(int64(buff.Len()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ func (p *PacketConnCounter) WritePacket(buff *buf.Buffer, destination M.Socksadd
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
p.storage.UpCounter.Add(int64(n))
|
p.storage.DownCounter.Add(int64(n))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
28
conf/node.go
28
conf/node.go
@ -33,9 +33,9 @@ type Options struct {
|
|||||||
CertConfig *CertConfig `json:"CertConfig"`
|
CertConfig *CertConfig `json:"CertConfig"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NodeConfig) UnmarshalJSON(b []byte) (err error) {
|
func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
|
||||||
r := rawNodeConfig{}
|
r := rawNodeConfig{}
|
||||||
err = json.Unmarshal(b, &r)
|
err = json.Unmarshal(data, &r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -48,14 +48,14 @@ func (n *NodeConfig) UnmarshalJSON(b []byte) (err error) {
|
|||||||
n.ApiConfig = ApiConfig{
|
n.ApiConfig = ApiConfig{
|
||||||
Timeout: 30,
|
Timeout: 30,
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(b, &n.ApiConfig)
|
err = json.Unmarshal(data, &n.ApiConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.OptRaw != nil {
|
if r.OptRaw != nil {
|
||||||
err = json.Unmarshal(*r.OptRaw, &n.Options)
|
data = *r.OptRaw
|
||||||
|
err = json.Unmarshal(data, &n.Options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -65,18 +65,18 @@ func (n *NodeConfig) UnmarshalJSON(b []byte) (err error) {
|
|||||||
ListenIP: "0.0.0.0",
|
ListenIP: "0.0.0.0",
|
||||||
SendIP: "0.0.0.0",
|
SendIP: "0.0.0.0",
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(b, &n.Options)
|
err = json.Unmarshal(data, &n.Options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch n.Options.Core {
|
}
|
||||||
case "xray":
|
switch n.Options.Core {
|
||||||
n.Options.XrayOptions = NewXrayOptions()
|
case "xray":
|
||||||
return json.Unmarshal(b, n.Options.XrayOptions)
|
n.Options.XrayOptions = NewXrayOptions()
|
||||||
case "sing":
|
return json.Unmarshal(data, n.Options.XrayOptions)
|
||||||
n.Options.SingOptions = NewSingOptions()
|
case "sing":
|
||||||
return json.Unmarshal(b, n.Options.SingOptions)
|
n.Options.SingOptions = NewSingOptions()
|
||||||
}
|
return json.Unmarshal(data, n.Options.SingOptions)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
17
conf/sing.go
17
conf/sing.go
@ -1,7 +1,12 @@
|
|||||||
package conf
|
package conf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/inazumav/sing-box/option"
|
||||||
|
)
|
||||||
|
|
||||||
type SingConfig struct {
|
type SingConfig struct {
|
||||||
LogConfig SingLogConfig `json:"Log"`
|
LogConfig SingLogConfig `json:"Log"`
|
||||||
|
NtpConfig SingNtpConfig `json:"NTP"`
|
||||||
OriginalPath string `json:"OriginalPath"`
|
OriginalPath string `json:"OriginalPath"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,6 +23,11 @@ func NewSingConfig() *SingConfig {
|
|||||||
Level: "error",
|
Level: "error",
|
||||||
Timestamp: true,
|
Timestamp: true,
|
||||||
},
|
},
|
||||||
|
NtpConfig: SingNtpConfig{
|
||||||
|
Enable: false,
|
||||||
|
Server: "time.apple.com",
|
||||||
|
ServerPort: 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,10 +35,17 @@ type SingOptions struct {
|
|||||||
EnableProxyProtocol bool `json:"EnableProxyProtocol"`
|
EnableProxyProtocol bool `json:"EnableProxyProtocol"`
|
||||||
TCPFastOpen bool `json:"EnableTFO"`
|
TCPFastOpen bool `json:"EnableTFO"`
|
||||||
SniffEnabled bool `json:"EnableSniff"`
|
SniffEnabled bool `json:"EnableSniff"`
|
||||||
|
DomainStrategy option.DomainStrategy `json:"DomainStrategy"`
|
||||||
SniffOverrideDestination bool `json:"SniffOverrideDestination"`
|
SniffOverrideDestination bool `json:"SniffOverrideDestination"`
|
||||||
FallBackConfigs *FallBackConfigForSing `json:"FallBackConfigs"`
|
FallBackConfigs *FallBackConfigForSing `json:"FallBackConfigs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SingNtpConfig struct {
|
||||||
|
Enable bool `json:"Enable"`
|
||||||
|
Server string `json:"Server"`
|
||||||
|
ServerPort uint16 `json:"ServerPort"`
|
||||||
|
}
|
||||||
|
|
||||||
type FallBackConfigForSing struct {
|
type FallBackConfigForSing struct {
|
||||||
// sing-box
|
// sing-box
|
||||||
FallBack FallBack `json:"FallBack"`
|
FallBack FallBack `json:"FallBack"`
|
||||||
|
@ -38,6 +38,7 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
|||||||
InboundOptions: option.InboundOptions{
|
InboundOptions: option.InboundOptions{
|
||||||
SniffEnabled: c.SingOptions.SniffEnabled,
|
SniffEnabled: c.SingOptions.SniffEnabled,
|
||||||
SniffOverrideDestination: c.SingOptions.SniffOverrideDestination,
|
SniffOverrideDestination: c.SingOptions.SniffOverrideDestination,
|
||||||
|
DomainStrategy: c.SingOptions.DomainStrategy,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var tls option.InboundTLSOptions
|
var tls option.InboundTLSOptions
|
||||||
@ -86,33 +87,43 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio
|
|||||||
case "tcp":
|
case "tcp":
|
||||||
t.Type = ""
|
t.Type = ""
|
||||||
case "ws":
|
case "ws":
|
||||||
network := WsNetworkConfig{}
|
var (
|
||||||
err := json.Unmarshal(n.NetworkSettings, &network)
|
path string
|
||||||
if err != nil {
|
ed int
|
||||||
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err)
|
headers map[string]option.Listable[string]
|
||||||
}
|
)
|
||||||
var u *url.URL
|
if len(n.NetworkSettings) != 0 {
|
||||||
u, err = url.Parse(network.Path)
|
network := WsNetworkConfig{}
|
||||||
if err != nil {
|
err := json.Unmarshal(n.NetworkSettings, &network)
|
||||||
return option.Inbound{}, fmt.Errorf("parse path error: %s", err)
|
if err != nil {
|
||||||
}
|
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err)
|
||||||
ed, _ := strconv.Atoi(u.Query().Get("ed"))
|
}
|
||||||
h := make(map[string]option.Listable[string], len(network.Headers))
|
var u *url.URL
|
||||||
for k, v := range network.Headers {
|
u, err = url.Parse(network.Path)
|
||||||
h[k] = option.Listable[string]{
|
if err != nil {
|
||||||
v,
|
return option.Inbound{}, fmt.Errorf("parse path error: %s", err)
|
||||||
|
}
|
||||||
|
path = u.Path
|
||||||
|
ed, _ = strconv.Atoi(u.Query().Get("ed"))
|
||||||
|
headers = make(map[string]option.Listable[string], len(network.Headers))
|
||||||
|
for k, v := range network.Headers {
|
||||||
|
headers[k] = option.Listable[string]{
|
||||||
|
v,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.WebsocketOptions = option.V2RayWebsocketOptions{
|
t.WebsocketOptions = option.V2RayWebsocketOptions{
|
||||||
Path: u.Path,
|
Path: path,
|
||||||
EarlyDataHeaderName: "Sec-WebSocket-Protocol",
|
EarlyDataHeaderName: "Sec-WebSocket-Protocol",
|
||||||
MaxEarlyData: uint32(ed),
|
MaxEarlyData: uint32(ed),
|
||||||
Headers: h,
|
Headers: headers,
|
||||||
}
|
}
|
||||||
case "grpc":
|
case "grpc":
|
||||||
err := json.Unmarshal(n.NetworkSettings, &t.GRPCOptions)
|
if len(n.NetworkSettings) != 0 {
|
||||||
if err != nil {
|
err := json.Unmarshal(n.NetworkSettings, &t.GRPCOptions)
|
||||||
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err)
|
if err != nil {
|
||||||
|
return option.Inbound{}, fmt.Errorf("decode NetworkSettings error: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if info.Type == "vless" {
|
if info.Type == "vless" {
|
||||||
|
@ -48,7 +48,7 @@ func New(c *conf.CoreConfig) (vCore.Core, error) {
|
|||||||
return nil, fmt.Errorf("open original config error: %s", err)
|
return nil, fmt.Errorf("open original config error: %s", err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
err = json.NewDecoder(f).Decode(options)
|
err = json.NewDecoder(f).Decode(&options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("decode original config error: %s", err)
|
return nil, fmt.Errorf("decode original config error: %s", err)
|
||||||
}
|
}
|
||||||
@ -59,6 +59,14 @@ func New(c *conf.CoreConfig) (vCore.Core, error) {
|
|||||||
Timestamp: c.SingConfig.LogConfig.Timestamp,
|
Timestamp: c.SingConfig.LogConfig.Timestamp,
|
||||||
Output: c.SingConfig.LogConfig.Output,
|
Output: c.SingConfig.LogConfig.Output,
|
||||||
}
|
}
|
||||||
|
options.NTP = &option.NTPOptions{
|
||||||
|
Enabled: c.SingConfig.NtpConfig.Enable,
|
||||||
|
WriteToSystem: true,
|
||||||
|
ServerOptions: option.ServerOptions{
|
||||||
|
Server: c.SingConfig.NtpConfig.Server,
|
||||||
|
ServerPort: c.SingConfig.NtpConfig.ServerPort,
|
||||||
|
},
|
||||||
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ctx = pause.ContextWithDefaultManager(ctx)
|
ctx = pause.ContextWithDefaultManager(ctx)
|
||||||
createdAt := time.Now()
|
createdAt := time.Now()
|
||||||
|
@ -22,7 +22,7 @@ func buildInbound(option *conf.Options, nodeInfo *panel.NodeInfo, tag string) (*
|
|||||||
var err error
|
var err error
|
||||||
var network string
|
var network string
|
||||||
switch nodeInfo.Type {
|
switch nodeInfo.Type {
|
||||||
case "v2ray":
|
case "vmess", "vless":
|
||||||
err = buildV2ray(option, nodeInfo, in)
|
err = buildV2ray(option, nodeInfo, in)
|
||||||
network = nodeInfo.VAllss.Network
|
network = nodeInfo.VAllss.Network
|
||||||
case "trojan":
|
case "trojan":
|
||||||
|
@ -16,6 +16,13 @@
|
|||||||
|
|
||||||
"Level": "error",
|
"Level": "error",
|
||||||
"Timestamp": true
|
"Timestamp": true
|
||||||
|
},
|
||||||
|
"NTP": {
|
||||||
|
// 同 SingBox ntp 部分配置
|
||||||
|
// VMess VLESS 建议开启
|
||||||
|
"Enable": true,
|
||||||
|
"Server": "time.apple.com",
|
||||||
|
"ServerPort": 0
|
||||||
}
|
}
|
||||||
// More
|
// More
|
||||||
},
|
},
|
||||||
@ -56,7 +63,12 @@
|
|||||||
// 开启 Proxy Protocol,参见 https://github.com/haproxy/haproxy/blob/master/doc/proxy-protocol.txt
|
// 开启 Proxy Protocol,参见 https://github.com/haproxy/haproxy/blob/master/doc/proxy-protocol.txt
|
||||||
"EnableProxyProtocol": false,
|
"EnableProxyProtocol": false,
|
||||||
// 开启 TCP Fast Open
|
// 开启 TCP Fast Open
|
||||||
"EnableTFO": true
|
"EnableTFO": true,
|
||||||
|
|
||||||
|
// 设置 Domain Strategy
|
||||||
|
// 可选 prefer_ipv4 / prefer_ipv6 / ipv4_only / ipv6_only
|
||||||
|
"DomainStrategy": "ipv4_only",
|
||||||
|
|
||||||
// More
|
// More
|
||||||
}
|
}
|
||||||
/*,
|
/*,
|
||||||
@ -74,6 +86,7 @@
|
|||||||
"Core": "sing",
|
"Core": "sing",
|
||||||
"EnableProxyProtocol": true,
|
"EnableProxyProtocol": true,
|
||||||
"EnableTFO": true
|
"EnableTFO": true
|
||||||
|
"DomainStrategy": "ipv4_only",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user