feat: add config_parser

This commit is contained in:
mzz2017
2023-01-27 02:10:27 +08:00
parent 916a55d480
commit edbce81e88
53 changed files with 6696 additions and 733 deletions

View File

@ -0,0 +1,34 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) since 2023, mzz2017 (mzz@tuta.io). All rights reserved.
*/
package config_parser
import (
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
"github.com/v2rayA/dae-config-dist/go/dae_config"
)
func Parse(in string) (sections []*Section, err error) {
errorListener := NewConsoleErrorListener()
lexer := dae_config.Newdae_configLexer(antlr.NewInputStream(in))
lexer.RemoveErrorListeners()
lexer.AddErrorListener(errorListener)
input := antlr.NewCommonTokenStream(lexer, 0)
parser := dae_config.Newdae_configParser(input)
parser.RemoveErrorListeners()
parser.AddErrorListener(errorListener)
parser.BuildParseTrees = true
tree := parser.Start()
walker := NewWalker(parser)
antlr.ParseTreeWalkerDefault.Walk(walker, tree)
if errorListener.ErrorBuilder.Len() != 0 {
return nil, fmt.Errorf("%v", errorListener.ErrorBuilder.String())
}
return walker.Sections, nil
}

View File

@ -0,0 +1,91 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) since 2023, mzz2017 (mzz@tuta.io). All rights reserved.
*/
package config_parser
import "testing"
func TestParse(t *testing.T) {
sections, err := Parse(`
# gugu
include {
another.conf
}
global {
# tproxy port to listen.
tproxy_port: 12345
# Node connectivity check url.
check_url: 'https://connectivitycheck.gstatic.com/generate_204'
# Now only support UDP and IP:Port.
# Please make sure DNS traffic will go through and be forwarded by dae.
dns_upstream: '1.1.1.1:53'
# Now only support one interface.
ingress_interface: docker0
}
# subscription will be resolved as nodes and merged into node pool below.
subscription {
https://LINK
}
node {
'ss://LINK'
'ssr://LINK'
'vmess://LINK'
'vless://LINK'
'trojan://LINK'
'trojan-go://LINK'
'socks5://LINK#name'
'http://LINK#name'
'https://LINK#name'
}
group {
my_group {
# Pass node links as input of lua script filter.
# gugu
filter: link(lua:filename.lua)
# Randomly select a node from the group for every connection.
policy: random
}
disney {
# Pass node names as input of keyword/regex filter.
filter: name(regex:'^.*hk.*$', keyword:'sg') && name(keyword:'disney')
# Select the node with min average of the last 10 latencies from the group for every connection.
policy: min_avg10
}
netflix {
# Pass node names as input of keyword filter.
filter: name(keyword:netflix)
# Select the first node from the group for every connection.
policy: fixed(0)
}
}
routing {
domain(geosite:category-ads) -> block
domain(geosite:disney) -> disney
domain(geosite:netflix) -> netflix
ip(geoip:cn) -> direct
domain(geosite:cn) -> direct
final: my_group
}
`)
if err != nil {
t.Fatalf("\n%v", err)
}
for _, section := range sections {
t.Logf("\n%v", section.String())
}
}

View File

