mirror of https://github.com/XTLS/Xray-core
Reuse Client
parent
9bd719aa1a
commit
53cf8ca599
|
@ -88,7 +88,10 @@ type echConfigRecord struct {
|
||||||
expire time.Time
|
expire time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
var GlobalECHConfigCache = utils.NewTypedSyncMap[string, *ECHConfigCache]()
|
var (
|
||||||
|
GlobalECHConfigCache = utils.NewTypedSyncMap[string, *ECHConfigCache]()
|
||||||
|
clientForECHDOH = utils.NewTypedSyncMap[string, *http.Client]()
|
||||||
|
)
|
||||||
|
|
||||||
// Update updates the ECH config for given domain and server.
|
// Update updates the ECH config for given domain and server.
|
||||||
// this method is concurrent safe, only one update request will be sent, others get the cache.
|
// this method is concurrent safe, only one update request will be sent, others get the cache.
|
||||||
|
@ -164,6 +167,8 @@ func dnsQuery(server string, domain string) ([]byte, uint32, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, 0, err
|
return []byte{}, 0, err
|
||||||
}
|
}
|
||||||
|
var client *http.Client
|
||||||
|
if client, _ = clientForECHDOH.Load(server); client == nil {
|
||||||
// All traffic sent by core should via xray's internet.DialSystem
|
// All traffic sent by core should via xray's internet.DialSystem
|
||||||
// This involves the behavior of some Android VPN GUI clients
|
// This involves the behavior of some Android VPN GUI clients
|
||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
|
@ -181,10 +186,12 @@ func dnsQuery(server string, domain string) ([]byte, uint32, error) {
|
||||||
return conn, nil
|
return conn, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
client := &http.Client{
|
c := &http.Client{
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
Transport: tr,
|
Transport: tr,
|
||||||
}
|
}
|
||||||
|
client, _ = clientForECHDOH.LoadOrStore(server, c)
|
||||||
|
}
|
||||||
req, err := http.NewRequest("POST", server, bytes.NewReader(msg))
|
req, err := http.NewRequest("POST", server, bytes.NewReader(msg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, 0, err
|
return []byte{}, 0, err
|
||||||
|
|
Loading…
Reference in New Issue