mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-06-03 06:13:53 -04:00
isolate sniffer config
This commit is contained in:
parent
b8e81f01fa
commit
3e68a192f5
42
infra/conf/cfgcommon/sniffer/sniffer.go
Normal file
42
infra/conf/cfgcommon/sniffer/sniffer.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package sniffer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/v2fly/v2ray-core/v4/app/proxyman"
|
||||||
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:generate go run github.com/v2fly/v2ray-core/v4/common/errors/errorgen
|
||||||
|
|
||||||
|
type SniffingConfig struct {
|
||||||
|
Enabled bool `json:"enabled"`
|
||||||
|
DestOverride *cfgcommon.StringList `json:"destOverride"`
|
||||||
|
MetadataOnly bool `json:"metadataOnly"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build implements Buildable.
|
||||||
|
func (c *SniffingConfig) Build() (*proxyman.SniffingConfig, error) {
|
||||||
|
var p []string
|
||||||
|
if c.DestOverride != nil {
|
||||||
|
for _, domainOverride := range *c.DestOverride {
|
||||||
|
switch strings.ToLower(domainOverride) {
|
||||||
|
case "http":
|
||||||
|
p = append(p, "http")
|
||||||
|
case "tls", "https", "ssl":
|
||||||
|
p = append(p, "tls")
|
||||||
|
case "fakedns":
|
||||||
|
p = append(p, "fakedns")
|
||||||
|
case "fakedns+others":
|
||||||
|
p = append(p, "fakedns+others")
|
||||||
|
default:
|
||||||
|
return nil, newError("unknown protocol: ", domainOverride)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &proxyman.SniffingConfig{
|
||||||
|
Enabled: c.Enabled,
|
||||||
|
DestinationOverride: p,
|
||||||
|
MetadataOnly: c.MetadataOnly,
|
||||||
|
}, 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/sniffer"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/dns"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/dns"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/log"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/log"
|
||||||
"github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router"
|
"github.com/v2fly/v2ray-core/v4/infra/conf/synthetic/router"
|
||||||
@ -57,39 +58,6 @@ func toProtocolList(s []string) ([]proxyman.KnownProtocols, error) {
|
|||||||
return kp, nil
|
return kp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SniffingConfig struct {
|
|
||||||
Enabled bool `json:"enabled"`
|
|
||||||
DestOverride *cfgcommon.StringList `json:"destOverride"`
|
|
||||||
MetadataOnly bool `json:"metadataOnly"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build implements Buildable.
|
|
||||||
func (c *SniffingConfig) Build() (*proxyman.SniffingConfig, error) {
|
|
||||||
var p []string
|
|
||||||
if c.DestOverride != nil {
|
|
||||||
for _, domainOverride := range *c.DestOverride {
|
|
||||||
switch strings.ToLower(domainOverride) {
|
|
||||||
case "http":
|
|
||||||
p = append(p, "http")
|
|
||||||
case "tls", "https", "ssl":
|
|
||||||
p = append(p, "tls")
|
|
||||||
case "fakedns":
|
|
||||||
p = append(p, "fakedns")
|
|
||||||
case "fakedns+others":
|
|
||||||
p = append(p, "fakedns+others")
|
|
||||||
default:
|
|
||||||
return nil, newError("unknown protocol: ", domainOverride)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &proxyman.SniffingConfig{
|
|
||||||
Enabled: c.Enabled,
|
|
||||||
DestinationOverride: p,
|
|
||||||
MetadataOnly: c.MetadataOnly,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
type MuxConfig struct {
|
type MuxConfig struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Concurrency int16 `json:"concurrency"`
|
Concurrency int16 `json:"concurrency"`
|
||||||
@ -155,7 +123,7 @@ type InboundDetourConfig struct {
|
|||||||
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
||||||
StreamSetting *StreamConfig `json:"streamSettings"`
|
StreamSetting *StreamConfig `json:"streamSettings"`
|
||||||
DomainOverride *cfgcommon.StringList `json:"domainOverride"`
|
DomainOverride *cfgcommon.StringList `json:"domainOverride"`
|
||||||
SniffingConfig *SniffingConfig `json:"sniffing"`
|
SniffingConfig *sniffer.SniffingConfig `json:"sniffing"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user