@ -0,0 +1,91 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) since 2022, mzz2017 (mzz@tuta.io). All rights reserved.
*/
package config_parser
import (
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
"reflect"
"strings"
)
type ErrorType string
const (
ErrorType_Unsupported ErrorType = "is not supported"
ErrorType_NotSet ErrorType = "is not set"
)
type ConsoleErrorListener struct {
ErrorBuilder strings.Builder
}
func NewConsoleErrorListener() *ConsoleErrorListener {
return &ConsoleErrorListener{}
}
func (d *ConsoleErrorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) {
// Do not accumulate errors.
if d.ErrorBuilder.Len() > 0 {
return
}
backtrack := column
if backtrack > 30 {
backtrack = 30
}
starting := fmt.Sprintf("line %v:%v ", line, column)
offset := len(starting) + backtrack
var (
simplyWrite bool
token antlr.Token
)
if offendingSymbol == nil {
simplyWrite = true
} else {
token = offendingSymbol.(antlr.Token)
simplyWrite = token.GetTokenType() == -1
}
if simplyWrite {
d.ErrorBuilder.WriteString(fmt.Sprintf("%v%v", starting, msg))
return
}
beginOfLine := token.GetStart() - backtrack
strPeek := token.GetInputStream().GetText(beginOfLine, token.GetStop()+30)
wrap := strings.IndexByte(strPeek, '\n')
if wrap == -1 {
wrap = token.GetStop() + 30
} else {
wrap += beginOfLine - 1
}
strLine := token.GetInputStream().GetText(beginOfLine, wrap)
d.ErrorBuilder.WriteString(fmt.Sprintf("%v%v\n%v%v: %v\n", starting, strLine, strings.Repeat(" ", offset), strings.Repeat("^", token.GetStop()-token.GetStart()+1), msg))
}
func (d *ConsoleErrorListener) ReportAmbiguity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, exact bool, ambigAlts *antlr.BitSet, configs antlr.ATNConfigSet) {
}
func (d *ConsoleErrorListener) ReportAttemptingFullContext(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex int, conflictingAlts *antlr.BitSet, configs antlr.ATNConfigSet) {
}
func (d *ConsoleErrorListener) ReportContextSensitivity(recognizer antlr.Parser, dfa *antlr.DFA, startIndex, stopIndex, prediction int, configs antlr.ATNConfigSet) {
}
func BaseContext(ctx interface{}) (baseCtx *antlr.BaseParserRuleContext) {
val := reflect.ValueOf(ctx)
for val.Kind() == reflect.Pointer && val.Type() != reflect.TypeOf(&antlr.BaseParserRuleContext{}) {
val = val.Elem()
}
if val.Type() == reflect.TypeOf(&antlr.BaseParserRuleContext{}) {
baseCtx = val.Interface().(*antlr.BaseParserRuleContext)
} else {
baseCtxVal := val.FieldByName("BaseParserRuleContext")
if !baseCtxVal.IsValid() {
panic("has no field BaseParserRuleContext")
}
baseCtx = baseCtxVal.Interface().(*antlr.BaseParserRuleContext)
}
return baseCtx
}

View File

