2021-09-04 07:37:53 -04:00
|
|
|
package sniffer
|
|
|
|
|
|
|
|
import (
|
2021-10-28 06:34:19 -04:00
|
|
|
"strings"
|
|
|
|
|
2021-09-04 07:37:53 -04:00
|
|
|
"github.com/v2fly/v2ray-core/v4/app/proxyman"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/infra/conf/cfgcommon"
|
|
|
|
)
|
|
|
|
|
|
|
|
//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")
|
2021-11-02 07:36:55 -04:00
|
|
|
case "quic":
|
|
|
|
p = append(p, "quic")
|
2021-09-04 07:37:53 -04:00
|
|
|
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
|
|
|
|
}
|