github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/net/dns/dot.go (about)

     1  package dns
     2  
     3  import (
     4  	"crypto/tls"
     5  
     6  	"github.com/Asutorufa/yuhaiin/pkg/net/netapi"
     7  	"github.com/Asutorufa/yuhaiin/pkg/protos/config/dns"
     8  	"github.com/Asutorufa/yuhaiin/pkg/protos/statistic"
     9  )
    10  
    11  func init() {
    12  	Register(dns.Type_dot, NewDoT)
    13  }
    14  
    15  func NewDoT(config Config) (netapi.Resolver, error) {
    16  	tlsConfig := &tls.Config{}
    17  	d, err := newTCP(config, "853", tlsConfig)
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  	if config.Servername == "" {
    22  		addr, err := ParseAddr(statistic.Type_tcp, config.Host, "853")
    23  		if err != nil {
    24  			return nil, err
    25  		}
    26  		config.Servername = addr.Hostname()
    27  	}
    28  	tlsConfig.ServerName = config.Servername
    29  	return d, nil
    30  }