mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-02-16 06:23:14 +03:00
Add new doh server format
This commit is contained in:
parent
b7529723c6
commit
8322c1919c
@ -6,6 +6,7 @@ import (
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -19,13 +20,28 @@ func ApplyECH(c *Config, config *tls.Config) error {
|
||||
var ECHConfig []byte
|
||||
var err error
|
||||
|
||||
nameToQuery := c.ServerName
|
||||
var DOHServer string
|
||||
|
||||
parts := strings.Split(c.Ech_DOHserver, "+")
|
||||
if len(parts) == 2 {
|
||||
// parse ECH DOH server in format of "example.com+https://1.1.1.1/dns-query"
|
||||
nameToQuery = parts[0]
|
||||
DOHServer = parts[1]
|
||||
} else if len(parts) == 1 {
|
||||
// normal format
|
||||
DOHServer = parts[0]
|
||||
} else {
|
||||
return errors.New("Invalid ECH DOH server format: ", c.Ech_DOHserver)
|
||||
}
|
||||
|
||||
if len(c.EchConfig) > 0 {
|
||||
ECHConfig = c.EchConfig
|
||||
} else { // ECH config > DOH lookup
|
||||
if config.ServerName == "" {
|
||||
return errors.New("Using DOH for ECH needs serverName")
|
||||
if nameToQuery == "" {
|
||||
return errors.New("Using DOH for ECH needs serverName or use dohServer format example.com+https://1.1.1.1/dns-query")
|
||||
}
|
||||
ECHConfig, err = QueryRecord(c.ServerName, c.Ech_DOHserver)
|
||||
ECHConfig, err = QueryRecord(nameToQuery, DOHServer)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -41,14 +57,13 @@ type record struct {
|
||||
}
|
||||
|
||||
var (
|
||||
dnsCache = make(map[string]record)
|
||||
dnsCache = make(map[string]record)
|
||||
// global Lock? I'm not sure if I need finer grained locks.
|
||||
// If we do this, we will need to nest another layer of struct
|
||||
dnsCacheLock sync.RWMutex
|
||||
updating sync.Mutex
|
||||
)
|
||||
|
||||
|
||||
// QueryRecord returns the ECH config for given domain.
|
||||
// If the record is not in cache or expired, it will query the DOH server and update the cache.
|
||||
func QueryRecord(domain string, server string) ([]byte, error) {
|
||||
@ -95,7 +110,6 @@ func QueryRecord(domain string, server string) ([]byte, error) {
|
||||
return echConfig, nil
|
||||
}
|
||||
|
||||
|
||||
// dohQuery is the real func for sending type65 query for given domain to given DOH server.
|
||||
// return ECH config, TTL and error
|
||||
func dohQuery(server string, domain string) ([]byte, uint32, error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user