github.com/moqsien/xraycore@v1.8.5/infra/conf/dns_proxy.go (about)

     1  package conf
     2  
     3  import (
     4  	"github.com/moqsien/xraycore/common/net"
     5  	"github.com/moqsien/xraycore/proxy/dns"
     6  	"google.golang.org/protobuf/proto"
     7  )
     8  
     9  type DNSOutboundConfig struct {
    10  	Network    Network  `json:"network"`
    11  	Address    *Address `json:"address"`
    12  	Port       uint16   `json:"port"`
    13  	UserLevel  uint32   `json:"userLevel"`
    14  	NonIPQuery string   `json:"nonIPQuery"`
    15  }
    16  
    17  func (c *DNSOutboundConfig) Build() (proto.Message, error) {
    18  	config := &dns.Config{
    19  		Server: &net.Endpoint{
    20  			Network: c.Network.Build(),
    21  			Port:    uint32(c.Port),
    22  		},
    23  		UserLevel: c.UserLevel,
    24  	}
    25  	if c.Address != nil {
    26  		config.Server.Address = c.Address.Build()
    27  	}
    28  	switch c.NonIPQuery {
    29  	case "":
    30  		c.NonIPQuery = "drop"
    31  	case "drop", "skip":
    32  	default:
    33  		return nil, newError(`unknown "nonIPQuery": `, c.NonIPQuery)
    34  	}
    35  	config.Non_IPQuery = c.NonIPQuery
    36  	return config, nil
    37  }