@ -0,0 +1,187 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) since 2023, mzz2017 (mzz@tuta.io). All rights reserved.
*/
package config_parser
import (
"fmt"
"strconv"
"strings"
)
type ItemType int
const (
ItemType_RoutingRule ItemType = iota
ItemType_Param
ItemType_Section
)
func (t ItemType) String() string {
switch t {
case ItemType_RoutingRule:
return "RoutingRule"
case ItemType_Param:
return "Param"
case ItemType_Section:
return "Section"
default:
return "<Unknown>"
}
}
func NewRoutingRuleItem(rule *RoutingRule) *Item {
return &Item{
Type: ItemType_RoutingRule,
Value: rule,
}
}
func NewParamItem(param *Param) *Item {
return &Item{
Type: ItemType_Param,
Value: param,
}
}
func NewSectionItem(section *Section) *Item {
return &Item{
Type: ItemType_Param,
Value: section,
}
}
type Item struct {
Type ItemType
Value interface{}
}
func (i *Item) String() string {
var builder strings.Builder
builder.WriteString("type: " + i.Type.String() + "\n")
var content string
switch val := i.Value.(type) {
case *RoutingRule:
content = val.String(false)
case *Param:
content = val.String()
case *Section:
content = val.String()
default:
return "<Unknown>\n"
}
lines := strings.Split(content, "\n")
for i := range lines {
lines[i] = "\t" + lines[i]
}
builder.WriteString(strings.Join(lines, "\n"))
return builder.String()
}
type Section struct {
Name string
Items []*Item
}
func (s *Section) String() string {
var builder strings.Builder
builder.WriteString("section: " + s.Name + "\n")
var strItemList []string
for _, item := range s.Items {
lines := strings.Split(item.String(), "\n")
for i := range lines {
lines[i] = "\t" + lines[i]
}
strItemList = append(strItemList, strings.Join(lines, "\n"))
}
builder.WriteString(strings.Join(strItemList, "\n"))
return builder.String()
}
type Param struct {
Key string
Val string
AndFunctions []*Function
}
func (p *Param) String() string {
if p.Key == "" {
return p.Val
}
if p.AndFunctions != nil {
a := paramAndFunctions{
Key: p.Key,
AndFunctions: p.AndFunctions,
}
return a.String()
}
return p.Key + ": " + p.Val
}
type Function struct {
Name string
Params []*Param
}
func (f *Function) String() string {
var builder strings.Builder
builder.WriteString(f.Name + "(")
var strParamList []string
for _, p := range f.Params {
strParamList = append(strParamList, p.String())
}
builder.WriteString(strings.Join(strParamList, ", "))
builder.WriteString(")")
return builder.String()
}
type paramAndFunctions struct {
Key string
AndFunctions []*Function
}
func (p *paramAndFunctions) String() string {
var builder strings.Builder
builder.WriteString(p.Key + ": ")
var strFunctionList []string
for _, f := range p.AndFunctions {
strFunctionList = append(strFunctionList, f.String())
}
builder.WriteString(strings.Join(strFunctionList, " && "))
return builder.String()
}
type RoutingRule struct {
AndFunctions []*Function
Outbound string
}
func (r *RoutingRule) String(calcN bool) string {
var builder strings.Builder
var n int
for _, f := range r.AndFunctions {
if builder.Len() != 0 {
builder.WriteString(" && ")
}
var paramBuilder strings.Builder
n += len(f.Params)
for _, p := range f.Params {
if paramBuilder.Len() != 0 {
paramBuilder.WriteString(", ")
}
if p.Key != "" {
paramBuilder.WriteString(p.Key + ": " + p.Val)
} else {
paramBuilder.WriteString(p.Val)
}
}
builder.WriteString(fmt.Sprintf("%v(%v)", f.Name, paramBuilder.String()))
}
builder.WriteString(" -> " + r.Outbound)
if calcN {
builder.WriteString(" [n = " + strconv.Itoa(n) + "]")
}
return builder.String()
}

239
pkg/config_parser/walker.go Normal file
View File

@ -0,0 +1,239 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright (c) since 2022, mzz2017 (mzz@tuta.io). All rights reserved.
*/
package config_parser
import (
"fmt"
"github.com/antlr/antlr4/runtime/Go/antlr/v4"
"github.com/v2rayA/dae-config-dist/go/dae_config"
"log"
"strconv"
)
type Walker struct {
*dae_config.Basedae_configListener
parser antlr.Parser
Sections []*Section
}
func NewWalker(parser antlr.Parser) *Walker {
return &Walker{
parser: parser,
}
}
type paramParser struct {
list []*Param
}
func getValueFromLiteral(literal *dae_config.LiteralContext) string {
quote := literal.Quote_literal()
if quote == nil {
return literal.GetText()
}
text := quote.GetText()
return text[1 : len(text)-1]
}
func (p *paramParser) parseParam(ctx *dae_config.ParameterContext) *Param {
children := ctx.GetChildren()
if len(children) == 3 {
return &Param{
Key: children[0].(*antlr.TerminalNodeImpl).GetText(),
Val: getValueFromLiteral(children[2].(*dae_config.LiteralContext)),
}
} else if len(children) == 1 {
return &Param{
Key: "",
Val: getValueFromLiteral(children[0].(*dae_config.LiteralContext)),
}
}
panic("unexpected")
}
func (p *paramParser) parseNonEmptyParamList(ctx *dae_config.NonEmptyParameterListContext) {
children := ctx.GetChildren()
if len(children) == 3 {
p.list = append(p.list, p.parseParam(children[2].(*dae_config.ParameterContext)))
p.parseNonEmptyParamList(children[0].(*dae_config.NonEmptyParameterListContext))
} else if len(children) == 1 {
p.list = append(p.list, p.parseParam(children[0].(*dae_config.ParameterContext)))
}
}
func (w *Walker) parseNonEmptyParamList(list *dae_config.NonEmptyParameterListContext) []*Param {
paramParser := new(paramParser)
paramParser.parseNonEmptyParamList(list)
return paramParser.list
}
func (w *Walker) reportKeyUnsupportedError(ctx interface{}, keyName, funcName string) {
w.ReportError(ctx, ErrorType_Unsupported, fmt.Sprintf("key %v in %v()", strconv.Quote(keyName), funcName))
}
type functionVerifier func(function *Function, ctx interface{}) bool
func (w *Walker) parseFunctionPrototype(ctx *dae_config.FunctionPrototypeContext, verifier functionVerifier) *Function {
children := ctx.GetChildren()
funcName := children[0].(*antlr.TerminalNodeImpl).GetText()
paramList := children[2].(*dae_config.OptParameterListContext)
children = paramList.GetChildren()
if len(children) == 0 {
w.ReportError(ctx, ErrorType_Unsupported, "empty parameter list")
return nil
}
nonEmptyParamList := children[0].(*dae_config.NonEmptyParameterListContext)
params := w.parseNonEmptyParamList(nonEmptyParamList)
f := &Function{
Name: funcName,
Params: params,
}
// Verify function name and param keys.
if verifier != nil && !verifier(f, ctx) {
return nil
}
return f
}
func (w *Walker) ReportError(ctx interface{}, errorType ErrorType, target ...string) {
//debug.PrintStack()
bCtx := BaseContext(ctx)
tgt := strconv.Quote(bCtx.GetStart().GetText())
if len(target) != 0 {
tgt = target[0]
}
if errorType == ErrorType_NotSet {
w.parser.NotifyErrorListeners(fmt.Sprintf("%v %v.", tgt, errorType), nil, nil)
return
}
w.parser.NotifyErrorListeners(fmt.Sprintf("%v %v.", tgt, errorType), bCtx.GetStart(), nil)
}
func (w *Walker) parseDeclaration(ctx dae_config.IDeclarationContext) *Param {
children := ctx.GetChildren()
key := children[0].(*antlr.TerminalNodeImpl).GetText()
switch valueCtx := children[2].(type) {
case *dae_config.LiteralContext:
value := getValueFromLiteral(valueCtx)
return &Param{
Key: key,
Val: value,
}
case *dae_config.FunctionPrototypeExpressionContext:
andFunctions := w.parseFunctionPrototypeExpression(valueCtx, nil)
return &Param{
Key: key,
AndFunctions: andFunctions,
}
default:
w.ReportError(valueCtx, ErrorType_Unsupported)
return nil
}
}
func (w *Walker) parseFunctionPrototypeExpression(ctx dae_config.IFunctionPrototypeExpressionContext, verifier functionVerifier) (andFunctions []*Function) {
children := ctx.GetChildren()
for _, child := range children {
// And rules.
if child, ok := child.(*dae_config.FunctionPrototypeContext); ok {
function := w.parseFunctionPrototype(child, verifier)
andFunctions = append(andFunctions, function)
}
}
return andFunctions
}
func (w *Walker) parseRoutingRule(ctx dae_config.IRoutingRuleContext) *RoutingRule {
children := ctx.GetChildren()
//logrus.Debugln(ctx.GetText(), children)
left, ok := children[0].(*dae_config.RoutingRuleLeftContext)
if !ok {
w.ReportError(ctx, ErrorType_Unsupported, "not *RoutingRuleLeftContext: "+ctx.GetText())
return nil
}
outbound := children[2].(*dae_config.Bare_literalContext).GetText()
// Parse functions.
children = left.GetChildren()
functionList, ok := children[1].(*dae_config.FunctionPrototypeExpressionContext)
if !ok {
w.ReportError(ctx, ErrorType_Unsupported, "not *FunctionPrototypeExpressionContext: "+ctx.GetText())
return nil
}
andFunctions := w.parseFunctionPrototypeExpression(functionList, nil)
return &RoutingRule{
AndFunctions: andFunctions,
Outbound: outbound,
}
}
type routingRuleOrDeclarationOrLiteralOrExpressionListParser struct {
Items []*Item
Walker *Walker
}
func (p *routingRuleOrDeclarationOrLiteralOrExpressionListParser) Parse(ctx dae_config.IRoutingRuleOrDeclarationOrLiteralOrExpressionListContext) {
for _, elem := range ctx.GetChildren() {
switch elem := elem.(type) {
case dae_config.IRoutingRuleContext:
rule := p.Walker.parseRoutingRule(elem)
if rule == nil {
return
}
p.Items = append(p.Items, NewRoutingRuleItem(rule))
case dae_config.IDeclarationContext:
param := p.Walker.parseDeclaration(elem)
if param == nil {
return
}
p.Items = append(p.Items, NewParamItem(param))
case *dae_config.LiteralContext:
p.Items = append(p.Items, NewParamItem(&Param{
Key: "",
Val: getValueFromLiteral(elem),
}))
case dae_config.IExpressionContext:
section := p.Walker.parseExpression(elem)
if section == nil {
return
}
p.Items = append(p.Items, NewSectionItem(section))
case dae_config.IRoutingRuleOrDeclarationOrLiteralOrExpressionListContext:
p.Parse(elem)
default:
log.Printf("? %v", elem.(*dae_config.ExpressionContext))
p.Walker.ReportError(elem, ErrorType_Unsupported)
return
}
}
}
func (w *Walker) parseRoutingRuleOrDeclarationOrLiteralOrExpressionListContext(ctx dae_config.IRoutingRuleOrDeclarationOrLiteralOrExpressionListContext) []*Item {
parser := routingRuleOrDeclarationOrLiteralOrExpressionListParser{
Items: nil,
Walker: w,
}
parser.Parse(ctx)
return parser.Items
}
func (w *Walker) parseExpression(exp dae_config.IExpressionContext) *Section {
children := exp.GetChildren()
name := children[0].(*antlr.TerminalNodeImpl).GetText()
list := children[2].(dae_config.IRoutingRuleOrDeclarationOrLiteralOrExpressionListContext)
items := w.parseRoutingRuleOrDeclarationOrLiteralOrExpressionListContext(list)
return &Section{
Name: name,
Items: items,
}
}
func (w *Walker) EnterProgramStructureBlcok(ctx *dae_config.ProgramStructureBlcokContext) {
section := w.parseExpression(ctx.Expression())
if section == nil {
return
}
w.Sections = append(w.Sections, section)
}

View File

@ -3,11 +3,11 @@
package geodata
import (
_ "github.com/v2fly/v2ray-core/v5/common/protoext"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
_ "github.com/v2rayA/dae/pkg/geodata/protoext"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/runtime/protoimpl"
"reflect"
"sync"
)
const (

View File

@ -0,0 +1,355 @@
// Copied from https://github.com/v2fly/v2ray-core/tree/42b166760b2ba8d984e514b830fcd44e23728e43
package protoext
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
descriptorpb "google.golang.org/protobuf/types/descriptorpb"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type MessageOpt struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Type []string `protobuf:"bytes,1,rep,name=type,proto3" json:"type,omitempty"`
ShortName []string `protobuf:"bytes,2,rep,name=short_name,json=shortName,proto3" json:"short_name,omitempty"`
TransportOriginalName string `protobuf:"bytes,86001,opt,name=transport_original_name,json=transportOriginalName,proto3" json:"transport_original_name,omitempty"`
}
func (x *MessageOpt) Reset() {
*x = MessageOpt{}
if protoimpl.UnsafeEnabled {
mi := &file_common_protoext_extensions_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *MessageOpt) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*MessageOpt) ProtoMessage() {}
func (x *MessageOpt) ProtoReflect() protoreflect.Message {
mi := &file_common_protoext_extensions_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use MessageOpt.ProtoReflect.Descriptor instead.
func (*MessageOpt) Descriptor() ([]byte, []int) {
return file_common_protoext_extensions_proto_rawDescGZIP(), []int{0}
}
func (x *MessageOpt) GetType() []string {
if x != nil {
return x.Type
}
return nil
}
func (x *MessageOpt) GetShortName() []string {
if x != nil {
return x.ShortName
}
return nil
}
func (x *MessageOpt) GetTransportOriginalName() string {
if x != nil {
return x.TransportOriginalName
}
return ""
}
type FieldOpt struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
AnyWants []string `protobuf:"bytes,1,rep,name=any_wants,json=anyWants,proto3" json:"any_wants,omitempty"`
AllowedValues []string `protobuf:"bytes,2,rep,name=allowed_values,json=allowedValues,proto3" json:"allowed_values,omitempty"`
AllowedValueTypes []string `protobuf:"bytes,3,rep,name=allowed_value_types,json=allowedValueTypes,proto3" json:"allowed_value_types,omitempty"`
// convert_time_read_file_into read a file into another field, and clear this field during input parsing
ConvertTimeReadFileInto string `protobuf:"bytes,4,opt,name=convert_time_read_file_into,json=convertTimeReadFileInto,proto3" json:"convert_time_read_file_into,omitempty"`
// forbidden marks a boolean to be inaccessible to user
Forbidden bool `protobuf:"varint,5,opt,name=forbidden,proto3" json:"forbidden,omitempty"`
// convert_time_resource_loading read a file, and place its resource hash into another field
ConvertTimeResourceLoading string `protobuf:"bytes,6,opt,name=convert_time_resource_loading,json=convertTimeResourceLoading,proto3" json:"convert_time_resource_loading,omitempty"`
// convert_time_parse_ip parse a string ip address, and put its binary representation into another field
ConvertTimeParseIp string `protobuf:"bytes,7,opt,name=convert_time_parse_ip,json=convertTimeParseIp,proto3" json:"convert_time_parse_ip,omitempty"`
}
func (x *FieldOpt) Reset() {
*x = FieldOpt{}
if protoimpl.UnsafeEnabled {
mi := &file_common_protoext_extensions_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *FieldOpt) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*FieldOpt) ProtoMessage() {}
func (x *FieldOpt) ProtoReflect() protoreflect.Message {
mi := &file_common_protoext_extensions_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use FieldOpt.ProtoReflect.Descriptor instead.
func (*FieldOpt) Descriptor() ([]byte, []int) {
return file_common_protoext_extensions_proto_rawDescGZIP(), []int{1}
}
func (x *FieldOpt) GetAnyWants() []string {
if x != nil {
return x.AnyWants
}
return nil
}
func (x *FieldOpt) GetAllowedValues() []string {
if x != nil {
return x.AllowedValues
}
return nil
}
func (x *FieldOpt) GetAllowedValueTypes() []string {
if x != nil {
return x.AllowedValueTypes
}
return nil
}
func (x *FieldOpt) GetConvertTimeReadFileInto() string {
if x != nil {
return x.ConvertTimeReadFileInto
}
return ""
}
func (x *FieldOpt) GetForbidden() bool {
if x != nil {
return x.Forbidden
}
return false
}
func (x *FieldOpt) GetConvertTimeResourceLoading() string {
if x != nil {
return x.ConvertTimeResourceLoading
}
return ""
}
func (x *FieldOpt) GetConvertTimeParseIp() string {
if x != nil {
return x.ConvertTimeParseIp
}
return ""
}
var file_common_protoext_extensions_proto_extTypes = []protoimpl.ExtensionInfo{
{
ExtendedType: (*descriptorpb.MessageOptions)(nil),
ExtensionType: (*MessageOpt)(nil),
Field: 50000,
Name: "v2ray.core.common.protoext.message_opt",
Tag: "bytes,50000,opt,name=message_opt",
Filename: "common/protoext/extensions.proto",
},
{
ExtendedType: (*descriptorpb.FieldOptions)(nil),
ExtensionType: (*FieldOpt)(nil),
Field: 50000,
Name: "v2ray.core.common.protoext.field_opt",
Tag: "bytes,50000,opt,name=field_opt",
Filename: "common/protoext/extensions.proto",
},
}
// Extension fields to descriptorpb.MessageOptions.
var (
// optional v2ray.core.common.protoext.MessageOpt message_opt = 50000;
E_MessageOpt = &file_common_protoext_extensions_proto_extTypes[0]
)
// Extension fields to descriptorpb.FieldOptions.
var (
// optional v2ray.core.common.protoext.FieldOpt field_opt = 50000;
E_FieldOpt = &file_common_protoext_extensions_proto_extTypes[1]
)
var File_common_protoext_extensions_proto protoreflect.FileDescriptor
var file_common_protoext_extensions_proto_rawDesc = []byte{
0x0a, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x78,
0x74, 0x2f, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x12, 0x1a, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63,
0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x78, 0x74, 0x1a, 0x20,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f,
0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x22, 0x79, 0x0a, 0x0a, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x12, 0x12,
0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79,
0x70, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x5f, 0x6e, 0x61, 0x6d, 0x65,
0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x73, 0x68, 0x6f, 0x72, 0x74, 0x4e, 0x61, 0x6d,
0x65, 0x12, 0x38, 0x0a, 0x17, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x6f,
0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0xf1, 0x9f, 0x05,
0x20, 0x01, 0x28, 0x09, 0x52, 0x15, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x4f,
0x72, 0x69, 0x67, 0x69, 0x6e, 0x61, 0x6c, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0xd0, 0x02, 0x0a, 0x08,
0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x61, 0x6e, 0x79, 0x5f,
0x77, 0x61, 0x6e, 0x74, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x08, 0x61, 0x6e, 0x79,
0x57, 0x61, 0x6e, 0x74, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64,
0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0d, 0x61,
0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x12, 0x2e, 0x0a, 0x13,
0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x65, 0x64, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x5f, 0x74, 0x79,
0x70, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x09, 0x52, 0x11, 0x61, 0x6c, 0x6c, 0x6f, 0x77,
0x65, 0x64, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x3c, 0x0a, 0x1b,
0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x72, 0x65, 0x61,
0x64, 0x5f, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x69, 0x6e, 0x74, 0x6f, 0x18, 0x04, 0x20, 0x01, 0x28,
0x09, 0x52, 0x17, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x52, 0x65,
0x61, 0x64, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x74, 0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x6f,
0x72, 0x62, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x66,
0x6f, 0x72, 0x62, 0x69, 0x64, 0x64, 0x65, 0x6e, 0x12, 0x41, 0x0a, 0x1d, 0x63, 0x6f, 0x6e, 0x76,
0x65, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63,
0x65, 0x5f, 0x6c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52,
0x1a, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x6f,
0x75, 0x72, 0x63, 0x65, 0x4c, 0x6f, 0x61, 0x64, 0x69, 0x6e, 0x67, 0x12, 0x31, 0x0a, 0x15, 0x63,
0x6f, 0x6e, 0x76, 0x65, 0x72, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x5f, 0x70, 0x61, 0x72, 0x73,
0x65, 0x5f, 0x69, 0x70, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x12, 0x63, 0x6f, 0x6e, 0x76,
0x65, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x50, 0x61, 0x72, 0x73, 0x65, 0x49, 0x70, 0x3a, 0x6a,
0x0a, 0x0b, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x5f, 0x6f, 0x70, 0x74, 0x12, 0x1f, 0x2e,
0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e,
0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0,
0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63,
0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x65, 0x78, 0x74, 0x2e, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x52, 0x0a,
0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x4f, 0x70, 0x74, 0x3a, 0x62, 0x0a, 0x09, 0x66, 0x69,
0x65, 0x6c, 0x64, 0x5f, 0x6f, 0x70, 0x74, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f,
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0xd0, 0x86, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x24,
0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x6d,
0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x78, 0x74, 0x2e, 0x46, 0x69, 0x65, 0x6c,
0x64, 0x4f, 0x70, 0x74, 0x52, 0x08, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x42, 0x6f,
0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65,
0x2e, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65, 0x78, 0x74,
0x50, 0x01, 0x5a, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x76,
0x32, 0x66, 0x6c, 0x79, 0x2f, 0x76, 0x32, 0x72, 0x61, 0x79, 0x2d, 0x63, 0x6f, 0x72, 0x65, 0x2f,
0x76, 0x35, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x65,
0x78, 0x74, 0xaa, 0x02, 0x1a, 0x56, 0x32, 0x52, 0x61, 0x79, 0x2e, 0x43, 0x6f, 0x72, 0x65, 0x2e,
0x43, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x45, 0x78, 0x74, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_common_protoext_extensions_proto_rawDescOnce sync.Once
file_common_protoext_extensions_proto_rawDescData = file_common_protoext_extensions_proto_rawDesc
)
func file_common_protoext_extensions_proto_rawDescGZIP() []byte {
file_common_protoext_extensions_proto_rawDescOnce.Do(func() {
file_common_protoext_extensions_proto_rawDescData = protoimpl.X.CompressGZIP(file_common_protoext_extensions_proto_rawDescData)
})
return file_common_protoext_extensions_proto_rawDescData
}
var file_common_protoext_extensions_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_common_protoext_extensions_proto_goTypes = []interface{}{
(*MessageOpt)(nil), // 0: v2ray.core.common.protoext.MessageOpt
(*FieldOpt)(nil), // 1: v2ray.core.common.protoext.FieldOpt
(*descriptorpb.MessageOptions)(nil), // 2: google.protobuf.MessageOptions
(*descriptorpb.FieldOptions)(nil), // 3: google.protobuf.FieldOptions
}
var file_common_protoext_extensions_proto_depIdxs = []int32{
2, // 0: v2ray.core.common.protoext.message_opt:extendee -> google.protobuf.MessageOptions
3, // 1: v2ray.core.common.protoext.field_opt:extendee -> google.protobuf.FieldOptions
0, // 2: v2ray.core.common.protoext.message_opt:type_name -> v2ray.core.common.protoext.MessageOpt
1, // 3: v2ray.core.common.protoext.field_opt:type_name -> v2ray.core.common.protoext.FieldOpt
4, // [4:4] is the sub-list for method output_type
4, // [4:4] is the sub-list for method input_type
2, // [2:4] is the sub-list for extension type_name
0, // [0:2] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_common_protoext_extensions_proto_init() }
func file_common_protoext_extensions_proto_init() {
if File_common_protoext_extensions_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_common_protoext_extensions_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*MessageOpt); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_common_protoext_extensions_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*FieldOpt); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_common_protoext_extensions_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 2,
NumServices: 0,
},
GoTypes: file_common_protoext_extensions_proto_goTypes,
DependencyIndexes: file_common_protoext_extensions_proto_depIdxs,
MessageInfos: file_common_protoext_extensions_proto_msgTypes,
ExtensionInfos: file_common_protoext_extensions_proto_extTypes,
}.Build()
File_common_protoext_extensions_proto = out.File
file_common_protoext_extensions_proto_rawDesc = nil
file_common_protoext_extensions_proto_goTypes = nil
file_common_protoext_extensions_proto_depIdxs = nil
}

View File

@ -19,6 +19,7 @@ func NewLogger(verbose int) *logrus.Logger {
default:
level = logrus.TraceLevel
}
log.SetLevel(level)
return log